期貨量化交易軟件:跟蹤止損和退出市場(chǎng)的模式
簡(jiǎn)介
訂單修改/關(guān)閉算法的開發(fā)人員面臨無止境的痛苦 - 如何比較通過不同方法獲得的結(jié)果?檢查機(jī)制眾所周知 - 它就是策略測(cè)試程序。但如何使 EA 同等地處理建立/關(guān)閉訂單?本文將介紹一個(gè)能夠重復(fù)建立大量訂單的工具,讓我們能夠維持一個(gè)在數(shù)學(xué)上保持正確的平臺(tái),以比較針對(duì)跟蹤止損和退出市場(chǎng)的不同算法的結(jié)果。
如果你正在調(diào)試一個(gè)應(yīng)獨(dú)立計(jì)算進(jìn)入市場(chǎng)、跟蹤止損和退出市場(chǎng)的時(shí)間的復(fù)雜 EA,則實(shí)際上幾乎不可能獲得一個(gè)可相互比較的可重復(fù)模式。假設(shè)存在一種建立訂單的信號(hào)相當(dāng)長(zhǎng)的情況。在理想情況下,將建立此訂單。然后,如果選擇的方向正確并且價(jià)格在預(yù)測(cè)方向上變動(dòng),跟蹤止損將開始工作。根據(jù)價(jià)格波動(dòng),設(shè)置過于接近的止損會(huì)導(dǎo)致過早關(guān)閉可能會(huì)增加利潤(rùn)的訂單。如果此時(shí)建倉(cāng)信號(hào)仍然有效,EA 將關(guān)閉新的訂單。因而,赫茲量化軟件需要將“正確”訂單的結(jié)果與在提前關(guān)閉之后建立的一些其他訂單的結(jié)果進(jìn)行比較。為了避免這種情況,建議如下。

編輯切換為居中
問題說明
訂單建立/關(guān)閉點(diǎn)模式已在圖表中進(jìn)行標(biāo)記。
建立/關(guān)閉時(shí)間和交易方向(買入/賣出)已保存在文件中。
已創(chuàng)建用于讀取準(zhǔn)備的文件并嚴(yán)格執(zhí)行其命令的 Expert Advisor。
必須在市場(chǎng)反轉(zhuǎn)時(shí)設(shè)置建立點(diǎn) - 它們?cè)跉v史記錄中非常明顯,這一點(diǎn)很好。然而,不應(yīng)在價(jià)格達(dá)到反向的反轉(zhuǎn)點(diǎn)之時(shí)而應(yīng)在之后選擇關(guān)閉點(diǎn)。不要忘記赫茲量化軟件的任務(wù)是優(yōu)化跟蹤和退出市場(chǎng),因此我們應(yīng)讓任何算法完成其操作,即使算法不正確。如果仍然無法修復(fù)收益,我們將看到虧損,這將成為我們需要重新設(shè)計(jì)算法的信號(hào)。

