今天看網站中翻到一個交易策略,老實說我花了一點時間才看懂,雖然我認為這種作法不適合台指期的操作(因為策略邏輯偏向盤整思考,而且進場是使用limit單)。但如果能先判斷出接下來行情容易盤整,再進行操作,可能是一種較正確的思考方向,在這裡提供網站程式碼供大家參考,希望大家能從中學習程式碼思考的方式即可。

Vars: SumVS(0),

AvgVS(0),

DiffVS(0),

StdVS(0),

SetArr(0),

SumArr(0),

DiffArr(0),

VSLow(0),

VSMid(0),

VSHigh(0),

RiskReward(0);

Array: VS[20](0);

 

For SetArr = 0 To 4 Begin

VS[SetArr * 4 + 0] = (Open[SetArr] - AvgPrice[SetArr + 1]) / AvgPrice[SetArr + 1];

VS[SetArr * 4 + 1] = (High[SetArr] - AvgPrice[SetArr + 1]) / AvgPrice[SetArr + 1];

VS[SetArr * 4 + 2] = (Low[SetArr] - AvgPrice[SetArr + 1]) / AvgPrice[SetArr + 1];

VS[SetArr * 4 + 3] = (Close[SetArr] - AvgPrice[SetArr + 1]) / AvgPrice[SetArr + 1];

End;

 

For SumArr = 0 To 19 Begin

If SumArr = 0 Then

SumVS = 0;

SumVS = SumVS + VS[SumArr];

If SumArr = 19 Then

AvgVS = SumVS / 20;

For DiffArr = 0 To 19 Begin

If DiffArr = 0 Then

DiffVS = 0;

DiffVS = DiffVS + Square(VS[DiffArr] - AvgVS);

If DiffArr = 19 Then

StdVS = SquareRoot(DiffVS / 20);

End;

End;

 

VSLow = AvgPrice * (1 + (AvgVS - StdVS * 2));

VSMid = AvgPrice * (1 + AvgVS);

VSHigh = AvgPrice * (1 + (AvgVS + StdVS * 2));

If MarketPosition = 0 Then Begin

Buy ("Buy") Tomorrow at VSLow Limit;

RiskReward = VSMid-VSLow;

End;

 

If MarketPosition = 1 Then

ExitLong ("PT") Tomorrow At VSHigh Limit;

If MarketPosition = 1 Then

ExitLong ("TS") Tomorrow At VSLow Stop;

If Open Tomorrow >= VSLow Then

ExitLong ("SLa") From Entry ("Buy") At (VSLow-(VSMid-VSLow)) Stop;

If Open Tomorrow < VSLow Then

ExitLong ("SLb") From Entry ("Buy") At (Open Tomorrow-(VSMid-VSLow)) Stop;

   

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 wenschair 的頭像
    wenschair

    程式交易≠Holy Grail

    wenschair 發表在 痞客邦 留言(0) 人氣()