Convert to ProCODE
{
MAD (Moving Average Difference) Indicator
(C) 2021 John F. Ehlers
}
Inputs:
ShortLength(8),
LongLength(23);
Vars:
MAD(0);
MAD = 100*(Average(Close, ShortLength) - Average(Close, LongLength)) / Average(Close, LongLength);
Plot1(MAD, "", red, 4, 4);
Plot2(0,"", white, 1, 1);
Ok lo farò, ma per favore la prossima volta aggiungi una descrizione completa e uno screenshot del codice originale, mi aiuta molto e velocizza il processo di conversione! Questo codice è probabilmente una normalizzazione di un MACD.
Ecco il codice tradotto e compatibile con ProRealTime per "Moving Average Difference Indicator – J. Ehlers"
ShortLength=8
LongLength=23
MAD = 100*(Average[ShortLength] - Average[LongLength]) / Average[LongLength]
RETURN MAD coloured(255,0,0) style(line,4), 0
ok, grazie mille davvero! ti invio anche l’evoluzione di questo codice che si chiama MADH
{
MADH (Moving Average Difference - Hann) Indicator
(C) 2021 John F. Ehlers
}
Inputs:
ShortLength(8),
DominantCycle(27);
Vars:
LongLength(20),
Filt1(0),
Filt2(0),
coef(0),
count(0),
MADH(0);
LongLength = IntPortion(ShortLength + DominantCycle / 2);
Filt1 = 0;
coef = 0;
For count = 1 to ShortLength Begin
Filt1 = Filt1 + (1 - Cosine(360*count / (ShortLength + 1)))*Close[count - 1];
coef = coef + (1 - Cosine(360*count / (ShortLength + 1)));
End;
If coef <> 0 Then Filt1 = Filt1 / coef;
Filt2 = 0;
coef = 0;
For count = 1 to LongLength Begin
Filt2 = Filt2 + (1 - Cosine(360*count / (LongLength + 1)))*Close[count - 1];
coef = coef + (1 - Cosine(360*count / (LongLength + 1)));
End;
If coef <> 0 Then Filt2 = Filt2 / coef;
//Computed as percentage of price
If Filt2 <> 0 Then MADH = 100*(Filt1 - Filt2) / Filt2;
Plot1(MADH, "", yellow, 4, 4);
Plot2(0, "", white, 1, 1);
Eccolo:
// MADH indicator
//
// (MAD Enhanced by John Ehlers)
//
// https://www.tradingview.com/script/vraaRpAA-TASC-2021-11-MADH-Moving-Average-Difference-Hann/
//
Source = close
ShortLen = 8
DomCycle = 27
LongLen = round((DomCycle * 0.5) + ShortLen)
PI = 3.14159//26535897932
PIx2LongLen = PI * 2.0 / (LongLen + 1)
PIx2ShortLen = PI * 2.0 / (ShortLen + 1)
filt1 = 0
coefs = 0
FOR count = 1 TO ShortLen
coefHann = 1 - cos(count * PIx2ShortLen)
filt1 = filt1 + (coefHann * source[count - 1])
coefs = coefs + coefHann
NEXT
filt1 = filt1 / coefs
filt2 = 0
coefs = 0
FOR count = 1 TO LongLen
coefHann = 1 - cos(count * PIx2LongLen)
filt2 = filt2 + (coefHann * source[count - 1])
coefs = coefs + coefHann
NEXT
filt2 = filt2 / coefs
MadH = (filt1 - filt2) / filt2 * 100
RETURN MadH AS "MADH"