Plutôt que d’ouvrir plein de topics pour la conversion d’indicateurs (comme j’ai déjà fait :o)), je préfère créer un thread ici pour centraliser les indicateurs que j’aimerais convertir sous PRT.
Merci d’avance à tous pour votre aide!
Du code MT4 pour un filtre Kalman de Jurik
double jkalman(int index,double price,int len,int bar)
{
double alpha = (Phase*Order)/(len + Phase*Order-1);
double beta = 1 - alpha;
if(jk_prevtime[index] != Time[bar])
{
for(int k=0;k<2*Order;k++) jk_tmp[k][index][1] = jk_tmp[k][index][0];
jk_prevtime[index] = Time[bar];
}
if(bar==Bars-2)
{
ArrayInitialize(jk_tmp,price);
}
for(k=0;k<Order;k++)
{
int j=2*k;
jk_tmp[j][index][0] = beta*jk_tmp[j][index][1] + alpha*price;
jk_tmp[j+1][index][0] = beta*jk_tmp[j+1][index][1] + alpha*jk_tmp[j][index][0];
price = jk_tmp[j][index][0] + Amplitude *(jk_tmp[j][index][0] - jk_tmp[j+1][index][0]);
}
return(price);
}
Du code MultiCharts (pareil que Tradestation) pour un Filtre Médian
// MF - Median Filter by John Ehlers
// Series
// Len
MF = Median(Series, 2 * Len + 1);
RETURN MF
Et un autre filtre Median d’Ehlers
// MMADF - Median-MA Difference Filter by John Ehlers
Inputs:
Series ( NumericSeries ),
Len ( NumericSimple ),
Threshold ( NumericSimple );
Variables:
Alpha ( 0 ),
Length ( 0 ),
Smooth ( 0 );
Length = Len;
Smooth = (Series + 2 * Series[1] + 2 * Series[2] + Series[3]) / 6;
Value3 = 1;
while Value3 > Threshold
begin
Alpha = 2 / (Length + 1);
Value1 = Median(Smooth, Length);
Value2 = Alpha * Smooth + (1 - Alpha) * Value2[1];
if Value1 <> 0 then
Value3 = AbsValue(Value1 - Value2) / Value1;
Length = Length - 2;
end;
if Length < 3 then
Length = 3;
Alpha = 2 / (Length + 1);
if CurrentBar < 4 then
MMADF = Series
else
MMADF = Alpha * Smooth + (1 - Alpha) * MMADF[1];
Un autre filtre d’Ehlers!
// DCEF - Distance Coefficient Ehlers Filter by John Ehlers
Inputs:
Series ( NumericSeries ),
Len ( NumericSimple );
Variables:
j ( 0 ),
Smooth ( 0 ),
LookBack ( 0 ),
Num ( 0 ),
SumCoef ( 0 );
Array:
Coef[50](0),
Distance2[50](0);
Smooth = (Series + 2 * Series[1] + 2 * Series[2] + Series[3]) / 6;
for j = 0 to Len - 1
begin
Distance2[j] = 0;
for Lookback = 1 to Len-1
begin
Distance2[j] = Distance2[j] + (Smooth[j] - Smooth[j + Lookback]) * (Smooth[j] - Smooth[j + Lookback]);
end;
Coef[j] = Distance2[j];
end;
Num = 0;
SumCoef = 0;
for j = 0 to Len - 1
begin
Num = Num + Coef[j] * Smooth[j];
SumCoef = Sumcoef + Coef[j];
end;
if SumCoef <> 0 then
DCEF = Num / SumCoef
else
DCEF = Series;
C’est déjà pas mal pour le moment :o)
Ces indicateurs te sont utiles pour quelles applications stp ? Des exemples d’utilisations peut être ? Merci.
jkalman = Un filtre Kalman fait par Jurik. Tu peux t’en servir comme filtre sur les prix et ça te fait une moyenne mobile super réactive et lisse. C’est sûrement un des meilleurs filtres (un peu comme jsmooth).
Le filtre médian, c’est pas trop utile en tant que tel, mais c’est utilisé par d’autres filtres comme le Median-MA Difference Filter de John Ehlers. Un lien pour avoir une idée d’à quoi ça ressemble http://www.stockspotter.com/Files/whatsthedifference.pdf
Ca peut servir de filtre encore une fois, de moyenne mobile et de STOP 😉
Même genre pour DCEF, https://www.mesasoftware.com/papers/EhlersFilters.pdf
Dans le genre sexy de chez sexy qui peut s’utiliser pour lisser des prix, des filtres Butterworth, Bessel, Critically Damped de 1 à 5 pôles :
http://unicorn.us.com/trading/src/_filter2pole.txt
A traduire de TradeStation. A mon avis ça doit être vraiment sympa 🙂
J’ai trouvé 2 versions du filtre Kalman sur le blog de HK-Lisse, les voici:
///////////// Kalman Filter ///////////////////
pr=medianprice
once pred=pr
if barindex>0 then
dk=pr-pred
smooth=pred+dk*SQRT((gain/10000)*2)
velo=velo+((gain/10000)*dk)
pred=smooth+velo
kf=pred
endif
return kf
////////////// Kalman version Ehlers ///////////////////
prix=totalprice
once kil=prix
if barindex>4 then
kil=.33*(prix+.5*(prix-prix[3]))+.67*kil[1]
endif
return kil
Quelques indicateurs du jour 😀
Double smoothed EMA
Je suppose que ça doit être une DEMA plus lisse.
double workDsema[][_maWorkBufferx2];
#define _ema1 0
#define _ema2 1
double iDsema(double price, double period, int r, int instanceNo=0)
{
if (ArraySize(workDsema)!= Bars) ArrayResize(workDsema,Bars); instanceNo*=2;
double alpha = 2.0 /(1.0+MathSqrt(period));
workDsema[r][_ema1+instanceNo] = workDsema[r-1][_ema1+instanceNo]+alpha*(price -workDsema[r-1][_ema1+instanceNo]);
workDsema[r][_ema2+instanceNo] = workDsema[r-1][_ema2+instanceNo]+alpha*(workDsema[r][_ema1+instanceNo]-workDsema[r-1][_ema2+instanceNo]);
return(workDsema[r][_ema2+instanceNo]);
}
Smoothed MA
Une simple MA plus lisse?
double workSmma[][_maWorkBufferx1];
double iSmma(double price, double period, int r, int instanceNo=0)
{
if (ArrayRange(workSmma,0)!= Bars) ArrayResize(workSmma,Bars);
if (r<period)
workSmma[r][instanceNo] = price;
else workSmma[r][instanceNo] = workSmma[r-1][instanceNo]+(price-workSmma[r-1][instanceNo])/period;
return(workSmma[r][instanceNo]);
}
Parabolic weighted MA
/
double workLwmp[][_maWorkBufferx1];
double iLwmp(double price, double period, int r, int instanceNo=0)
{
if (ArraySize(workLwmp)!= Bars) ArrayResize(workLwmp,Bars);
workLwmp[r][instanceNo] = price;
double sumw = period*period;
double sum = sumw*price;
for(int k=1; k<period && (r-k)>=0; k++)
{
double weight = (period-k)*(period-k);
sumw += weight;
sum += weight*workLwmp[r-k][instanceNo];
}
return(sum/sumw);
}
Une zéro lag que je ne connais pas!
double workZl[][_maWorkBufferx2];
#define _price 0
#define _zlema 1
double iZeroLag(double price, double length, int r, int instanceNo=0)
{
if (ArrayRange(workZl,0)!=Bars) ArrayResize(workZl,Bars); instanceNo *= 2;
//
//
//
//
//
double alpha = 2.0/(1.0+length);
int per = (length-1.0)/2.0;
workZl[r][_price+instanceNo] = price;
if (r<per)
workZl[r][_zlema+instanceNo] = price;
else workZl[r][_zlema+instanceNo] = workZl[r-1][_zlema+instanceNo]+alpha*(2.0*price-workZl[r-per][_price+instanceNo]-workZl[r-1][_zlema+instanceNo]);
return(workZl[r][_zlema+instanceNo]);
}
Moyenne Mobile Leader
double workLeader[][_maWorkBufferx2];
double iLeader(double price, double period, int r, int instanceNo=0)
{
if (ArrayRange(workLeader,0)!= Bars) ArrayResize(workLeader,Bars); instanceNo*=2;
period = MathMax(period,1);
double alpha = 2.0/(period+1.0);
workLeader[r][instanceNo ] = workLeader[r-1][instanceNo ]+alpha*(price -workLeader[r-1][instanceNo ]);
workLeader[r][instanceNo+1] = workLeader[r-1][instanceNo+1]+alpha*(price-workLeader[r][instanceNo]-workLeader[r-1][instanceNo+1]);
return(workLeader[r][instanceNo]+workLeader[r][instanceNo+1]);
}
Comment on traduirait instanceNo+instanceNo+1? C’est le temps? le prix? Une autre variable?
J’ai du mal à voir.
C’est un truc dans le genre?
double alpha = 2.0/(period+1.0)
i1 = i1[1] + alpha * (price – i1[1])
i2 = i2[1] + alpha * (price – i1 – i2[1])
return i1 + i2
?
Smoothed Simple Moving Average
Voilà j’ai tenté la conversion 😉
// --- parameters
Series = CustomClose
// Period = 20
// ---
IF BarIndex < Period THEN
SMMA = Series
ELSE
SMMA = SMMA[1] + (Series - SMMA[1]) / Period
ENDIF
RETURN SMMA
Leader Exponential Moving Average
J’ai tenté la conversion 😉
//-----------------------------------//
// Leader Exponential Moving Average //
//-----------------------------------//
// --- parameters
Series = CustomClose
// Period = 20
// ---
Period = MAX(Period, 1)
IF BarIndex <= Period THEN
p1 = Series
p2 = Series
ELSE
alpha = 2 / (Period + 1)
p1 = p1[1] + alpha * (Series - p1[1])
p2 = p2[1] + alpha * (Series - p1 - p2[1])
ENDIF
LEMA = p1 + p2
RETURN LEMA