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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      81 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      42 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      64 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      66 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      54 views
      0 likes
      Last Post CarlTrading  
      Working...
      X