Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Adding Volume

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

    Adding Volume

    I am having problems adding two volumes together. The below code works as long as I do not set the "barsago" higher than 5. How do I add twovolumes together and display them to check. I would like to add current bar "Volume [0]" and add a data bar's volume 1000 bars ago "Volume [1000]"

    Every instance I change the "Volume [3]" to > Volume [5] nothing displays.

    double Myvolume = Volume [0] + Volume [3];
    DrawTextFixed("tag1", Myvolume.ToString(), TextPosition.TopLeft);
    Last edited by loujen213; 02-05-2012, 09:42 PM.

    #2
    loujen213, do you see any error message in the log tab of NT's Control Center when the indicator stops to work for you? What CurrentBars check do you run at the OnBarUpdate() start? Is this perhaps not high enough for your 5 bar lookback?

    Comment


      #3
      No error message in the control center. CurrentBar check? Is there a different way to add two volume bars together Volume [1] and Volume [120] and then display it at the top to check? If so can you show me a different way?

      I do not think the look back is the problem. I have a 1 minute chart with 24hr continuous data.


      Thank you for your help. I am very new to ninjascript so i apologize for not understanding

      Comment


        #4
        This is not to be confused with the lookback for the chart, let me explain.

        As your chart and therefore OnBarUpdate() calls for the script begin you are on the first bar of the series, so think of CurrentBar == 0.

        At this point in time there is no prior bar available, so any call to an index other then 0 will fail unfortunately.

        To prevent this, ensure OnBarUpdate() is called from bar 5 for example onwards - if you add

        if (CurrentBar < 5) return;

        at the top of your OnBarUpdate() and press F5 to compile those changes in and then rerun the script, would it work for you?

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        152 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        89 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        131 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        127 views
        1 like
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        107 views
        0 likes
        Last Post CarlTrading  
        Working...
        X