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

Amount of Bars, which is added by Add()

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

    Amount of Bars, which is added by Add()

    Hello

    1) I opened M1 Chart (100 M1 Bars on a chart).
    2) In indicator i added Tick Bars data:
    Code:
    Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Bid);
    3) I want to get an amount of bars on Tick timeframe:
    Code:
    int tick_bar = BarsArray[1].Count
    tick_bar = 100 - it is eqally amount of bar in M1 chart (look at 1) point in my post)

    Question: can i get an information from other Timeframes with bar index > amount of bar on current TF

    For example, i have 100 bar on M1 TF and i want to get Times[] from bar with index 300 from tick TF. How can i do it?

    #2
    Welcome to our forums - unfortunately you could not control via the Add how many bars are loaded, this would be determined by the primary series used. For the future we have an enhanced Add method here on our feedback list for consideration.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Times[1][0] Error

      Thanks for your answer.
      I've another issue to resolve:

      1.
      Code:
      Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Last);
      2.
      Code:
      protected override void OnBarUpdate()
              {
                  
                 if (BarsInProgress == 1) Log("Volumes: "+" BarsArray "+" Time_0"+Times[1][0], NinjaTrader.Cbi.LogLevel.Information);
      3. In Log i hav an error: "Error on calling 'OnBarUpdate' method for indocator 'Indicator_1' on bar 0: Bar index need to be greater/equal 0"
      Why? Times[1][0] Bar index =0!!!

      4. If i do
      Code:
      protected override void OnBarUpdate()
              {
                  
                  if (BarsInProgress == 1) Log("Volumes: "+" BarsArray "+"  Time_0"+Times[1][-1], NinjaTrader.Cbi.LogLevel.Information);
      It means that i changed Times[1][0] to Times[1][-1] it returns an open time of last right bar - why?

      How can i get open time for last left bar with index BarsArray[1].Count? If i write Times[1][BarsArray[1].Count-1] there is the same error:

      In Log i hav an error: "Error on calling 'OnBarUpdate' method for indocator 'Indicator_1' on bar 0: Bar index need to be greater/equal 0"

      Help me, please

      Comment


        #4
        Hello agafon2,
        You cannot reference a bar as -1. If you are trying to reference the previous bar then simply append 1 (one) and not -1 (minus one).

        To assist you further can you please send a toy NinjaScript code* replicating the behavior to support[AT]ninjatrader[DOT]com

        Please append Attn:Joydeep in the subject line of the email and give a reference of this thread in the body of the email.

        I look forward to assisting you further.

        *The "toy" just means something that is a stripped down version that isn't necessarily the whole logic. It makes things easier to rout out.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Period and Digits for chart

          1) How can i get an information about char period?

          For example, i opened chart:
          Type: Minute
          Value: 1
          How can i get information, that type of chart is Minute and Value = 1 by NinjaScript?

          2) How can i get an information about Digits of chart?

          For example: There is a price 1.3422 on chart - it means that Digits = 4 (amount of numbers after dot)
          if price = 1.34223, Digits = 5

          How can i get an information about Digits from chart by NinjaScript?

          Comment


            #6
            Hello agafon2,
            The BarsPeriod object provides all the information regarding the bars. Please refer to our help guide to know more about it



            Unfortunately there are no native way to get the decimal value. You have to custom code it. You can refer to this post which demonstrates a sample code regarding it
            JoydeepNinjaTrader Customer Service

            Comment


              #7
              Write to binary file

              How can i write to binary file

              Look at this functions: http://docs.mql4.com/files

              Are the same functions to work with files in NinjaScript?

              Comment


                #8
                Hello agafon2,
                NinjaScript is basically C# and you can use unsupported C# methods to write data to a binary file. This is however not officially supported though you may refer to the below link as a reference.
                How to read and write a binary file in C# and some of its applications. Writing files in .NET is useful in many scenarios.
                JoydeepNinjaTrader Customer Service

                Comment


                  #9
                  Index of max left bar

                  Why if i do like
                  Log("d_time: "+Time[Bars.Count-1], NinjaTrader.Cbi.LogLevel.Information);

                  There is an error, but if i do like

                  Log("d_time: "+Time[Bars.Count-2], NinjaTrader.Cbi.LogLevel.Information);

                  It's OK?

                  How to count an index of max left bar on chart?

                  Comment


                    #10
                    Seconds amount

                    How to count an amount of in seconds, that has passed since 00:00 a.m. of 1 January, 1970 to current time?

                    Comment


                      #11
                      Hello agafon2,
                      Please try the below code to get the difference in seconds.
                      Code:
                      Print(DateTime.Now.Subtract(new DateTime(1970,1,1)).TotalSeconds);
                      JoydeepNinjaTrader Customer Service

                      Comment


                        #12
                        Reply

                        Originally posted by NinjaTrader_Joydeep View Post
                        Hello agafon2,
                        Please try the below code to get the difference in seconds.
                        Code:
                        Print(DateTime.Now.Subtract(new DateTime(1970,1,1)).TotalSeconds);
                        Result of this code is like:
                        1358971008,03289
                        How to get an integer part of this number?
                        For example, for number 1358971008,03289 integer part is 1358971008

                        Comment


                          #13
                          Hello agafon2,
                          You have to cast/convert the double value to integer. You can use the below code to do it.
                          Code:
                          Print(Convert.ToInt32(DateTime.Now.Subtract(new DateTime(1970,1,1)).TotalSeconds));
                          JoydeepNinjaTrader Customer Service

                          Comment


                            #14
                            Originally posted by agafon2 View Post
                            Why if i do like
                            Log("d_time: "+Time[Bars.Count-1], NinjaTrader.Cbi.LogLevel.Information);

                            There is an error, but if i do like

                            Log("d_time: "+Time[Bars.Count-2], NinjaTrader.Cbi.LogLevel.Information);

                            It's OK?

                            How to count an index of max left bar on chart?
                            On every char amount Bars.Count less than last CurrentBar on 2 - why? It should be less on just 1 !!!
                            It means that i can get only Time[Bars.Count-2] value, but i can't take Time[Bars.Count-1] ! Why?

                            Comment


                              #15
                              Hello agafon2,
                              To assist you further may I know have you set CalculateOnBarClose to True or False.

                              I look forward to assisting you further.
                              JoydeepNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by kaywai, Today, 06:26 AM
                              1 response
                              6 views
                              0 likes
                              Last Post kaywai
                              by kaywai
                               
                              Started by ct, 05-07-2023, 12:31 PM
                              6 responses
                              203 views
                              0 likes
                              Last Post wisconsinpat  
                              Started by kevinenergy, 02-17-2023, 12:42 PM
                              118 responses
                              2,780 views
                              1 like
                              Last Post kevinenergy  
                              Started by briansaul, Today, 05:31 AM
                              0 responses
                              10 views
                              0 likes
                              Last Post briansaul  
                              Started by traderqz, Yesterday, 12:06 AM
                              11 responses
                              28 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Working...
                              X