Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Synchronizing (the dates) for plotting (outside) data in a graph

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

    Synchronizing (the dates) for plotting (outside) data in a graph

    Dear Traders,

    we are programming an custom indicator with ninja script by using outside data and now have the following problem:

    1) We have two coresponding lists with data (imported from a txt file): one contains "DateTime" objects, the other the value we want to plot. How can we plot this synchonized with the time of the chart?

    Please note that sometimes there are gaps in our data eg. missing 5 days, for those cases the line should just be a constant untill we have the next value given from the "txt".


    Thanks a lot in advance,

    Best Regards

    Max


    #2
    Hello Max,

    It sounds like you are needing to find a bar by the date and time and then set the plot Value[0] to the value from the file.

    First, below is a link to the StreamReader reference sample for reading from a text file.


    And a link to GetBar() for finding a barAgo number by datetime.


    And this can be supplied as the index for Value[int barsAgo] to assign the plot value.




    On the days that there is no value, set the value to the previous bars value (if you want).
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hey ChelseaB,

      first of all thanks a lot - this got us way closer allready! However we still face problems...

      We are importing the data with the StreamReader just as mentioned by you (works fine, we checked the outcome via Print on console). This gives us two lists: 1.Dates(all dates) and 2.Data (all corresponding data, Dates[0] is corresponding with Data[0]). Please note that our lists are longer than 256 items, which brings an error, untill we hardcode a barrier (for our used counter) on 256 counts(-->"k").

      Obviously we tried to use the MaximumBarsLookBack.infinite parameter, however getting stuck after the first iteration. We could find out (from the forum) that the MaximumBarsLookBack.infinite needs to be set in the strategie file for the costum indicator. How can we find this strategy file and are able to edit it, in order to give our arrays in the indicator more(max) items.

      Here is the code with MaximumBarsLookBack.TwoHundredFiftySix set to 256.

      else if(State == State.DataLoaded)
      {
      MySeries = new Series<double>(this, MaximumBarsLookBack.TwoHundredFiftySix);
      int k = 0;
      for (int i = Intervall; i < Data.Count-1; i++)
      {

      for(int j= 0; j<Bars.Count; j++)
      {

      if (DateTime.Compare(Bars.GetTime(j), date[i]) > 0 && DateTime.Compare(Bars.GetTime(j), date[i + 1]) < 0)
      {
      Print("i: " + i + "\t j:" + j+"\t k:"+k);
      if(k<256)
      MySeries[k] = Data[i];
      k++;
      }
      }
      }
      }


      ----------------------------------

      protected override void OnBarUpdate()
      {
      Values[0][0] = MySeries[0];
      }



      Thanks a lot in advance,

      with best trading regards

      Max





      Comment


        #4
        Hello Wenkey,

        Custom Series use barsAgo indexes the same as other series like Value or Close. Meaning if you want to put the data in a custom series of just setting the value directly to the Value series, the values for this custom series should also be set in OnBarUpdate().
        https://ninjatrader.com/support/help...t8/seriest.htm

        You can wait until the last historical bar.

        if (State == State.Historical && CurrentBar == Count - 2)
        {
        // last closed historical bar, all series barsAgo indexes are now updated to the last index
        }

        The way you are using the k variable as an index 'MySeries[k]' doesn't appear to be a barsAgo value and may be used as an absolute bar index (not barsAgo).

        CurrentBar - Bars.GetBar() would provide a barsAgo value.
        Last edited by NinjaTrader_ChelseaB; 02-11-2020, 02:14 PM.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        648 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
        574 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X