Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Value outside of range - divide by zero issue

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Value outside of range - divide by zero issue

    I've got a simple indicator that compares the relative changes in price to changes in another oscillator. I've printed the resulting data to the output window and the values vary from negative to positive and are in a relatively tight range except when there is no change in price and I end up with a spike to infinity (which prints to the output window) this seems to occurr because when price doesn't change there is a divide by zero incident.

    Is there a way to check for divide by zero and not plot that? or is there another approach I should take to compare the relative changes of two sets of data?

    Here is my code:

    Code:
    			double RsiDelta = (RSI(2,3)[0] + RSI(2,3)[1] + RSI(2,3)[2]) - 
    								(RSI(2,3)[1] + RSI(2,3)[2] + RSI(2,3)[3]);
    			
    			double PriceDelta = (Close[0] - Close[1]) * 100;
    			
    			Print("RsiDelta is " + RsiDelta);
    			Print("PriceDelta is " + PriceDelta);
    			Print("RsiDelta divided by PriceDelta is " + RsiDelta / PriceDelta);
    
                PTR.Set(RsiDelta / PriceDelta);

    #2
    ShruggedAtlas,

    double PriceDelta = (Close[0] - Close[1]) * 100;

    and

    PTR.Set(RsiDelta / PriceDelta);

    Is the culprit here. This may be zero, as such you need to check :

    if ( PriceDelta < Double.Epsilon )
    {
    //do something
    }

    You may want to use the prior PriceDelta that wasn't zero, i.e. keep track of the previous PriceDelta and only update the previous one if PriceDelta isn't zero.

    Please let me know if I may assist further.
    Last edited by NinjaTrader_AdamP; 02-15-2012, 10:23 AM.
    Adam P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by AlgoDreamer, Today, 10:39 AM
    2 responses
    12 views
    0 likes
    Last Post AlgoDreamer  
    Started by warpinator, Today, 10:44 AM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by kevinenergy, 02-17-2023, 12:42 PM
    121 responses
    2,863 views
    1 like
    Last Post RedRock
    by RedRock
     
    Started by Brillo, Today, 10:35 AM
    1 response
    4 views
    0 likes
    Last Post NinjaTrader_Zachary  
    Started by FAQtrader, 04-25-2024, 12:00 PM
    13 responses
    208 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Working...
    X