您好,我是用元大Multicharts寫程式。
目前寫好在做回測時,卻發生一個大問題,就是當我在[設定]的[屬性]裡面, 改變[固定委託股數]時,卻發現填入1或2或3...,其訊號出現的時間、點位...等,均 出現完全不一樣的結果。導致該程式變成無法加碼。 我[當沖]的程式碼如下: Inputs : R1(0), HighLowTerm(9), Price(Close), AA(1), BB(2), Displace(0); Variable : TMR(0), Factor(1/3), Var0(0), K0(0), D0(0), Count01(0), Count02(0), In01(0), In02(0); Value1 = Value1[1] + (Factor * (FastK( HighLowTerm) - Value1[1])); Value2 = BB/(AA+BB) * Value2[1] + Value1 * AA/(AA+BB); K0 = Value1; D0 = Value2; If date[0] <> date[1] then begin Count01 = 0; Count02 = 0; end; If marketposition = 0 then begin In01 = 0; In02 = 0; end; Condition1 = K0 >= K0[1] and D0 >= D0[1] and marketposition = 0; If condition1 and Time >= 0845 and Time <= 1325 and currentbar > Var0 and EntriesToday(date) <= 5 and ExitsToday(date) <= 5 then begin buy("buy01") next bar at market; Count01 = 0; Var0 = currentbar + 1; In01 = 1; end; if In01 = 1 then setstoploss(30*bigpointvalue); if In01 = 1 then setpercenttrailing(20*bigpointvalue,50); Condition2 = K0 <= K0[1] and D0 <= D0[1] and marketposition = 0; If condition2 and Time >= 0845 and Time <= 1325 and currentbar > Var0 and EntriesToday(date) <= 5 and ExitsToday(date) <= 5 then begin sellshort("sell02") next bar at market; Count02 = 0; Var0 = currentbar + 1; In02 = 1; end; if In02 = 1 then setstoploss(30*bigpointvalue); if In02 = 1 then setpercenttrailing(20*bigpointvalue,50); If time_s >= 133455 then begin If MarketPosition <> 0 then begin sell next bar at market; buytocover next bar at market; end; end; //MTHLY CHANGE TMR = JulianToDate(DateToJulian(Date)); if (DayOfWeek(TMR) = 3 and Mod(TMR, 100) >= 15 and Mod(TMR, 100) <= 21) and marketposition > 0 and time = 1325 then begin sell("REGULLAR EXIT SELL") this bar; end; if (DayOfWeek(TMR) = 3 and Mod(TMR,100) >= 15 and Mod(TMR, 100) <= 21) and marketposition < 0 and time = 1325 then begin buytocover("REGULLAR EXIT BUY") this bar; end;//MTHLY CHANGE //SPECIAL ROLLING if (Date = ELDate(02,22,2010) or Date = ELDate(06,17,2010) or Date = ELDate(08,22,2013) or Date = ELDate(02,24,2015)) and marketposition > 0 and time = 1325 then begin sell("SPECIAL EXIT SELL*") this bar; end; if (Date = ELDate(02,22,2010) or Date = ELDate(06,17,2010) or Date = ELDate(08,22,2013) or Date = ELDate(02,24,2015)) and marketposition < 0 and time = 1325 then begin buytocover("SPECIAL EXIT BUY*") this bar; end;
最後面加一行指令,試看看
setstopcontract;