Change the MACD indicator to Zero Lag MACD
Forums › ProRealTime English forum › ProOrder support › Change the MACD indicator to Zero Lag MACD
- This topic has 17 replies, 4 voices, and was last updated 1 year ago by GraHal.
-
-
08/14/2023 at 10:33 PM #21908912345678910111213141516171819202122232425262728293031323334353637383940// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter long positionsindicator1 = MACDline[37,77,9](close)indicator2 = MACDSignal[37,77,9](close)c1 = (indicator1 CROSSES OVER indicator2)indicator3 = RSI[14](close)c2 = (indicator3 <= 55)indicator4 = MACDSignal[37,77,9](close)indicator5 = MACD[37,77,9](close)c3 = (indicator4 < indicator5)indicator6 = MACDline[37,77,9](close)indicator7 = MACD[37,77,9](close)c4 = (indicator6 < indicator7)IF c1 AND c2 AND c3 AND c4 THENBUY 10 SHARES AT MARKETENDIF// Conditions to enter short positionsindicator8 = MACDSignal[37,77,9](close)indicator9 = MACDline[37,77,9](close)c5 = (indicator8 CROSSES OVER indicator9)indicator10 = RSI[14](close)c6 = (indicator10 >= 45)indicator11 = MACDSignal[37,77,9](close)indicator12 = MACD[37,77,9](close)c7 = (indicator11 > indicator12)indicator13 = MACDline[37,77,9](close)indicator14 = MACD[37,77,9](close)c8 = (indicator13 > indicator14)IF c5 AND c6 AND c7 AND c8 THENSELLSHORT 10 SHARES AT MARKETENDIF// Stops and targetsSET STOP pTRAILING 20SET TARGET pPROFIT 60
Hello,
This is my first time posting here and I am slowly getting to grips with the world of coding. I used the simple programming option to create an algorithm that uses the MACD and have had some good results depending on the timeframe; currently I’, on a 10 minute on the S&P 500. I have since read that there are alternatives to the standard MACD and would like to see whether anyone would be able to help me modify the code to use the Zero Lag MACD. I would also be more than grateful for any other suggestions or changes that I should try to implement.
Thank you
08/15/2023 at 11:03 AM #219097Well done ErrorCodeT !
Try your code on DJI 3 min TF over 10K bars using SL and TP with separate values for Buy and SellShort.
08/15/2023 at 11:17 AM #219098Hello, thank you for the suggestion. I’ll try out DJI as soon as I’m home and on the laptop.
In regards for separate SL and TP for buy and sell short, how would you code this please?
08/15/2023 at 11:24 AM #219099As below, where A19 and A20 are variable values to be optimised as min = 0.1 max = 1 step = 0.1 .
Do same fo SellShort.
12345IF c1 AND c2 AND c3 AND c4 THENBUY 1 SHARES AT MARKETSET STOP %LOSS A19SET TARGET %PROFIT A20ENDIFI could attach my version, but you will be more chuffed if you do it yourself?
08/15/2023 at 11:47 AM #219100Thank you, I’ll get on with finding out about optimisation. I presume the optimisation function will find the best combination.
I certainly would be more chuffed if I did it myself but equally grateful for your version too.
08/15/2023 at 11:56 AM #219101I assumed you had used the Optimiser to arrive at these values MACDline[37,77,9](close) as these are not standard MACD parameters.
Do below (as you won’t need them) when you follow my example (with % SL and % TP) in previous post.
12//SET STOP pTRAILING 20//SET TARGET pPROFIT 6008/15/2023 at 12:17 PM #219102It was a code I got from a friend that used these values, it proved good results and I thought I’d modify it with short trades as well.
Do you know if can just type ZeroLagMACD to use that indicator instead of the current lines?
08/15/2023 at 1:17 PM #219103ZeroLagMACD is not a standard / default PRT Indicator and so you would need to …
- Include code for MACDZeroLag into the strategy (easiest way maybe).
OR - Add the MACDZeroLag as an Indicator to your Platform and then you would need to ‘call’ the MACDZeroLag as below (more complex) …
1MACDZL = CALL "MACDZeroLag"[12, 26, 9]
- Here is a link to the MACDZeroLag Indicator.
https://www.prorealcode.com/prorealtime-indicators/zerolag-macd/
You have a lot of excitement to get through tonight when you get home!!?? 😉
1 user thanked author for this post.
08/15/2023 at 1:29 PM #219104The call of MACDZeroLag may need to be something like this …
1myZeroLagMACD, mySignalMACD, myMyHistogram = CALL "MACDZeroLag"[12, 26, 9]It be best to get familiar with the PRT default MACD and use of the Optimiser etc before getting too ambitious?
08/15/2023 at 3:06 PM #219109Classic, ‘Don’t run before you can walk.’
08/16/2023 at 5:17 PM #219193I used your (ErrorCodeT) code and tried to add the suggestions of GraHal. Looks good in the short perspective (10k bars @3min) but I find it hard to get a good equity curve over longer times..
1 user thanked author for this post.
08/16/2023 at 5:32 PM #219196Thank you for taking the time to look at the code. What would you suggest I do to improve the equity curve over a longer time?
Thanks
08/16/2023 at 5:52 PM #219198I’ve also imported the file and can’t seem to get any trades executing. I must be doing something completely wrong as I’d be more than happy with the above results.
08/16/2023 at 7:59 PM #21921408/16/2023 at 8:17 PM #219217 - Include code for MACDZeroLag into the strategy (easiest way maybe).
-
AuthorPosts
Find exclusive trading pro-tools on