[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Possible division by 0 error



PureBytes Links

Trading Reference Links

Can anybody see a way to adjust this "Dynamic Momentum Index " 
formula from the Library so that it always returns a value and 
not "Empty" on some intraday charts:

_SECTION_BEGIN("Dynamic Momentum Index");
period = Param( "RSI Period", 13, 1, 100, 1 );
MAperiod = Param( "MA Period", 5, 1, 100, 1 );
StDevperiod = Param( "StDev Period", 8, 1, 100, 1 );

upday=IIf(C>Ref(C,-1),C-Ref(C,-1),0);
downday=IIf(Ref(C,-1)> C,Ref(C,-1)-C,0);

Stda=MA(StDev(C,StDevperiod),MAperiod);
V1=StDev(C,StDevperiod)/Stda;
TD=int(period/V1);

Su=Sum(upday,TD);
Sd=Sum(downday,TD);
M1=(Su-Sd);
M2=abs(Su+Sd);
DMI=50*(M1+M2)/M2;
xs=Param("Smoothing",3,1,10,1);
xs1=Param("Trigger Line",5,1,10,1);

Plot(EMA(DMI,xs),"Dynamic Momentum Index ",colorRed,1);
Plot(MA(DMI,xs1),"trigger",colorBlue,1);
Buy=Cross(EMA(DMI,xs),MA(DMI,xs1));
Sell=Cross(MA(DMI,xs1),EMA(DMI,xs));
PlotShapes(IIf(Buy ,shapeUpArrow,shapeNone) ,colorBrightGreen);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorOrange);
Plot(70,"",2,1);Plot(30,"",2,1);
_SECTION_END();

I have tried substituting:
 Max(C,0.0001) instead of close
also:  DMI = (50*M1)/M2 + 50; 
instead of: DMI=50*(M1+M2)/M2;
These were attempts to clear out any division by zero errors but 
didn't make a difference.
Any suggestions on ways to make it work please?
Patrick




------------------------------------

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/