Start to look for conditions after crossover
- This topic has 5 replies, 3 voices, and was last updated 2 years ago by .
Viewing 6 posts - 1 through 6 (of 6 total)
Viewing 6 posts - 1 through 6 (of 6 total)
Similar topics:
Forums › ProRealTime English forum › ProOrder support › Start to look for conditions after crossover
Trying to get the algorithm to wait for a crossover between the two moving averages to occur, and then checks the RSI value in the next 5 candles. If the RSI is below 30 in one of those candles, the algorithm generates a buy signal. This way, the algorithm waits for confirmation of the oversold condition before entering a trade. This code do not work it trades on the crossover but the crossover should only indicate the starting point from where it should look at the RSI
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
// Define the lengths of the moving averages and RSI indicator maLength1 = 20 maLength2 = 30 rsiLength = 14 // Calculate the moving averages and RSI value ma1 = Average[maLength1](close) ma2 = Average[maLength2](close) nrsi = rsi[rsiLength](close) // Identify the cross over using the moving averages crossover = 0 if ma1 > ma2 and ma1[1] < ma2[1] Then crossover = 1 // moving average crossover occurred Endif // Use the cross over signal and RSI value to determine the entry price direction = 0 if crossover = 1 Then for i = 0 to 4 if nrsi[i] < 30 Then direction = 1 // buy Endif NEXT Endif If direction = 1 Then Buy 1 contract at market Endif // Stops and targets SET STOP pLOSS 100 SET TARGET pPROFIT 100 |
Hi JS, nope unfortunately it does not work. The idea is that the algo should look at the next 5 bars whether the RSI is in oversold territory just after the cross over up of the 20SMA and 30SMA. The trade has to take place within 5 bars after the cross over. If the RSI does not go into oversold territory within the next 5 bars the trade aborts and wait for the next cross over.
Here is a new attempt, store the barindex of the event, then check bars elasped since. Not tested.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
// Define the lengths of the moving averages and RSI indicator maLength1 = 20 maLength2 = 30 rsiLength = 14 // Calculate the moving averages and RSI value ma1 = Average[maLength1](close) ma2 = Average[maLength2](close) nrsi = rsi[rsiLength](close) // Identify the cross over using the moving averages if ma1 > ma2 and ma1[1] < ma2[1] Then crossover = barindex // moving average crossover occurred = store the barindex Endif // Use the cross over signal and RSI value to determine the entry price if barindex-crossover <= 5 and crossover>0 Then //crossover occured less than 5 bars ago if nrsi < 30 Then Buy 1 contract at market crossover = 0 //reset and prevent next order with same crossover Endif endif // Stops and targets SET STOP pLOSS 100 SET TARGET pPROFIT 100 |
Find exclusive trading pro-tools on