Hi, in my system I need it to buy/short when a moving average crosses the price and when the RSI has been over 60/under 40 in the last 3 candles. Please help i don’t know how to do this. 🙂
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
33
34
35
36
37
38
39
defparam preloadbars = 15
defparam CUMULATEORDERS = false
indicator2 = call "example5 : RSI" [ 14 ]
brsi = (indicator2 < 45 )
indicator3 = call "example5 : RSI" [ 14 ]
srsi = (indicator3 > 65 )
indicator1 = Average [ 9 ] (close )
once haclose= close
once haopen= open
if barindex > 1 then
haclose= (open + close + low + high )/ 4
haopen= (haopen[ 1 ] + haclose[ 1 ] )/ 2
endif
//buy condition
cBuy = (haclose CROSSES OVER indicator1 and brsi)
//sell condition
cSell = (haclose CROSSES UNDER indicator1 and srsi)
If cbuy then
buy 5000 CASH at market
endif
If csell then
sell at market
endif
if csell then
sellshort 5000 CASH at market
endif
if cbuy then
exitshort at market
endif