赫茲股票期貨量化交易軟件:指標(biāo)外部參數(shù)的圖形控制
簡介
你不得不設(shè)置或更改指標(biāo)外部參數(shù)的頻率有多高? 很多人一定考慮過,使用鼠標(biāo)將外部參數(shù)移到圖表上,從而能夠方便的拖動圖標(biāo)或?qū)ο蟮剿璧奈恢茫院喕笜?biāo)的設(shè)置過程。赫茲量化語言允許在屏幕上顯示指標(biāo)設(shè)置。
編輯切換為居中
參數(shù)的圖形控制
首先,赫茲量化需要找出指標(biāo)中有哪些參數(shù),以及打算對哪些參數(shù)進(jìn)行更改。 為此,打開指標(biāo)屬性并寫下需要在工作過程中更改的參數(shù)的名稱。
例如,赫茲量化使用標(biāo)準(zhǔn)終端版本中包含的鋸齒形調(diào)整浪指標(biāo)。 在屬性中選擇變量的名稱。
編輯
指標(biāo)參數(shù)
ExtDepth=12
ExtDeviation=5
ExtBackstep=3
赫茲量化繼續(xù)創(chuàng)建將用于更改指標(biāo)參數(shù)值的變量和數(shù)組。
根據(jù)我們要控制的指標(biāo)的參數(shù),給出指標(biāo)參數(shù)的名稱。
// Initial indicator values int ? ? ? ? ? ? ? ExtDepth=12; int ? ? ? ? ? ? ? ExtDeviation=5; int ? ? ? ? ? ? ? ExtBackstep=3; //---- indicator buffers double ? ? ? ? ? ?ZigzagBuffer[]; double ? ? ? ? ? ?HighMapBuffer[]; double ? ? ? ? ? ?LowMapBuffer[]; // Array of indicator parameter variables string ? ? ? ? ? ?ArrExt[3,3] ? ?={"12","21","34", "5","8","21", "3","13","34"}; // Arrays of indices string ? ? ? ? ? ?Array_Index[]={"Dep -> ","Dev -> ","Back ->"}; int ? ? ? ? ? ? ? Coordinats_IndexUp[]={65,160,260}; int ? ? ? ? ? ? ? Coordinats_Index[] ?={35,130,230}; int ? ? ? ? ? ? ? Coordinats_IndexDn[]={5, 100,200}; // Color for parameter blocks and indices color ? ? ? ? ? ? Color_[]={Blue,Green,Red};
在這一步,我認(rèn)為一切都很清晰。
"Dep -> ","Dev -> ","Back ->"
分別是 ExtDepth、ExtDeviation 和 ExtBackstep。 下面是它們在圖表中的顯示。
對于每個參數(shù),我們使用三個變量值
string ? ? ? ? ? ?ArrExtDepth[] ? ?={"12","15","20"}; string ? ? ? ? ? ?ArrExtDeviation[]={"5", ?"8","21"}; string ? ? ? ? ? ?ArrExtBackstep[] ={"3", "13","34"};
出于方便,存儲在一個三維數(shù)組內(nèi):
string ? ? ? ? ? ?ArrExt[3,3] ? ?={"12","21","34", "5","8","21", "3","13","34"};
3、5、12 是標(biāo)準(zhǔn)鋸齒形調(diào)整浪指標(biāo)的參數(shù)中默認(rèn)設(shè)置的標(biāo)準(zhǔn)值。
這里的其他值作為示例給出。 它們將用作指標(biāo)控制的參數(shù)變量。
考慮到這里將涉及很多繪圖,赫茲量化加入一個函數(shù),用來創(chuàng)建對象并將對象移到單獨(dú)的程序塊:
void Obj_CreateMove_Text (int CreateMove, string Name, int Type, string Number, ?color text_color, ? ? ? ? ? ? ? ? ? ? ? ? ?int DistX, int DistY) ? { ? ? ?if (CreateMove==0) ? ? ?ObjectCreate(Name,Type,0,0,0); ? ? ?ObjectSetText(Name,Number,10,"Arial",text_color); ? ? ?ObjectSet(Name,101,3); ? ? ?ObjectSet(Name, 102, DistX); ? ? ?ObjectSet(Name, 103, DistY); ? }
為了確??刂品奖愫捅3执a緊湊,圖形對象的所有坐標(biāo)都儲存在數(shù)組中。 這在上面已經(jīng)進(jìn)行了展示(查看文章的開頭)。
現(xiàn)在我們在圖表窗口繪制所有的對象。
圖表的右手側(cè)加載的信息較少,所以將沿著窗口右邊界垂直分布變量。 每一個參數(shù)都有自己的索引,其顏色跟相應(yīng)的參數(shù)變量的顏色相同。
因此,赫茲量化需要為每個參數(shù)創(chuàng)建三個參數(shù)索引和三個變量值。
在屏幕上為指標(biāo)參數(shù)創(chuàng)建對象,顯示這些參數(shù)的變量數(shù)值,并在每個參數(shù)塊旁邊創(chuàng)建對應(yīng)的索引。
// Create objects ? for( ii=0;ii<3;ii++) ? ? ?for( i=0;i<3;i++) ? ? ?Obj_CreateMove_Text (0, Array_Index[ii]+i, 23, (ArrExt[ii,i]), Color_[ii], 5, Coordinats_IndexDn[ii]+30*i); ? ? ?for( i=0;i<3;i++) ? ? ?Obj_CreateMove_Text (0, "Index"+Array_Index[i], 23, (Array_Index[i]), ? Color_[i], 25, Coordinats_Index[i]);
編輯
圖 1
現(xiàn)在我們只需要創(chuàng)建一個程序塊,在相關(guān)的索引移動時處理用戶的操作。
赫茲量化擁有對象在圖表上的錨點(diǎn),根據(jù)錨點(diǎn)我們逐個讀取索引參數(shù)并確定程序邏輯。
// Read index coordinates from the chart ? ? ?for( i=0;i<3;i++) ? ? ? ? ? { ? ? ? ? ? ?Coordinats[i]=ObjectGet("Index"+Array_Index[i],OBJPROP_YDISTANCE); ? ? ? ? ? ? ? if (Coordinats[i]==0)//If outside of the chart, set again ? ? ? ? ? ? ? ? ?Obj_CreateMove_Text (1, "Index"+Array_Index[i], 23, Array_Index[i], Color_[i], 25, Coordinats_IndexDn[i]); ? ? ? ? ? } ? ?
在保存了得到的值后,赫茲量化需要分析它們在圖表上的位置并采取必要的操作。 對于分析,我們使用索引的實(shí)際位置,作為每個索引的三個基值相對于使用的參數(shù)值的參考點(diǎn)。 如果索引移到其組內(nèi)的最高值以上,將視為已經(jīng)移至其最高值。 如果索引移到最低的參數(shù)值以下,也會類似的移到最低的參數(shù)值。 如果索引介于參數(shù)的最高和最低值之間,則取中間值。 為了進(jìn)行對比,我們使用垂直標(biāo)度,即
the OBJPROP_YDISTANCE parameter
來自于
ObjectGet()
// Analyze positions of indices ? ? ?for( i=0;i<3;i++) ? ? ? ? { ? ? ? ? ? ?if (Coordinats[i]>Coordinats_IndexUp[i]) ? ? ? ? ? ? ? ? ?{Move[i] = Coordinats_IndexUp[i]; index[i]=2;}// Index has been moved up ? ? ? ? ? ?if (Coordinats[i]>Coordinats_IndexDn[i] ?&& ? ? ? ? ? ? ? ?Coordinats[i]<Coordinats_IndexUp[i]) ? ? ? ? ? ? ? ? ?{Move[i] = Coordinats_Index[i]; ? index[i]=1;}// Index is in the middle ? ? ? ? ? ?if (Coordinats[i]<Coordinats_IndexDn[i]) ? ? ? ? ? ? ? ? ?{Move[i] = Coordinats_IndexDn[i]; index[i]=0;}// Index has been moved down ? ? ? ? ? ?if (Move[i]!=0)
然后我們對齊已經(jīng)移動的對象。
保存新的參數(shù)值以繪制鋸齒形調(diào)整浪。
基于這些值,使用圖形控制繪制指標(biāo)。
// Move and align the objects depending on their positions ? ? ? ? ? ?Obj_CreateMove_Text (1, "Index"+Array_Index[i], 23, Array_Index[i], Color_[i], 25, Move[i]); ? ? // Save ZigZag parameter values ? ? ? ? ? ?switch (i) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ?case 0: ?ExtDepth = ? ? StrToInteger(ArrExt[0,index[i]]); ?break; ? ? ? ? ? ? ? ?case 1: ?ExtDeviation = StrToInteger(ArrExt[1,index[i]]); ?break; ? ? ? ? ? ? ? ?case 2: ?ExtBackstep = ?StrToInteger(ArrExt[2,index[i]]); ?break; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }/**/ ? ? ? ? ?} // Pass parameter values to the custom indicator and plot ZigZag based on the obtained values ? ? for(i=300;i>0;i--) ? ? ? ? ? ?{ ? ? ? ? ? ? ? ZigzagBuffer[i]=iCustom(NULL,0,"ZigZag",ExtDepth,ExtDeviation,ExtBackstep,0,i); ? ? ? ? ? ? ? HighMapBuffer[i]=iCustom(NULL,0,"ZigZag",ExtDepth,ExtDeviation,ExtBackstep,1,i); ? ? ? ? ? ? ? LowMapBuffer[i]=iCustom(NULL,0,"ZigZag",ExtDepth,ExtDeviation,ExtBackstep,2,i); ? ? ? ? ? ?}
在任意圖形對象上雙擊將其激活。 激活后,可以使用鼠標(biāo)控制對象。 每次決定更改參數(shù)值的時候,都要這樣做。
編輯
圖 2
編輯
圖 3
編輯