I am new to PRorealtime. Thank you GURU’s for reading the topic.
I am trying to build a code where in when MACD crossover happens with 26 & 52 period EMA.
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
// Conditions to enter long positions
defparamCUMULATEORDERS=false
//macdline
c2=MACDline[26,52,12](close)
//signalline
c3=ExponentialAverage[12](c2)
//histogram heigt
histbar=c2–c3
c5=histbarcrosses over0
c6=histbarcrosses under0
IFNOTLongOnMarketANDc5THEN
BUY1CONTRACTSATMARKET
sl=lowest[3](low)
set stoplosssl
tgt=(POSITIONPRICE–SL)*1.5
set target$profittgt
ENDIF
// Conditions to exit long positions
// Conditions to enter short positions
IFNOTShortOnMarketANDc6THEN
SELLSHORT1CONTRACTSATMARKET
sl=highest[3](high)
set stoplosssl
tgt=(sl–POSITIONPRICE)*1.5
set target$profittgt
ENDIF
The above code is not setting up the Stop loss & targets. The stop loss should be lowest of last three candles when going long & highest when shorting.
Also i notice that order is place after 2 candles are formed delaying the entry of the order.
To help us continually offer you the best experience on ProRealCode, we use cookies. By clicking on "Continue" you are agreeing to our use of them. You can also check our "privacy policy" page for more information.Continue