MULTI DEVIATION
Forums › ProRealTime forum Français › Support ProBuilder › MULTI DEVIATION
- This topic has 1 reply, 2 voices, and was last updated 1 month ago by
Iván.
Viewing 2 posts - 1 through 2 (of 2 total)
-
-
10/24/2025 at 7:23 PM #25300910/28/2025 at 11:56 AM #253105
voici:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346//----------------------------------------------------//PRC_Multi Deviation Scaled Moving Average by ChartPrime//version = 0//28.10.2025//Iván González @ www.prorealcode.com//Sharing ProRealTime knowledge//----------------------------------------------------// USER INPUTS//----------------------------------------------------Periods = 30 // Period (Default: 30)Sensitivity = 60 // Sensitivity (0-100), Higher = More Sensitive (Default: 60)// Visualization Colors (RGB)upperColorR = 65upperColorG = 161upperColorB = 206downColorR = 206downColorG = 133downColorB = 65//----------------------------------------------------// INDICATOR CALCULATIONS//----------------------------------------------------// --- DSMA Calculation Setup ---// Invert sensitivity and ensure step is at least 1step = 100 - SensitivityIF step < 1 THENstep = 1ENDIF//----------------------------------------------------pi = 3.1415926535897932g = SQRT(2)ONCE filt1 = 0ONCE filt2 = 0ONCE filt3 = 0ONCE filt4 = 0ONCE filt5 = 0ONCE filt6 = 0ONCE filt7 = 0ONCE filt8 = 0ONCE dsmaVal1 = typicalpriceONCE dsmaVal2 = typicalpriceONCE dsmaVal3 = typicalpriceONCE dsmaVal4 = typicalpriceONCE dsmaVal5 = typicalpriceONCE dsmaVal6 = typicalpriceONCE dsmaVal7 = typicalpriceONCE dsmaVal8 = typicalprice//----------------------------------------------------// --- Calculate DSMA 1 ---if barindex > periods then// Smooth with a Super SmoothercurrentPeriods = Periodss = 2 * pi / currentPeriodsa1 = EXP(-g * pi / (0.5 * currentPeriods))b1 = 2 * a1 * COS((g * s / (0.5 * currentPeriods)) * 180 / pi)c2 = b1c3 = -a1 * a1c1 = 1 - c2 - c3zeros = close - close[2]filt1 = c1 * (zeros + zeros[1]) / 2 + c2 * filt1[1] + c3 * filt1[2]rms1 = SQRT(ExponentialAverage[currentPeriods](SQUARE(filt1)))IF rms1 <> 0 THENscaledFilt1 = filt1 / rms1ELSEscaledFilt1 = 0ENDIFalpha1 = ABS(scaledFilt1) * 5 / currentPeriodsIF alpha1 > 1 THEN // Clamp alphaalpha1 = 1ENDIFdsmaVal1 = alpha1 * close + (1 - alpha1) * dsmaVal1[1]endif//----------------------------------------------------// --- Calculate DSMA 2 ---if barindex>Periods + step thencurrentPeriods = Periods + steps = 2 * pi / currentPeriodsa1 = EXP(-g * pi / (0.5 * currentPeriods))b1 = 2 * a1 * COS((g * s / (0.5 * currentPeriods)) * 180 / pi)c2 = b1c3 = -a1 * a1c1 = 1 - c2 - c3zeros = close - close[2]filt2 = c1 * (zeros + zeros[1]) / 2 + c2 * filt2[1] + c3 * filt2[2]rms2 = SQRT(ExponentialAverage[currentPeriods](SQUARE(filt2)))IF rms2 <> 0 THENscaledFilt2 = filt2 / rms2ELSEscaledFilt2 = 0ENDIFalpha2 = ABS(scaledFilt2) * 5 / currentPeriodsIF alpha2 > 1 THEN // Clamp alphaalpha2 = 1ENDIFdsmaVal2 = alpha2 * close + (1 - alpha2) * dsmaVal2[1]endif//----------------------------------------------------// --- Calculate DSMA 3 ---if barindex > Periods + 2 * step thencurrentPeriods = Periods + 2 * steps = 2 * pi / currentPeriodsa1 = EXP(-g * pi / (0.5 * currentPeriods))b1 = 2 * a1 * COS((g * s / (0.5 * currentPeriods)) * 180 / pi)c2 = b1c3 = -a1 * a1c1 = 1 - c2 - c3zeros = close - close[2]filt3 = c1 * (zeros + zeros[1]) / 2 + c2 * filt3[1] + c3 * filt3[2]rms3 = SQRT(ExponentialAverage[currentPeriods](SQUARE(filt3)))IF rms3 <> 0 THENscaledFilt3 = filt3 / rms3ELSEscaledFilt3 = 0ENDIFalpha3 = ABS(scaledFilt3) * 5 / currentPeriodsIF alpha3 > 1 THEN // Clamp alphaalpha3 = 1ENDIFdsmaVal3 = alpha3 * close + (1 - alpha3) * dsmaVal3[1]endif//----------------------------------------------------// --- Calculate DSMA 4 ---if barindex>Periods + 3 * step thencurrentPeriods = Periods + 3 * steps = 2 * pi / currentPeriodsa1 = EXP(-g * pi / (0.5 * currentPeriods))b1 = 2 * a1 * COS((g * s / (0.5 * currentPeriods)) * 180 / pi)c2 = b1c3 = -a1 * a1c1 = 1 - c2 - c3zeros = close - close[2]filt4 = c1 * (zeros + zeros[1]) / 2 + c2 * filt4[1] + c3 * filt4[2]rms4 = SQRT(ExponentialAverage[currentPeriods](SQUARE(filt4)))IF rms4 <> 0 THENscaledFilt4 = filt4 / rms4ELSEscaledFilt4 = 0ENDIFalpha4 = ABS(scaledFilt4) * 5 / currentPeriodsIF alpha4 > 1 THEN // Clamp alphaalpha4 = 1ENDIFdsmaVal4 = alpha4 * close + (1 - alpha4) * dsmaVal4[1]endif//----------------------------------------------------// --- Calculate DSMA 5 ---if barindex>Periods + 4 * step thencurrentPeriods = Periods + 4 * steps = 2 * pi / currentPeriodsa1 = EXP(-g * pi / (0.5 * currentPeriods))b1 = 2 * a1 * COS((g * s / (0.5 * currentPeriods)) * 180 / pi)c2 = b1c3 = -a1 * a1c1 = 1 - c2 - c3zeros = close - close[2]filt5 = c1 * (zeros + zeros[1]) / 2 + c2 * filt5[1] + c3 * filt5[2]rms5 = SQRT(ExponentialAverage[currentPeriods](SQUARE(filt5)))IF rms5 <> 0 THENscaledFilt5 = filt5 / rms5ELSEscaledFilt5 = 0ENDIFalpha5 = ABS(scaledFilt5) * 5 / currentPeriodsIF alpha5 > 1 THEN // Clamp alphaalpha5 = 1ENDIFdsmaVal5 = alpha5 * close + (1 - alpha5) * dsmaVal5[1]endif//----------------------------------------------------// --- Calculate DSMA 6 ---if barindex>Periods+5*step thencurrentPeriods = Periods + 5 * steps = 2 * pi / currentPeriodsa1 = EXP(-g * pi / (0.5 * currentPeriods))b1 = 2 * a1 * COS((g * s / (0.5 * currentPeriods)) * 180 / pi)c2 = b1c3 = -a1 * a1c1 = 1 - c2 - c3zeros = close - close[2]filt6 = c1 * (zeros + zeros[1]) / 2 + c2 * filt6[1] + c3 * filt6[2]rms6 = SQRT(ExponentialAverage[currentPeriods](SQUARE(filt6)))IF rms6 <> 0 THENscaledFilt6 = filt6 / rms6ELSEscaledFilt6 = 0ENDIFalpha6 = ABS(scaledFilt6) * 5 / currentPeriodsIF alpha6 > 1 THEN // Clamp alphaalpha6 = 1ENDIFdsmaVal6 = alpha6 * close + (1 - alpha6) * dsmaVal6[1]endif//----------------------------------------------------// --- Calculate DSMA 7 ---if barindex>periods+6*step thencurrentPeriods = Periods + 6 * steps = 2 * pi / currentPeriodsa1 = EXP(-g * pi / (0.5 * currentPeriods))b1 = 2 * a1 * COS((g * s / (0.5 * currentPeriods)) * 180 / pi)c2 = b1c3 = -a1 * a1c1 = 1 - c2 - c3zeros = close - close[2]filt7 = c1 * (zeros + zeros[1]) / 2 + c2 * filt7[1] + c3 * filt7[2]rms7 = SQRT(ExponentialAverage[currentPeriods](SQUARE(filt7)))IF rms7 <> 0 THENscaledFilt7 = filt7 / rms7ELSEscaledFilt7 = 0ENDIFalpha7 = ABS(scaledFilt7) * 5 / currentPeriodsIF alpha7 > 1 THEN // Clamp alphaalpha7 = 1ENDIFdsmaVal7 = alpha7 * close + (1 - alpha7) * dsmaVal7[1]endif//----------------------------------------------------// --- Calculate DSMA 8 ---if barindex>periods+7*step thencurrentPeriods = Periods + 7 * steps = 2 * pi / currentPeriodsa1 = EXP(-g * pi / (0.5 * currentPeriods))b1 = 2 * a1 * COS((g * s / (0.5 * currentPeriods)) * 180 / pi)c2 = b1c3 = -a1 * a1c1 = 1 - c2 - c3zeros = close - close[2]filt8 = c1 * (zeros + zeros[1]) / 2 + c2 * filt8[1] + c3 * filt8[2]rms8 = SQRT(ExponentialAverage[currentPeriods](SQUARE(filt8)))IF rms8 <> 0 THENscaledFilt8 = filt8 / rms8ELSEscaledFilt8 = 0ENDIFalpha8 = ABS(scaledFilt8) * 5 / currentPeriodsIF alpha8 > 1 THEN // Clamp alphaalpha8 = 1ENDIFdsmaVal8 = alpha8 * close + (1 - alpha8) * dsmaVal8[1]endif//----------------------------------------------------// --- Calculate Average DSMA ---//----------------------------------------------------ma = (dsmaVal1 + dsmaVal2 + dsmaVal3 + dsmaVal4 + dsmaVal5 + dsmaVal6 + dsmaVal7 + dsmaVal8) / 8//----------------------------------------------------// --- Calculate Score ---//----------------------------------------------------score = 0val = 0.14285714 // Approximately 1/7IF dsmaVal1 > dsmaVal8 THENscore = score + valENDIFIF dsmaVal2 > dsmaVal8 THENscore = score + valENDIFIF dsmaVal3 > dsmaVal8 THENscore = score + valENDIFIF dsmaVal4 > dsmaVal8 THENscore = score + valENDIFIF dsmaVal5 > dsmaVal8 THENscore = score + valENDIFIF dsmaVal6 > dsmaVal8 THENscore = score + valENDIFIF dsmaVal7 > dsmaVal8 THENscore = score + valENDIF// Ensure score is within 0-1 range (can slightly exceed due to float precision)IF score > 1 THENscore = 1ELSIF score < 0 THENscore = 0ENDIF// --- Determine Color based on Score (Manual Gradient) ---// If score > 0.5, gradient from transparent (at 0.5) to upperColor (at 1)// If score <= 0.5, gradient from downColor (at 0) to transparent (at 0.5)colorR = 0colorG = 0colorB = 0alpha = 255 // OpacityIF score > 0.5 THEN// Scale score from 0 (at 0.5) to 1 (at 1.0)gradientFactor = (score - 0.5) * 2colorR = Round(upperColorR * gradientFactor)colorG = Round(upperColorG * gradientFactor)colorB = Round(upperColorB * gradientFactor)alpha = Round(255 * gradientFactor) // Fade inELSE// Scale score from 0 (at 0.0) to 1 (at 0.5)gradientFactor = score * 2colorR = Round(downColorR * (1 - gradientFactor)) // Color fades outcolorG = Round(downColorG * (1 - gradientFactor))colorB = Round(downColorB * (1 - gradientFactor))alpha = Round(255 * (1- gradientFactor)) // Fade outENDIF// Clamp color values just in caseIF colorR < 0 THENcolorR = 0ELSIF colorR > 255 THENcolorR = 255ENDIFIF colorG < 0 THENcolorG = 0ELSIF colorG > 255 THENcolorG = 255ENDIFIF colorB < 0 THENcolorB = 0ELSIF colorB > 255 THENcolorB = 255ENDIFIF alpha < 0 THENalpha = 0ELSIF alpha > 255 THENalpha = 255ENDIF// --- Detect Crossovers for Signal Generation ---crossUp = (score CROSSES OVER 0.3)crossDn = (score CROSSES UNDER 0.7)//----------------------------------------------------// VISUALIZATION//----------------------------------------------------// --- Plot Signals using Arrows ---IF crossUp THENDRAWARROWUP(barindex, ma) COLOURED(upperColorR, upperColorG, upperColorB)ENDIFIF crossDn THENDRAWARROWDOWN(barindex, ma) COLOURED(downColorR, downColorG, downColorB)ENDIF// --- Plot the score ---if islastbarupdate thenupPercent=round(score*100,0)dnPercent=100-upPercentdrawrectangle(-130,110,-137,110+upPercent)anchor(bottomright,xshift,yshift)fillcolor(upperColorR, upperColorG, upperColorB, alpha)drawtext("#upPercent#",-134,120+upPercent)anchor(bottomright,xshift,yshift)drawrectangle(-110,110,-117,110+dnPercent)anchor(bottomright,xshift,yshift)fillcolor(downColorR, downColorG, downColorB, alpha)drawtext("#dnPercent#",-114,120+dnPercent)anchor(bottomright,xshift,yshift)drawrectangle(-155,100,-100,max(120+dnPercent,120+uppercent)+20)anchor(bottomright,xshift,yshift)endif//----------------------------------------------------RETURN ma COLOURED(colorR, colorG, colorB, alpha) AS "Multi DSMA Avg" STYLE(Line, 2) // Style 2 for slightly thicker line -
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
