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 Remove Leading Digits in Index Price

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

    How to Remove Leading Digits in Index Price

    In the following DrawText method, I would like to remove the leading digits of the Russell 2000 index. If the Index is trading at 1121.40 I would like to only display 21.4. I have been able to remove the trailing "0" but haven't found a way to remove the leading "11".

    DrawText("Low[0]",true," < " + Convert.ToString(string.Format("{0:0.0}",Low[0] - 1 * TickSize)),-6,Low[0] - 1 * TickSize, 0, Color.DarkRed, textFontSmall, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);

    regards,
    taddypole...

    #2
    Hello Taddypole,

    Thank you for your post.

    You might be able to use .TrimStart() for the string that you are returning for the TF

    Example -
    Code:
    string s = Close[0].ToString().TrimStart(new Char[] { '1' });
    http://msdn.microsoft.com/en-us/libr...v=vs.110).aspx
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Thank you Cal,

      I was reading the Microsoft pages but still couldn't figure it out. Now have it working.

      Comment


        #4
        Originally posted by Taddypole View Post
        Thank you Cal,

        I was reading the Microsoft pages but still couldn't figure it out. Now have it working.
        What about if we get to 1210.30 or 1092.20? That is, if the first 2 characters are not both "1".

        Of course, you could make the array of removal characters contain: 0, 1, 2, on the assumption that we are not ever getting to 1300+ or less than 1000.

        If you want to have just the last 5 characters in the string, you should probably be looking at String.Substring() instead.

        ref: http://msdn.microsoft.com/en-us/libr...vs.110%29.aspx
        Last edited by koganam; 08-08-2014, 03:53 PM.

        Comment


          #5
          Thanks Koganam,

          I tried your suggestion and have run into another snag. If I use a substring of (2,2) I can get the "22" in 1122.4 for example. But if I use a substring of (2,3) [or anything higher than 3 for the length] - I get an argument out of range exception. "Index and length must refer to a location within the string".

          I'm thinking it is having a problem with the decimal. Does Substring only work on integers?

          regards,
          taddypole...

          Comment


            #6
            Originally posted by Taddypole View Post
            Thanks Koganam,

            I tried your suggestion and have run into another snag. If I use a substring of (2,2) I can get the "22" in 1122.4 for example. But if I use a substring of (2,3) [or anything higher than 3 for the length] - I get an argument out of range exception. "Index and length must refer to a location within the string".

            I'm thinking it is having a problem with the decimal. Does Substring only work on integers?

            regards,
            taddypole...
            You may have missed a cast? Would you mind posting the actual code line that you are attempting to use?

            Comment


              #7
              My bar type is a renko chart and I'm trying to plot the value that the bar will reverse. I plot the "own" time frame and a higher time frame channel.

              I've been playing around with converting to string, using the Substring method and then converting back to a Double. It kind of works but looks like it needs some padding because sometimes there are 2 digits and sometimes 3.

              Haven't coded the breakout's (reversals) yet.

              Code and picture are attached...
              Attached Files

              Comment


                #8
                Originally posted by Taddypole View Post
                My bar type is a renko chart and I'm trying to plot the value that the bar will reverse. I plot the "own" time frame and a higher time frame channel.

                I've been playing around with converting to string, using the Substring method and then converting back to a Double. It kind of works but looks like it needs some padding because sometimes there are 2 digits and sometimes 3.

                Haven't coded the breakout's (reversals) yet.

                Code and picture are attached...
                A little testing, with a liberal sprinkling of Print()'s all over the place, showed that double.ToString(), somewhat shockingly to me, drops trailing zeros on the decimal portion of a double. Hence our strange "index overflow" error. That means that we have to explicitly format our double when we convert it to string!
                Code:
                                    double testDouble = 1123.50;
                                    Print("testDouble - 0.00 format: " + testDouble.ToString("0.00").Substring(2, 5));
                                    Print("testDouble - #.00 format: " + testDouble.ToString("#.00").Substring(2, 5));
                                    Print("testDouble - F2 format: " + testDouble.ToString("F2").Substring(2, 5));
                all work.
                Last edited by koganam; 08-09-2014, 10:37 AM.

                Comment


                  #9
                  Thanks Koganam,

                  Exactly what I was looking for. Works perfectly now.
                  Attached Files

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by ZenCortexHurry, Today, 01:07 PM
                  0 responses
                  3 views
                  0 likes
                  Last Post ZenCortexHurry  
                  Started by ZenCortexHurry, Today, 01:04 PM
                  0 responses
                  2 views
                  0 likes
                  Last Post ZenCortexHurry  
                  Started by f.saeidi, Today, 12:14 PM
                  3 responses
                  10 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by Russ Moreland, Today, 12:54 PM
                  1 response
                  5 views
                  0 likes
                  Last Post NinjaTrader_Erick  
                  Started by philmg, Today, 12:55 PM
                  1 response
                  6 views
                  0 likes
                  Last Post NinjaTrader_ChristopherJ  
                  Working...
                  X