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

How to Get the Added Series MasterInstrument.TickSize on a different instrument chart

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

    How to Get the Added Series MasterInstrument.TickSize on a different instrument chart

    I have a YEN added series in a multi-series indicator. This indicator is added to a CL Chart.
    For some reason Test0 in the Print below returns the SMA(20)[0] value of 100.6973685 which is the CL instrument SMA(20)[0] value, when it is clearly stipulated YEN as the instrument to get the SMA 20 from (not CL, YEN, please see in bolded red below).

    print Statement


    Print("Test0 : " + YEN.MasterInstrument.RoundToTickSize(SMA(20)[0]).ToString());



    print output

    Test0 : 100.6973685
    How to get the YEN SMA(20)[0] (which should be < 0, not 100.6973685)?

    NinjaTrader_Jesse


    ...it seems your script may have multiple series
    Yes it is a multi-series script.


    Do you still see a problem using a single series script applied directly to the Yen? If so then we could cover that directly.
    I need the script to work for a multi-series, not a single series.
    I isolated in post #4 the correct TickSize for YEN (please see Testx : 5E-07). Therefore it works for multi-series, therefore the problem does not relate to the multi-series.
    Last edited by PaulMohn; 04-26-2022, 11:38 AM.

    #2
    Hello PaulMohn,

    Are you supplying BarsArray[1] as the input series to the indicator?

    Below is a link to the help guide which includes sample code.
    https://ninjatrader.com/support/help.../barsarray.htm


    Are you looking at BarsArray[1].Instrument.MasterInstrument.TickSize to get the TickSize?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea and thanks for the reply.

      No, I didn't use BarsArray[1], I used a regular series YENSeries[0] = Closes[1][0];

      I used Jim's custom method to get the expiry date in the instrument local variable YEN

      protected override void OnBarUpdate()
      Instrument YEN = Instrument.GetInstrument(GetCurrentFuture("6J"));

      YENSeries[0] = Closes[1][0];

      (Math.Abs(YEN.MasterInstrument.RoundToTickSize(YEN Series[0]) - YEN.MasterInstrument.RoundToTickSize(SMA(20)[0])) / YEN.MasterInstrument.TickSize).ToString())

      Comment


        #4
        Hello PaulMohn,

        So you are using an Instrument object for the RoundToTickSize but you are rounding a value from a completely different instrument (which may have a different tick size)?

        You stated "How to get the YEN SMA(20)[0]", you do this by using the Bars from the BarsArray that has the Yen series and supply this as the input series to the indicator call. The indicator will use the primary series if no input series is specified, or will use the input series you specify if you specify one.

        Also, is this a completely new inquiry or is this a duplication of a thread you already have open?
        Last edited by NinjaTrader_ChelseaB; 04-26-2022, 12:23 PM.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Oh, so the solution should be

          BarsArray[3].Instrument.MasterInstrument.TickSize

          instead of

          YEN.MasterInstrument.TickSize

          when BarsArray[3] corresponds to the YEN series series index of 3 (if all I have on my CL 1 minute chart is 2 added series (CL 10 min, and YEN 10 min)

          (i.e.
          // the 1st series is the series displayed on the chart (i.e. CL 1 min)
          AddDataSeries(GetCurrentFuture("CL"), RangePeriod, RangeInterval); //2. Crude Oil Futures - NYMEX
          AddDataSeries(GetCurrentFuture("6J"), RangePeriod, RangeInterval); //3. YEN/6J - GLOBEX
          )
          ?

          If so can I just call the BarsArray[3] statement for example as
          (Math.Abs(YEN.MasterInstrument.RoundToTickSize(YEN Series[0]) - BarsArray[3].Instrument.MasterInstrument.TickSize(SMA(20)[0])) / YEN.MasterInstrument.TickSize).ToString())
          as is?

          Or do I need to declare and initialize the BarsArray[3] as well?

          Or do you had another idea in mind?

          On a side note, why does it require the additional less intuitive BarsArray statement and cannot do with the simpler YEN.MasterInstrument.RoundToTickSize(SMA(20)[0]) one (if there's a way to use this simpler statement I'd use it preferably)? Thanks!

          Please answer today if you can, I'll get back tomorrow (up with this simple issue for 3 days now).

          Jesse suggested opening a new thread here

          Comment


            #6
            Hello PaulMohn,

            Not quite, I am saying SMA(20)[0] should be SMA(BarsArray[1], 20)[0]. I am saying that the indicator should be using the BarsArray of the input series you want it do calculations with.

            BarsArray is the collection of bars that have been added with AddDataSeries(). If you have called AddDataSeries, then this was added as BarsArray[1]. The primary series, or chart bars, is BarsArray[0].

            If you have called AddDataSeries() 3 times in State.Configure, then there will be 4 series in BarsArray, indexes 0 through 3.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Thank you a lot Chelsea for the solution clarity and simplicity! Now it's working as needed.


              Prints Output

              Testz : 0.01
              Testy : 101.982631578948
              Testx : 0.00783078947368422

              Prints Statements
              PHP Code:
              Print("Testz : " Crude.MasterInstrument.TickSize.ToString());
              Print(
              "Testy : " SMA(BarsArray[1], 20)[0]);
              Print(
              "Testx : " SMA(BarsArray[2], 20)[0]); 

              Uses
              PHP Code:
              // the 1st series is the series displayed on the chart (i.e. CL 1 min)
              AddDataSeries(GetCurrentFuture("CL"), RangePeriodRangeInterval); //2. Crude Oil Futures - NYMEX
              AddDataSeries(GetCurrentFuture("6J"), RangePeriodRangeInterval); //3. YEN/6J - GLOBEX

              (Math.Abs(Crude.MasterInstrument.RoundToTickSize(CLSeries[0] - SMA(BarsArray[1], 20)[0])) / Crude.MasterInstrument.TickSize).ToString() )

              (
              Math.Abs(YEN.MasterInstrument.RoundToTickSize(YENSeries[0] - SMA(BarsArray[2], 20)[0])) / YEN.MasterInstrument.TickSize).ToString() ) 

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by bortz, 11-06-2023, 08:04 AM
              47 responses
              1,610 views
              0 likes
              Last Post aligator  
              Started by jaybedreamin, Today, 05:56 PM
              0 responses
              9 views
              0 likes
              Last Post jaybedreamin  
              Started by DJ888, 04-16-2024, 06:09 PM
              6 responses
              19 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by Jon17, Today, 04:33 PM
              0 responses
              6 views
              0 likes
              Last Post Jon17
              by Jon17
               
              Started by Javierw.ok, Today, 04:12 PM
              0 responses
              22 views
              0 likes
              Last Post Javierw.ok  
              Working...
              X