"Long (max loss)" indication in backtest

Hi

I've been looking into this for quite a while now and can't see where I'm going wrong with my code/logic.

I have a simple backtest whereby I want to enter a trade the day after the Long signal (at the open), and exit the next day (at the open also). It appears that the error/message "Long (max loss)" shows when there are 'clusters' of buys one day after the other. E.g. I get a buy signal on 1st July (so trade correctly enters at the open on the 2nd July, i.e. buy delay =1, then exits on 3rd July (sell delay=0).

I then get a buy signal on 2nd July, for an entry on the 3rd July. I exit on the 4th July. However, on this 2nd trade (in a row), I get the message "Long (max loss)". The result which causes an issue in my backtest is that a number of trades subsequent to this appear not to trigger properly - i.e. they fail to record a profit or a loss.

The problem is recurring in that every time there's a cluster of buy signals on consecutive days, this is what happens for multiple trades after the occurrence.

Any guidance to help me along would be greatly appreciated - I hope I've been clear in my description of the problem.

I've attached my formula for reference:

_SECTION_BEGIN("2 Period ROC"); // My first indicator

TwoPeriodROC = Ref(C,-1) + (C - Ref(C,-2));

Plot(TwoPeriodROC , "2 Period ROC", colorTurquoise , styleLine); // 2 Period ROC

// Trading Logic

BuyCondition = Close > TwoPeriodROC AND Close < Open;

Buy = BuyCondition;
Sell = BarsSince (BuyCondition > 0);

PositionSize = 10000;

// Plot Buy and Sell Signal Arrow //
PlotShapes(IIf(Buy, shapeSquare, shapeNone), colorGreen, 0, L, Offset=-20);
PlotShapes(IIf(Buy, shapeSquare, shapeNone), colorLime, 0, L, Offset=-30);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone), colorWhite, 0, L, Offset=-25);
PlotShapes(IIf(Sell, shapeSquare, shapeNone), colorRed, 0, H, Offset=20);
PlotShapes(IIf(Sell, shapeSquare, shapeNone), colorOrange, 0, H, Offset=30);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone), colorWhite, 0, H, Offset=-25);

_SECTION_END();

I believe I've solved my own problem....I found a related topic on the forum.

I've used the following code for my sell:

SetOption("HoldMinBars",1);
Sell = 1;

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.