From cf3525f7afe4f05edd50b679b87c847bad9bda05 Mon Sep 17 00:00:00 2001 From: Pietro Giacobazzi Date: Wed, 17 Jun 2026 06:51:00 +0000 Subject: [PATCH 1/3] PaPP v2 indicatore: pannello con Velocita'/Accelerazione/Volatilita' = mediana delle 7 scale (dalle nostre MA, no ATR MT5) Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- PaPP v2/PaPP_Median.mq5 | 57 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/PaPP v2/PaPP_Median.mq5 b/PaPP v2/PaPP_Median.mq5 index cef4aa6..cb922c5 100644 --- a/PaPP v2/PaPP_Median.mq5 +++ b/PaPP v2/PaPP_Median.mq5 @@ -15,6 +15,8 @@ input bool Smooth = true; // interpola tra i valori D1 -> linea morbida input bool ShowMA = true; // mostra anche le 7 MA (oltre alla mediana) #define ANCHOR_TF PERIOD_D1 // calcolo ancorato a D1: linea identica su ogni TF +#define KSLOPE 5 // barre D1 per velocita'/accelerazione +#define NVOL 14 // barre D1 per la volatilita' double Buff_Median[]; double B0[],B1[],B2[],B3[],B4[],B5[],B6[]; @@ -154,6 +156,49 @@ double MedianAtD1(int d1shift) return Median(vals,cnt); } +//+------------------------------------------------------------------+ +// valore valido = positivo e finito (esclude EMPTY_VALUE di warmup) +bool IsVal(double v) { return (v>0.0 && v<1.0e12); } + +//+------------------------------------------------------------------+ +// mediana dei primi c valori di src +double MedArr(double &src[],int c) + { + if(c<=0) return 0; + double a[]; ArrayResize(a,c); + for(int j=0;j=2) + { + double mean=0; for(int j=0;j0) { ds+=MathAbs(v-median)/median*100; dc++; } } - double vol = (dc>0)?ds/dc:0; - Lbl("V","Cluster +/-"+DoubleToString(vol,3)+"%",x,y,FontSize,clrGray,false); y+=lh+2; + double clu = (dc>0)?ds/dc:0; + Lbl("V","Cluster +/-"+DoubleToString(clu,3)+"%",x,y,FontSize,clrGray,false); y+=lh; + + //--- Velocita'/Accelerazione/Volatilita' = mediana delle 7 scale (dalle nostre MA) + double velo,acc,volat; ScaleMetrics(velo,acc,volat); + Lbl("VEL",StringFormat("Velocita' %dg: %+.3f%%",KSLOPE,velo),x,y,FontSize,(velo>0)?clrLimeGreen:clrTomato,false); y+=lh; + Lbl("ACC",StringFormat("Accel %dg: %+.4f%%",KSLOPE,acc),x,y,FontSize,(acc>0)?clrLimeGreen:clrTomato,false); y+=lh; + Lbl("VOL",StringFormat("Volatilita' %dg: %.4f%%",NVOL,volat),x,y,FontSize,clrAqua,false); y+=lh+2; //--- Valori delle 7 MA (giorni : valore) con colore = linea for(int m=0;m<7;m++) From a1023b573ef0eba41cf2db24fd4fff625389df37 Mon Sep 17 00:00:00 2001 From: Pietro Giacobazzi Date: Wed, 17 Jun 2026 06:53:56 +0000 Subject: [PATCH 2/3] PaPP v2 indicatore: Cluster contestualizzato con percentile storico (stretto/normale/largo) + valore tipico Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- PaPP v2/PaPP_Median.mq5 | 45 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/PaPP v2/PaPP_Median.mq5 b/PaPP v2/PaPP_Median.mq5 index cb922c5..39d515d 100644 --- a/PaPP v2/PaPP_Median.mq5 +++ b/PaPP v2/PaPP_Median.mq5 @@ -17,6 +17,7 @@ input bool ShowMA = true; // mostra anche le 7 MA (oltre alla mediana) #define ANCHOR_TF PERIOD_D1 // calcolo ancorato a D1: linea identica su ogni TF #define KSLOPE 5 // barre D1 per velocita'/accelerazione #define NVOL 14 // barre D1 per la volatilita' +#define CLWIN 252 // finestra D1 (~1 anno) per il percentile del cluster double Buff_Median[]; double B0[],B1[],B2[],B3[],B4[],B5[],B6[]; @@ -25,6 +26,7 @@ int gDays[7] = {365,182,121,30,14,7,3}; color gCol[7] = {clrDodgerBlue,clrDeepSkyBlue,clrTurquoise,clrLimeGreen,clrOrange,clrTomato,clrRed}; int hMA[7]; int bars[7]; +struct PBuf { double v[]; }; // buffer dinamico per copiare una MA string _pfx = "PM_"; // oggetti pannello string _pfx2 = "PME_"; // etichette a fine linea @@ -199,6 +201,38 @@ void ScaleMetrics(double &velo,double &acc,double &vol) velo=MedArr(va,cv); acc=MedArr(aa,ca); vol=MedArr(wa,cw); } +//+------------------------------------------------------------------+ +// Contestualizza il cluster: percentile dell'ampiezza attuale sugli ultimi 'win' giorni D1 +// cur = cluster oggi, pctl = posizione 0..1 nella storia, typ = ampiezza tipica (mediana storica) +void ClusterStats(int win,double &cur,double &pctl,double &typ) + { + cur=0; pctl=0.5; typ=0; + int need=win+1; + PBuf mb[7]; + for(int m=0;m<7;m++) + { + ArraySetAsSeries(mb[m].v,true); + if(CopyBuffer(hMA[m],0,0,need,mb[m].v)!=need) return; + } + double cl[]; int cc=0; ArrayResize(cl,win); + for(int j=1;j<=win;j++) + { + double vals[7]; int vc=0; + for(int m=0;m<7;m++){ double v=mb[m].v[j]; if(IsVal(v)) vals[vc++]=v; } + if(vc<2) continue; + double md=MedArr(vals,vc); + if(md<=0) continue; + double ds=0; + for(int m=0;m0) { ds+=MathAbs(v-median)/median*100; dc++; } } - double clu = (dc>0)?ds/dc:0; - Lbl("V","Cluster +/-"+DoubleToString(clu,3)+"%",x,y,FontSize,clrGray,false); y+=lh; + //--- Cluster contestualizzato: valore + percentile storico (stretto/normale/largo) + double clu_cur,clu_pctl,clu_typ; ClusterStats(CLWIN,clu_cur,clu_pctl,clu_typ); + string clab = (clu_pctl<0.33)?"stretto":((clu_pctl>0.66)?"largo":"normale"); + color cclr = (clu_pctl<0.33)?clrLimeGreen:((clu_pctl>0.66)?clrTomato:clrSilver); + Lbl("V",StringFormat("Cluster %.3f%% P%.0f %s (tip %.3f%%)",clu_cur,clu_pctl*100,clab,clu_typ), + x,y,FontSize,cclr,false); y+=lh; //--- Velocita'/Accelerazione/Volatilita' = mediana delle 7 scale (dalle nostre MA) double velo,acc,volat; ScaleMetrics(velo,acc,volat); From b0012bf2fd8c5f4de53585b466d7122a6a25b6df Mon Sep 17 00:00:00 2001 From: Pietro Giacobazzi Date: Wed, 17 Jun 2026 06:56:47 +0000 Subject: [PATCH 3/3] PaPP v2 indicatore: descrizione a parole (percentile storico) per Cluster/Velocita'/Accelerazione/Volatilita' Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- PaPP v2/PaPP_Median.mq5 | 144 +++++++++++++++++++++++++++------------- 1 file changed, 97 insertions(+), 47 deletions(-) diff --git a/PaPP v2/PaPP_Median.mq5 b/PaPP v2/PaPP_Median.mq5 index 39d515d..981f552 100644 --- a/PaPP v2/PaPP_Median.mq5 +++ b/PaPP v2/PaPP_Median.mq5 @@ -175,62 +175,107 @@ double MedArr(double &src[],int c) } //+------------------------------------------------------------------+ -// Velocita'/accelerazione/volatilita' = mediana delle 7 scale (dalle nostre MA, no ATR) -void ScaleMetrics(double &velo,double &acc,double &vol) +// Metriche a una specifica barra D1 (j), calcolate sui buffer gia' copiati mb[7] +double ClusterAtJ(PBuf &mb[],int j) { - velo=0; acc=0; vol=0; - int need = MathMax(1+2*KSLOPE,1+NVOL)+1; - double va[7],aa[7],wa[7]; int cv=0,ca=0,cw=0; + double v[7]; int c=0; + for(int m=0;m<7;m++){ double x=mb[m].v[j]; if(IsVal(x)) v[c++]=x; } + if(c<2) return 0; + double md=MedArr(v,c); if(md<=0) return 0; + double ds=0; for(int m=0;m=2) { - double mean=0; for(int j=0;j0) cA[cc++]=cv; + vA[vc++]=MathAbs(VelAtJ(mb,j,KSLOPE)); + aA[ac++]=MathAbs(AccAtJ(mb,j,KSLOPE)); + double ov=VolAtJ(mb,j,NVOL); if(ov>0) oA[oc++]=ov; } - if(cc<=0) return; - cur=cl[0]; // j=1 = ultima barra D1 chiusa - typ=MedArr(cl,cc); - int below=0; for(int k=0;k0?up:down)+" "+forza; } //+------------------------------------------------------------------+ @@ -377,18 +422,23 @@ void DrawInfo() Lbl("M","Median: "+DoubleToString(median,_Digits),x,y,FontSize,clrGold,false); y+=lh; Lbl("D","Dist: "+distS,x,y,FontSize,distC,true); y+=lh+2; - //--- Cluster contestualizzato: valore + percentile storico (stretto/normale/largo) - double clu_cur,clu_pctl,clu_typ; ClusterStats(CLWIN,clu_cur,clu_pctl,clu_typ); - string clab = (clu_pctl<0.33)?"stretto":((clu_pctl>0.66)?"largo":"normale"); - color cclr = (clu_pctl<0.33)?clrLimeGreen:((clu_pctl>0.66)?clrTomato:clrSilver); - Lbl("V",StringFormat("Cluster %.3f%% P%.0f %s (tip %.3f%%)",clu_cur,clu_pctl*100,clab,clu_typ), - x,y,FontSize,cclr,false); y+=lh; + //--- Cluster/Velocita'/Accelerazione/Volatilita' con percentile storico + descrizione a parole + double cluCur,cluPct,velCur,velPct,accCur,accPct,volCur,volPct; + AllMetrics(CLWIN,cluCur,cluPct,velCur,velPct,accCur,accPct,volCur,volPct); - //--- Velocita'/Accelerazione/Volatilita' = mediana delle 7 scale (dalle nostre MA) - double velo,acc,volat; ScaleMetrics(velo,acc,volat); - Lbl("VEL",StringFormat("Velocita' %dg: %+.3f%%",KSLOPE,velo),x,y,FontSize,(velo>0)?clrLimeGreen:clrTomato,false); y+=lh; - Lbl("ACC",StringFormat("Accel %dg: %+.4f%%",KSLOPE,acc),x,y,FontSize,(acc>0)?clrLimeGreen:clrTomato,false); y+=lh; - Lbl("VOL",StringFormat("Volatilita' %dg: %.4f%%",NVOL,volat),x,y,FontSize,clrAqua,false); y+=lh+2; + string cluTxt = MagWord(cluPct,"molto stretto","stretto","normale","largo","molto largo"); + color cluC = (cluPct<0.40)?clrLimeGreen:((cluPct>0.60)?clrTomato:clrSilver); + Lbl("V",StringFormat("Cluster %.3f%% - %s (P%.0f)",cluCur,cluTxt,cluPct*100),x,y,FontSize,cluC,false); y+=lh; + + string velTxt = DirWord(velCur,velPct,"in salita","in discesa","quasi piatta"); + Lbl("VEL",StringFormat("Velocita' %+.3f%% - %s",velCur,velTxt),x,y,FontSize,(velCur>0)?clrLimeGreen:clrTomato,false); y+=lh; + + string accTxt = DirWord(accCur,accPct,"in accelerazione","in decelerazione","stabile"); + Lbl("ACC",StringFormat("Accel %+.4f%% - %s",accCur,accTxt),x,y,FontSize,(accCur>0)?clrLimeGreen:clrTomato,false); y+=lh; + + string volTxt = MagWord(volPct,"molto bassa","bassa","normale","alta","molto alta"); + color volC = (volPct<0.40)?clrLimeGreen:((volPct>0.60)?clrTomato:clrAqua); + Lbl("VOL",StringFormat("Volatilita' %.4f%% - %s (P%.0f)",volCur,volTxt,volPct*100),x,y,FontSize,volC,false); y+=lh+2; //--- Valori delle 7 MA (giorni : valore) con colore = linea for(int m=0;m<7;m++)