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
JSParticipant
Senior
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 (%)"
Thanks a lot! it is working properly, the IA I use is unable to properly convert pinestreet code into PRT code