Take profit and stop loss not being placed when back testing
Take profit and stop loss not being placed when back testing
04 Mar 2024, 09:27
private void PlaceTrade(TradeType tradeType)
{
if (Positions.Find("QuickCandleFormationBot", SymbolName) != null)
{
Print("An open position already exists for this symbol. No new position will be opened.");
return;
}
var volumeInUnits = Symbol.QuantityToVolumeInUnits(VolumeInLots);
var entryPrice = tradeType == TradeType.Buy ? Symbol.Ask : Symbol.Bid; // Use Ask for Buy, Bid for Sell
var stopLoss = tradeType == TradeType.Buy ? entryPrice - StopLossPips * Symbol.PipSize : entryPrice + StopLossPips * Symbol.PipSize;
var takeProfit = tradeType == TradeType.Buy ? entryPrice + TakeProfitPips * Symbol.PipSize : entryPrice - TakeProfitPips * Symbol.PipSize;
// Debug print statement to log TP, SL, and entry price values
Print($"Placing {tradeType} order. Entry: {entryPrice}, SL: {stopLoss}, TP: {takeProfit}");
ExecuteMarketOrder(tradeType, SymbolName, volumeInUnits, "QuickCandleFormationBot", stopLoss, takeProfit);
}
Any help, prints to log saying placed
Replies
parkermark446
05 Mar 2024, 09:40
( Updated at: 05 Mar 2024, 19:02 )
stop loos and take profit not being placed correctly
}
@parkermark446
PanagiotisCharalampous
05 Mar 2024, 13:33
As far as I can see you are using absolute prices as SL and TP. You should use pips instead.
@PanagiotisCharalampous
parkermark446
05 Mar 2024, 18:58
RE: Take profit and stop loss not being placed when back testing
PanagiotisCharalampous said:
As far as I can see you are using absolute prices as SL and TP. You should use pips instead.
Could you little more specific please
@parkermark446
PanagiotisCharalampous
06 Mar 2024, 06:47
RE: RE: Take profit and stop loss not being placed when back testing
parkermark446 said:
PanagiotisCharalampous said:
As far as I can see you are using absolute prices as SL and TP. You should use pips instead.
Could you little more specific please
The stopLoss and takeProfit parameters in the method below should be in pips, not in actual price
ExecuteMarketOrder(tradeType, SymbolName, volumeInUnits, "QuickCandleFormationBot", stopLoss, takeProfit);
@PanagiotisCharalampous
PanagiotisCharalampous
04 Mar 2024, 14:13
Hi there,
Better share the complete cBot code, backtesting parameters and the logs you mention so that we can reproduce and advise accordingly.
Best regards,
Panagiotis
@PanagiotisCharalampous