2014年3月10日 星期一

●抄底逃頂系統 [程式碼]

EasyTrader ArtNo 119
最近看到 Wen大介紹 底部釣魚系統 , 想到自己有看過的抄底逃頂系統的概念相接近,因此將它轉化為策略程式,並作了幾個商品的測試

inputs: EntryType(1),ExitType(2),BarNo(6),UpRatio(1),DnRatio(1),HB(1),LB(1),TradeProfit(0.05),TradeStopLoss(0.045),NBarL(18),NBarS(18);
input: FastLen(5),SlowLen(15),AvgLen(9),SHB(1),SLB(1),K1(0.7);
input:HighBand(90),LowBand(10),UpBand(80),DnBand(20);
vars: IsBalanceDay(False),MP(0),PF(0),PL(0),UBuy(0),BuyStop(0),USell(0),SellStop(0),movAvg(0);

MP = MarketPosition ;

if DAYofMonth(Date) > 14 and DAYofMonth(Date) < 22 and DAYofWeek(Date)= 3 then isBalanceDay = True else isBalanceDay =False ;

PF = AvgPrice*TradeProfit ;
PL = AvgPrice*TradeStopLoss ;

Condition1 = Lowest(Low,FastLen) <= Lowest(Low,SlowLen);
Condition2 = (High-Low) > AvgPrice * UpRatio/100 ;
Condition3 = Close > Open and (Close-Open) > AvgPrice * DnRatio/100 ;
Condition4 = Highest(High,FastLen) >= Highest(High,SlowLen);
Condition5 = (High-Low) > AvgPrice * UpRatio/100 ;
Condition6 = Close < Open and (Open -Close) > AvgPrice * DnRatio/100 ;

if Condition1[1] and condition2[1] and Condition3[1] then Buy ("B2") this bar on close ;
if Condition4[1] and condition5[1] and Condition6[1] then Sell ("S2") this bar on close ;

if ExitType = 1 then SetStopLoss(PL * BigPointValue) ;


if ExitType = 2 then Begin
SetStopLoss(PL * BigPointValue) ;
setProfitTarget(PF * BigPointValue) ;
end;

if ExitType = 3 then Begin
if MP > 0 and BarsSinceEntry = NBarL then ExitLong next bar at Market ;
if MP < 0 and BarsSinceEntry = NBarS then ExitShort next bar at Market ;
end;

if ExitType = 4 then Begin
SetStopLoss(PL * BigPointValue) ;
setProfitTarget(PF * BigPointValue) ;
if MP > 0 and BarsSinceEntry = NBarL then Sell {ExitLong} next bar at Market ;
if MP < 0 and BarsSinceEntry = NBarS then Buy {ExitShort} next bar at Market ;
end;
{
if IsBalanceDay then setExitonClose ;
}






台指期

S&P 500


恆生期


黃金(美元)

蠻不錯的核心策略元素

0 留言:

張貼留言

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

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