//-------------------------------------------------------------------------
// Main code : Mov&RSI
//-------------------------------------------------------------------------
DEFPARAM CumulateOrders = false
ShortRSI = RSI[3](close)
LongRSI = RSI[25](close) //1 month RSI
MA = Average[22,0](close) //1 month moving average of close
Slope = MA/MA[1]-1 //Slope of 1 month moving average
LongEntry = LongEntry AND ShortRSI < 15 //Buy when RSI2 below 15
LongEntry = LongEntry AND LongRSI > 50 //Filter for long RSI above 50
LongEntry = LongEntry AND Slope > 0 //Filter for positive slope of MovAvg
LongExit = ShortRSI > 65 //Exit position when short RSI above 65
// Conditions to enter long positions
IF LongEntry THEN
BUY AT MARKET
ENDIF
// Conditions to exit long positions
IF LongExit THEN
SELL AT MARKET
ENDIF
ShortEntry = ShortEntry AND ShortRSI > 85 //Sell when RSI2 above 85
ShortEntry = ShortEntry AND LongRSI < 50 //Filter for long RSI under 50
ShortEntry = ShortEntry AND Slope < 0 //Filter for negative slope of MovAvg
ShortExit = ShortRSI < 35 //Exit position when short RSI under 35
// Conditions to enter short positions
IF ShortEntry THEN
SELL AT MARKET
ENDIF
// Conditions to exit short positions
IF ShortExit THEN
BUY AT MARKET
ENDIF