// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
//20 bar restriction saying a new trade cant be entered into until x bars have passed since a long or short position was exited. The no of bars is defined as the number in the quote "BarCount > ____".
ONCE BarCount = 0
ONCE TradeON = 1 //1=trading allowed 0=trading disbaled
IF LongOnMarket OR ShortOnMarket AND Not LongOnMarket[1] AND Not ShortOnMarket[1] THEN
TradeON = 0 //disable trading
BarCount = 0 //reset counter
ENDIF
IF Not LongOnMarket And Not ShortOnMarket THEN //Increase counter when not on market
BarCount = BarCount + 1
ENDIF
IF BarCount > 1 THEN
TradeON = 1
ENDIF
// Conditions to enter long positions
c1 = (open > close)
IF c1 AND TradeON THEN
BUY 1 SHARES AT MARKET
ENDIF
// Conditions to exit long positions
c2 = (open < close)
IF c2 THEN
SELL AT MARKET
ENDIF
// Conditions to enter short positions
c3 = (open < close)
IF c3 AND TradeOn THEN
SELLSHORT 1 SHARES AT MARKET
ENDIF
// Conditions to exit short positions
c4 = (open > close)
IF c4 THEN
EXITSHORT AT MARKET
ENDIF