Help with this Code (cant get an MA to display correctly)

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #91331 quote
    VPT PRT
    Participant
    Junior

    Hi all,

     

    I’m hoping to get some help with a small problem.

     

    In the attached .itf file I have been trying to code in Upper and Lower boundaries (like dynamic reference points).  I would like to apply a EMA to the upper and lower boundary plots, but when I try to do this it always ends up changing the original boundary, and all I want is a new EMA plot of the boundary.

     

    Can anyone please tell me where I’m going wrong?

    NR-TSI-AO1EMA.itf
    #91334 quote
    VPT PRT
    Participant
    Junior

    All I want to do is use the EMA to smooth out the boundaries.

     

    So in the picture attached are two EMA’s that I have applied to the two boundaries.  I just used the ‘add indicator’ button on the indicator settings tap.  I just want to hardwire the EMA’s into the .itf attached…….

     

    Hoping you can help

     

    Thanks

     

    Ross

    Screenshot-2019-02-13-at-20.11.20.png Screenshot-2019-02-13-at-20.11.20.png
    #91349 quote
    Nicolas
    Keymaster
    Master

    Please post your code into your next message, better for people to answer directly into your code than to import file and then get back here.. Thank you.

    #91355 quote
    VPT PRT
    Participant
    Junior

    Thanks for that Nicolas, good point.

     

    Here is the code:

     

    if PeriodsBefore>0 then
    a = (ExponentialAverage[iFirstMaPeriod](ExponentialAverage[iSecondMaPeriod](ROC[1](close[PeriodsBefore]))))
    b = (ExponentialAverage[iFirstMaPeriod](ExponentialAverage[iSecondMaPeriod](ABS(ROC[1](close[PeriodsBefore])))))
    
    MyMacd = 100 * (a/b)
    else
    a = (ExponentialAverage[iFirstMaPeriod](ExponentialAverage[iSecondMaPeriod](ROC[1](close))))
    b = (ExponentialAverage[iFirstMaPeriod](ExponentialAverage[iSecondMaPeriod](ABS(ROC[1](close)))))
    
    MyMacd = 100 * (a/b)
    endif
    //NormMidpointValue = 0//(NormUpperboundary+NormLowerBoundary)/2
    //MidpointValue =0
    
    if NormUpperboundary < MyMacd+ShieldValue then
    NormUpperboundary = MyMacd+ShieldValue
    else
    if (NormUpperboundary-ABS(NormUpperboundary-NormLowerBoundary)* Percentage/100)>= MyMacd then
    NormUpperboundary = NormUpperboundary-(ABS(NormUpperboundary-NormLowerBoundary)* Percentage/100)
    endif
    endif
    
    if NormLowerBoundary > MyMacd-ShieldValue Then
    NormLowerBoundary = MyMacd-ShieldValue
    else
    
    if (NormLowerBoundary + ABS(NormUpperboundary-NormLowerBoundary)* Percentage/100) <= MyMaCD then
    NormLowerBoundary = (NormLowerBoundary + (ABS((NormUpperboundary-NormLowerBoundary))* Percentage/100))
    endif
    endif
    
    Indicator = 0
    
    Indicator = ((MyMacd - NormLowerBoundary) *200/(NormUpperboundary-NormLowerBoundary) -100)
    //NormMidpointValue = ((NormMidpointValue - NormLowerBoundary) *200/(NormUpperboundary-NormLowerBoundary) -100)> 100
    
    If TypeOfRange >0 then
    if UpperBoundary <= TypeOfRange then
    UpperBoundary = TypeOfRange
    endif
    endif
    
    if Upperboundary < Indicator+RangeShieldValue then
    UpperBoundary = Indicator+RangeShieldValue
    else
    if (UpperBoundary-ABS(UpperBoundary-LowerBoundary)* RangePercentage/100)>= Indicator then
    UpperBoundary = UpperBoundary-(ABS(UpperBoundary-LowerBoundary)* RangePercentage/100)
    endif
    endif
    UpperBoundary = Average[1](UpperBoundary)
    If TypeOfRange >0 then
    if LowerBoundary >= 0-TypeOfRange then
    LowerBoundary = 0-TypeOfRange
    endif
    endif
    if LowerBoundary > Indicator-RangeShieldValue Then
    LowerBoundary = Indicator-RangeShieldValue
    else
    if (LowerBoundary + ABS(UpperBoundary-LowerBoundary)* RangePercentage/100) <= Indicator then
    LowerBoundary = (LowerBoundary + (ABS((UpperBoundary-LowerBoundary))* RangePercentage/100))
    endif
    endif
    LowerBoundary = Average[1](LowerBoundary)
    
    return Indicator*Multiplier COLOURED(100, 100, 100) as "MACD", UpperBoundary COLOURED(0,0, 255) as "Upper Boundary", 0 COLOURED(255, 0, 0) as "midline", LowerBoundary COLOURED( 0,255, 0) as "Lower Boundary", (UpperBoundary+LowerBoundary)/2 as "range midline"
    #91356 quote
    Vonasi
    Moderator
    Master

    VPT PRT – please use the ‘Insert PRT Code’ button when posting code. It makes it far easier for others to read. I have tidied up your post for you 🙂

    #91357 quote
    Vonasi
    Moderator
    Master

    Create a new variable to be used as your displayed value this way you don’t mess up your calculations.

    UB = ExponentialAverage[10](UpperBoundary)
    LB = ExponentialAverage[10](LowerBoundary)
    
    return Indicator*Multiplier COLOURED(100, 100, 100) as "MACD", UB COLOURED(0,0, 255) as "Upper Boundary", 0 COLOURED(255, 0, 0) as "midline", LB COLOURED( 0,255, 0) as "Lower Boundary", (UB+LB)/2 as "range midline"
    Nicolas thanked this post
    #91425 quote
    VPT PRT
    Participant
    Junior

    Thank you very much for that Vonasi, thats sorted my problem.

    Cheers

    Ross

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

Help with this Code (cant get an MA to display correctly)


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
VPT PRT @vpt-prt Participant
Summary

This topic contains 6 replies,
has 3 voices, and was last updated by VPT PRT
6 years, 12 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 02/13/2019
Status: Active
Attachments: 2 files
Logo Logo
Loading...