Compare commits

...

8 Commits

Author SHA1 Message Date
Pietro Giacobazzi f930e88592 PaPP v2 export: aggiunta traiettoria forward bar-by-bar (cret_1..20) per studiare lo sviluppo dopo l'incrocio
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-06-17 06:26:03 +00:00
Pietro Giacobazzi 908d0e9187 PaPP v2 export: scarta i valori EMPTY (DBL_MAX) di warmup; esporta solo barre con tutte le 7 MA valide
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-06-16 20:22:24 +00:00
Pietro Giacobazzi 8e6fe91b70 PaPP v2 export: fix compile (array MA 2D non valido in MQL5 -> struct MABuf)
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-06-16 20:15:53 +00:00
Pietro Giacobazzi a6f6c0510b PaPP v2: script export CSV degli incroci (ancorato a D1, intervallo date o tutto lo storico, feature + esiti 1/3/5/10/20g)
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-06-16 20:12:09 +00:00
Pietro Giacobazzi f1d1a2230f PaPP v2 indicatore: etichette a fine linea (nome MA/Mediana, colore=linea) + legenda pannello con colori delle linee
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-06-16 19:36:32 +00:00
Pietro Giacobazzi b79cf56412 PaPP v2 indicatore: label 'Median:' da bianco a oro (era invisibile su sfondo bianco)
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-06-16 19:31:06 +00:00
Pietro Giacobazzi 392706088a PaPP v2 indicatore: disegna anche le 7 MA come linee separate (input ShowMA)
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-06-16 19:24:36 +00:00
Pietro Giacobazzi f2515243e3 PaPP v2 indicatore: fix linea invisibile - attende dati D1, bulk load + cache mediana, ricalcolo robusto
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-06-16 19:19:33 +00:00
2 changed files with 436 additions and 28 deletions
+241
View File
@@ -0,0 +1,241 @@
//+------------------------------------------------------------------+
//| PaPP_CrossExport.mq5 |
//| PaPP v2 |
//| Esporta in CSV TUTTI gli incroci tra le 9 linee (prezzo+Mediana |
//| +7 MA), calcolati ANCORATI a D1 (come l'indicatore), con il |
//| contesto di ogni incrocio e gli esiti futuri a 1/3/5/10/20 g. |
//| Si puo' esportare un intervallo di date oppure tutto lo storico. |
//+------------------------------------------------------------------+
#property copyright "PaPP v2"
#property version "1.00"
#property script_show_inputs
//--- input
input string InpSymbol = ""; // simbolo ("" = simbolo del grafico)
input bool InpAllHistory = true; // true = tutto lo storico D1
input datetime InpStart = D'2010.01.01'; // inizio intervallo (se AllHistory=false)
input datetime InpEnd = D'2100.01.01'; // fine intervallo (se AllHistory=false)
input string InpFileName = ""; // nome file ("" = automatico)
//--- costanti (stesse 7 MA dell'indicatore)
#define ANCHOR_TF PERIOD_D1
#define NSER 9 // PRICE, MED, MA365..MA3
#define KSLOPE 5 // barre per pendenza / variazione cluster
#define MAXH 20 // orizzonte massimo per gli esiti
int gDays[7] = {365,182,121,30,14,7,3};
string SER[NSER]= {"PRICE","MED","MA365","MA182","MA121","MA30","MA14","MA7","MA3"};
int gHor[5] = {1,3,5,10,20};
//--- contenitore per un buffer MA dinamico (MQL5 non permette double ma[7][])
struct MABuf { double v[]; };
//+------------------------------------------------------------------+
int TimeToBarsD1(string sym,int d)
{
datetime n = TimeCurrent();
if(n==0) return MathMax(1,(int)((long)d*86400L/PeriodSeconds(ANCHOR_TF)));
return MathMax(1,Bars(sym,ANCHOR_TF,n-(long)d*86400,n));
}
//+------------------------------------------------------------------+
// valore valido = positivo e finito (MT5 usa EMPTY_VALUE=DBL_MAX nei warmup)
bool IsVal(double v) { return (v>0.0 && v<1.0e12); }
//+------------------------------------------------------------------+
double Median7(double &v[]) // mediana dei valori validi in v[0..6]
{
double a[]; int c=0; ArrayResize(a,7);
for(int m=0;m<7;m++) if(IsVal(v[m])) { a[c]=v[m]; c++; }
if(c==0) return 0;
ArrayResize(a,c); ArraySort(a);
if((c&1)==1) return a[c/2];
return 0.5*(a[c/2-1]+a[c/2]);
}
//+------------------------------------------------------------------+
void OnStart()
{
string sym = (InpSymbol=="") ? _Symbol : InpSymbol;
if(!SymbolSelect(sym,true)) { Print("Simbolo non valido: ",sym); return; }
int digits = (int)SymbolInfoInteger(sym,SYMBOL_DIGITS);
//--- handle delle 7 MA su D1 + ATR
int hMA[7];
for(int m=0;m<7;m++)
{
int per = TimeToBarsD1(sym,gDays[m]);
hMA[m] = iMA(sym,ANCHOR_TF,per,0,MODE_SMA,PRICE_CLOSE);
if(hMA[m]==INVALID_HANDLE) { Print("iMA fallita m=",m); return; }
}
int hATR = iATR(sym,ANCHOR_TF,14);
if(hATR==INVALID_HANDLE) { Print("iATR fallita"); return; }
//--- attendo che lo storico D1 sia pronto
int total=0;
for(int t=0; t<100; t++)
{
total = Bars(sym,ANCHOR_TF);
bool ok = (total>MAXH+KSLOPE+50);
for(int m=0;m<7 && ok;m++) if(BarsCalculated(hMA[m])<total) ok=false;
if(ok && BarsCalculated(hATR)>=total) break;
Sleep(100);
}
total = Bars(sym,ANCHOR_TF);
if(total<=MAXH+KSLOPE+50) { Print("Storico D1 insufficiente: ",total," barre"); return; }
//--- carico tutta la storia D1 (indice 0 = piu' vecchio)
datetime tm[]; double cl[],hi[],lo[],atr[];
MABuf ma[7];
ArraySetAsSeries(tm,false); ArraySetAsSeries(cl,false);
ArraySetAsSeries(hi,false); ArraySetAsSeries(lo,false);
ArraySetAsSeries(atr,false);
if(CopyTime(sym,ANCHOR_TF,0,total,tm)<=0) { Print("CopyTime KO"); return; }
if(CopyClose(sym,ANCHOR_TF,0,total,cl)<=0) { Print("CopyClose KO"); return; }
if(CopyHigh(sym,ANCHOR_TF,0,total,hi)<=0) { Print("CopyHigh KO"); return; }
if(CopyLow(sym,ANCHOR_TF,0,total,lo)<=0) { Print("CopyLow KO"); return; }
if(CopyBuffer(hATR,0,0,total,atr)<=0) { Print("CopyATR KO"); return; }
for(int m=0;m<7;m++)
{
ArraySetAsSeries(ma[m].v,false);
if(CopyBuffer(hMA[m],0,0,total,ma[m].v)<=0) { Print("CopyBuffer MA KO m=",m); return; }
}
int n = ArraySize(cl);
//--- costruisco le 9 serie allineate per barra: S[i][k]
double S[][NSER];
ArrayResize(S,n);
for(int i=0;i<n;i++)
{
double mv[7];
for(int m=0;m<7;m++) mv[m] = ma[m].v[i];
S[i][0] = cl[i]; // PRICE
S[i][1] = Median7(mv); // MED
for(int m=0;m<7;m++) S[i][2+m] = mv[m]; // MA365..MA3
}
//--- intervallo di scansione (eventi)
datetime from = InpAllHistory ? 0 : InpStart;
datetime to = InpAllHistory ? TimeCurrent(): InpEnd;
int iStart = KSLOPE+1, iEnd = n-1;
for(int i=KSLOPE+1;i<n;i++) if(tm[i]>=from) { iStart=i; break; }
for(int i=n-1;i>=0;i--) if(tm[i]<=to) { iEnd=i; break; }
//--- apro il file CSV
string fname = (InpFileName=="") ? ("PaPP_crosses_"+sym+"_D1.csv") : InpFileName;
int fh = FileOpen(fname,FILE_WRITE|FILE_TXT|FILE_ANSI);
if(fh==INVALID_HANDLE) { Print("FileOpen KO: ",fname," err=",GetLastError()); return; }
//--- header
string head = "time,symbol,pair,a,b,dir,price,med,ma365,ma182,ma121,ma30,ma14,ma7,ma3,"
"dist_med_pct,cluster_pct,cluster_exp,slope_a,slope_b,trend,atr_pct,dow,month";
for(int hh=0;hh<5;hh++)
{
string s=IntegerToString(gHor[hh]);
head += ",ret_"+s+",mfe_"+s+",mae_"+s+",dir_"+s+",rev_"+s;
}
for(int b=1;b<=MAXH;b++) head += ",cret_"+IntegerToString(b); // traiettoria forward bar-by-bar
head += ",bars_to_revert,disc_max_pct";
FileWriteString(fh,head+"\r\n");
//--- scansione incroci
long rows=0;
for(int i=iStart;i<=iEnd;i++)
{
if(i<KSLOPE+1) continue;
//--- esporto solo barre con TUTTE le 9 serie valide (cluster completo)
bool allok=true;
for(int k=0;k<NSER && allok;k++)
if(!IsVal(S[i][k]) || !IsVal(S[i-1][k]) || !IsVal(S[i-KSLOPE][k])) allok=false;
if(!allok) continue;
double price=S[i][0], med=S[i][1], ma365=S[i][2];
//--- feature comuni a tutti gli incroci di questa barra
double dist_med = (price-med)/med*100.0;
double cmax=-1, cmin=1e18;
for(int k=2;k<NSER;k++){ double v=S[i][k]; if(v>cmax)cmax=v; if(v<cmin)cmin=v; }
double cluster = (cmax-cmin)/price*100.0;
double cmaxP=-1,cminP=1e18;
for(int k=2;k<NSER;k++){ double v=S[i-KSLOPE][k]; if(v>cmaxP)cmaxP=v; if(v<cminP)cminP=v; }
double clusterP = (cmaxP-cminP)/S[i-KSLOPE][0]*100.0;
double cluster_exp = cluster-clusterP;
int trend = (price>ma365)?1:-1;
double atr_pct = atr[i]/price*100.0;
MqlDateTime dt; TimeToStruct(tm[i],dt);
//--- esito globale: ritorno alla Mediana entro MAXH
int side = (price>med)?1:-1;
int b2rev=-1; double discMax=0;
int jmax = MathMin(i+MAXH,n-1);
for(int j=i+1;j<=jmax;j++)
{
if(!IsVal(S[j][0]) || !IsVal(S[j][1])) continue;
int sj=(S[j][0]>S[j][1])?1:-1;
if(b2rev<0 && sj!=side) b2rev=j-i;
double d=(S[j][0]-S[j][1])/S[j][1]*100.0;
if(MathAbs(d)>MathAbs(discMax)) discMax=d;
}
//--- controllo ogni coppia (a,b)
for(int a=0;a<NSER;a++)
for(int b=a+1;b<NSER;b++)
{
double d0=S[i-1][a]-S[i-1][b];
double d1=S[i][a]-S[i][b];
int dir=0;
if(d0<=0 && d1>0) dir=1; else if(d0>=0 && d1<0) dir=-1;
if(dir==0) continue;
double slope_a = (S[i][a]-S[i-KSLOPE][a])/S[i-KSLOPE][a]*100.0;
double slope_b = (S[i][b]-S[i-KSLOPE][b])/S[i-KSLOPE][b]*100.0;
double thr = 0.25*atr_pct;
string row = StringFormat("%s,%s,%sx%s,%s,%s,%d,",
TimeToString(tm[i],TIME_DATE),sym,SER[a],SER[b],SER[a],SER[b],dir);
row += DoubleToString(price,digits)+","+DoubleToString(med,digits)+",";
for(int k=2;k<NSER;k++) row += DoubleToString(S[i][k],digits)+",";
row += DoubleToString(dist_med,5)+","+DoubleToString(cluster,5)+","
+DoubleToString(cluster_exp,5)+","+DoubleToString(slope_a,5)+","
+DoubleToString(slope_b,5)+","+IntegerToString(trend)+","
+DoubleToString(atr_pct,5)+","+IntegerToString(dt.day_of_week)+","
+IntegerToString(dt.mon);
//--- esiti per orizzonte
for(int hh=0;hh<5;hh++)
{
int h=gHor[hh], iH=i+h;
if(iH>n-1 || S[i][0]<=0) { row += ",,,,,"; continue; }
double ret=(cl[iH]-cl[i])/cl[i]*100.0;
double mxh=-1e18,mnl=1e18;
for(int j=i+1;j<=iH;j++){ if(hi[j]>mxh)mxh=hi[j]; if(lo[j]<mnl)mnl=lo[j]; }
double mfe=(mxh-cl[i])/cl[i]*100.0;
double mae=(mnl-cl[i])/cl[i]*100.0;
int dlab=(ret>thr)?1:((ret<-thr)?-1:0);
int rev=(b2rev>0 && b2rev<=h)?1:0;
row += ","+DoubleToString(ret,5)+","+DoubleToString(mfe,5)+","
+DoubleToString(mae,5)+","+IntegerToString(dlab)+","+IntegerToString(rev);
}
//--- traiettoria: rendimento cumulato a +1..+MAXH barre
for(int b=1;b<=MAXH;b++)
{
int iB=i+b;
if(iB>n-1) { row += ","; continue; }
row += ","+DoubleToString((cl[iB]-cl[i])/cl[i]*100.0,5);
}
row += ","+(b2rev>0?IntegerToString(b2rev):"")+","+DoubleToString(discMax,5);
FileWriteString(fh,row+"\r\n");
rows++;
}
if((i%200)==0) Comment(StringFormat("PaPP export: %d/%d barre, %d eventi",i-iStart,iEnd-iStart,(int)rows));
}
FileClose(fh);
for(int m=0;m<7;m++) IndicatorRelease(hMA[m]);
IndicatorRelease(hATR);
Comment("");
PrintFormat("PaPP export COMPLETATO: %d incroci -> %s (cartella MQL5\\Files)",(int)rows,fname);
Print("Periodo: ",TimeToString(tm[iStart])," -> ",TimeToString(tm[iEnd]));
}
//+------------------------------------------------------------------+
+195 -28
View File
@@ -7,20 +7,57 @@
#property description "PaPP Median - Mediana 7 MA (3g-1y)"
#property description "Calcolo ancorato a D1 = linea uguale su ogni timeframe"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_buffers 8
#property indicator_plots 8
input int FontSize = 9;
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
double Buff_Median[];
double B0[],B1[],B2[],B3[],B4[],B5[],B6[];
int gDays[7] = {365,182,121,30,14,7,3};
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];
string _pfx = "PM_";
string _pfx = "PM_"; // oggetti pannello
string _pfx2 = "PME_"; // etichette a fine linea
//+------------------------------------------------------------------+
// scrive il valore nel buffer della MA m
void SetBuf(int m,int idx,double v)
{
switch(m)
{
case 0: B0[idx]=v; break;
case 1: B1[idx]=v; break;
case 2: B2[idx]=v; break;
case 3: B3[idx]=v; break;
case 4: B4[idx]=v; break;
case 5: B5[idx]=v; break;
case 6: B6[idx]=v; break;
}
}
//+------------------------------------------------------------------+
// legge il valore corrente (barra 0) del buffer della MA m
double GetBuf(int m)
{
switch(m)
{
case 0: return B0[0];
case 1: return B1[0];
case 2: return B2[0];
case 3: return B3[0];
case 4: return B4[0];
case 5: return B5[0];
case 6: return B6[0];
}
return 0;
}
//+------------------------------------------------------------------+
int TimeToBars(int d)
@@ -45,13 +82,36 @@ int OnInit()
}
SetIndexBuffer(0,Buff_Median,INDICATOR_DATA);
SetIndexBuffer(1,B0,INDICATOR_DATA);
SetIndexBuffer(2,B1,INDICATOR_DATA);
SetIndexBuffer(3,B2,INDICATOR_DATA);
SetIndexBuffer(4,B3,INDICATOR_DATA);
SetIndexBuffer(5,B4,INDICATOR_DATA);
SetIndexBuffer(6,B5,INDICATOR_DATA);
SetIndexBuffer(7,B6,INDICATOR_DATA);
ArraySetAsSeries(Buff_Median,true);
ArraySetAsSeries(B0,true); ArraySetAsSeries(B1,true);
ArraySetAsSeries(B2,true); ArraySetAsSeries(B3,true);
ArraySetAsSeries(B4,true); ArraySetAsSeries(B5,true);
ArraySetAsSeries(B6,true);
//--- plot 0 = mediana (linea principale)
PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_LINE);
PlotIndexSetInteger(0,PLOT_LINE_COLOR,clrGold);
PlotIndexSetInteger(0,PLOT_LINE_WIDTH,2);
PlotIndexSetString(0,PLOT_LABEL,"PaPP Median");
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
//--- plot 1..7 = le 7 MA
for(int p=0;p<7;p++)
{
PlotIndexSetInteger(p+1,PLOT_DRAW_TYPE,ShowMA?DRAW_LINE:DRAW_NONE);
PlotIndexSetInteger(p+1,PLOT_LINE_COLOR,gCol[p]);
PlotIndexSetInteger(p+1,PLOT_LINE_WIDTH,1);
PlotIndexSetString(p+1,PLOT_LABEL,"MA "+IntegerToString(gDays[p])+"g");
PlotIndexSetDouble(p+1,PLOT_EMPTY_VALUE,0.0);
}
IndicatorSetString(INDICATOR_SHORTNAME,"PaPP Median");
return INIT_SUCCEEDED;
}
@@ -61,6 +121,7 @@ void OnDeinit(const int reason)
{
for(int i=0;i<7;i++) if(hMA[i]!=INVALID_HANDLE) IndicatorRelease(hMA[i]);
ObjectsDeleteAll(0,_pfx);
ObjectsDeleteAll(0,_pfx2);
}
//+------------------------------------------------------------------+
@@ -93,6 +154,27 @@ double MedianAtD1(int d1shift)
return Median(vals,cnt);
}
//+------------------------------------------------------------------+
// interpolazione lineare con fallback se uno dei valori manca
double Interp(double vStart,double vEnd,double frac)
{
if(vStart>0 && vEnd>0) return vStart+frac*(vEnd-vStart);
if(vEnd>0) return vEnd;
return vStart;
}
//+------------------------------------------------------------------+
// Mediana dei primi n valori di src
double MedianN(const double &src[],int n)
{
if(n<=0) return 0;
double a[]; ArrayResize(a,n);
for(int i=0;i<n;i++) a[i]=src[i];
ArraySort(a);
if((n&1)==1) return a[n/2];
return 0.5*(a[n/2-1]+a[n/2]);
}
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
@@ -109,37 +191,91 @@ int OnCalculate(const int rates_total,
ArraySetAsSeries(close,true);
ArraySetAsSeries(time,true);
int limit = rates_total - prev_calculated;
if(limit>1) limit=rates_total-1;
//--- i dati D1 devono essere pronti, altrimenti ritenta al prossimo tick
int d1bars = Bars(_Symbol,ANCHOR_TF);
if(d1bars<2) return 0;
if(BarsCalculated(hMA[0])<=0) return 0;
for(int idx=limit;idx>=0;idx--)
//--- carica le 7 MA D1 in blocco e calcola la mediana per ogni barra D1
double med_d1[]; ArrayResize(med_d1,d1bars); ArraySetAsSeries(med_d1,true);
double cols[][7]; ArrayResize(cols,d1bars);
for(int m=0;m<7;m++)
{
//--- barra D1 che contiene il tempo di questa barra grafico
int d1cur = iBarShift(_Symbol,ANCHOR_TF,time[idx],false);
if(d1cur<0) { Buff_Median[idx]=0; continue; }
double tmp[]; ArraySetAsSeries(tmp,true);
int got = CopyBuffer(hMA[m],0,0,d1bars,tmp);
if(got<=0) return 0; // non pronto: ritenta
for(int s=0;s<d1bars;s++) cols[s][m] = (s<got) ? tmp[s] : 0.0;
}
for(int s=0;s<d1bars;s++)
{
double vv[7]; int c=0;
for(int m=0;m<7;m++) if(cols[s][m]>0) { vv[c]=cols[s][m]; c++; }
med_d1[s] = MedianN(vv,c);
}
if(!Smooth)
//--- range di barre grafico da (ri)calcolare:
// tutto al primo load o quando nasce una nuova barra D1, altrimenti solo oggi
static int s_lastD1 = -1;
int recalcFrom;
if(prev_calculated==0 || d1bars!=s_lastD1)
recalcFrom = rates_total-1;
else
{
datetime todayOpen = iTime(_Symbol,ANCHOR_TF,0);
recalcFrom = 0;
while(recalcFrom < rates_total-1 && time[recalcFrom] >= todayOpen) recalcFrom++;
}
s_lastD1 = d1bars;
for(int idx=recalcFrom; idx>=0; idx--)
{
int d1cur = iBarShift(_Symbol,ANCHOR_TF,time[idx],false);
if(d1cur<0 || d1cur>=d1bars)
{
//--- gradino: ultima barra D1 chiusa (non-repaint)
Buff_Median[idx]=MedianAtD1(d1cur+1);
Buff_Median[idx]=0;
for(int m=0;m<7;m++) SetBuf(m,idx,0.0);
continue;
}
//--- linea morbida: interpola tra mediana di inizio e fine giornata
double vEnd = MedianAtD1(d1cur); // giornata corrente
double vStart = MedianAtD1(d1cur+1); // giornata precedente
datetime t0 = iTime(_Symbol,ANCHOR_TF,d1cur);
datetime t1 = (d1cur>0) ? iTime(_Symbol,ANCHOR_TF,d1cur-1)
: t0 + PeriodSeconds(ANCHOR_TF);
double frac = (t1>t0) ? (double)(time[idx]-t0)/(double)(t1-t0) : 0.0;
frac = MathMax(0.0,MathMin(1.0,frac));
int sj=d1cur+1; // barra D1 precedente (inizio giornata)
if(vStart>0 && vEnd>0) Buff_Median[idx]=vStart+frac*(vEnd-vStart);
else if(vEnd>0) Buff_Median[idx]=vEnd;
else Buff_Median[idx]=vStart;
//--- frazione di giornata trascorsa (solo se Smooth)
double frac=0.0;
if(Smooth)
{
datetime t0 = iTime(_Symbol,ANCHOR_TF,d1cur);
datetime t1 = (d1cur>0) ? iTime(_Symbol,ANCHOR_TF,d1cur-1)
: t0 + PeriodSeconds(ANCHOR_TF);
frac = (t1>t0) ? (double)(time[idx]-t0)/(double)(t1-t0) : 0.0;
frac = MathMax(0.0,MathMin(1.0,frac));
}
//--- mediana
if(!Smooth)
Buff_Median[idx] = (sj<d1bars) ? med_d1[sj] : 0.0;
else
{
double vS = (sj<d1bars) ? med_d1[sj] : 0.0;
Buff_Median[idx] = Interp(vS,med_d1[d1cur],frac);
}
//--- le 7 MA
for(int m=0;m<7;m++)
{
double val;
if(!Smooth)
val = (sj<d1bars) ? cols[sj][m] : 0.0;
else
{
double vS2 = (sj<d1bars) ? cols[sj][m] : 0.0;
val = Interp(vS2,cols[d1cur][m],frac);
}
SetBuf(m,idx,val);
}
}
DrawInfo();
DrawTags(time[0]);
return rates_total;
}
@@ -159,7 +295,7 @@ void DrawInfo()
double distPct = (bid-median)/median*100;
string distS = StringFormat("%+.2f%%",distPct);
color distC = (distPct>0)?clrRed:clrLimeGreen;
Lbl("M","Median: "+DoubleToString(median,_Digits),x,y,FontSize,clrWhite,false); y+=lh;
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)
@@ -168,20 +304,51 @@ void DrawInfo()
double vol = (dc>0)?ds/dc:0;
Lbl("V","Cluster +/-"+DoubleToString(vol,3)+"%",x,y,FontSize,clrGray,false); y+=lh+2;
//--- Valori delle 7 MA (giorni : valore)
//--- Valori delle 7 MA (giorni : valore) con colore = linea
for(int m=0;m<7;m++)
{
double v=GetMA(m,1);
color cma = (v>median)?clrSalmon:clrLightGreen;
Lbl("a"+IntegerToString(m),
StringFormat("MA %3dg: %s",gDays[m],DoubleToString(v,_Digits)),
x,y,FontSize-1,(v>0)?cma:clrGray,false);
x,y,FontSize-1,(v>0)?gCol[m]:clrGray,false);
y+=lh-2;
}
y+=2;
Lbl("H","Sopra=SELL | Sotto=BUY",x,y,FontSize-1,clrGray,false);
}
//+------------------------------------------------------------------+
// etichetta di testo ancorata a (t,price); se price<=0 la rimuove
void Tag(string n,datetime t,double price,string txt,color c)
{
string o=_pfx2+n;
if(price<=0) { ObjectDelete(0,o); return; }
if(ObjectFind(0,o)<0) ObjectCreate(0,o,OBJ_TEXT,0,0,0);
ObjectSetInteger(0,o,OBJPROP_TIME,t);
ObjectSetDouble(0,o,OBJPROP_PRICE,price);
ObjectSetString(0,o,OBJPROP_TEXT," "+txt);
ObjectSetString(0,o,OBJPROP_FONT,"Consolas");
ObjectSetInteger(0,o,OBJPROP_FONTSIZE,FontSize);
ObjectSetInteger(0,o,OBJPROP_COLOR,c);
ObjectSetInteger(0,o,OBJPROP_ANCHOR,ANCHOR_LEFT);
ObjectSetInteger(0,o,OBJPROP_BACK,false);
ObjectSetInteger(0,o,OBJPROP_SELECTABLE,false);
ObjectSetInteger(0,o,OBJPROP_HIDDEN,true);
}
//+------------------------------------------------------------------+
// etichette a fine linea, nel margine vuoto a destra
void DrawTags(datetime tlast)
{
datetime tfut = tlast + 2*PeriodSeconds(_Period);
Tag("med",tfut,Buff_Median[0],"Mediana",clrGold);
for(int m=0;m<7;m++)
{
double p = ShowMA ? GetBuf(m) : 0.0;
Tag(IntegerToString(m),tfut,p,IntegerToString(gDays[m])+"g",gCol[m]);
}
}
//+------------------------------------------------------------------+
void Lbl(string n,string t,int x,int y,int fs,color c,bool b)
{