Backtest Problem

Hello Everyone.

The following afl has only bar stop and stop profit (No other sell or cover condition):

SetTradeDelays(1, 0, 1, 0);
SetPositionSize(1, spsShares);

NewYear = Year() != Ref(Year(), -1);
NewMonth = Month() != Ref(Month(), -1);

MH = Ref(HHV(H, 20), -1);
ML = Ref(LLV(L, 20), -1);

Buy = C > MH AND Ref(C, -1) <= MH;
Sell = 0;
Short = C < ML AND Ref(C, -1) >= ML;
Cover = 0;

BuyPrice = O;
ShortPrice = O;

ApplyStop(stopTypeProfit, stopModePercent, 3);
ApplyStop(stopTypeNBar, stopModeBars, 10);

The column "Trade" in the backtest result should be "Long (n-bar)","Long (profit)", "Short (n-bar)","Short (profit)". But I found that there are some "Long" or "Short" in column Trade. Is it the coding problem? Thank you!

This is so because you have “Reverse entry signal causes exit” option set in the Settings.

1 Like

It looks okay now. Thanks! :wink:

2 posts were split to a new topic: Endless loop detection