Reverse Engineering of the Zero Lag MACD

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #88596 quote
    stefou102
    Participant
    Veteran

    Hello,

    For those using this indicator to trade, it may be useful to know in advance at which price the MACD will cross its signal line. Please find the code here below. If someone knows how to draw text on the right hand of the chart and not on the last candle, please shoot.

     

    defparam drawonlastbaronly=true
    
    ONCE FastAvg = 12
    ONCE SlowAvg = 26
    ONCE SigAvg  = 9
    
    EMAshort1 = exponentialaverage[FastAvg](close)
    EMAshort2 = exponentialaverage[FastAvg](EMAshort1)
    DifferenceShort = EMAshort1 - EMAshort2
    ZeroLagShort = EMAshort1 + DifferenceShort
    
    EMAlong1 = exponentialaverage[SlowAvg](close)
    EMAlong2 = exponentialaverage[SlowAvg](EMAlong1)
    DifferenceLong = EMAlong1 - EMAlong2
    ZeroLagLong = EMAlong1 + DifferenceLong
    
    ZeroLagMACD = ZeroLagShort - ZeroLagLong
    
    signal1=ExponentialAverage[SigAvg](ZEROLAGMACD)
    signal2=ExponentialAverage[SigAvg](signal1)
    DIFFERENCE2=signal1-signal2
    
    SignalMACD=signal1+DIFFERENCE2
    
    
    alphaX=2/(1+FastAvg)
    alphaY=2/(1+SlowAvg)
    prevEMA1=ZeroLagShort[1]
    prevEMA2=ZeroLagLong[1]
    
    
    
    macdValue=SignalMACD
    
    priceMACD=(macdValue+((1-alphaY)*prevEMA2)-((1-alphaX)*prevEMA1))/(alphaX-alphaY)
    
    pricerounded=round(priceMACD)
    drawtext("ZMACD crossing:#pricerounded#",barindex,priceMACD+2,SansSerif,Bold,10)
    DRAWSEGMENT(barindex-10,priceMACD,barindex,priceMACD) coloured(0,0,0)
    
    return
    Nicolas, DerekMills, oljemace and Bodaris thanked this post
    #88604 quote
    Vonasi
    Moderator
    Master

    Thanks for sharing the code but it is not possible to draw to the right of the current barindex with PRT unfortunately.

    #88609 quote
    stefou102
    Participant
    Veteran

    It’s what I thought thx for confirming Vonasi

    #88653 quote
    Nicolas
    Keymaster
    Master

    You can’t draw objects in the future, but you can add blank space in a text string:

    drawtext("                           *",barindex,priceMACD,SansSerif,Bold,10)
    stefou102 and oljemace thanked this post
    #119326 quote
    DerekMills
    Participant
    New

    Thank you all for sharing this code.

    I have the segment in the graphic, but cannot see the price tag on the scale on the right, even if marked in the indicator parameters.

    Is there anything to modify please ?

    #119329 quote
    Nicolas
    Keymaster
    Master

    Change the last line with:

    RETURN priceMACD
    DerekMills thanked this post
    #119330 quote
    DerekMills
    Participant
    New

    Perfect ! Thanks again guys for your quick answers 😉

    #125627 quote
    NicoMich
    Participant
    New

    Hi dear,

    Thank’s for sharing !

    I’m not using PRT but MT4 instead… I’m beginner with MQL4 langage but I’ve tried to code it, it gives me something but the line isn’t really smoothed lol.

    So I don’t know if it’s normal or not…

    I joined a screenshot of my result (it gives me the pink line).

    And following my MQL4, maybe somebody knows this langage and could help me to analyze it :

     

    double fastMultiplier = (2.0 / (MACD_fastAvg + 1.0) );
    double slowMultiplier = (2.0 / (MACD_slowAvg + 1.0) );
    double signalMultiplier = (2.0 / (MACD_sigAvg + 1.0) );

    //Print(“Fast Multiplier [” + fastMultiplier + “]”);
    //Print(“Slow Multiplier [” + slowMultiplier + “]”);
    //Print(“Signal Multiplier [” + signalMultiplier + “]”);

    double prevEMAShort = 0.0;
    double prevEMALong = 0.0;
    double prevEMASignal = 0.0;

    double priceMACD = 0.0;

    if(i==0)
    {

    prevEMAShort = SimpleMA(i,MACD_fastAvg,close);
    prevEMALong = SimpleMA(i,MACD_slowAvg,close);
    prevEMASignal = SimpleMA(i,MACD_sigAvg,close);

    } else {

    prevEMAShort = ExtZeroLagShortDevBuffer[i-1];
    prevEMALong = ExtZeroLagLongDevBuffer[i-1];
    prevEMASignal = ExtZeroLagSignalDevBuffer[i-1];

    }

    double EMAShort1 = (close[i] – prevEMAShort) * fastMultiplier + prevEMAShort;
    double EMAShort2 = (EMAShort1 – prevEMAShort) * fastMultiplier + prevEMAShort;
    double DifferenceShort = EMAShort1 – EMAShort2;
    double ZeroLagShort = EMAShort1 + DifferenceShort;
    ExtZeroLagShortDevBuffer[i] = ZeroLagShort;

    double EMALong1 = (close[i] – prevEMALong) * slowMultiplier + prevEMALong;
    double EMALong2 = (EMALong1 – prevEMALong) * slowMultiplier + prevEMALong;
    double DifferenceLong = EMALong1 – EMALong2;
    double ZeroLagLong = EMALong1 + DifferenceLong;
    ExtZeroLagLongDevBuffer[i] = ZeroLagLong;

    double ZeroLagMACD = ZeroLagShort – ZeroLagLong;

    double Signal1 = (ZeroLagMACD – prevEMASignal) * signalMultiplier + prevEMASignal;
    double Signal2 = (Signal1 – prevEMASignal) * signalMultiplier + prevEMASignal;
    double DifferenceSignal = Signal1 – Signal2;
    double SignalMACD = Signal1 + DifferenceSignal;
    ExtZeroLagSignalDevBuffer[i] = SignalMACD;

    double macdValue = SignalMACD;
    priceMACD = (macdValue+((1-slowMultiplier)*prevEMALong)-((1-fastMultiplier)*prevEMAShort))/(fastMultiplier-slowMultiplier);

    ExtReverseZeroLagMacdBuffer[i]=NormalizeDouble(priceMACD, InpDecimalAccurate);

    #125629 quote
    stefou102
    Participant
    Veteran

    Hello NicoMich, sorry but you can’t come on a PRT forum and expects someone is going to help you with MT4…

    Vonasi thanked this post
    #125632 quote
    Vonasi
    Moderator
    Master

    NicoMich – Welcome to the forums. These forums are dedicated to the ProRealTime platform.  We do not discuss other programming languages. You can use the paid for programming services for other languages if you want to. The link for it can be found under the ‘Help’ menu.

    #136695 quote
    oljemace
    Participant
    New

    Bonjour,

    Peux-t-on avoir ce même type de reverse lorsque la ligne du MACD ZR uniquement (non pas la ligne de signal)  devient croissante ou décroissante ?

    Merci d’avance.

    Hello,

    Can we have this same type of reverse when the MACD ZR line only (not the signal line) becomes increasing or decreasing?

    Thank you in advance.

    #136699 quote
    robertogozzi
    Moderator
    Master

    @oljemace

    • Only post in the language of the forumthat you are posting in. For example English only in the English speaking forums and French only in the French speaking forums.

    Thank you 😊

    #186680 quote
    tuxfox
    Participant
    Junior

    Hello,
    Thank you for this very interesting code. On the other hand, I would like to display the indicator in relation to the data of the previous candle in order to identify the zone to break for the MACD to turn around. Could you let me know how to go about it?
    Thank you for your help

    #222162 quote
    Bodaris
    Participant
    New

    Well done ! and a big thank you.

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.

Reverse Engineering of the Zero Lag MACD


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
stefou102 @stefou102 Participant
Summary

This topic contains 13 replies,
has 2 voices, and was last updated by Bodaris
2 years, 4 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 01/14/2019
Status: Active
Attachments: 1 files
Logo Logo
Loading...