Shorts exiting longs

Hi All

Being new to putting a long and short systems in the same code I have quite a basic question.

Put quite simply, my short code is exiting open long trades before my applystop for 255 bars (prematurely) when the shorting criteria is satisfied with existing open long trades.

Is there a way to leave the long open as well as opening a short trade for the same stock which will also be open for 255 bars?

I am using the All Ordinaries from the ASX using norgate’s NDU data.

Thanks

Either uncheck "Reverse entry signal forces exit" in backtest settings.
723

Or add SetOption at the top of the code (SetOptions override backtest settings).

SetOption("ReverseSignalForcesExit", False );

period = 20; 
m = EMA( Close, period ); 
Buy = Cross( Close, m );
Sell = 0;
Short = Cross( m, Close );
Cover = 0;

bars = 10; // exit after 10 bars
ApplyStop( stopTypeNBar, stopModeBars, bars, True );

If you want Long Short open at same time then see SetBackTestMode backtestRegularRawMulti

SetOption("ReverseSignalForcesExit", False );
SetBacktestMode(backtestRegularRawMulti);

SetPositionSize( 1, spsShares );

period = 20; 
m = EMA( Close, period ); 
Buy = Cross( Close, m );
Sell = 0;
Short = Cross( m, Close );
Cover = 0;

bars = 10; // exit after 10 bars
ApplyStop( stopTypeNBar, stopModeBars, bars, True );

908

2 Likes