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

Re: [amibroker] Re: DMI problem



PureBytes Links

Trading Reference Links

Yuki,

The code should avoid division by zero otherwise {INF} (infinity value) is produced
that will propagate through recursive smoothing like (D)EMA.

To avoid division by zero either add small constant like this: 
X/(Y+0.0000001)

Or use Nz function that can convert infinity to any value (zero by default):

Nz( X/Y )


In your code 

CMO5=DEMA(100 * Nz(( CMO5_1 -CMO5_2) /( CMO5_1+CMO5_2)),3);

Best regards,
Tomasz Janeczko
amibroker.com
----- Original Message ----- 
From: "Yuki Taga" <yukitaga@xxxxxxxxxxxxx>
To: "Jayson" <amibroker@xxxxxxxxxxxxxxx>
Sent: Thursday, August 07, 2003 12:01 PM
Subject: Re: [amibroker] Re: DMI problem


> Hi Jayson,
> 
> Maybe Tomasz can crack this?
> 
> Yuki
> 
> Thursday, August 7, 2003, 12:50:33 AM, you wrote:
> 
> J> I am just getting back from watching the Tennis Master tournament up in
> J> Montreal so am a bit bogged down here. The code I posted was simply
> J> translated from MS....... I will try to figure it out later in the day. I
> J> qouls have guessed that DT was on the right path I will experiment with the
> J> smoothing.......
> 
> J> Regards,
> J> Jayson
> J> -----Original Message-----
> J> From: DIMITRIS TSOKAKIS [mailto:TSOKAKIS@xxxxxxxxx]
> J> Sent: Wednesday, August 06, 2003 7:15 AM
> J> To: amibroker@xxxxxxxxxxxxxxx
> J> Subject: [amibroker] Re: DMI problem
> 
> 
> J> It is strange.
> J> The huge dmi in
> J> dmi=((StDev(C,5)* CMO5)+(StDev(C,10)* CMO10)+(StDev(C,20)*CMO20))/
> J> (StDev(C,5)+StDev(C,10)+StDev(C,20));
> J> is not because of some very small denominator [usual reason], but is
> J> due to a huge numerator.
> J> In this numerator, the huge is the CMO5 and in
> J> CMO5=DEMA(100 * (( CMO5_1 -CMO5_2) /( CMO5_1+CMO5_2)),3);
> J> we do not have very small denominator, the whole 100 * (( CMO5_1 -
> J> CMO5_2) /( CMO5_1+CMO5_2)) is cool, the DEMA(...,3) makes the huge
> J> value.
> J> You should cancel CMO5 from the formula, or limit it in the [-
> J> 100,100] interval.
> J> So, replace the first lines with
> J> //Cmo5 formula
> J> CMO5_1=Sum( IIf( C > Ref( C, -1 ) , ( C - Ref( C ,-1 ) ) ,0 ) ,5 ) ;
> J> CMO5_2=Sum( IIf( C < Ref( C ,-1 ) , ( Ref( C ,-1 ) - C ) ,0 ) ,5 );
> J> CMO5=DEMA(100 * (( CMO5_1 -CMO5_2) /( CMO5_1+CMO5_2)),3);
> J> CMO5=IIf(CMO5>100,99,CMO5);
> J> CMO5=IIf(CMO5<-100,-99,CMO5);
> J> //Cmo10 formula
> J> CMO10_1=Sum( IIf( C > Ref( C, -1 ) , ( C - Ref( C ,-1 ) ) ,0 ) ,10 ) ;
> J> CMO10_2=Sum( IIf( C < Ref( C ,-1 ) , ( Ref( C ,-1 ) - C ) ,0 ) ,10 );
> J> CMO10=DEMA(100 * (( CMO10_1 -CMO10_2) /( CMO10_1+CMO10_2)),3);
> J> CMO10=IIf(CMO10>100,99,CMO10);
> J> CMO10=IIf(CMO10<-100,-99,CMO10);
> 
> J> //Cmo20 formula
> J> CMO20_1=Sum( IIf( C > Ref( C, -1 ) , ( C - Ref( C ,-1 ) ) ,0 ) ,20 ) ;
> J> CMO20_2=Sum( IIf( C < Ref( C ,-1 ) , ( Ref( C ,-1 ) - C ) ,0 ) ,20 );
> J> CMO20=DEMA(100 * (( CMO20_1 -CMO20_2) /( CMO20_1+CMO20_2)),3);
> J> CMO20=IIf(CMO20>100,99,CMO20);
> J> CMO20=IIf(CMO20<-100,-99,CMO20);
> 
> J> Now we have just a few problems with 8308, 5406 and 1861.
> J> I noticed that there are also some EMA(dmi,pds) {empty} values !!!!!!!
> J> I give up, Jason should look at the formula again !!!
> J> Dimitris Tsokakis
> 
> J> --- In amibroker@xxxxxxxxxxxxxxx, "DIMITRIS TSOKAKIS" <TSOKAKIS@xxxx>
> J> wrote:
> >> I run the same for the ^N225 database and [!!] many examples
> J> appeared.
> >> Let me search please and revert.
> >> Dimitris Tsokakis
> >> --- In amibroker@xxxxxxxxxxxxxxx, "DIMITRIS TSOKAKIS"
> J> <TSOKAKIS@xxxx>
> >> wrote:
> >> > Yuki,
> >> > I added to your formula
> >> > Filter=1;
> >> > AddColumn(Highest(EMA(DMI,PDS)),"DMIh");
> >> > AddColumn(Lowest(EMA(DMI,PDS)),"DMIl");
> >> > AddColumn(Highest(MA(DMI,PDS1)),"TRIGGERh");
> >> > AddColumn(Lowest(MA(DMI,PDS1)),"TRIGGERl");
> >> > and explored for the n=1 last quotations the whole N100 database
> >> from
> >> > Jan2000 till now.
> >> > No value was found out of the [-100,100] range.
> >> > [101*900 different bars]
> >> > Dimitris Tsokakis
> >> > --- In amibroker@xxxxxxxxxxxxxxx, Yuki Taga <yukitaga@xxxx> wrote:
> >> > > I attach two charts, both displaying DMI as described by Jason:
> >> > >
> >> > >  //Dynamic Momentum Index Tushar Chande Translated to AFL by
> >> Jayson
> >> > Casavant
> >> > > //Cmo5 formula
> >> > > CMO5_1=Sum( IIf( C > Ref( C, -1 ) , ( C - Ref( C ,-
> >> 1 ) ) ,0 ) ,5 ) ;
> >> > > CMO5_2=Sum( IIf( C < Ref( C ,-1 ) , ( Ref( C ,-1 ) -
> >> C )  ,0 ) ,5 );
> >> > > CMO5=DEMA(100 * (( CMO5_1 -CMO5_2)  /( CMO5_1+CMO5_2)),3);
> >> > >
> >> > > //Cmo10 formula
> >> > > CMO10_1=Sum( IIf( C > Ref( C, -1 ) , ( C - Ref( C ,-
> >> > 1 ) ) ,0 ) ,10 ) ;
> >> > > CMO10_2=Sum( IIf( C < Ref( C ,-1 ) , ( Ref( C ,-1 ) -
> >> > C )  ,0 ) ,10 );
> >> > > CMO10=DEMA(100 * (( CMO10_1 -CMO10_2)  /( CMO10_1+CMO10_2)),3);
> >> > >
> >> > > //Cmo20 formula
> >> > > CMO20_1=Sum( IIf( C > Ref( C, -1 ) , ( C - Ref( C ,-
> >> > 1 ) ) ,0 ) ,20 ) ;
> >> > > CMO20_2=Sum( IIf( C < Ref( C ,-1 ) , ( Ref( C ,-1 ) -
> >> > C )  ,0 ) ,20 );
> >> > > CMO20=DEMA(100 * (( CMO20_1 -CMO20_2)  /( CMO20_1+CMO20_2)),3);
> >> > >
> >> > > // dmi formula
> >> > > dmi=((StDev(C,5)* CMO5)+(StDev(C,10)* CMO10)+(StDev(C,20)*
> >> > > CMO20))/(StDev(C,5)+StDev(C,10)+StDev(C,20));
> >> > > pds=Param("Smoothing",3,1,10,1);
> >> > > pds1=Param("Trigger Line",5,1,10,1);
> >> > >
> >> > > Plot(EMA(dmi,pds),"Dynamic Momentum Index",colorDarkGreen,1);
> >> > > Plot(MA(dmi,pds1),"trigger",colorRed,1);
> >> > >
> >> > > Buy=Cross(EMA(dmi,pds),MA(dmi,pds1));// AND Trend;
> >> > > Sell=Cross(MA(dmi,pds1),EMA(dmi,pds));// AND NOT (Trend);
> >> > > PlotShapes(IIf(Buy,shapeUpArrow,shapeNone) ,colorBrightGreen);
> >> > > PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed);
> >> > >
> >> > > What is the difference in these two DMI plots?  I simply
> J> scrolled
> >> > the
> >> > > screen one date to the right.
> >> > >
> >> > > I have this problem with several stocks, but the date that the
> >> > > indicator goes haywire on is not the same for any of them.  I
> J> also
> >> > > cannot find anything wrong with the data on the date that the
> >> > > indicator goes nuts.  It is data that is right in line with both
> >> > > price and volume, not extraordinary in any way.  But the
> J> indicator
> >> > > becomes worthless, suddenly.
> >> > >
> >> > > Can anyone clue me in here?
> >> > >
> >> > > Yuki
> 
> 
> 
> Send BUG REPORTS to bugs@xxxxxxxxxxxxx
> Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
> -----------------------------------------
> Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
> (Web page: http://groups.yahoo.com/group/amiquote/messages/)
> --------------------------------------------
> Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
> 
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 
> 
> 
> 

------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for Your HP, Epson, Canon or Lexmark
Printer at Myinks.com. Free s/h on orders $50 or more to the US & Canada. http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/l.m7sD/LIdGAA/qnsNAA/GHeqlB/TM
---------------------------------------------------------------------~->

Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 

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