Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help with converting decimal to fraction.

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

    Help with converting decimal to fraction.

    Im writing an indicator that needs to convert the decimal form of an output to the nearest fractional tick. For example:
    Bollingers will give decimals for ZT(2yr note)
    I have found a bit of code that converts the price markers from decimals to the appropriate fractions. Is there anyway to to get streamwriter to write a line of text that wil have the exact same values as teh price markers i need them in the same format as the order book.

    If the price marker outputs 110'750 for x then i want it to write that to a file. But im not sure how to access the pricemarkers, if i call Upper[0], Lower[0], or Close[0] it will give me a decimal.



    The code that changes the price markers:

    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;
    Last edited by floyd084; 01-09-2013, 04:57 PM.

    #2
    Well I figured out how to get it to post, now im getting values that aren't equivalnt to a minimum tick

    for example zt is quoted in 1/4 of 1/32 so 110'000, 110'002, 110'005, 110'007, 110'010

    so occasionally the indicator will output say 110'001 or 110'004 or 110'008

    how can I round these so that they match the price ladder quotes?

    Comment


      #3
      Floyd, I think you could Round2TickSize first and then do your conversion logic as per the first post?

      http://www.ninjatrader.com/support/h...Round2TickSize
      BertrandNinjaTrader Customer Service

      Comment


        #4
        Yes that's essentially what i did. i took the decimal and placed it in variable x
        then :
        double XdecimalLower = Math.Floor(NdecimalLower * 128) / 128.0;

        then convert to int32
        it helps to round down by .0001 when converting to 32 so that for all ticks ending in 7.5/128 will read xxx'xx7 instead of xxx'xx8. all other ticks work great. Thanks for the help.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by parkinsonbr, Today, 08:23 PM
        0 responses
        1 view
        0 likes
        Last Post parkinsonbr  
        Started by jc.am, Today, 07:59 PM
        0 responses
        3 views
        0 likes
        Last Post jc.am
        by jc.am
         
        Started by i2w8am9ii2, Today, 04:36 PM
        2 responses
        13 views
        0 likes
        Last Post i2w8am9ii2  
        Started by WeyldFalcon, Today, 02:07 PM
        2 responses
        14 views
        0 likes
        Last Post WeyldFalcon  
        Started by hfwiley, Today, 03:02 PM
        2 responses
        19 views
        0 likes
        Last Post hfwiley
        by hfwiley
         
        Working...
        X