Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Changing chart Days / Bars To Load with an Indicator

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

    Changing chart Days / Bars To Load with an Indicator

    Hi there:

    I'm developing a custom indicator which is based on the main chart (a very small timeframe), and another added DataSeries which stays hidden (This second data series has a significantly bigger time frame than the first one).

    I noticed while developing than the results from certain calculations had problems, some values returned unexpected outputs. After trying different things, I found out that the problem was caused due to the Days/Bars to load configured. Somehow, due to the added data series being significantly bigger than the other timeframe, I had to load a lot of bars to make the calculations work correctly.

    E.g. if I load 1500 Bars in the chart, the output is incorrect, but when loading 15000 Bars, it works perfectly (without the code being modified).
    Quick note: Loading this amount of bars did not affect performance on an old laptop which I also tried just to make sure.


    So my question here is: Is there any way to change/set the Days or Bars to load from inside an indicator? I would like to do this just to make sure that no matter the user input, the needed amount of bars will be loaded so that the indicator works correctly.

    Thanks in advance!

    #2
    Hello DonMiguelo,

    There is not a way to change the bars to load using an indicator but you can add secondary series to the indicator with a set number of bars to load.

    AddDataSeries(string instrumentName, BarsPeriod barsPeriod, int barsToLoad, string tradingHoursName, bool? isResetOnNewTradingDay)

    Comment


      #3
      Hi! Thanks Jesse.

      Is there any way to specify the parameters I want to give to the function? Instead of using the default overloads?
      In the documentation the only syntax that allows for adding bars to load is the longest and has additional parameters I find unnecessary.
      Click image for larger version

Name:	image.png
Views:	100
Size:	4.6 KB
ID:	1316138

      I tried to use the optional argument syntaxis ... "barsToLoad: 100", but I get the error: The best overload does not have a parameter named 'barsToLoad'.

      Click image for larger version

Name:	image.png
Views:	73
Size:	3.7 KB
ID:	1316137

      Also, in case I need to use that syntaxis, how do I create the BarsPeriod Objet? As it must have both packed, type and value and creating BarsPeriod object didn't work

      Ty

      Comment


        #4
        Hello DonMiguelo,

        In this case you would need to use that override, unfortunately there is not a way to control that using a property, the parameters in the method need to be used to configure the series.

        To create a BarsPeriod you can use the following syntax:

        new BarsPeriod() { BarsPeriodType = BarsPeriodType.Minute, Value = 10 }

        Comment


          #5
          Hi again Jesse:

          Sorry for bothering so much with this but I have another question now: What's the right way to get the instrument name here??

          These are both working for me
          Code:
          this.Instrument.FullName
          Bars.Instrument.MasterInstrument.Name
          But the documentation strongly advises against using either one before the State has reached State.DataLoaded and the AddDateSeries function should ONLY be called from the OnStateChange() method during State.Configure

          Should I use something like
          Code:
           if (Instrument != null)
          or what is the actual correct way to do this?

          Thank you!

          Comment


            #6
            Hello DonMiguelo,

            To use the primary instrument you can just use null for the instrument name.

            AddDataSeries(null,

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            647 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            369 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            108 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            572 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            573 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X