Smaller stop loss than expected
Smaller stop loss than expected
04 Mar 2024, 17:17
Hello, I have a problem: my bot is setting smaller stop losses than expected. For example, the stop loss should be 12 pips below the close of a candle, but the bot sets it at 3.4 pips below. I have no idea what the problem is, but I imagine it has to do with when to use the addition (+) and subtraction (-) in the calculation of a stop loss.
[Parameter("Initial Stop Loss", DefaultValue = 10)]
public double SL { get; set; }
protected override void OnBarClosed()
{
MarketSeries series = MarketData.GetSeries(TimeFrame);
// Uzyskaj dane o ostatniej świeczce
double open = series.Open.LastValue;
double close = series.Close.LastValue;
double low = series.Low.LastValue;
double bodySize = Math.Abs(open - close);
// Sprawdź kolor świeczki
bool isBullish = close > open;
// Ustaw stop loss zgodnie z warunkiem
double stopLoss;
double candleBodySize = Math.Abs(MarketSeries.Close[index] - MarketSeries.Open[index]);
if (isBullish)
{
if (bodySize < 10 * Symbol.PipSize)
{
stopLoss = close - SL * Symbol.PipSize;
}
else
{
stopLoss = open - SL * Symbol.PipSize;
}
}
else
{
if (low - close <= 10 * Symbol.PipSize)
{
stopLoss = close + SL * Symbol.PipSize;
}
else
{
stopLoss = low - 10 * Symbol.PipSize + SL * Symbol.PipSize;
}
}
// Execute market order only when the conditions are met
ExecuteMarketOrder(TradeType.Buy, Symbol, InitialVolume, "Frann", SL, TP);
isAlreadyInTrade = true;
}
firemyst
06 Mar 2024, 09:58 ( Updated at: 06 Mar 2024, 14:00 )
Of course it's doing that. That's exactly what you told it to do.
Look at your logic. For starters:
@firemyst