EasyTrader YM_Test 02
// Public Variable
vars:MP(0),PF(0),PL(0),BuyPrice(0),ShortPrice(0),BasePF(600),BasePL(300) ;
vars:BarPass(5),HLRange(0),WinPoint(0),HBarPos(0),LBarPos(0),ExitH(0),ExitL(0),TimeOK(false),EntryExitCond(false),SelectNo(0) ;
vars:jumpPoint(0) ;
jumpPoint = MinMove/PriceScale ;
//計算停損利參考值
//****************** Basic Setup ****************************************
MP = MarketPosition ;
if MP <> 0 then Begin
PF = EntryPrice*TradeProfit ;
PL = EntryPrice*TradeStopLoss ;
end else begin
PF = AvgPrice*TradeProfit ;
PL = AvgPrice*TradeStopLoss ;
end ;
PF = MinList(PF,2500/BigPointValue) ;
PL = MinList(PL,1000/BigPointValue) ;
//計算KD值
// ************ KD *****************
vars:vKA(0),vKB(0),vDA(0),vDB(0),vJA(0),vJB(0),DivSlowKCondA(false),DivSlowKCondB(false) ;
vKA = SlowK(LenA2) ;
vDA = SlowD(LenA2) ;
vJA = 3*vDA-2*vKA ;
vKB = FastK(LenB2) ;
vDB = FastD(LenB2) ;
vJB = 3*vDB-2*vKB ;
// ************* Time Set Up *************
TimeOK = (time >= 1300 or time <= 0100) ;
//***************** BuyPrice & ShortPrice Setup *****************
BuyPrice = HighW(0)+MaxList(TrueRange*RatioL/10,6*jumpPoint) ;
ShortPrice = Maxlist(HighD(0),HighD(1),HighD(2))+Range*0.5 ;
// ********** Main Strategy *********
// ********** Entry Method
//計算凱特通道區間價
// ******** Keltner Entry ***********
vars:KeltnerL(0),KeltnerS(0),KAvgL(0),KAvgS(0) ;
KAvgL = Average(TypicalPrice,LenA1) ;
KAvgS = Average(TypicalPrice,LenB1) ;
KeltnerL = KavgL+AvgTrueRange(LenA1)*FracA ;
KeltnerS = KavgS-AvgTrueRange(LenB1)*FracB ;
if TimeOK then begin
vars:MP(0),PF(0),PL(0),BuyPrice(0),ShortPrice(0),BasePF(600),BasePL(300) ;
vars:BarPass(5),HLRange(0),WinPoint(0),HBarPos(0),LBarPos(0),ExitH(0),ExitL(0),TimeOK(false),EntryExitCond(false),SelectNo(0) ;
vars:jumpPoint(0) ;
jumpPoint = MinMove/PriceScale ;
//計算停損利參考值
//****************** Basic Setup ****************************************
MP = MarketPosition ;
if MP <> 0 then Begin
PF = EntryPrice*TradeProfit ;
PL = EntryPrice*TradeStopLoss ;
end else begin
PF = AvgPrice*TradeProfit ;
PL = AvgPrice*TradeStopLoss ;
end ;
PF = MinList(PF,2500/BigPointValue) ;
PL = MinList(PL,1000/BigPointValue) ;
//計算KD值
// ************ KD *****************
vars:vKA(0),vKB(0),vDA(0),vDB(0),vJA(0),vJB(0),DivSlowKCondA(false),DivSlowKCondB(false) ;
vKA = SlowK(LenA2) ;
vDA = SlowD(LenA2) ;
vJA = 3*vDA-2*vKA ;
vKB = FastK(LenB2) ;
vDB = FastD(LenB2) ;
vJB = 3*vDB-2*vKB ;
// ************* Time Set Up *************
TimeOK = (time >= 1300 or time <= 0100) ;
//***************** BuyPrice & ShortPrice Setup *****************
BuyPrice = HighW(0)+MaxList(TrueRange*RatioL/10,6*jumpPoint) ;
ShortPrice = Maxlist(HighD(0),HighD(1),HighD(2))+Range*0.5 ;
// ********** Main Strategy *********
// ********** Entry Method
//計算凱特通道區間價
// ******** Keltner Entry ***********
vars:KeltnerL(0),KeltnerS(0),KAvgL(0),KAvgS(0) ;
KAvgL = Average(TypicalPrice,LenA1) ;
KAvgS = Average(TypicalPrice,LenB1) ;
KeltnerL = KavgL+AvgTrueRange(LenA1)*FracA ;
KeltnerS = KavgS-AvgTrueRange(LenB1)*FracB ;
if TimeOK then begin
//近N根K棒 出現 最高價突破凱特通道上限 則收盤價突破設定價位做多
if MP <> 1 and MRO(High Cross over KeltnerL,NBarL,1) > 0 and Close < BuyPrice then
Buy ("LE_KeltnerAT") next bar at BuyPrice stop;
Buy ("LE_KeltnerAT") next bar at BuyPrice stop;
end ;
// ******** Slow KD Entry ***********
vars:SKbuy(false),SKshort(false) ;
SKbuy = vKA > vDA and vKA > 55;
SKshort = vKB < vDB and vKB < 45;
if TimeOK then begin
// ******** Slow KD Entry ***********
vars:SKbuy(false),SKshort(false) ;
SKbuy = vKA > vDA and vKA > 55;
SKshort = vKB < vDB and vKB < 45;
if TimeOK then begin
//K值大於D值 且K值大於55 最低價大於N根前最低價 則收盤價突破設定價位做多
if MP <> 1 and SKbuy and Low > Low[LenA1*0.5] and Close < BuyPrice then
Buy ("LE_SKT") next bar at BuyPrice stop;
if MP <> 1 and SKbuy and Low > Low[LenA1*0.5] and Close < BuyPrice then
Buy ("LE_SKT") next bar at BuyPrice stop;
end ;
//基本停利/停損出場
// ************* Base Exit *************
if MP > 0 then Sell ("2PL1_"+NumtoStr(PL,0)) next bar at EntryPrice-PL stop ;
if MP > 0 then Sell ("2PF1_"+NumtoStr(PF,0)) next bar at EntryPrice+PF limit ;
//多單部位獲利不如預期 平倉出場
if MP > 0 and (BarsSinceEntry >= 300/Barinterval and MaxPositionprofit/currentcontracts < 200)
then Sell ("WrongEntryL5") next bar at Close stop ;
//基本停利/停損出場
// ************* Base Exit *************
if MP > 0 then Sell ("2PL1_"+NumtoStr(PL,0)) next bar at EntryPrice-PL stop ;
if MP > 0 then Sell ("2PF1_"+NumtoStr(PF,0)) next bar at EntryPrice+PF limit ;
//多單部位獲利不如預期 平倉出場
if MP > 0 and (BarsSinceEntry >= 300/Barinterval and MaxPositionprofit/currentcontracts < 200)
then Sell ("WrongEntryL5") next bar at Close stop ;
沒有留言:
張貼留言