網路上看到一個老美寫的S&P的交易策略,提供給各位當作語法練習就好了。另外我發現美國人寫的策略很多都有使用「開盤價」,這點倒讓我很印象深刻。

 

我隨便拿來測試台指期的結果如下(使用DATA1=15 min、DATA2=60min)

 

ScreenHunter_01 Jul. 08 22.59  

 

Inputs:waitPeriodMins(45),initTradesEndTime(1330),liqRevEndTime(1300),
thrustPrcnt1(0.20),thrustPrcnt2(0.40),mmStop(1000);

Variables:averageRange(0),averageOCRange(0),canTrade(0),buyEasierDay(FALSE),
sellEasierDay(FALSE),buyBOPoint(0),sellBOPoint(0),myBarCount(0),
longLiqPoint(0),shortLiqPoint(0),buysToday(0),sellsToday(0);


if(Date <> Date[1]) then
begin
canTrade = 0;
if(Range of Data2 = MinList(Range of data2,Range[1] of data2,
Range[2] of Data2,Range[3] of data2)) then canTrade = 1;
buyEasierDay = FALSE;
sellEasierDay = FALSE;

if(Close of Data2 > Close[1] of Data2 and
Open > Close of Data2) then buyEasierDay = TRUE;
if(Close of Data2 < Close[1] of Data2 and
Open < Close of Data2) then sellEasierDay =TRUE;

buyBOPoint = Open + thrustPrcnt2*AvgTrueRange(10)of data2;
sellBOPoint = Open - thrustPrcnt2*AvgTrueRange(10)of data2;
if(buyEasierDay) then buyBOPoint = Open + thrustPrcnt1*AvgTrueRange(10)of data2;
if(sellEasierDay) then sellBOPoint= Open - thrustPrcnt1*AvgTrueRange(10)of data2;
myBarCount = 0;
buysToday = 0;sellsToday = 0;
end;

myBarCount = myBarCount + 1;
if(myBarCount >= waitPeriodMins/BarInterval and canTrade = 1) then {have we waited long enough}
begin
if(MarketPosition = 1) then buysToday = 1;

if(MarketPosition =-1) then sellsToday= 1;

if(buysToday = 0 and Time < initTradesEndTime) then
Buy("LBreakOut") next bar at buyBOPoint stop;
if(sellsToday= 0 and Time < initTradesEndTime) then
SellShort("SBreakout") next bar at sellBOPoint stop;

if(MarketPosition = 1) then
begin
longLiqPoint = EntryPrice-mmStop/(pointValue*priceScale);
if(Time < liqRevEndTime and sellsToday = 0) then
begin
SellShort("LongLiqRev") next bar at longLiqPoint stop;
end
else begin
Sell("LongLiq") next bar at longLiqPoint stop;
end;
end;
if(MarketPosition =-1) then
begin
shortLiqPoint = EntryPrice+mmStop/(pointValue*priceScale);
if(Time < liqRevEndTime and buysToday = 0 ) then
begin
Buy("ShortLiqRev") next bar at shortLiqPoint stop;
end
else begin
BuyToCover("ShortLiq") next bar at shortLiqPoint stop;
end;
end;
end;
SetExitOnClose;
setstoploss(6000);

創作者介紹

程式交易≠Holy Grail

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