N Bar Stop Price

Hello All! Happy new year to everyone!

I am using the following code to assess exits of my TS:

nBar = Optimize( "nBar",  1, 1, 10, 1 );
ApplyStop( stopTypeNBar, stopModeBars, nBar );

For my Short trades, exits are being computed at the Low of nBar = 1, and for Longs, at the High of nBar = 1.

Would there be a way to set Exit Price at Open or Close of nBar = 1 using ApplyStop Function?

I have also tried the BarSince alternative. It works nicely, but them I am stuck at another point. In this case, I would like the system to make a new entry only after the system´s “natural” exit is hit, even if a particular trade was previously closed with a nBar Stop.

myRsi = RSI(2);

systemEntry = Cross (30, myRsi);
Buy = systemEntry;
BuyPrice = C;

systemExit = Cross (myRsi, 70);
nBar = BarsSince(Buy);
nBarTh = Optimize( "nBarTh",  1, 1, 10, 1 );
nBarExit = nBar == nBarTh;
Sell = systemExit OR nBarExit;
SellPrice = C;

In this case, I would like to make a new entry only after systemExit, even if a particular trade was previously closed with nBarExit.

Any input is well appreciated. Many Thanks!

Fava

You ever figure out how to set an exit price on nbar stops? I'm having the same problem.

You BackTest Mode isn't clear but this option is available with a limitation to Regular BackTest mode.

ExitAtStop = 0 uses SellPrice/CoverPrice variables in backtestRegular mode only, in other modes it uses trade prices from the Settings dialog (not overridable via SellPrice/CoverPrice)

from here https://www.amibroker.com/guide/afl/applystop.html

1 Like