Hello i need some help for modify existing algo made by Wilko.
Curent algo take only Long postion and i want modify for taking both.
Original code (only buy ):
ShortRSI = RSI[2](close)
LongRSI = RSI[30](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
MaxPos = 1 //Set to tolerated maximum position
LongEntry = CountOfLongShares < MaxPos //Buy until MaxPos reached
LongEntry = LongEntry AND ShortRSI < 15 //Buy when RSI2 below 15
LongEntry = LongEntry AND LongRSI > 50 //Filter for 1month RSI above 50
LongEntry = LongEntry AND Slope > 0 //Filter for positive slope of MA22
LongExit = LongOnMarket
LongExit = LongExit AND ShortRSI > 60 //Exit position when RSI2 above 60
// Conditions to enter long positions
IF LongEntry THEN
BUY 2 CONTRACTS AT MARKET
ENDIF
// Conditions to exit long positions
IF LongExit THEN
SELL AT MARKET
ENDIF
My (bad )modification for short :
ShortRSI = RSI[2](close)
LongRSI = RSI[30](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
MaxPos = 2 //Set to tolerated maximum position
ShortEntry = CountOfShortShares < MaxPos //Buy until MaxPos reached
ShortEntry = ShortEntry AND ShortRSI > 60 //Short when RSI2 above 60
ShortEntry = ShortEntry AND LongRSI < 50 //Filter for 1month RSI below 50
ShortEntry = ShortEntry AND Slope > 0 //Filter for positive slope of MA22
ShortExit = ShortOnMarket
ShortExit = ShortExit AND ShortRSI < 15 //Exit position when RSI2 below 15
// Conditions to enter short positions
IF ShortEntry THEN
SELL 2 CONTRACTS AT MARKET
ENDIF
// Conditions to exit short positions
IF ShortExit THEN
BUY AT MARKET
ENDIF
With my modification when i backtest i have zero results
Thanks for your helps
At first look the BUY and SELL instructions that you use are the wrong ones. You need to use SELLSHORT and EXITSHORT for short position entry and exit. BUY and SELL are for long positions only.
// Conditions to enter short positions
IF ShortEntry THEN
SellShort 2 CONTRACTS AT MARKET
ENDIF
// Conditions to exit short positions
IF ShortExit THEN
ExitShort AT MARKET
ENDIF
Where you have the exclamation marks use the term mySellShort and myExitShort.
Sorry for jumping in Vonasi, just keeping the momentum going! 🙂
Sorry for jumping in Vonasi
Jump in all you like GraHal. I’ve been out enjoying myself sailing in the rain. Rain in Greece in June! …..and Trump says there is no global warming!
Your short code was fine. It is just that:
BUY // Used to open a long position.
SELL // Used to close a long position
SELLSHORT // Used to open a short position
EXITSHORT // Used to close a short position
So your code would be:
ShortRSI = RSI[2](close)
LongRSI = RSI[30](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
MaxPos = 2 //Set to tolerated maximum position
ShortEntry = CountOfShortShares < MaxPos //Buy until MaxPos reached
ShortEntry = ShortEntry AND ShortRSI > 60 //Short when RSI2 above 60
ShortEntry = ShortEntry AND LongRSI < 50 //Filter for 1month RSI below 50
ShortEntry = ShortEntry AND Slope > 0 //Filter for positive slope of MA22
ShortExit = ShortOnMarket
ShortExit = ShortExit AND ShortRSI < 15 //Exit position when RSI2 below 15
// Conditions to enter short positions
IF ShortEntry THEN
SELLSHORT 2 CONTRACTS AT MARKET
ENDIF
// Conditions to exit short positions
IF ShortExit THEN
EXITSHORT AT MARKET
ENDIF