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
Start condition check
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
ifma1>ma2andma1[1]<ma2[1]Then
crossover=1// moving average crossover occurred
Endif
// Use the cross over signal and RSI value to determine the entry price
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.
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.Ok