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

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 joselube001, 05-10-2024, 12:17 PM
      4 responses
      19 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by lorem, 04-25-2024, 09:18 AM
      17 responses
      75 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by DawnTreader, 05-08-2024, 05:58 PM
      21 responses
      81 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by doihaveto13, Today, 12:46 PM
      2 responses
      4 views
      0 likes
      Last Post doihaveto13  
      Started by Vitamite, Today, 12:48 PM
      1 response
      9 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X