EasyTrader ArtNo 078
日內動量指標 (Intraday Momentum Index)是仿造相對強弱指標(RSI)的公式而來,日內動量指標:IMI = [ Iu / ( Iu + Id )] *100
- Iu 為在N日期間內的某日收盤價大於開盤價時(K棒為紅K線), 則將(收盤價-開盤價) 後予以加總的值。
- Id為在N日期間內的某日開盤價大於收盤價時(K棒為黑K線),則將(開盤價-收盤價)後予以加總的值。
所以我們只要觀察這個指標值是在50以上的時間多,還是在50以下的時間多,就可以判斷出這商品究竟是容易收紅K或是收黑K。若是一支股票的IMI指標若大多數時間都在50以上,則是較佳的投資標的,反之,則可能就不是好的投資對象。
動量強度:這是把每日的IMI值減去50後全部予以累加,作為分母。再把IMI指標值大於50的區域加總作為分子,兩者相除而得。
日內動量指標程式碼
Input:BarNo(14),UpBand(70),DnBand(30) ;
Vars:SumBar(0),Zscore(0),Tscore(0),QStick(0),IFT_IMI(0),IMI(0),Strength(0);
Value1 = Summation(AbsValue(Close-Open),BarNo) ;
if Value1 <> 0 then IMI = (Summation(iff(Close > Open ,Close-Open,0),BarNo)/Value1)*100 ;
Plot1(IMI,"IMI") ;
Plot2(0,"Zero") ;
Plot3(UpBand,"UpBand") ;
Plot4(DnBand,"DnBand") ;
動量強度 程式碼
Input:BarNo(14),UpBand(50),DnBand(50) ;
Value2 = Summation(AbsValue(IMI-50),BarNo) ;
Value3 = Summation(iff((IMI-50)>0,(IMI-50),0),BarNo) ;
if Value2 <> 0 then Strength = Value3/Value2 * 100 ;
Plot1(Strength,"Strength") ;
Plot2(0,"Zero") ;
Plot3(UpBand,"UpBand") ;
Plot4(DnBand,"DnBand") ;
測試程式碼
Input:BarNo(14),UpBand(5),DnBand(5),TradeStopLoss(0.02),TradeProfit(0.05),HLRange(100) ,Type(1);
Inputs:HighBand(60),LowBand(40) ,NbarL(6),NbarS(6);
Vars:MP(0),IsBalanceDay(false),PF(0),PL(0),OpenPrice(0),IMI(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 ;
Value1 = Summation(AbsValue(Close-Open),BarNo) ;
if Value1 <> 0 then IMI = (Summation(iff(Close > Open ,Close-Open,0),BarNo)/Value1)*100 ;
Value2 = Summation(AbsValue(IMI-50),BarNo) ;
Value3 = Summation(iff((IMI-50)>0,(IMI-50),0),BarNo) ;
if Value2 <> 0 then Strength = Value3/Value2 * 100 ;
Condition1 = IMI Cross over UpBand ;
Condition2 = IMI Cross under DnBand ;
Condition3 =Strength Cross over HighBand ;
Condition4 = Strength Cross under LowBand ;
Condition5 = IMI > UpBand and Strength > HighBand ;
Condition6 = IMI < DnBand and Strength < LowBand ;
if Type = 1 then Begin
if Condition1 then Buy next bar at Highest(High,3) stop {Market} ;
if Condition2 then Sell next bar at Lowest(Low,3) stop { Market} ;
end;
if Type = 2 then Begin
if Condition3 then Buy next bar at {Highest(High,3) stop} Market ;
if Condition4 then Sell next bar at {Lowest(Low,3) stop} Market ;
end;
if Type = 3 then Begin
if Condition5 then Buy next bar at Highest(High,3) stop {Market} ;
if Condition6 then Sell next bar at Lowest(Low,3) stop { Market} ;
end;
SetProfitTarget(PF*BigPointValue) ;
Setstoploss(PL*BigPointValue) ;
if IsBalanceDay then SetExitonClose ;
讀者可以先自己動手測試看看喔!
沒有留言:
張貼留言