Error codeing MACD crossover happens with 26 & 52 period EMA
Forums › ProRealTime English forum › ProOrder support › Error codeing MACD crossover happens with 26 & 52 period EMA
- This topic has 2 replies, 2 voices, and was last updated 4 years ago by robertogozzi.
-
-
07/27/2020 at 4:24 AM #140161
Hi ,
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.
12345678910111213141516171819202122232425262728293031// Conditions to enter long positionsdefparam CUMULATEORDERS = false//macdlinec2 = MACDline[ 26 , 52, 12 ](close)//signallinec3 = ExponentialAverage[12](c2)//histogram heigthistbar = c2 – c3c5 = histbar crosses over 0c6 = histbar crosses under 0IF NOT LongOnMarket AND c5 THENBUY 1 CONTRACTS AT MARKETsl = lowest[3](low)set stop loss sltgt = ( POSITIONPRICE – SL ) * 1.5set target $profit tgtENDIF// Conditions to exit long positions// Conditions to enter short positionsIF NOT ShortOnMarket AND c6 THENSELLSHORT 1 CONTRACTS AT MARKETsl = highest[3](high)set stop loss sltgt = ( sl – POSITIONPRICE ) * 1.5set target $profit tgtENDIFThe 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.
Can anyone help what is wrong in the code.
07/27/2020 at 8:38 AM #140164- Give your topic a meaningful title.Describe your question or your subject in your title. Do not use meaningless titles such as ‘Coding Help Needed’.
- Always use the ‘Insert PRT Code’ button when putting code in your posts to make it easier for others to read.
Thank you 🙂
07/27/2020 at 8:48 AM #140168SET STOP LOSS and SET TARGET PROFIT require a difference between prices (Close – Low), not a price (Low).
Replace lines 16-19 as follows:
1234sl = abs(close-lowest[3](low))set stop loss sltgt = SL * 1.5set target profit tgtdo the same for the Short side using HIGHEST.
Do not use $ for PROFIT, it’s intended for currency values, such as 400 etc…
-
AuthorPosts
Find exclusive trading pro-tools on