Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bond price prints

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

    Bond price prints

    Hello

    Is there a way of printing in the output window the US treasury bond prices as they appear on the ladder, in 1/32 format (i.e. 138'275), rather than decimal?

    Thank you

    #2
    Hello itrader46,

    This would need to be calculated by you with custom logic and converted to string.

    Fortunately, a community member has done the hard work.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Oh... thanks.. I was hoping it would be be something simpler than that, as that is what I came up with and it looked like it's gotta be an easier way:

      PS: for ZF, the {:000} format rounds 125'067 to 125'068, but my way it shows 125'0675

      Code:
      private string FormatAsk(double price)
              {
                  if (Bars.Instrument.MasterInstrument.Name == "ZB")             
                      return String.Format ("{0}'{1:00}", Math.Truncate(price), (price - Math.Truncate(price)) * 32);
      
                  else if (Bars.Instrument.MasterInstrument.Name == "ZN")
                      return String.Format ("{0}'{1:000}", Math.Truncate(price), (price - Math.Truncate(price)) * 320);
      
                  else if (Bars.Instrument.MasterInstrument.Name == "ZF" )
                      return String.Format ("{0}'{1:0000}", Math.Truncate(price), (price - Math.Truncate(price)) * 3200);
      
                  else 
                      return String.Format ("{0}", price);
              }
      
      private string FormatBid(double price)
              {
                  if (Bars.Instrument.MasterInstrument.Name == "ZB")             
                      return String.Format ("{0}'{1:00}", Math.Truncate(price - TickSize), ((price - TickSize) - Math.Truncate(price - TickSize)) * 32);
      
                  else if (Bars.Instrument.MasterInstrument.Name == "ZN")            
                      return String.Format ("{0}'{1:000}", Math.Truncate(price - TickSize), ((price - TickSize) - Math.Truncate(price - TickSize)) * 320);
      
                  else if (Bars.Instrument.MasterInstrument.Name == "ZF" )            
                      return String.Format ("{0}'{1:0000}", Math.Truncate(price - TickSize), ((price - TickSize) - Math.Truncate(price - TickSize)) * 3200);
      
                  else 
                      return String.Format ("{0}", price - TickSize);
              }
      
      Print(FormatAsk(Close[0] + FormatBid(Close[0]));
      Last edited by itrader46; 04-13-2020, 06:30 AM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      580 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      335 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      102 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      554 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      552 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X