// Check if there are no active positions in the time of the entry if (Positions.Count == 0) { // Calculate Take Profit and Stop Loss levels in pips (supposedly) double takeProfit = TakeProfitPips; double stopLoss = StopLossPips;
// Execute Buy order if the buy condition is met if (buyCondition) ExecuteMarketOrder(TradeType.Buy, Symbol, Symbol.VolumeInUnitsMin, "Buy", null, stopLoss, takeProfit);
// Execute Sell order if the sell condition is met if (sellCondition) ExecuteMarketOrder(TradeType.Sell, Symbol, Symbol.VolumeInUnitsMin, "Sell", null, stopLoss, takeProfit); } } } }
loziniko6
24 Jul 2023, 17:15
RE: In a 'Robot.ExecuteMarketOrder' TP/SL not working
PanagiotisChar said:
Thanks for your response. I removed that multiplier but it still doesn't work.
}
protected override void OnBar()
{
// Entry conditions for Buy and Sell orders
bool buyCondition = MarketSeries.Close.Last(1) > _ma.Result.Last(1) && _rsi.Result.Last(1) > RSILevel;
bool sellCondition = MarketSeries.Close.Last(1) < _ma.Result.Last(1) && _rsi.Result.Last(1) < RSILevel;
// Check if there are no active positions in the time of the entry
if (Positions.Count == 0)
{
// Calculate Take Profit and Stop Loss levels in pips (supposedly)
double takeProfit = TakeProfitPips;
double stopLoss = StopLossPips;
// Execute Buy order if the buy condition is met
if (buyCondition)
ExecuteMarketOrder(TradeType.Buy, Symbol, Symbol.VolumeInUnitsMin, "Buy", null, stopLoss, takeProfit);
// Execute Sell order if the sell condition is met
if (sellCondition)
ExecuteMarketOrder(TradeType.Sell, Symbol, Symbol.VolumeInUnitsMin, "Sell", null, stopLoss, takeProfit);
}
}
}
}
@loziniko6