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

Trying to plot a cumulative index

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

    Trying to plot a cumulative index

    Hi,

    Trying to create a cumulative index using the formula ((Close[0]-Open[0])/(High[0]-Low[0])).

    The code is attached. The error I am getting is "Error on plotting indicator 'pressurecum'. Please check the 'OnBarUpdate' or the Plot method: Overflow error. I suppose when High[0] - Low[0] = 0, that is when the problem happens.

    Can someone help with a workaround? Thanks!
    Attached Files

    #2
    Hello,

    I didn't look in your zip (we don't really debug for people), but you might want to just build a condition that filters out that 0 occurance:
    if(High[0] != Low[0])
    {
    //plot here
    }
    DenNinjaTrader Customer Service

    Comment


      #3
      Ben,

      Apart from the Add(new Plot...)line, I only have this line:-

      PCum.Set((Close[0]-Open[0])/(High[0]-Low[0]));

      Not sure what I can do here to address the issue of (High[0]-Low[0]) = 0.

      If I want to keep the previous value in such circumstances, what would I have to write in the script?

      Comment


        #4
        Originally posted by kaywai View Post
        Ben,

        Apart from the Add(new Plot...)line, I only have this line:-

        PCum.Set((Close[0]-Open[0])/(High[0]-Low[0]));

        Not sure what I can do here to address the issue of (High[0]-Low[0]) = 0.

        If I want to keep the previous value in such circumstances, what would I have to write in the script?
        Try this http://www.ninjatrader-support2.com/...ead.php?t=3170

        Comment


          #5
          PrTester, I don't have an issue with insufficient bars. The issue lies with the denominator (High[0]-Low[0])=0. As you know, nothing can be divisible by zero....

          Comment


            #6
            Originally posted by kaywai View Post
            PrTester, I don't have an issue with insufficient bars. The issue lies with the denominator (High[0]-Low[0])=0. As you know, nothing can be divisible by zero....
            double denom = (High[0]-Low[0]);
            if( denom <= 0)
            denom =1;

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by GussJ, 03-04-2020, 03:11 PM
            11 responses
            3,222 views
            0 likes
            Last Post xiinteractive  
            Started by andrewtrades, Today, 04:57 PM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by chbruno, Today, 04:10 PM
            0 responses
            7 views
            0 likes
            Last Post chbruno
            by chbruno
             
            Started by josh18955, 03-25-2023, 11:16 AM
            6 responses
            438 views
            0 likes
            Last Post Delerium  
            Started by FAQtrader, Today, 03:35 PM
            0 responses
            10 views
            0 likes
            Last Post FAQtrader  
            Working...
            X