Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Fractions as inputs for an indicator running on Bonds

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

    Fractions as inputs for an indicator running on Bonds

    I have an indicator that takes two prices as inputs.

    For most instruments there isn't an issue, but for bonds that trade in fractions it's much easier to say 138'2 than 138.0625. Is there a type converter or tool that would convert the Bond's shorthand given as a string to a double?
    daqu40
    NinjaTrader Ecosystem Vendor - QTradez

    #2
    Hello Dan,

    Thanks for your post.

    There isn't a TypeConverter available that I could suggest, but you could consider parsing the string, checking if it has a ' and then you can divide the subscript by 32 and add it to the whole number.

    Code:
    string input = "123'2";
    string[] split = input.Split('\'');
    double subscript = double.Parse(split[1]);
    subscript = subscript / 32;
    double number = double.Parse(split[0]);
    Print((number + subscript).ToString());
    I look forward to assisting.

    Comment


      #3
      Thanks Jim.

      I didn't think there was anything, but wanted to check to be sure.

      FYI for everyone reading this...
      Jim's example is good for the specific case of ZB. To make this work for all instruments using the apostrophe use:

      Code:
      subscript = subscript * Instrument.MasterInstrument.TickSize;
      Also some supporting code to make sure you are starting with a number and didn't get any other characters in your string that won't convert to a number.
      daqu40
      NinjaTrader Ecosystem Vendor - QTradez

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by charlesugo_1, 05-26-2026, 05:03 PM
      0 responses
      68 views
      0 likes
      Last Post charlesugo_1  
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      151 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      162 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 05-10-2026, 08:12 PM
      0 responses
      100 views
      0 likes
      Last Post CarlTrading  
      Started by Hwop38, 05-04-2026, 07:02 PM
      0 responses
      288 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Working...
      X