Distance in pips between two SMA

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #168415 quote
    cfg
    Participant
    New

    Hi,

    As the title says… anyone knows how to calculate and display in the chart the distance in pips between two simple moving averages? i.e. SMA 300 and SMA 20.

    Thnx

    cfg

    #168417 quote
    robertogozzi
    Moderator
    Master

    Post your topic in the correct forum:
    _ ProRealTime Platform Support: only platform related issues.
    _ ProOrder: only strategy topics.
    _ ProBuilder: only indicator topics.
    _ ProScreener: only screener topics
    _ General Discussion: any other topics.
    _ Welcome New Members: for new forum members to introduce themselves.

    I moved it from ProRealTime Platform Support.

    Thank you 🙂

     

    This will display both averages and the difference as an average of the difference from Sma300 (to be added ON the price chart):

    Sma20  = average[20,0](close)
    Sma300 = average[300.0](close)
    Diff    = Sma20 - Sma300
    Return Sma20 as "Sma20", Sma300 as "Sma300",(Sma300-Diff) as "Difference"

     

    This one will plot a line for the sole difference (to added BELOW the price chart):

    Sma20  = average[20,0](close)
    Sma300 = average[300.0](close)
    Diff    = Sma20 - Sma300
    Return Diff as "Difference"
    cfg thanked this post
    #168692 quote
    cfg
    Participant
    New

    Hi Robertogozzi, thank you for your message.

    Apologies for posting in the wrong section.

    Both indicators are working correctly, but I cannot understand the “difference”. The difference in pips between 119.868 and 119.739 cannot be 119.97, but 0.129. How can I display the difference in pips between the two simple moving averages? i.e +32 when sma20 superior to sma300 or -32 when sma20 is below sma300.

    Thanks in advance.

    cfg

    #168703 quote
    robertogozzi
    Moderator
    Master

    Use the second one, you will have to put it UNDER the price (not ON it), like Macd, etc…, because they are not on the same scale.

    The first one cannot work, actually.

    #168704 quote
    robertogozzi
    Moderator
    Master

    In both indicators 300.0 must be replaced with:

    300,0
    #168774 quote
    Zigo
    Participant
    Master

    It can also like this:

    //Zigo
    //4/05/2021
    MA300=Average[300](close)
    MA20=Average[20](close)
    diff=round(MA300-MA20)
    a= ((MA300+MA20)/2)
    
    if diff -diff[1] <0 then
    r=0
    g=155
    bl=155
    elsif diff-diff[1]>0 then
    r=255
    g=0
    bl=0
    endif
    DRAWTEXT("                       #diff#", barindex, a, dialog, standard, 12)coloured(r,g,bl,255)
    return
    cfg thanked this post
    DAX-521-ticksdiff.png DAX-521-ticksdiff.png
    #169239 quote
    cfg
    Participant
    New

    Good morning Zigo,

    Thank you for your message.

    Your code seems to be working well, but it doesn’t display the pips in numbers as in your picture.

    Does it work for pro-real-time?

    USDCHF-Daily.png USDCHF-Daily.png pipsbetween.png pipsbetween.png
    #169251 quote
    Nicolas
    Keymaster
    Master

    Because the rounding isn’t using decimals, try with a value transformed in points:

    //Zigo
    //4/05/2021
    MA300=Average[300](close)
    MA20=Average[20](close)
    diff=round((MA300-MA20)/pointsize)
    a= ((MA300+MA20)/2)
    
    if diff -diff[1] <0 then
    r=0
    g=155
    bl=155
    elsif diff-diff[1]>0 then
    r=255
    g=0
    bl=0
    endif
    DRAWTEXT("                       #diff#", barindex, a, dialog, standard, 12)coloured(r,g,bl,255)
    return
    cfg thanked this post
    #169258 quote
    cfg
    Participant
    New

    Hi Nicolas.

    Thank you for your message.

    It is working now, thank you so much. Can you clarify if this code would work with JPY pairs?

    #169269 quote
    Nicolas
    Keymaster
    Master

    Yes it works OK with forex pairs with JPY.

    #169279 quote
    cfg
    Participant
    New

    What about the XAUUSD?

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

Distance in pips between two SMA


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
cfg @cfg Participant
Summary

This topic contains 10 replies,
has 4 voices, and was last updated by cfg
4 years, 9 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 04/29/2021
Status: Active
Attachments: 3 files
Logo Logo
Loading...