Backtesting RSI and MA
Forums › ProRealTime English forum › ProOrder support › Backtesting RSI and MA
- This topic has 5 replies, 2 voices, and was last updated 3 years ago by kosmo.
-
-
02/22/2021 at 1:47 PM #162339
Hi guys,
I am trying to figure out how to set up with the following conditions:
Enter Long position:
If the RSI crosses under 30 and while the RSI is below 70 and MA9 CROSSES OVER MA21. I have tried with an IF condition with the RSI and if that triggers I want to have the MA9 crosses over the MA21 and only then I want to go long.
Is it possible to have a system like that and if so Could you please help me with that?
Thanks,
02/22/2021 at 3:04 PM #162354There you go:
12345678910111213141516171819Defparam CumulateOrders = falseOnce CondL = 0Once RsiCross = 0MyRsi = Rsi[14](close)Ob = 70Os = 100 - ObSma9 = average[9,0](close)Sma21 = average[21,0](close)If OnMarket or (MyRsi >= Ob) thenCondL = 0RsiCross = 0EndifIf MyRsi crosses under Os thenRsiCross = 1EndifCondL = RsiCross and Sma9 crosses over Sma21If CondL and not OnMarket ThenBuy 1 contract at MarketEndifyou only need to add SL & TP.
1 user thanked author for this post.
02/22/2021 at 7:44 PM #162374Hi Robertogozzi,
Thank you so much for your help.
This was exactly what I looked for, but what about exiting the long position without the TP and SL, I mean to exit the trade once the RSI is over 70 and the MA9 is crossing under the MA21?
and if I want to reverse the long to short, I need to need to create a new variable eg. CondS?
02/22/2021 at 11:08 PM #162387To exit long trades, you can append these lines to my code:
1234ExitL = (MyRsi > Ob) AND (Sma9 CROSSES UNDER Sma21)IF ExitL AND LongOnMarket THENSELL AT MarketENDIFYes, to support SHORT trades you need to add CondS (and now also ExitS) to which you will have to assign the opposite conditions to both enter and exit trades.
02/22/2021 at 11:11 PM #162388I have the code like this, but it does not allow me to exit the market
123456789101112131415161718192021222324252627282930313233343536// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivatedOnce CondL = 0Once RsiCrossUnder = 0Once RsiCrossOver = 0MyRsi = Rsi[14](close)Ob = 70Os = 100 - ObSma9 = average[9,0](close)Sma21 = average[21,0](close)if OnMarket or (MyRsi >= Ob) thenCondL = 0RsiCrossUnder = 0endifif MyRsi crosses under Os thenRsiCrossUnder = 1endifCondL = RsiCrossUnder and Sma9 crosses over Sma21if CondL and not OnMarket ThenBuy 100 contract at Marketendifif myRsi crosses over Ob thenRsiCrossOver = 1endifCondExitL = RsiCrossOver and Sma9 crosses under Sma9if CondExitL thenSELL 100 contract AT MARKETendif02/22/2021 at 11:16 PM #162389 -
AuthorPosts
Find exclusive trading pro-tools on