Compare commits

...

1 Commits

Author SHA1 Message Date
Pietro Giacobazzi ef3b2b668c PaPP v2 indicatore: pannello mostra anche Volatilita' (ATR%) e Accelerazione (pendenza mediana + espansione cluster su 5 barre D1)
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-06-17 06:44:14 +00:00
+42 -5
View File
@@ -15,6 +15,7 @@ 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 pendenza/accelerazione
double Buff_Median[];
double B0[],B1[],B2[],B3[],B4[],B5[],B6[];
@@ -22,6 +23,7 @@ double B0[],B1[],B2[],B3[],B4[],B5[],B6[];
int gDays[7] = {365,182,121,30,14,7,3};
color gCol[7] = {clrDodgerBlue,clrDeepSkyBlue,clrTurquoise,clrLimeGreen,clrOrange,clrTomato,clrRed};
int hMA[7];
int hATR = INVALID_HANDLE;
int bars[7];
string _pfx = "PM_"; // oggetti pannello
string _pfx2 = "PME_"; // etichette a fine linea
@@ -80,6 +82,8 @@ int OnInit()
hMA[i] = iMA(_Symbol,ANCHOR_TF,bars[i],0,MODE_SMA,PRICE_CLOSE);
if(hMA[i]==INVALID_HANDLE) return INIT_FAILED;
}
hATR = iATR(_Symbol,ANCHOR_TF,14);
if(hATR==INVALID_HANDLE) return INIT_FAILED;
SetIndexBuffer(0,Buff_Median,INDICATOR_DATA);
SetIndexBuffer(1,B0,INDICATOR_DATA);
@@ -120,6 +124,7 @@ int OnInit()
void OnDeinit(const int reason)
{
for(int i=0;i<7;i++) if(hMA[i]!=INVALID_HANDLE) IndicatorRelease(hMA[i]);
if(hATR!=INVALID_HANDLE) IndicatorRelease(hATR);
ObjectsDeleteAll(0,_pfx);
ObjectsDeleteAll(0,_pfx2);
}
@@ -134,6 +139,27 @@ double GetMA(int m,int d1shift)
return 0;
}
//+------------------------------------------------------------------+
// ATR D1 (volatilita') alla barra d1shift
double GetATR(int d1shift)
{
if(d1shift<0) return 0;
double b[1];
if(CopyBuffer(hATR,0,d1shift,1,b)==1) return b[0];
return 0;
}
//+------------------------------------------------------------------+
// dispersione media delle 7 MA dalla mediana (%) alla barra d1shift
double ClusterAtD1(int d1shift)
{
double md = MedianAtD1(d1shift);
if(md<=0) return 0;
double ds=0; int dc=0;
for(int m=0;m<7;m++) { double v=GetMA(m,d1shift); if(v>0) { ds+=MathAbs(v-md)/md*100; dc++; } }
return (dc>0)?ds/dc:0;
}
//+------------------------------------------------------------------+
double Median(double &a[],int n)
{
@@ -298,11 +324,22 @@ 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;
//--- Dispersione MA e bande (info)
double ds=0; int dc=0;
for(int m=0;m<7;m++) { double v=GetMA(m,1); if(v>0) { 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;
//--- Cluster (dispersione media delle MA dalla mediana)
double vol = ClusterAtD1(1);
Lbl("V","Cluster +/-"+DoubleToString(vol,3)+"%",x,y,FontSize,clrGray,false); y+=lh;
//--- Volatilita' (ATR D1 in % del prezzo)
double atrv = GetATR(1);
double atrPct = (atrv>0)?atrv/median*100:0;
Lbl("VOL","Volatilita' ATR: "+DoubleToString(atrPct,3)+"%",x,y,FontSize,clrAqua,false); y+=lh;
//--- Accelerazione su KSLOPE barre D1: pendenza mediana + espansione cluster
double medK = MedianAtD1(1+KSLOPE);
double slope = (medK>0)?(median-medK)/medK*100:0;
double clExp = vol - ClusterAtD1(1+KSLOPE);
color accC = (slope>0)?clrLimeGreen:clrTomato;
Lbl("ACC",StringFormat("Accel %dg: med %+.3f%% | cluster %+.3f%%",KSLOPE,slope,clExp),
x,y,FontSize,accC,false); y+=lh+2;
//--- Valori delle 7 MA (giorni : valore) con colore = linea
for(int m=0;m<7;m++)