|
新增功能——通過(guò)文件讀寫(xiě)函數(shù)實(shí)現(xiàn)跨周期數(shù)據(jù)調(diào)用
TB3.2.2增加了文件讀寫(xiě)功能函數(shù),SetTBProfileString和GetTBProfileString,
通過(guò)使用這兩個(gè)函數(shù),可以實(shí)現(xiàn)較復(fù)雜的應(yīng)用,比如跨周期數(shù)據(jù)調(diào)用。 SetTBProfileString將數(shù)據(jù)內(nèi)容寫(xiě)到用戶(hù)公式目錄tblprofile.ini文件下。 下文以5分鐘周期調(diào)用日線(xiàn)指標(biāo)數(shù)據(jù)舉例講解具體應(yīng)用。 操作步驟如下: 1、新建一個(gè)工作區(qū),包含上下兩個(gè)圖表窗體,上面選擇日線(xiàn)周期,下面選擇5分鐘周期。 2、新建一個(gè)技術(shù)指標(biāo),命名為MyDayMA。編譯成功后插入日線(xiàn)圖表中。詳細(xì)代碼如下: Params Numeric length(10); Vars Numeric MA; string strkey; string strValue; Begin MA = AverageFC(Close,length); strKey = DateToString(Date); strValue = Text(MA); SetTBProfileString("DayMA",strKey,strValue); PlotNumeric("MA",MA); End 3、新建一個(gè)技術(shù)指標(biāo),My5MinMA。編譯成功后插入5分鐘圖表中,詳細(xì)代碼如下: Vars NumericSeries DayMAValue; string strKey; string strValue; Begin strKey = DateToString(Date); strValue = GetTBProfileString("DayMA",strKey); If(strValue != InvalidString) { DayMAValue = Value(strValue); }Else { DayMAValue = DayMAValue[1]; } PlotNumeric("DayMA",DayMAValue); End 4、上面的指標(biāo)實(shí)際使用了未來(lái)數(shù)據(jù),用來(lái)寫(xiě)指標(biāo)是可以的,但用來(lái)做交易指令進(jìn)行自動(dòng)交易就會(huì)出問(wèn)題,為了更準(zhǔn)確合理的使用跨周期數(shù)據(jù),我們應(yīng)該稍作修改,代碼如下: Vars NumericSeries DayMAValue; StringSeries strKey; string strValue; Begin If(Date!=Date[1]) { strKey = DateToString(Date[1]); }Else { strKey = strKey[1]; } strValue = GetTBProfileString("DayMA",strKey); If(strValue != InvalidString) { DayMAValue = Value(strValue); }Else { DayMAValue = DayMAValue[1]; } PlotNumeric("DayMA",DayMAValue); End |
|
|