Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,38 @@
# cTrader Algo API Samples
cBot / Indicator Samples of cTrader Algo API
using cAlgo.API;

namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class FirstTickBuyBot : Robot
{
private bool _tradeOpened = false;

[Parameter("Volume (Lots)", DefaultValue = 0.01)]
public double VolumeInLots { get; set; }

[Parameter("Take Profit %", DefaultValue = 0.10)]
public double TakeProfitPercent { get; set; }

[Parameter("Stop Loss %", DefaultValue = 0.05)]
public double StopLossPercent { get; set; }

protected override void OnTick()
{
// Only run once (on the first tick)
if (_tradeOpened)
return;

double entryPrice = Symbol.Bid;
long volumeInUnits = Symbol.QuantityToVolume(VolumeInLots);

// Calculate TP and SL in price terms
double tpPrice = entryPrice + (entryPrice * TakeProfitPercent / 100.0);
double slPrice = entryPrice - (entryPrice * StopLossPercent / 100.0);

// Place Buy Order with TP and SL
ExecuteMarketOrder(TradeType.Buy, SymbolName, volumeInUnits, "FirstTickBuy", slPrice, tpPrice);

_tradeOpened = true;
}
}
}