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 display " ' " price notation

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

    How to display " ' " price notation

    Hello,

    Certain instruments like bonds display price on the margin as so 135'13. When I reference the price values programatically, 135'13 is returned as 135.40625. In some tracing that I'm doing, I'm printing these values to the output window.

    Is there a way to print 135'13 instead of 135.40625? Thank you!

    #2
    Hello MercuryScripter,

    Where x = the bond value (ex. 135.40625) you can get the raw bond value (ex. 135'13) using the following formula:

    Code:
    System.Math.Floor(x) + "'" + ((x - System.Math.Floor(x))*32).ToString("00")
    For a more advanced solution, please see this forum post: http://www.ninjatrader.com/support/f...ead.php?t=7122

    If we can be of further assistance, please let us know.
    Michael M.NinjaTrader Quality Assurance

    Comment


      #3
      Hello Michael

      I followed the thread you pointed me to earlier and implemented the below code/function in my strategy. However, I get the following compilation error and don't understand how to resolve:

      'NinjaTrader.Strategy.TheAutomatedPitTrader.Format PriceMarker(float)': no suitable method found to override

      public override string FormatPriceMarker(double price)
      {
      double trunc = Math.Truncate(price);
      int fraction = Convert.ToInt32(320 * Math.Abs(price - trunc) - 0.0001); // rounding down for ZF and ZT
      string priceMarker = "";
      if (TickSize == 0.03125)
      {
      fraction = fraction/10;
      if (fraction < 10)
      priceMarker = trunc.ToString() + "'0" + fraction.ToString();
      else
      priceMarker = trunc.ToString() + "'" + fraction.ToString();
      }
      else if (TickSize == 0.015625 || TickSize == 0.0078125)
      {
      if (fraction < 10)
      priceMarker = trunc.ToString() + "'00" + fraction.ToString();
      else if (fraction < 100)
      priceMarker = trunc.ToString() + "'0" + fraction.ToString();
      else
      priceMarker = trunc.ToString() + "'" + fraction.ToString();
      }
      else
      priceMarker = price.ToString(Gui.Globals.GetTickFormatString(Tic kSize));
      return priceMarker;
      }

      Comment


        #4
        Hello MercuryScripter,

        You are receiving this error because NinjaScript strategies cannot override the FormatPriceMarker() method. The FormatPriceMarker() method is for indicators. To resolve this problem, simply adjust your method name and remove the override:

        Code:
        public string toFractionalPrice(double price)
        {
        double trunc = Math.Truncate(price);
        int fraction = Convert.ToInt32(320 * Math.Abs(price - trunc) - 0.0001); // rounding down for ZF and ZT
        string priceMarker = "";
        if (TickSize == 0.03125) 
        {
        fraction = fraction/10;
        if (fraction < 10)
        priceMarker = trunc.ToString() + "'0" + fraction.ToString();
        else 
        priceMarker = trunc.ToString() + "'" + fraction.ToString();
        }
        else if (TickSize == 0.015625 || TickSize == 0.0078125)
        {
        if (fraction < 10)
        priceMarker = trunc.ToString() + "'00" + fraction.ToString();
        else if (fraction < 100)
        priceMarker = trunc.ToString() + "'0" + fraction.ToString();
        else	
        priceMarker = trunc.ToString() + "'" + fraction.ToString();
        }
        else
        priceMarker = price.ToString(Gui.Globals.GetTickFormatString(TickSize));
        return priceMarker;
        }
        and then reference it in your code like this:

        Code:
        double price = 135.40625;
        string newprice = toFractionalPrice(price);
        The variable newprice would look like this: 135'13

        If we can be of further assistance, please let us know.
        Michael M.NinjaTrader Quality Assurance

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by algospoke, 04-17-2024, 06:40 PM
        3 responses
        26 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by bmartz, 03-12-2024, 06:12 AM
        3 responses
        27 views
        0 likes
        Last Post NinjaTrader_Zachary  
        Started by Aviram Y, Today, 05:29 AM
        2 responses
        8 views
        0 likes
        Last Post Aviram Y  
        Started by gentlebenthebear, Today, 01:30 AM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by cls71, Today, 04:45 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X