• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 pstrusi, Today, 03:29 PM
        2 responses
        9 views
        0 likes
        Last Post pstrusi
        by pstrusi
         
        Started by ntbone, Today, 03:06 PM
        0 responses
        4 views
        0 likes
        Last Post ntbone
        by ntbone
         
        Started by AMATX, Today, 01:43 PM
        2 responses
        7 views
        0 likes
        Last Post AMATX
        by AMATX
         
        Started by razeus, Today, 12:00 PM
        4 responses
        17 views
        0 likes
        Last Post razeus
        by razeus
         
        Started by kitwit, Today, 09:47 AM
        5 responses
        24 views
        0 likes
        Last Post NinjaTrader_PaulH  
        Working...
        X