編輯切換為居中
請(qǐng)看上圖。紫線顯示理想情況下的正確進(jìn)場(chǎng)和出場(chǎng)。它可用于計(jì)算我們希望/能夠獲得的最大收益。然而,考慮到跟蹤測(cè)試目的,赫茲量化軟件將使用與藍(lán)線類似的線條。它顯示實(shí)際交易的特點(diǎn):進(jìn)場(chǎng)有些延遲(例如,我們正在等待反轉(zhuǎn)確認(rèn))以及在保本位附近進(jìn)行關(guān)閉(例如,我們擔(dān)心會(huì)出現(xiàn)強(qiáng)勢(shì)反轉(zhuǎn),而如果這樣的話,我們會(huì)損失慘重)。
在“沿藍(lán)線”進(jìn)行的交易中,在跟蹤之后,有三個(gè)可能會(huì)觸發(fā)止損的點(diǎn):
與當(dāng)前價(jià)格距離最近時(shí)觸發(fā)積極跟蹤。
通常,觸發(fā)“耐心”跟蹤。
觸發(fā)理想跟蹤,使收益最大化。
除此之外,點(diǎn) 4 周圍的區(qū)域可能會(huì)錯(cuò)誤地觸發(fā)過于急躁的跟蹤。
既然我們知道如何“標(biāo)記”理想?yún)^(qū)域,接下來唯一的事情就是使其盡可能的妥當(dāng)。
標(biāo)記工具
為了便于使用理想線條對(duì)圖表標(biāo)記,我們來準(zhǔn)備一組腳本。兩個(gè)腳本 TL_Buy 和 TL_Sell 將分別針對(duì)買入和賣出操作創(chuàng)建標(biāo)記線條。腳本 TL_Write 將查看所有創(chuàng)建的線條并將它們的特點(diǎn)保存在一個(gè)文件中以便 Expert Advisor TL_Trade 使用。另一個(gè)腳本 TL_Read 將能夠讀取創(chuàng)建的文件并基于此文件重組所有線條。。這對(duì)更正可用線條、添加一些新的線條或者刪除現(xiàn)有線條可能很有幫助。
為了讀取/寫入腳本能夠使用它們的線條,我們將根據(jù)一定的規(guī)則命名所有線條:
所有理想線條的名稱以同一前綴 (TL_) 開頭。你以后可以使用此前綴來選擇和刪除線條;
前綴后面跟的是一個(gè)表示操作代碼的字符:B-買入,S-賣出;
在線條名稱中,操作代碼后面跟的是線條之間相互區(qū)分的線條編號(hào)。
因此,赫茲量化軟件應(yīng)在圖表中獲得具有例如以下名稱的線條:TL_B1、TL_B2、TL_S3 等。 只需將繪制線條的腳本拖放在圖表上,將在拖放點(diǎn)上出現(xiàn)相應(yīng)的線條。你可以移動(dòng)它的端點(diǎn),以便它們標(biāo)記交易所需的理想“藍(lán)線”。讀取/寫入腳本在連接到圖表后,會(huì)要求提供要保存和讀取的文件名。這樣,我們可以輕松地使用不同的線條集,例如針對(duì)不同的貨幣對(duì)。 這些腳本的代碼相當(dāng)透明,而且提供所有必要的注釋,因此我冒昧地跳過它們的算法說明 - 你可以從它們的代碼中看到算法。
/**************************************************************** PATTERN TRADING: TL_Buy - creation of a new, pattern buying line Copyright ? 2006-2008, Sergey Kravchuk. http://forextools.com.ua *****************************************************************/ #include <WinUser32.mqh> #define _prefix_ "TL_" int start() { ?int MaxNo=0,i,No; ? ?if(WindowOnDropped()!=0) { MessageBox("Script should be dropped in the main window","ERROR", IDOK + MB_ICONERROR); return(1); } ?// find the maximum suffix number for all lines ?for(i=0;i<ObjectsTotal();i++) ?{ ? ?if(StringFind(ObjectName(i),_prefix_)==0) ? ?{ ? ? ?No=StrToInteger(StringSubstr(ObjectName(i),StringLen(_prefix_)+1)); // select the line number ? ? ?if(MaxNo<No) MaxNo=No; // store it, if it is larger ? ?} ?} ? ?datetime t0=WindowTimeOnDropped(); double p0=WindowPriceOnDropped(); // find the coordinates of the script dropping point ?int width = 5*Period()*60; ? ? ? ? ? ? ? ? ? ? ? ? ? ? // width of the created line in bars converted into time units ?double height = 20*MarketInfo(Symbol(),MODE_TICKSIZE); // height of the created line in ticks converted into price units ? ?string LineName = _prefix_+"B"+(MaxNo+1); ?// create a name for a new line ?ObjectCreate(LineName,OBJ_TREND,0,t0-width,p0-height, t0+width,p0+height); // create a line ?ObjectSet(LineName,OBJPROP_RAY,False); // make it a section, not a ray ?ObjectSet(LineName,OBJPROP_WIDTH,2); ? // set its width ?ObjectSet(LineName,OBJPROP_COLOR,Blue); // set its color }
/**************************************************************** PATTERN TRADING: TL_Sell - creation of a new, pattern selling line Copyright ? 2006-2008, Sergey Kravchuk. http://forextools.com.ua *****************************************************************/ #include <WinUser32.mqh> #define _prefix_ "TL_" int start() { ?int MaxNo=0,i,No; ? ?if(WindowOnDropped()!=0) { MessageBox("Script should be dropped in the main window","ERROR", IDOK + MB_ICONERROR); return(1); } ?// find the maximum suffix number for all lines ?for(i=0;i<ObjectsTotal();i++) ?{ ? ?if(StringFind(ObjectName(i),_prefix_)==0) ? ?{ ? ? ?No=StrToInteger(StringSubstr(ObjectName(i),StringLen(_prefix_)+1)); // select the line number ? ? ?if(MaxNo<No) MaxNo=No; // store it, if it is larger ? ?} ?} ? ?datetime t0=WindowTimeOnDropped(); double p0=WindowPriceOnDropped(); // find the coordinates of the script dropping point ?int width = 5*Period()*60; ? ? ? ? ? ? ? ? ? ? ? ? ? ? // width of the created line in bars converted into time units ?double height = 20*MarketInfo(Symbol(),MODE_TICKSIZE); // height of the created line in ticks converted into price units ? ?string LineName = _prefix_+"S"+(MaxNo+1); ?// create a name for a new line ?ObjectCreate(LineName,OBJ_TREND,0,t0-width,p0+height, t0+width,p0-height); // create a line ?ObjectSet(LineName,OBJPROP_RAY,False); // make it a section, not a ray ?ObjectSet(LineName,OBJPROP_WIDTH,2); ? // set its width ?ObjectSet(LineName,OBJPROP_COLOR,Red); // set its color }
/**************************************************************** PATTERN TRADING: TL_Write - saving the coordinates of pattern lines in a file Copyright ? 2006-2008, Sergey Kravchuk. http://forextools.com.ua *****************************************************************/ #include <WinUser32.mqh> #define _prefix_ "TL_" #property show_inputs extern string FileNameForWrite = "TL_DATA.TXT"; int start() { ?int LinesCNT=0,i; string Operation; double p; datetime t; ? ?int fh=FileOpen(FileNameForWrite,FILE_CSV|FILE_WRITE,';'); ?// look through all lines created and save the opening commands for the EA from them ?for(i=0;i<ObjectsTotal();i++) ?{ ? ?if(StringFind(ObjectName(i),_prefix_)==0) // our line ? ?{ ? ? ?string LineName = ObjectName(i); ? ? ? ?datetime t1=ObjectGet(LineName,OBJPROP_TIME1); ? ? ?datetime t2=ObjectGet(LineName,OBJPROP_TIME2); ? ? ?double p1=ObjectGet(LineName,OBJPROP_PRICE1); ? ? ?double p2=ObjectGet(LineName,OBJPROP_PRICE2); ? ? ?LinesCNT++; // increase the counter for producing the final message ? ? ? ? ? ?Operation = StringSubstr(ObjectName(i),StringLen(_prefix_),1); ? ? ? ? ? ?// prices are necessary only for restoring the line in the chart ? ? ?FileWrite(fh,Operation,TimeToStr(t1),DoubleToStr(p1,Digits),TimeToStr(t2),DoubleToStr(p2,Digits)); ? ?} ?} ? ?FileClose(fh); ? ?MessageBox("Stored sections "+(LinesCNT)+" pcs.","Done", IDOK + MB_ICONINFORMATION); }