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'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<doubleCLSeries;

        protected 
    override void OnStateChange()
        {
          if (
    State == State.SetDefaults)
          {
          }
          else if (
    State == State.Configure)
          {
            
    AddDataSeries(GetCurrentFuture("CL"), BarsPeriodType.Day1);
          }
          else if (
    State == State.DataLoaded)
          {
            
    CLSeries = new Series<double>(thisMaximumBarsLookBack.Infinite);
          }


        protected 
    override void OnBarUpdate()
        {
          
    NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Courier New"12) { Size 12Bold 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
    Chris L.NinjaTrader Customer Service

    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);
        Chris L.NinjaTrader Customer Service

        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 Waxavi, Today, 02:10 AM
          0 responses
          3 views
          0 likes
          Last Post Waxavi
          by Waxavi
           
          Started by TradeForge, Today, 02:09 AM
          0 responses
          7 views
          0 likes
          Last Post TradeForge  
          Started by Waxavi, Today, 02:00 AM
          0 responses
          2 views
          0 likes
          Last Post Waxavi
          by Waxavi
           
          Started by elirion, Today, 01:36 AM
          0 responses
          4 views
          0 likes
          Last Post elirion
          by elirion
           
          Started by gentlebenthebear, Today, 01:30 AM
          0 responses
          4 views
          0 likes
          Last Post gentlebenthebear  
          Working...
          X