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 cmtjoancolmenero, Yesterday, 03:58 PM
            1 response
            17 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by benmarkal, Yesterday, 12:52 PM
            3 responses
            23 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by helpwanted, Today, 03:06 AM
            1 response
            20 views
            0 likes
            Last Post sarafuenonly123  
            Started by Brevo, Today, 01:45 AM
            0 responses
            11 views
            0 likes
            Last Post Brevo
            by Brevo
             
            Started by pvincent, 06-23-2022, 12:53 PM
            14 responses
            244 views
            0 likes
            Last Post Nyman
            by Nyman
             
            Working...
            X