Here's the problematic line of code: isBreakingHigh = (High[1] >= MAX(High, 55)[0]);
I expect this condition to mean that a trade will only be placed if the high of the penultimate bar is the biggest bar of the last 55 candles. As you can see from the first attached screenshot, this is clearly not the case. I chose 55 because the trade does not enter at 56 for some reason.
In addition, I included different print statements that should trigger based on whether or not the entry conditions were triggered. As you can see in the second screenshot, the print statement associated with entry conditions being met was not printed.
I also noticed that the entry was not made on the candle or wick (see third screenshot. Is this due to the slippage of 1 that I added?
Here's the relevant portion of code:
for (int i = table.Rows.Count - 1; i >= 0; i--)
{
Print($"Checking row {i}: Supply/Demand = {table.Rows[i]["Supply/Demand"]}, RangeHigh = {table.Rows[i]["RangeHigh"]}, RangeLow = {table.Rows[i]["RangeLow"]}, timeAdded = {table.Rows[i]["timeAdded"]}, barIndex = {table.Rows[i]["barIndex"]}, Current Time = {Time[0]}");
region Short Trades
bool isSupply = table.Rows[i]["Supply/Demand"] == "Supply";
bool isAboveRangeLow = (High[0] > Convert.ToDouble(table.Rows[i]["rangeLow"]) || High[1] > Convert.ToDouble(table.Rows[i]["rangeLow"]));
bool isCloseValid = Close[0] < Low[1];
bool isBreakingHigh = (High[1] >= MAX(High, 55)[0]);
if (isSupply && isAboveRangeLow && isCloseValid && isBreakingHigh)
{
Print("All conditions met, trade should enter here");
double stopLossPriceShort = MAX(High, 5)[0] + ATR(14)[0] + StopLossMultiplier * (Math.Abs(Close[0] - MAX(High, 5)[0]));
double riskAmountShort = Math.Abs(Close[0] - stopLossPriceShort);
double takeProfitAmountShort = TakeProfitMultiplier * riskAmountShort;
double takeProfitPriceShort = Close[0] - takeProfitAmountShort;
Print("stopLossPriceShort = " + stopLossPriceShort);
Print("Math.Abs(Close[0] - MAX(High, 5)[0] = " + Math.Abs(Close[0] - MAX(High, 5)[0]));
Print("Close[0] = " + Close[0]);
Print("MAX(High, 55)[0] = " + MAX(High, 55)[0]);
Print("Low[1] = " + Low[1]);
Print("High[1] = " + High[1]);
Print("riskAmountShort = " + riskAmountShort);
//Set SL and TP
SetStopLoss(CalculationMode.Price, stopLossPriceShort);
SetProfitTarget(CalculationMode.Price, takeProfitPriceShort);
//Want to risk 200 / trade
int entryAmountShort = Convert.ToInt32(Math.Round((200/2)/riskAmountShort));
//Enter Trade
EnterShort(entryAmountShort, "FVG Short " + entryAmountShort);
Print("TradeEntered");
}
else
{
Print("Not all conditions met, trade should not enter");
}

Comment