Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to fetch specific number of periods for MTF series

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

    How to fetch specific number of periods for MTF series

    I need to do a calculation requiring 100 daily bars, but using the code below I seem to only get up to 24 daily bars.

    When I add Print(CurrentBars[1]); before the if statement it prints a range of numbers from -1 to 22.

    Is there an error in my code or a better way to ensure I get 100 daily bars?

    Code:
     
    [FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]protected [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]override [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]void[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] Initialize()[/FONT]
    [FONT=Courier New]{[/FONT]
    [FONT=Courier New]   BarsRequired = [/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]100[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New];[/FONT]
    [FONT=Courier New]   Add(PeriodType.Day, [/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]1[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]);[/FONT]
    [FONT=Courier New]}[/FONT]
    [FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]protected [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]override [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]void[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] OnBarUpdate()[/FONT]
    [FONT=Courier New]{[/FONT]
     
    [FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]   if[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] (CurrentBars[[/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]1[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]] < BarsRequired)[/FONT]
    [FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]       return[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New];[/FONT]
     
    [FONT=Courier New]   // My code down here requiring 100 bars never executes [/FONT]
    [FONT=Courier New]   // because [/FONT][FONT=Courier New]the highest value in CurrentBars is 22[/FONT]
    [FONT=Courier New]}[/FONT]

    #2
    orion176, the loaded days amount is not controlled via code but rather by what you've setup on the chart data series settings you run this script from.

    Comment


      #3
      Aha, setting the "Days to load" to 100+ was the first thing I tried, but I didn't realize it is calendar days, so the number of days needs to be a lot bigger than 100 to get 100 daily bars.

      Comment


        #4
        Is there an elegant way to get a 2nd input series to feed into my indicator without plotting the 2nd series on the main chart or adding a 2nd panel?

        I need the 100 day ATR as input for an indicator that is plotted on a 3 minute chart. It's a bit inefficient to load 100 trading days of intraday historical data just to get a 100 day ATR if you only need a couple of days of data displayed on the chart.

        Comment


          #5
          You could also Add() the series programmatically to have access in the code (this series would not be visualized) but the loaded days amount would still have to cover the 100 calendar days then for your use as the all series would share the lookback of the primary series on the chart.

          Comment


            #6
            Yes that's what I am doing. The problem is that when you have lots of charts open and want to refresh them to make sure the data is up to date, refreshing the 100 days of intraday minute data is a pretty slow option, compared to if I could just get 100 daily bars and 3 days of intraday minute data.

            Comment


              #7
              Thanks for clarifying orion176, allowing more flexibility here is on our list for future consideration.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              579 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              334 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              101 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              554 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              551 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X