量化軟件下載:赫茲量化峰谷指標(biāo)新鮮的方法,新穎的解決方案
我們現(xiàn)在來快速了解一下幾何學(xué)。想像軌道線指標(biāo)的線池是一個(gè) 3D 平面。將一個(gè)平面垂直放到價(jià)格圖表上,并于當(dāng)前(零)柱處切割平面。
結(jié)果,我們得到了呈一條曲線的表面橫截面(上圖所示是曲線成為直線的一種特殊情況)。要做預(yù)測,有曲線上每個(gè)點(diǎn)的坐標(biāo)就足夠了,而且它們還會被用于進(jìn)一步的計(jì)算當(dāng)中。
我們將需要下述橫截面特征:最大與最小點(diǎn),以及橫截面的重心(所有點(diǎn)值的算術(shù)平均值)。獲得的特征點(diǎn)將被投向到當(dāng)前(零)柱上,相關(guān)數(shù)據(jù)則被存儲于歷史中。這些特征點(diǎn)將充當(dāng)當(dāng)前與下一個(gè)峰谷節(jié)點(diǎn)的基礎(chǔ)。
由于包絡(luò)帶搜索分高峰與低谷執(zhí)行,所以我們要獲取兩個(gè)橫截面:一個(gè)為高峰,另一個(gè)為低谷。
要獲取預(yù)測,我們將使用最近的特征點(diǎn)。比如說,搜索某峰谷高峰時(shí),我們?nèi)≤壍谰€指標(biāo)上軌線與某個(gè)截平面交叉所產(chǎn)生的橫截面的特征點(diǎn)。相反,搜索某低谷時(shí),我們則取軌道線指標(biāo)下軌線與某個(gè)截平面交叉所產(chǎn)生的橫截面的特征點(diǎn)。
?
測試新指標(biāo)
完成了方法的定義,現(xiàn)在我們來創(chuàng)建指標(biāo)。我們首先會找到峰谷指標(biāo)的最后節(jié)點(diǎn),并在圖表中完成繪制。為此,我們將采用專為手頭任務(wù)而編寫的?AdvancedZigZag?類:
//+------------------------------------------------------------------+//|?????????????????????????????????????????????? AdvancedZigZag.mqh |//|?????????????????????????????????????????? Copyright 2013, DC2008 |//|?????????????????????????? https://www.mql5.com/ru/users/DC2008 |//+------------------------------------------------------------------+#property copyright "Copyright 2013, DC2008"#property link??????"https://www.mql5.com/ru/users/DC2008"#property version?? "1.00"//+------------------------------------------------------------------+//|???????????????????????????????????????????????? GetExtremums.mqh |//+------------------------------------------------------------------+#include <GetExtremums.mqh>?? // author of the code Yurich#property copyright "Copyright 2012, Yurich"#property link??????"https://www.mql5.com/ru/users/Yurich"//+------------------------------------------------------------------+//| ZigZag node structure????????????????????????????????????????????|//+------------------------------------------------------------------+struct MqlZigZag ??{ ?? double????????????price;?? // Node coordinate?? datetime??????????t;?????? // Time??};//+------------------------------------------------------------------+//| The AdvancedZigZag class???????????????????????????????????????? |//+------------------------------------------------------------------+class AdvancedZigZag ??{private: ?? MqlRates??????????rt[]; ?? dextremum???????? zz[]; ?? int?????????????? history; ?? double????????????amplitude;public: ?? dextremum???????? zHL[]; ?? MqlZigZag???????? zzH[],zzL[]; ?? int?????????????? Count(const double range); ?? int?????????????? Read(const int nodes); ???????????????????? AdvancedZigZag(const int bars); ????????????????????~AdvancedZigZag(); ??};//+------------------------------------------------------------------+//| Class constructor?????????????????????????????????????????????? ?|//+------------------------------------------------------------------+AdvancedZigZag::AdvancedZigZag(const int bars) ??{ ?? history=bars; ?? amplitude=0; ??}//+------------------------------------------------------------------+//| The Read method of the class???????????????????????????????????? |//+------------------------------------------------------------------+int AdvancedZigZag::Read(const int nodes) ??{ ?? CopyRates(NULL,0,TimeCurrent(),history,rt); ?? int cnt=GetExtremums(amplitude,rt,zHL,nodes); ?? return(cnt); ??}//+------------------------------------------------------------------+//| The Count method of the class??????????????????????????????????? |//+------------------------------------------------------------------+int AdvancedZigZag::Count(const double range) ??{ ?? amplitude=range; ?? CopyRates(NULL,0,TimeCurrent(),history,rt); ?? int cnt=GetExtremums(amplitude,rt,zz); ?? ArrayResize(zzH,cnt); ?? ArrayResize(zzL,cnt); ?? int h=0; ?? int l=0; ?? for(int i=0; i<cnt; i++) ???? { ??????if(zz[i].type>0) ????????{ ???????? zzH[h]=(MqlZigZag)zz[i]; ???????? h++; ????????} ??????else????????{ ???????? zzL[l]=(MqlZigZag)zz[i]; ???????? l++; ????????} ???? } ?? ArrayResize(zzH,h); ?? ArrayResize(zzL,l); ?? return(cnt); ??}//+------------------------------------------------------------------+//|??????????????????????????????????????????????????????????????????|//+------------------------------------------------------------------+AdvancedZigZag::~AdvancedZigZag() ??{ ??}
共有兩種方法:
計(jì)數(shù)法會找到某給定時(shí)間周期(柱數(shù))內(nèi)的所有峰谷節(jié)點(diǎn),并將其保存到各種數(shù)組中,實(shí)現(xiàn)高峰與低谷的區(qū)分。如此一來,軌道線的分析和計(jì)算就更簡單了;
讀取法會找到最后的節(jié)點(diǎn),并將其保存到一個(gè)單一數(shù)組中。我們需要此方法來實(shí)現(xiàn)峰谷指標(biāo)可視化;
GetExtremums?庫(由?Yury Kulikov?提供)在搜索節(jié)點(diǎn)時(shí)亦不可或缺。
我們將該指標(biāo)放到一個(gè) EA 交易中研究一下。為什么是 EA 交易、而不是指標(biāo)呢?這當(dāng)然是個(gè)人口味問題,但對我來講,這種方式似乎更高效。毫無疑問,EA 交易的圖形功能是弱了些,但我們收獲的卻是性能。因?yàn)橄嗤灰灼贩N的指標(biāo)都在一個(gè)單一數(shù)據(jù)流中運(yùn)行,而每個(gè) EA 都在于自己獨(dú)立的數(shù)據(jù)流中運(yùn)行。我們來看看代碼:
//+------------------------------------------------------------------+//|?????????????????????????????????????????????????? two_Comets.mq5 |//|?????????????????????????????????????????? Copyright 2013, DC2008 |//|?????????????????????????? https://www.mql5.com/ru/users/DC2008 |//+------------------------------------------------------------------+#property copyright "Copyright 2013, DC2008"#property link??????"https://www.mql5.com/ru/users/DC2008"#property version?? "1.00"#include <AdvancedZigZag.mqh>//--- Depth of history for the indicator calculationinput int??????depth_stories=5000;??// Depth stories for calculating the indicator [bars]//--- Minimum ZigZag amplitude valueinput int??????amplitude=100;????????// The minimum value of the amplitude of the indicator [points]//--- Declaring the classAdvancedZigZag Azz(depth_stories);//---#define NUMBER_MA?? 227#define START_MA????5//--- macros#define SIZE(i)???????????????????? (double)i*0.3<1?1:(int)(i*0.25)#define ObjF1?????????????????????? ObjectSetString(0,name,OBJPROP_FONT,"Wingdings")#define ObjF2?????????????????????? ObjectSetInteger(0,name,OBJPROP_ANCHOR,ANCHOR_CENTER)#define ObjF3(T)????????????????????ObjectSetInteger(0,name,OBJPROP_TIME,T)#define ObjF4(P)????????????????????ObjectSetDouble(0,name,OBJPROP_PRICE,P)#define ObjF5(size)???????????????? ObjectSetInteger(0,name,OBJPROP_FONTSIZE,size)#define ObjF6(code)???????????????? ObjectSetString(0,name,OBJPROP_TEXT,CharToString(code))#define ObjF7(clr)??????????????????ObjectSetInteger(0,name,OBJPROP_COLOR,clr)#define ObjF8?????????????????????? ObjectSetInteger(0,name,OBJPROP_COLOR,clrMagenta)#define ObjF9?????????????????????? ObjectSetInteger(0,name,OBJPROP_WIDTH,3)#define ObjF10??????????????????????ObjectSetInteger(0,name,OBJPROP_BACK,true) #define ObjFont???????????????????? ObjF1;ObjF2;#define ObjCoordinates(T,P)???????? ObjF3(T);ObjF4(P);#define ObjProperty(size,code,clr)??ObjF5(size);ObjF6(code);ObjF7(clr);#define ObjZZ?????????????????????? ObjF8;ObjF9;ObjF10;//---double??????MA[1],sumHi[NUMBER_MA],sumLo[NUMBER_MA];int???????? handle_MA_H[NUMBER_MA],handle_MA_L[NUMBER_MA];datetime????t[1];int???????? H,L;int???????? t_min,t_max;int???????? err=-1;double??????sumH[2],maxH[2],minH[2];double??????sumL[2],maxL[2],minL[2];string??????name;int???????? count;int???????? shift;//+------------------------------------------------------------------+//| Expert initialization function?????????????????????????????????? |//+------------------------------------------------------------------+int OnInit() ??{ ?? shift=PeriodSeconds()/30;//--- calculation of ZigZag nodes using historical data?? Azz.Count(amplitude*Point()); ?? H=ArraySize(Azz.zzH); ?? L=ArraySize(Azz.zzL); ?? if(H<30 || L<30) ???? { ??????Print("Not enough data to calculate ZigZag nodes: "+ ????????????"increase the depth of history; "+ ????????????"or decrease the amplitude value."); ??????return(-1); ???? }//---?? for(int i=0; i<NUMBER_MA; i++) ???? { ??????handle_MA_H[i]=iMA(NULL,0,i+START_MA,0,MODE_SMA,PRICE_HIGH); ??????handle_MA_L[i]=iMA(NULL,0,i+START_MA,0,MODE_SMA,PRICE_LOW); ???? }//---?? return(0); ??}//+------------------------------------------------------------------+//| Expert deinitialization function???????????????????????????????? |//+------------------------------------------------------------------+void OnDeinit(const int reason) ??{ ?? ObjectsDeleteAll(0,-1,-1); ?? for(int i=0; i<NUMBER_MA; i++) ???? { ??????IndicatorRelease(handle_MA_H[i]); ??????IndicatorRelease(handle_MA_L[i]); ???? }//---??}//+------------------------------------------------------------------+//| Expert tick function???????????????????????????????????????????? |//+------------------------------------------------------------------+void OnTick() ??{//--- get the current bar's opening time value?? CopyTime(NULL,0,0,1,t);//--- ZigZag: last 7 nodes?? count=Azz.Read(7); ?? for(int i=1; i<count; i++) ???? { ??????name="ZZ"+(string)i; ??????ObjectCreate(0,name,OBJ_TREND,0,0,0); ??????ObjectSetInteger(0,name,OBJPROP_COLOR,clrRed); ??????ObjectSetInteger(0,name,OBJPROP_WIDTH,10); ??????ObjectSetInteger(0,name,OBJPROP_BACK,true); ??????ObjectSetDouble(0,name,OBJPROP_PRICE,0,Azz.zHL[i-1].value); ??????ObjectSetInteger(0,name,OBJPROP_TIME,0,Azz.zHL[i-1].time); ??????ObjectSetDouble(0,name,OBJPROP_PRICE,1,Azz.zHL[i].value); ??????ObjectSetInteger(0,name,OBJPROP_TIME,1,Azz.zHL[i].time); ???? }//--- check for integrity of preliminary calculations?? if(err<0) ???? { ??????//--- calculate the sums of deviations of the nodes from MA for ZigZag peaks??????ArrayInitialize(sumHi,0.0); ??????for(int j=H-1; j>=0; j--) ????????{ ???????? for(int i=0; i<NUMBER_MA; i++) ?????????? { ????????????err=CopyBuffer(handle_MA_H[i],0,Azz.zzH[j].t,1,MA); ????????????if(err<0) return; ????????????sumHi[i]+=Azz.zzH[j].price-MA[0]; ?????????? } ????????} ??????//--- calculate the sums of deviations of the nodes from MA for ZigZag troughs??????ArrayInitialize(sumLo,0.0); ??????for(int j=L-1; j>=0; j--) ????????{ ???????? for(int i=0; i<NUMBER_MA; i++) ?????????? { ????????????err=CopyBuffer(handle_MA_L[i],0,Azz.zzL[j].t,1,MA); ????????????if(err<0) return; ????????????sumLo[i]+=MA[0]-Azz.zzL[j].price; ?????????? } ????????} ???? } ??}//+------------------------------------------------------------------+