EasyTrader ArtNo 078
日內動量指標 (Intraday Momentum Index)是仿造相對強弱指標(RSI)的公式而來,
日內動量指標:IMI = [ Iu / ( Iu + Id )] *100
- Iu 為在N日期間內的某日收盤價大於開盤價時(K棒為紅K線), 則將(收盤價-開盤價) 後予以加總的值。
- Id為在N日期間內的某日開盤價大於收盤價時(K棒為黑K線),則將(開盤價-收盤價)後予以加總的值。
所以IMI是先計算出在N日期間內所有紅K棒實體的加總值,與黑K棒實體的加總值,將兩者相加作為分母,分子則是紅K棒實體的加總值。意思也就是「在所有的K棒中,紅K棒所佔的百分比」。這個指標值理論上最大是100(全部紅K棒),最小是0(全部黑K棒),而50則為中間值(紅黑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;
{
if MP > 0 and BarsSinceEntry = NbarL then ExitLong next bar at Market ;
if MP < 0 and BarsSinceEntry = NbarS then ExitShort next bar at Market ;
}
setProfitTarget(PF*BigPointValue) ;
setstoploss(PL*BigPointValue) ;
if IsBalanceDay then SetExitonClose ;
讀者可以先自己動手測試看看喔!
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;
{
if MP > 0 and BarsSinceEntry = NbarL then ExitLong next bar at Market ;
if MP < 0 and BarsSinceEntry = NbarS then ExitShort next bar at Market ;
}
setProfitTarget(PF*BigPointValue) ;
setstoploss(PL*BigPointValue) ;
if IsBalanceDay then SetExitonClose ;
讀者可以先自己動手測試看看喔!
0 留言:
張貼留言
如果有私人問題想請教,請透過網站右方『與站長聯絡』之表單,謝謝!