On screen calculator

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #247231 quote
    segie
    Participant
    Senior

    Hi,

    Will it possible to do an indicator that calculates the difference in price between two moving averages, example a 20  and 50? To be displayed on a chart.

    Regards,

    Segie

    #247235 quote
    JC_Bywan
    Moderator
    Master

    Hi,

    Something like that, with a pixel position from top right corner (hence the negative Xpixel and Ypixel values, customisable as long as they remain negative to indicate going leftward and downward from top right corner).With another use of drawtext, it would also be possible to just keep display on a given barindex rather than a pixel position if preferred.

     

    defparam drawonlastbaronly=true
    
    // Choose pixel fixed position from top right corner with negative X and Y values
    Xpixel= -100
    Ypixel= -50
    
    ma20= Average[20](close)
    ma50= Average[50](close)
    diff= ma20-ma50
    
    DRAWTEXT("MA20-MA50= #diff#", Xpixel, Ypixel) anchor(topright, Xshift, Yshift)
    
    return
    segie and Iván González thanked this post
    #247245 quote
    segie
    Participant
    Senior

    Works well. Thank you very much

    #247246 quote
    segie
    Participant
    Senior

    Can you also help to display the difference as a percentage below the calculation?

    e.g. MA20=2  and MA50= 8

    The difference = -6

    (-6/2) X 100 = 300%

    Regards,

    Segie

    #247254 quote
    JS
    Participant
    Senior

    Hi,

    The current calculation is the absolute difference between the two averages:

    AbsDiff = (MA20 – MA50)

    If you want to calculate the relative difference in percentages: RelDiff = (MA20 – MA50) / MA50 * 100
    Or alternatively written as:
    RelDiff = (MA20 / MA50 – 1) * 100

    defparam drawonlastbaronly=true
    
    // Choose pixel fixed position from top right corner with negative X and Y values
    Xpixel= -100
    Ypixel= -50
    
    ma20= Average[20](close)
    ma50= Average[50](close)
    diff= ma20-ma50
    DiffPct=(ma20-ma50)/ma50*100
    
    DRAWTEXT("Abs. Difference=#diff#", Xpixel, Ypixel) anchor(topright, Xshift, Yshift)
    DRAWTEXT("Relat. Difference=#diffpct#%", Xpixel, Ypixel-20) anchor(topright, Xshift, Yshift)
    
    return ma20 as "Fast" coloured("red"), ma50 as "Slow" coloured("green")

    segie and Iván González thanked this post
    #247262 quote
    segie
    Participant
    Senior
    Looks good. Thank you
    JS thanked this post
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

On screen calculator


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
segie @segie Participant
Summary

This topic contains 5 replies,
has 3 voices, and was last updated by segie
8 months, 3 weeks ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 05/17/2025
Status: Active
Attachments: 1 files
Logo Logo
Loading...