Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to get the Added series's TickSize

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

    How to get the Added series's TickSize

    I have an Added Data Series "CLSeries" to a main GC Chart.

    From the Instrument.GetInstrument() doc I'm trying to display its range with the correct TickSize for CL on the chart with the Instrument.GetInstrument("CL"); and Draw.TextFixed() methods in below snippet

    PHP Code:
    namespace NinjaTrader.NinjaScript.Indicators
    {
      public class jimsExpiryMethod : Indicator
      {
        private Series<double> CLSeries;
    
        protected override void OnStateChange()
        {
          if (State == State.SetDefaults)
          {
          }
          else if (State == State.Configure)
          {
            AddDataSeries(GetCurrentFuture("CL"), BarsPeriodType.Day, 1);
          }
          else if (State == State.DataLoaded)
          {
            CLSeries = new Series<double>(this, MaximumBarsLookBack.Infinite);
          }
    
    
        protected override void OnBarUpdate()
        {
          NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Courier New", 12) { Size = 12, Bold = true };
    
          CLSeries[0] = Highs[1][0]-Lows[1][0];
    
          Print("CLSeries " + CLSeries[0]);
    
          Instrument Crude = Instrument.GetInstrument("CL");
    
          Draw.TextFixed(
                this,
                "CLSeries",
                "CL DR: "+Crude.MasterInstrument.RoundToTickSize(CLSeries[0] / TickSize),
                TextPosition.TopRight,
                Brushes.White,
                myFont,
                Brushes.Transparent,
                Brushes.Transparent,
                0); 
    

    The problem is it's returning the TickSize of GC (54.5 (as 0.1 for GC basis point) instead of 544 expected for CL 0.01 Basis point).

    How to get it to return the right TickSize (544 instead of 54.4) for CL on the GC chart? Thanks!

    #2
    Hi Paul, thanks for posting. The GetInstrument needs an exact Instrument name:

    Instrument Crude = Instrument.GetInstrument("CL 05-22");

    The tick size for the CS is 0.01.

    Kind regards,
    -ChrisL

    Comment


      #3
      Hi again Chris and thanks for the modification.

      I tested with Jim's Expiry method

      Expiry method and here from Jim

      PHP Code:
                  Instrument Crude = Instrument.GetInstrument(GetCurrentFuture("CL")); 
      

      Jim's Expiry method
      PHP Code:
          private string GetCurrentFuture(string name)
          {
          foreach (Instrument inst in Instrument.All)
          {
            if (inst.MasterInstrument.Name == name && inst.MasterInstrument.InstrumentType == InstrumentType.Future)
            {
            string instFullName = String.Format("{0} {1}-{2}",
                name,
                inst.MasterInstrument.GetNextExpiry(Core.Globals.Now).Month.ToString("D2"),
                inst.MasterInstrument.GetNextExpiry(Core.Globals.Now).ToString("yy"));
            return instFullName;
            }
          }
          return name;
          } 
      

      but it doesn't correct the tick size of 54.4 for 5.44 points Daily range which should be 544 for CL 0.01 tick Size (please see the attached image).

      Is there something else missing? Thanks!

      The complete script
      Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
      Last edited by PaulMohn; 03-25-2022, 03:11 PM.

      Comment


        #4
        Hi Paul, You are using just "TickSize" in your equation, which is referencing the primary series TickSize. To get the CL tick size use Crude.MasterInstrument.TickSize. You can also debug the values you are getting by printing them to bridge the gap between expected results and actual results. Using Prints is an invaluable tool in the script development process. When you get stuck or find a bug, please use Print on all of the properties being used first:

        Print(Crude.MasterInstrument.TickSize);
        Print(TickSize);

        Comment


          #5
          Many thanks Chris. Sorry for that TickSize lack, but I assumed it was already specified/picked up by Jim's Expiry method and i wouldn't possible have been able to infer it was required also for the TickSize.

          But yes I could have tested printing the TickSize value alone to check. I'll be more rigorous going forward and test printing all "variables" (also the ones I assume are "constant/correct by default").

          Now it's working with
          PHP Code:
            Draw.TextFixed(
              this,
              "CLSeries",
              "CL DR: "+Crude.MasterInstrument.RoundToTickSize(CLSer ies[0] / Crude.MasterInstrument.TickSize),
              TextPosition.TopRight,
              Brushes.White,
              myFont,
              Brushes.Transparent,
              Brushes.Transparent,
              0); 
          

          with complete script
          Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.


          Have a good Weekend!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          649 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          370 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          109 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          573 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          576 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X