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

Average Volume on MultiTimeFrame not Plotting

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

    Average Volume on MultiTimeFrame not Plotting

    Hey guys, I have modified a indicator that plots average Volume. my goal is to make it show another Time frame on any timeframe. so I set it for 10minute via
    Code:
    Add(PeriodType.Minute, 10)
    and it plots just fine on 10min chart. but when I change to another T.F it won't plot anything.

    All I did was change all of the Time[0] to Times[1][0], and CurrentBar to CurrentBars[1], and Volume[0] to Volumes[1][0]. and I used the
    Code:
    if (BarsInProgress == 0) {}
    Can someone take a look at the code and see what else should be changed for MultiTimeframe object to work.

    Thanks so much
    Last edited by ginx10k; 03-02-2015, 07:41 AM.

    #2
    Hi,

    I don't understand your code much. However, the way you put all of your code inside BarsInProgress == 0 will produce lots of errors, unless you are extremely proficient at MTF programming.

    Here is what I see at a glance:


    if(BarsInProgress == 0) {
    ....

    if (CurrentBars[1] == 0) {
    startTime = Times[1][0];
    return;
    }

    else if (Times[1][0] < startTime.AddDays(7*weeks+1) || Times[1][0] < DateTime.Now.AddDays(-7*Lookback - 8)) {
    .........
    }
    When the condition in the bold line occurs, there is a chance that CurrentBars[1] < 0, which means the secondary data series does not exist at that moment. So your call Times[1][0] become invalid and produce errors. You should check for:

    else if (CurrentBars[1] > 0 && (Times[1][0] < startTime.AddDays(7*weeks+1) || Times[1][0] < DateTime.Now.AddDays(-7*Lookback - 8)) ) {
    However, you had better follow the programming style recommended by NT, that is to seperate 2 data series:

    if (BarsInProgress == 0) { primary data series coding here

    } else { secondary data series coding here

    }

    Cheers.
    Pi
    Last edited by ninZa; 03-02-2015, 04:14 AM.
    ninZa
    NinjaTrader Ecosystem Vendor - ninZa.co

    Comment


      #3
      Thanks for the attempt. but that didn't do anything. I changed (BarsInProgress != 1) return;

      I'll wait for some ninjaSupport. I much appreciate your help though. thanks!

      I uploaded a Multi Timeframe Volume indicator which plots just fine using the BarsInProgress in the same manner.
      Attached Files
      Last edited by ginx10k; 03-02-2015, 04:36 AM. Reason: uploaded FIle

      Comment


        #4
        ginx10k, first of all you should have a CurrentBars check in for all series, i.e.

        if (CurrentBars[0] < BarsRequired || CurrentBars[0] < BarsRequired)
        return;

        You would then get a more meaninful error message in your log, namely -

        Error on calling 'OnBarUpdate' method for indicator 'xxx' on bar yyy: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

        That's due to your barsAgo variable not being adapted to calculate for MultiSeries use - the below should be better imho -

        int barsAgo = CurrentBars[1] - BarsArray[1].GetBar(priorLocalTime);
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Bertrand. that's what I needed. thanks so Much. it worked.

          Much appreciated

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Haiasi, Today, 06:53 PM
          1 response
          3 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by ScottWalsh, Today, 06:52 PM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by ScottW, Today, 06:09 PM
          1 response
          4 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by ftsc2022, 10-25-2022, 12:03 PM
          5 responses
          256 views
          0 likes
          Last Post KeyonMatthews  
          Started by Board game geek, 10-29-2023, 12:00 PM
          14 responses
          244 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Working...
          X