%Difference Price vs 20DMA

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #250632 quote
    SagalSagal
    Participant
    New

    Hello, it was something that somehow I was watching manually. However, on X Ole Hansen from Saxobank mentioned and displayed an indicator that mesure the % difference between the price and the 20DMA. For Gold, there has been some correction in the past when the difference is above 20%. As I’m not at all a programer I asked IA (DeepSeek) to produce a code. I think currently v. 13 beta is not working well for this kind of things, but anyway can one of you tell me if this code should do the work?

    //@version=13
    // Indicator: Price Deviation from 200 DMA
    // Based on concept described by Ole S. Hansen (Saxo Bank)

    // Input parameters
    DeviationThreshold = 20.0 // 20% threshold
    MALength = 200 // 200-period moving average

    // Calculate 200-period Simple Moving Average
    MA200 = average[200](close)

    // Calculate percentage deviation from the MA
    Deviation = (close / MA200 – 1) * 100

    // Plot the deviation line
    RETURN Deviation AS “Deviation (%)”

    // Draw horizontal lines for the thresholds
    DRAWHLINE(DeviationThreshold) AS “Overbought Line”
    DRAWHLINE(-DeviationThreshold) AS “Oversold Line”
    DRAWHLINE(0) AS “Zero Line”

    // Color the background based on the deviation
    IF Deviation >= DeviationThreshold THEN
    DRAWONCE(1, color(200,0,0,80)) AS “Overbought Warning”
    ELSIF Deviation <= -DeviationThreshold THEN
    DRAWONCE(1, color(0,150,0,80)) AS “Oversold Warning”
    ENDIF

    #250635 quote
    SagalSagal
    Participant
    New

    I wanted to say 200DMA

    #250636 quote
    JSJS
    Participant
    Master

    Hi,

    Try this one (the messages are realtime)…

    //@version=13
    // Indicator: Price Deviation from 200 DMA
    // Based on concept described by Ole S. Hansen (Saxo Bank)
    
    DefParam DrawOnLastBarOnly=True
    
    // Input parameters
    DeviationThreshold = 20.0 // 20% threshold
    MALength = 200 // 200-period moving average
    
    // Calculate 200-period Simple Moving Average
    MA200 = average[200](close)
    
    // Calculate percentage deviation from the MA
    Deviation = (close / MA200 - 1) * 100
    
    // Draw horizontal lines for the thresholds
    DRAWHLINE(DeviationThreshold) Coloured("Green")
    DRAWHLINE(-DeviationThreshold)Coloured("Red")
    DRAWHLINE(0)
    
    // Color the background based on the deviation
    IF Deviation >= DeviationThreshold THEN
    DrawText("OverBought Warning",BarIndex,Deviation)
    ELSIF Deviation <= -DeviationThreshold THEN
    DrawText("OverSold Warning",BarIndex,Deviation)
    ENDIF
    
    // Plot the deviation line
    RETURN Deviation AS "Deviation (%)"
    robertogozzi and Iván González thanked this post
    Scherm­afbeelding-2025-09-10-om-16.05.51.png Scherm­afbeelding-2025-09-10-om-16.05.51.png
    #250648 quote
    SagalSagal
    Participant
    New

    Thanks a lot! it is working properly, the IA I use is unable to properly convert pinestreet code into PRT code

    JS thanked this post
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

%Difference Price vs 20DMA


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Sagal @sagal Participant
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by SagalSagal
1 year ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 09/10/2025
Status: Active
Attachments: 1 files
ProRealCode ProRealCode
Loading...