2013年11月26日 星期二

㊣ 程式碼自動產生器的開發 Part 4

EasyTrader ArtNo 060
在完成價格比對進出場規則後,如何將符合設定績效條件的程式碼輸出也是一個大工程,在 TS2000i 對於資料的輸出可以使用 Print 指令, 它原來是用於程式編輯偵錯除蟲 (Debug)用途,另一個保留字為 FileAppend , 在這裡簡單說明這兩個保留字用法

PRINT(Parameters)
將指定資訊輸出到程式編輯器的除錯視窗 ,若有特殊需求也可以輸出到指定檔案或預設的印表機. Parameter 可以是有效的文字 ,數字序列 ,數值表示 ,各不同資料中間以逗點區隔: 例如

Print( Date ,Time ,Close );
Print( "ABC",HighBand,"Color Yellow") ;

如果是輸出到檔案 ,需要給與一個包含路徑的檔名 ,放在 Print的第一個參數位置 ,同時路徑檔名必需以雙引號包住. 例如將日期/時間/收盤價 輸出到 C:\data\mydata.txtPrint(File("c:\data\mydata.txt"),Date, Time, Close);

若是要輸出到預設印表機,則為 Print(Printer, Date, Time, Close);
Sends information to an existing ASCII file specified by the user and adds the information to the bottom of the file.
FileAppend("str_Filename", "str_Text") ;

(str_Filename) 是要輸出的檔名路徑的文字表示式,若檔案已存在,則會將資料新增到原檔案的最後面,若檔案不存在則會自動開新檔案 string expression that is the path and file name for the existing ASCII text file to which you want to append the string of text. The path and file name should be enclosed in quotes.

(str_Text) 要輸出到文字檔的資料

Remarks
注意: 數值部份的資料要先以 NumToStr 先以函數轉成字串型態,例如

If Open > High[1] * 1.1 Then
    FileAppend("c:\mydata.txt", "This symbol gapped up on " + NumToStr(Date, 0) +
NewLine);

Mydata.txt 內容為 This symbol gapped up on 1110923

接下來是程式碼自動產生器的輸出部份內容

if ExitType = 3 then Begin
StrOut = " Net Profit = " + NumtoStr(NetProfit, 2) + ", Max DD = " + NumtoStr(MaxIDDrawDown, 2) +
", Num Trades = " + NumtoStr(TotalTrades, 0) + ", Percent Wins = " + NumtoStr(PercentProfit, 2) +
", Prof factor = " + NumtoStr(ProfFac, 3) +
", ExitType = " + NumtoStr(ExitType,0) +
", BarLenth = " + NumtoStr(BarLength,0) + Newline;
end;

if ExitType = 4 then Begin
StrOut = " Net Profit = " + NumtoStr(NetProfit, 2) + ", Max DD = " + NumtoStr(MaxIDDrawDown, 2) +
", Num Trades = " + NumtoStr(TotalTrades, 0) + ", Percent Wins = " + NumtoStr(PercentProfit, 2) +
", Prof factor = " + NumtoStr(ProfFac, 3) +
", ExitType = " + NumtoStr(ExitType,0) +
", TradeProfit = " + NumtoStr(TradeProfit,0) +Newline;
end;

FileAppend(FName, StrOut);
FileAppend(FileName, StrOut);

StrOut = "{ MagicQS168 System code starts - by EasyTrader }" + NewLine;
{FileAppend(FName, StrOut);}
FileAppend(FileName, StrOut);

{****************}

....
....

if ExitType = 3 then Begin
StrOut = "input: ExitType(" + NumtoStr(ExitType,0) + ")" + ", BarLength(" + NumtoStr(BarLength,0) + ") ;" + NewLine;

{FileAppend(FName, StrOut);}
FileAppend(FileName, StrOut);
end;

if ExitType = 4 then Begin
StrOut = "input: ExitType(" + NumtoStr(ExitType,0) + ")" +", TradeProfit(" + NumtoStr(TradeProfit,0) + ") ;" + NewLine;

{FileAppend(FName, StrOut);}
FileAppend(FileName, StrOut);
end;

{****************}
StrOut = "Var: EntryCheck (false);" + NewLine;
{FileAppend(FName, StrOut);}
FileAppend(FileName, StrOut);
StrOut = "";

For LoopNo = 0 to NRules - 1 Begin
If PriceL[LoopNo] = 0 then Begin
If PriceR[LoopNo] = 0 then Begin
If CompareSign[LoopNo] = 0 then
StrOut = StrOut + "Open[" + NumtoStr(BarLeft[LoopNo], 0) + "] >= Open[" + NumtoStr(BarRight[LoopNo], 0) + "]"
else if CompareSign[LoopNo] = 1 then
StrOut = StrOut + "Open[" + NumtoStr(BarLeft[LoopNo], 0) + "] <= Open[" + NumtoStr(BarRight[LoopNo], 0) + "]";
end

輸出的文字檔報告總表_MS168_CodeRpt.txt


本次共產生8個符合設定目標的程式策略碼

同步輸出的程式碼文字檔_MS168_11261145.txt


接下來就是將程式碼自行加入信號檔 ,先示範將 System 214 作成一個信號檔,結果如下



也就是程式碼自動產生器的運作是可行的,而且每一次執行都可以依據設定目標產生新的策略程式碼,距離聖盃追尋更近了

{----------待續-----------}

沒有留言:

張貼留言