提供一個國外逆勢策略的原始碼,我沒有作任何修改,下面是我測試台指期的結果,有興趣的可以自己練習研究,善用這個邏輯是可以寫出不錯的程式策略的。
我沒有修改程式參數,放在台指期15min及60min測試如下:
15min K (不設手續費,參數=8,14,4,20)
60min K (不設手續費,參數=8,14,4,20)
測到這裡,同一組參數,不同週期,雖然沒有設定手續費,但是可以看出趨勢向上,而且表現不凡,表示這個基本邏輯可能是正確的,更重要的一點是大部分進場的方式都算是逆勢進場,能有這種績效,算是十分不錯的了。
好吧!我就說到這裡了,如何把這個程式過濾成能在市場上交易的策略,就看大家各自的功力了。
Multicharts 語法
函數:
Inputs:
KPeriods(NumericSimple),
KSlow(NumericSimple);
Variables:
LoLo(0),
HiHi(0),
HLDIff(0);
LoLo = Lowest(Low, KPeriods);
HiHi = Highest(High, KPeriods);
HLDIff = HiHi - LoLo;
KPeriods(NumericSimple),
KSlow(NumericSimple);
Variables:
LoLo(0),
HiHi(0),
HLDIff(0);
LoLo = Lowest(Low, KPeriods);
HiHi = Highest(High, KPeriods);
HLDIff = HiHi - LoLo;
If HLDIff > 0 Then Begin
If KSlow <= 1 Then
StochCustom = (Close - LoLo) / HLDIff * 100
Else
StochCustom = Average(Close-LoLo,KSlow) / Average(HLDIff, KSlow)*100;
End;
If KSlow <= 1 Then
StochCustom = (Close - LoLo) / HLDIff * 100
Else
StochCustom = Average(Close-LoLo,KSlow) / Average(HLDIff, KSlow)*100;
End;
策略
Input: KPeriods(8), DPeriods(14), KSlow(4), ExitBars(20);
Variables: KVal(0), DVal(0);
KVal = StochCustom(KPeriods, KSlow);
DVal = Average(KVal, DPeriods);
Condition1 = DVal > DVal[1] AND DVal[1] > DVal[2];
Condition2 = DVal < DVal[1] AND DVal[1] < DVal[2];
Variables: KVal(0), DVal(0);
KVal = StochCustom(KPeriods, KSlow);
DVal = Average(KVal, DPeriods);
Condition1 = DVal > DVal[1] AND DVal[1] > DVal[2];
Condition2 = DVal < DVal[1] AND DVal[1] < DVal[2];
If Condition1 AND SwingLow(1, KVal, 1, 2) <> -1 Then
Buy This Bar on Close;
If Condition2 AND SwingHigh(1, KVal, 1, 2) <> -1 Then
Sellshort This Bar on Close;
Buy This Bar on Close;
If Condition2 AND SwingHigh(1, KVal, 1, 2) <> -1 Then
Sellshort This Bar on Close;
If MarketPosition = 1 AND BarsSinceEntry = ExitBars Then
sell This Bar on Close;
If MarketPosition = -1 AND BarsSinceEntry = ExitBars Then
buytocover This Bar on Close;
sell This Bar on Close;
If MarketPosition = -1 AND BarsSinceEntry = ExitBars Then
buytocover This Bar on Close;
0 留言:
張貼留言
如果有私人問題想請教,請透過網站右方『與站長聯絡』之表單,謝謝!