In a 'Robot.ExecuteMarketOrder' TP/SL not working
In a 'Robot.ExecuteMarketOrder' TP/SL not working
23 Jul 2023, 10:34
}
protected override void OnBar()
{
// Calculate Take Profit and Stop Loss levels in pips
double takeProfit = Symbol.PipSize * TakeProfitPips;
double stopLoss = Symbol.PipSize * StopLossPips;
// 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
if (Positions.Count == 0)
{
// Execute Buy order if buy condition is met
if (buyCondition)
ExecuteMarketOrder(TradeType.Buy, Symbol, Symbol.VolumeInUnitsMin, "Buy", null, stopLoss, takeProfit);
// Execute Sell order if sell condition is met
if (sellCondition)
ExecuteMarketOrder(TradeType.Sell, Symbol, Symbol.VolumeInUnitsMin, "Sell", null, stopLoss, takeProfit);
}
}
}
}
herein, a ‘Robot.ExecuteMarketOrder’ TP/SL doesn't work properly, maybe because it's obsolete but however I fix it, I get the same issue even once it's not obsolete anymore. How would you guys fix this?
Replies
loziniko6
24 Jul 2023, 17:15
RE: In a 'Robot.ExecuteMarketOrder' TP/SL not working
PanagiotisChar said:
Hi there,
Stop loss and take profit should be set in pips. No need to multiply it by Symbol.PipSize
Need help? Join us on Telegram
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
PanagiotisChar
24 Jul 2023, 06:12
Hi there,
Stop loss and take profit should be set in pips. No need to multiply it by Symbol.PipSize
Aieden Technologies
Need help? Join us on Telegram
@PanagiotisChar