2013年7月8日 星期一

★S&P system策略(含程式碼)


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

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

  

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);

0 留言:

張貼留言

如果有私人問題想請教,請透過網站右方『與站長聯絡』之表單,謝謝!

----------------------------------------------------------------------------------------------------
網站聲明(Disclaimer)
本教學網站內所提供之程式碼(包括函數、指標、訊號)屬開放程式碼,用意在於讓使用者學習程式語法之撰寫,使用者可以任意修改語法內容並調整參數。本網站所有之內容(包括文章、影片、歷史紀錄、程式碼、教材)限用於個人學習使用,請勿轉寄、濫用,嚴禁私自串接帳戶交易。
-------------------------------------------------------------------------------------------------