EasyTrader TestNo 002
參考文章 台指期貨的潛規則(I) - 固定時間進場// Public Variable
vars:MP(0),PF(0),PL(0),DayLast(1345),NightLast(0500),BuyPrice(0),ShortPrice(0),BasePF(150),BasePL(100) ;
vars:BarPass(5),HLRange(0),WinPoint(0),HBarPos(0),LBarPos(0),ExitH(0),ExitL(0),TimeOK(false) ;
//****************** 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 ;
// 依據目前指數來設定最大停利與停損點數
if Close > 10000 then begin
BasePF = BasePF+IntPortion((Close-10000)/1000)*30 ;
BasePF = MinList(BasePF,450) ;
BasePL = BasePL+IntPortion((Close-10000)/1000)*15 ;
BasePL = MinList(BasePL,225) ;
end ;
PF = MinList(PF,BasePF) ;
PL = MinList(PL,BasePL)*iff(CurrentContracts=1,1,0.67) ;
// ************ High/Low data *****************
BarPass = MaxList(HBar,LBar) ;
//***************** BuyPrice & ShortPrice Setup *****************
if BuyMode = 49 then BuyPrice = (OpenW(0)+CloseW(1))*0.5 ;
if ShortMode = 50 then ShortPrice = LowW(1) ;
// ********** Main Strategy *********
// ********** Entry Method
//符合條件的固定時間進場
if (time = 945 or time = 2200) and _IsSettlementDay = false then Begin
if AvgTrueRange(BarPass) < RatioL*12 and ADX(LenA1) < HighBand then
if MP <> 1 and Close > BuyPrice then Buy ("MQS02_L1T") next bar at Market ;
if AvgTrueRange(BarPass) > RatioS*12 and ADX(LenB1) > LowBand then
if MP <> 1 and Close < ShortPrice then SellShort ("MQS02_S1T") next bar at Market ;
end;
// ************* Base Exit *************
if MP <> 0 and BarsSinceEntry >= 1 then begin
if MP > 0 then Sell ("PL1_"+NumtoStr(PL,0)) next bar at EntryPrice-PL stop ;
if MP > 0 then Sell ("PF1_"+NumtoStr(PF,0)) next bar at EntryPrice+PF limit ;
if MP < 0 then BuytoCover ("PL2_"+NumtoStr(PL,0)) next bar at EntryPrice+PL stop ;
if MP < 0 then BuytoCover ("PF2_"+NumtoStr(PF,0)) next bar at EntryPrice-PF limit ;
end ;
//進場後部位損失大於預期則出場或做反手單
if MP > 0 and (BarsSinceEntry <= 300/Barinterval and maxpositionloss/currentcontracts < -20000)
then sellshort ("WrongEntryL12") next bar at Close stop ;
if MP < 0 and (BarsSinceEntry <= 300/Barinterval and maxpositionloss/currentcontracts < -20000)
then buytocover ("WrongEntryS12") next bar at Close stop ;
// ************* Rev EntryPrice PullBack *************
//跌破進場價格一段距離後反手做空
if MP > 0 and BarsSinceEntry > NBarL then
SellShort ("rLX_EntPricePB") next bar at EntryPrice - MaxList(FracA*AvgTrueRange(BarPass),100) stop;
//突破進場價格一段距離後反手做多
if MP < 0 and BarsSinceEntry > NBarS then
Buy ("rSX_EntPricePB") next bar at EntryPrice + MaxList(FracB*AvgTrueRange(BarPass),100) stop;
//結算日出場
if _IsSettlementDay and time >= CalcTime(1300,-1*BarInterVal) and Time <= 1330 then begin
if MP > 0 then Sell ("LX_Bal") next bar at market ;
if MP < 0 then BuyToCover ("SX_Bal") next bar at market ;
end;
台指期 60分K 留倉 交易週期 2018/1/1 ~ 2022/12/31 交易成本 1200
vars:MP(0),PF(0),PL(0),DayLast(1345),NightLast(0500),BuyPrice(0),ShortPrice(0),BasePF(150),BasePL(100) ;
vars:BarPass(5),HLRange(0),WinPoint(0),HBarPos(0),LBarPos(0),ExitH(0),ExitL(0),TimeOK(false) ;
//****************** 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 ;
// 依據目前指數來設定最大停利與停損點數
if Close > 10000 then begin
BasePF = BasePF+IntPortion((Close-10000)/1000)*30 ;
BasePF = MinList(BasePF,450) ;
BasePL = BasePL+IntPortion((Close-10000)/1000)*15 ;
BasePL = MinList(BasePL,225) ;
end ;
PF = MinList(PF,BasePF) ;
PL = MinList(PL,BasePL)*iff(CurrentContracts=1,1,0.67) ;
// ************ High/Low data *****************
BarPass = MaxList(HBar,LBar) ;
//***************** BuyPrice & ShortPrice Setup *****************
if BuyMode = 49 then BuyPrice = (OpenW(0)+CloseW(1))*0.5 ;
if ShortMode = 50 then ShortPrice = LowW(1) ;
// ********** Main Strategy *********
// ********** Entry Method
//符合條件的固定時間進場
if (time = 945 or time = 2200) and _IsSettlementDay = false then Begin
if AvgTrueRange(BarPass) < RatioL*12 and ADX(LenA1) < HighBand then
if MP <> 1 and Close > BuyPrice then Buy ("MQS02_L1T") next bar at Market ;
if AvgTrueRange(BarPass) > RatioS*12 and ADX(LenB1) > LowBand then
if MP <> 1 and Close < ShortPrice then SellShort ("MQS02_S1T") next bar at Market ;
end;
// ************* Base Exit *************
if MP <> 0 and BarsSinceEntry >= 1 then begin
if MP > 0 then Sell ("PL1_"+NumtoStr(PL,0)) next bar at EntryPrice-PL stop ;
if MP > 0 then Sell ("PF1_"+NumtoStr(PF,0)) next bar at EntryPrice+PF limit ;
if MP < 0 then BuytoCover ("PL2_"+NumtoStr(PL,0)) next bar at EntryPrice+PL stop ;
if MP < 0 then BuytoCover ("PF2_"+NumtoStr(PF,0)) next bar at EntryPrice-PF limit ;
end ;
//進場後部位損失大於預期則出場或做反手單
if MP > 0 and (BarsSinceEntry <= 300/Barinterval and maxpositionloss/currentcontracts < -20000)
then sellshort ("WrongEntryL12") next bar at Close stop ;
if MP < 0 and (BarsSinceEntry <= 300/Barinterval and maxpositionloss/currentcontracts < -20000)
then buytocover ("WrongEntryS12") next bar at Close stop ;
// ************* Rev EntryPrice PullBack *************
//跌破進場價格一段距離後反手做空
if MP > 0 and BarsSinceEntry > NBarL then
SellShort ("rLX_EntPricePB") next bar at EntryPrice - MaxList(FracA*AvgTrueRange(BarPass),100) stop;
//突破進場價格一段距離後反手做多
if MP < 0 and BarsSinceEntry > NBarS then
Buy ("rSX_EntPricePB") next bar at EntryPrice + MaxList(FracB*AvgTrueRange(BarPass),100) stop;
//結算日出場
if _IsSettlementDay and time >= CalcTime(1300,-1*BarInterVal) and Time <= 1330 then begin
if MP > 0 then Sell ("LX_Bal") next bar at market ;
if MP < 0 then BuyToCover ("SX_Bal") next bar at market ;
end;
台指期 60分K 留倉 交易週期 2018/1/1 ~ 2022/12/31 交易成本 1200
沒有留言:
張貼留言