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