MACD two lines

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #121191 quote
    k3rex
    Participant
    Junior

    Hi,

    Possible to have just two lines for MACD? Want the lines to be exponential moving average.

    macd.jpg macd.jpg
    #121193 quote
    robertogozzi
    Moderator
    Master

    Standard MACD is calculated using exponential averages.

    To disable the hystogram just make it INVISIBLE in the indicators’properties.

    This is the code for the MACD, if you want to customize it with different averages, you just need to change the variable MAtype:

    FastMA       = 12      //12  Fast average
    SlowMA       = 26      //26  Slow average
    Periods      = 9       //9   periods for the Signal
    MAtype       = 1       //1=ema   average type(see available types https://www.prorealcode.com/documentation/average/)
    MyMACD       = Average[FastMA,MAtype](close) - Average[SlowMA,MAtype](close) //difference of the two averages
    MySignalLine = Average[Periods,MAtype](MyMACD)                               //average of the MACD
    MyHisto      = MyMACD - MySignalLine                                         //hystogram
    RETURN MyMacd AS "Macd",MySignalLine AS "Signal",MyHisto as "histo"
    k3rex thanked this post
    #121234 quote
    k3rex
    Participant
    Junior

    Still a problem, its not smoothed as the picture. See below

    test1.jpg test1.jpg test2.jpg test2.jpg
    #121245 quote
    robertogozzi
    Moderator
    Master

    This is not smoothed since it’s the standard one, to smooth the Signal line we need to add a smoothing average:

    FastMA       = 12      //12  Fast average
    SlowMA       = 26      //26  Slow average
    Periods      = 9       //9   periods for the Signal
    MAtype       = 1       //1=ema   average type(see available types https://www.prorealcode.com/documentation/average/)
    SmoothPeriods= 20      //20  smppthing periods
    SmoothType   = 1       //1=ema   smoothing average type
    MyMACD       = Average[FastMA,MAtype](close) - Average[SlowMA,MAtype](close) //difference of the two averages
    MySignalLine = Average[Periods,MAtype](MyMACD)                               //average of the MACD
    MySignalLineS= Average[SmoothPeriods,SmoothType](MySignalLine)               //average of the SIGNAL line (smoothing)
    //MyHisto    = MyMACD - MySignalLine                                         //hystogram
    MyHisto      = MyMACD - MySignalLineS                                        //hystogram (smoothed)
    RETURN MyMacd AS "Macd",MySignalLineS AS "Signal",MyHisto as "histo"

    you  will set the periods and type of any average as best suits your needs. Expnential averages are used by default.

    As you can see from the attached pic, the MACD has the same value as the original, while the Signal line has a smoothed value.

    k3rex thanked this post
    x-2.jpg x-2.jpg
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

MACD two lines


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
k3rex @k3rex Participant
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by robertogozzi
5 years, 11 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 03/05/2020
Status: Active
Attachments: 4 files
Logo Logo
Loading...