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

Question about array

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

    Question about array

    Hello, please help to program the following task. I need to create two arrays on the price axis and the time axis. No problem with the price axis.

    var x = new double[N];
    for (var i = 0; i < N; i++) x[i] = Close[i];

    But what about the timeline I don't know. I need to Express it as a sequence of numbers relative to each bar.
    For example x[5]=Close[5] x[4]=Close[4] x[3]=Close[3] x[2]=Close[2]
    y[5]= 1 y[4]=2 y[3]=3 y[2]=4 etc


    #2
    Hello Kovalev,

    Are you wanting the time of each bar?

    This is provided with the Time series.

    Below is a link to the help guide.


    If the series are already provided to you, it would be redundant to copy these to an array. Is there something specific you are trying to achieve?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello Kovalev,

      Are you wanting the time of each bar?

      This is provided with the Time series.

      Below is a link to the help guide.
      https://ninjatrader.com/support/help...eries_time.htm

      If the series are already provided to you, it would be redundant to copy these to an array. Is there something specific you are trying to achieve?
      ChelseaB, thank you very much for the tip, but there was another question. I'm programming these actions in OnBarUpdate, doesn't that mean the action won't execute until a new bar appears?

      I did it this way. It turns out that this is wrong?
      var x = new double[N];
      for (var i = 0; i < N; i++)
      {
      x[i] = Close[i];
      Print("x ");
      Print(x[i]);
      }
      var y = new double[N];
      for (var j = N-1; j > -1; j--)
      {
      y[j] = j;
      Print("y ");
      Print(y[j]);
      }
      Last edited by Kovalev; 01-28-2019, 09:12 AM.

      Comment


        #4
        Hello Kovalev,

        OnBarUpdate() runs depending on the Calculate setting and whether the script is processing historical or real-time data and whether TickReplay is enabled or not.

        In real-time when Calculate is .OnEachTick OnBarUpdate() will run each time a tick is received, when Calculate is .OnPriceChange OnBarUpdate() will run any time the price changes, when Calculate is .OnBarClose OnBarUpdate() will run any time the bar closes.

        Below is a link to the help guide on Calculate.


        In historical data, Calculate is always .OnBarClose unless TickReplay is enabled.




        However, I'm unsure if your custom logic is wrong. Is this printing what you are wanting to print? Were not you not attempting to get the time of the bar?
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mizzouman1, Today, 07:35 AM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by Radano, 06-10-2021, 01:40 AM
        20 responses
        616 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by i019945nj, 12-14-2023, 06:41 AM
        6 responses
        68 views
        0 likes
        Last Post i019945nj  
        Started by aa731, Today, 02:54 AM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by BarzTrading, Today, 07:25 AM
        0 responses
        3 views
        0 likes
        Last Post BarzTrading  
        Working...
        X