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

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 Haiasi, 04-25-2024, 06:53 PM
        5 responses
        76 views
        0 likes
        Last Post alancurry  
        Started by ZeroKuhl, Today, 04:31 PM
        0 responses
        16 views
        0 likes
        Last Post ZeroKuhl  
        Started by Vulgoth_t_Destroyer, 05-09-2022, 04:45 PM
        54 responses
        5,337 views
        0 likes
        Last Post Gaterz
        by Gaterz
         
        Started by ETFVoyageur, 05-07-2024, 07:05 PM
        11 responses
        76 views
        0 likes
        Last Post -=Edge=-  
        Started by _Zero_, 04-10-2020, 03:21 PM
        145 responses
        7,902 views
        6 likes
        Last Post johng2
        by johng2
         
        Working...
        X