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

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, 05: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?

      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 Barry Milan, Yesterday, 10:35 PM
        5 responses
        18 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by DanielSanMartin, Yesterday, 02:37 PM
        2 responses
        13 views
        0 likes
        Last Post DanielSanMartin  
        Started by DJ888, 04-16-2024, 06:09 PM
        4 responses
        13 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by terofs, Today, 04:18 PM
        0 responses
        12 views
        0 likes
        Last Post terofs
        by terofs
         
        Started by nandhumca, Today, 03:41 PM
        0 responses
        8 views
        0 likes
        Last Post nandhumca  
        Working...
        X