Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f930e88592 | ||
|
|
908d0e9187 | ||
|
|
8e6fe91b70 |
@@ -27,6 +27,9 @@ int gDays[7] = {365,182,121,30,14,7,3};
|
|||||||
string SER[NSER]= {"PRICE","MED","MA365","MA182","MA121","MA30","MA14","MA7","MA3"};
|
string SER[NSER]= {"PRICE","MED","MA365","MA182","MA121","MA30","MA14","MA7","MA3"};
|
||||||
int gHor[5] = {1,3,5,10,20};
|
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)
|
int TimeToBarsD1(string sym,int d)
|
||||||
{
|
{
|
||||||
@@ -36,10 +39,14 @@ int TimeToBarsD1(string sym,int d)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
double Median7(double &v[]) // mediana dei valori >0 in v[0..6]
|
// 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);
|
double a[]; int c=0; ArrayResize(a,7);
|
||||||
for(int m=0;m<7;m++) if(v[m]>0) { a[c]=v[m]; c++; }
|
for(int m=0;m<7;m++) if(IsVal(v[m])) { a[c]=v[m]; c++; }
|
||||||
if(c==0) return 0;
|
if(c==0) return 0;
|
||||||
ArrayResize(a,c); ArraySort(a);
|
ArrayResize(a,c); ArraySort(a);
|
||||||
if((c&1)==1) return a[c/2];
|
if((c&1)==1) return a[c/2];
|
||||||
@@ -79,7 +86,7 @@ void OnStart()
|
|||||||
|
|
||||||
//--- carico tutta la storia D1 (indice 0 = piu' vecchio)
|
//--- carico tutta la storia D1 (indice 0 = piu' vecchio)
|
||||||
datetime tm[]; double cl[],hi[],lo[],atr[];
|
datetime tm[]; double cl[],hi[],lo[],atr[];
|
||||||
double ma[7][];
|
MABuf ma[7];
|
||||||
ArraySetAsSeries(tm,false); ArraySetAsSeries(cl,false);
|
ArraySetAsSeries(tm,false); ArraySetAsSeries(cl,false);
|
||||||
ArraySetAsSeries(hi,false); ArraySetAsSeries(lo,false);
|
ArraySetAsSeries(hi,false); ArraySetAsSeries(lo,false);
|
||||||
ArraySetAsSeries(atr,false);
|
ArraySetAsSeries(atr,false);
|
||||||
@@ -90,8 +97,8 @@ void OnStart()
|
|||||||
if(CopyBuffer(hATR,0,0,total,atr)<=0) { Print("CopyATR KO"); return; }
|
if(CopyBuffer(hATR,0,0,total,atr)<=0) { Print("CopyATR KO"); return; }
|
||||||
for(int m=0;m<7;m++)
|
for(int m=0;m<7;m++)
|
||||||
{
|
{
|
||||||
ArraySetAsSeries(ma[m],false);
|
ArraySetAsSeries(ma[m].v,false);
|
||||||
if(CopyBuffer(hMA[m],0,0,total,ma[m])<=0) { Print("CopyBuffer MA KO m=",m); return; }
|
if(CopyBuffer(hMA[m],0,0,total,ma[m].v)<=0) { Print("CopyBuffer MA KO m=",m); return; }
|
||||||
}
|
}
|
||||||
int n = ArraySize(cl);
|
int n = ArraySize(cl);
|
||||||
|
|
||||||
@@ -101,7 +108,7 @@ void OnStart()
|
|||||||
for(int i=0;i<n;i++)
|
for(int i=0;i<n;i++)
|
||||||
{
|
{
|
||||||
double mv[7];
|
double mv[7];
|
||||||
for(int m=0;m<7;m++) mv[m] = ma[m][i];
|
for(int m=0;m<7;m++) mv[m] = ma[m].v[i];
|
||||||
S[i][0] = cl[i]; // PRICE
|
S[i][0] = cl[i]; // PRICE
|
||||||
S[i][1] = Median7(mv); // MED
|
S[i][1] = Median7(mv); // MED
|
||||||
for(int m=0;m<7;m++) S[i][2+m] = mv[m]; // MA365..MA3
|
for(int m=0;m<7;m++) S[i][2+m] = mv[m]; // MA365..MA3
|
||||||
@@ -127,6 +134,7 @@ void OnStart()
|
|||||||
string s=IntegerToString(gHor[hh]);
|
string s=IntegerToString(gHor[hh]);
|
||||||
head += ",ret_"+s+",mfe_"+s+",mae_"+s+",dir_"+s+",rev_"+s;
|
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";
|
head += ",bars_to_revert,disc_max_pct";
|
||||||
FileWriteString(fh,head+"\r\n");
|
FileWriteString(fh,head+"\r\n");
|
||||||
|
|
||||||
@@ -135,20 +143,26 @@ void OnStart()
|
|||||||
for(int i=iStart;i<=iEnd;i++)
|
for(int i=iStart;i<=iEnd;i++)
|
||||||
{
|
{
|
||||||
if(i<KSLOPE+1) continue;
|
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];
|
double price=S[i][0], med=S[i][1], ma365=S[i][2];
|
||||||
if(price<=0 || med<=0) continue;
|
|
||||||
|
|
||||||
//--- feature comuni a tutti gli incroci di questa barra
|
//--- feature comuni a tutti gli incroci di questa barra
|
||||||
double dist_med = (med>0)?(price-med)/med*100.0:0;
|
double dist_med = (price-med)/med*100.0;
|
||||||
double cmax=-1, cmin=1e18;
|
double cmax=-1, cmin=1e18;
|
||||||
for(int k=2;k<NSER;k++){ double v=S[i][k]; if(v>0){ if(v>cmax)cmax=v; if(v<cmin)cmin=v; } }
|
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>0 && price>0)?(cmax-cmin)/price*100.0:0;
|
double cluster = (cmax-cmin)/price*100.0;
|
||||||
double cmaxP=-1,cminP=1e18;
|
double cmaxP=-1,cminP=1e18;
|
||||||
for(int k=2;k<NSER;k++){ double v=S[i-KSLOPE][k]; if(v>0){ if(v>cmaxP)cmaxP=v; if(v<cminP)cminP=v; } }
|
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>0)?(cmaxP-cminP)/S[i-KSLOPE][0]*100.0:0;
|
double clusterP = (cmaxP-cminP)/S[i-KSLOPE][0]*100.0;
|
||||||
double cluster_exp = cluster-clusterP;
|
double cluster_exp = cluster-clusterP;
|
||||||
int trend = (price>ma365 && ma365>0)?1:-1;
|
int trend = (price>ma365)?1:-1;
|
||||||
double atr_pct = (price>0)?atr[i]/price*100.0:0;
|
double atr_pct = atr[i]/price*100.0;
|
||||||
MqlDateTime dt; TimeToStruct(tm[i],dt);
|
MqlDateTime dt; TimeToStruct(tm[i],dt);
|
||||||
|
|
||||||
//--- esito globale: ritorno alla Mediana entro MAXH
|
//--- esito globale: ritorno alla Mediana entro MAXH
|
||||||
@@ -157,7 +171,7 @@ void OnStart()
|
|||||||
int jmax = MathMin(i+MAXH,n-1);
|
int jmax = MathMin(i+MAXH,n-1);
|
||||||
for(int j=i+1;j<=jmax;j++)
|
for(int j=i+1;j<=jmax;j++)
|
||||||
{
|
{
|
||||||
if(S[j][0]<=0 || S[j][1]<=0) continue;
|
if(!IsVal(S[j][0]) || !IsVal(S[j][1])) continue;
|
||||||
int sj=(S[j][0]>S[j][1])?1:-1;
|
int sj=(S[j][0]>S[j][1])?1:-1;
|
||||||
if(b2rev<0 && sj!=side) b2rev=j-i;
|
if(b2rev<0 && sj!=side) b2rev=j-i;
|
||||||
double d=(S[j][0]-S[j][1])/S[j][1]*100.0;
|
double d=(S[j][0]-S[j][1])/S[j][1]*100.0;
|
||||||
@@ -168,15 +182,14 @@ void OnStart()
|
|||||||
for(int a=0;a<NSER;a++)
|
for(int a=0;a<NSER;a++)
|
||||||
for(int b=a+1;b<NSER;b++)
|
for(int b=a+1;b<NSER;b++)
|
||||||
{
|
{
|
||||||
if(S[i][a]<=0||S[i][b]<=0||S[i-1][a]<=0||S[i-1][b]<=0) continue;
|
|
||||||
double d0=S[i-1][a]-S[i-1][b];
|
double d0=S[i-1][a]-S[i-1][b];
|
||||||
double d1=S[i][a]-S[i][b];
|
double d1=S[i][a]-S[i][b];
|
||||||
int dir=0;
|
int dir=0;
|
||||||
if(d0<=0 && d1>0) dir=1; else if(d0>=0 && d1<0) dir=-1;
|
if(d0<=0 && d1>0) dir=1; else if(d0>=0 && d1<0) dir=-1;
|
||||||
if(dir==0) continue;
|
if(dir==0) continue;
|
||||||
|
|
||||||
double slope_a = (S[i-KSLOPE][a]>0)?(S[i][a]-S[i-KSLOPE][a])/S[i-KSLOPE][a]*100.0:0;
|
double slope_a = (S[i][a]-S[i-KSLOPE][a])/S[i-KSLOPE][a]*100.0;
|
||||||
double slope_b = (S[i-KSLOPE][b]>0)?(S[i][b]-S[i-KSLOPE][b])/S[i-KSLOPE][b]*100.0:0;
|
double slope_b = (S[i][b]-S[i-KSLOPE][b])/S[i-KSLOPE][b]*100.0;
|
||||||
double thr = 0.25*atr_pct;
|
double thr = 0.25*atr_pct;
|
||||||
|
|
||||||
string row = StringFormat("%s,%s,%sx%s,%s,%s,%d,",
|
string row = StringFormat("%s,%s,%sx%s,%s,%s,%d,",
|
||||||
@@ -204,6 +217,13 @@ void OnStart()
|
|||||||
row += ","+DoubleToString(ret,5)+","+DoubleToString(mfe,5)+","
|
row += ","+DoubleToString(ret,5)+","+DoubleToString(mfe,5)+","
|
||||||
+DoubleToString(mae,5)+","+IntegerToString(dlab)+","+IntegerToString(rev);
|
+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);
|
row += ","+(b2rev>0?IntegerToString(b2rev):"")+","+DoubleToString(discMax,5);
|
||||||
FileWriteString(fh,row+"\r\n");
|
FileWriteString(fh,row+"\r\n");
|
||||||
rows++;
|
rows++;
|
||||||
|
|||||||
Reference in New Issue
Block a user