Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

last four numbers of close to variable

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

    last four numbers of close to variable

    I need to put the last four numbers of Close[0] into the variable MINI_CLOSE.

    example:

    1455.25 Close[0] would give me MINI_CLOSE = 55.25

    Think it needs to be a string and split but i cant get it to work

    any ideas? Thanks!!

    #2
    I think it will be

    double MINI_CLOSE = 0;

    string somevalue = Double.ToString(Close[0]);

    but not sure how to split it up from there

    Comment


      #3
      how about :

      string data= Close[0];
      data.Remove(0,2);

      or

      string data= Close[0];
      data.Substring(2);

      Comment


        #4
        // ok this is where i am so far


        string CLOSE_VALUE_STR = Convert.ToString(Close[0]);

        var CLOSE_VALUE_HUNDREDS_STR = CLOSE_VALUE_STR.Remove(2);

        double CLOSE_VALUE_HUNDREDS = Double.Parse(CLOSE_VALUE_HUNDREDS_STR);

        Print(CLOSE_VALUE_HUNDREDS);

        var CLOSE_VALUE_ONES_STR = CLOSE_VALUE_STR.Substring(2, 5);

        double CLOSE_VALUE_ONES = Double.Parse(CLOSE_VALUE_ONES_STR);

        Print(CLOSE_VALUE_ONES);


        // and i get the results i wanted from a close of 1453.25

        14
        53.25

        but i also get an error " error on calling ' onbarupdate' method for indicator on bar 1: you are accessing an index with a value that is invalid since its out of range"


        any ideas?
        Last edited by darkspeed; 09-29-2012, 03:32 PM.

        Comment


          #5
          this is what i get from catch:

          9/18/2012 16:32:00 System.ArgumentOutOfRangeException: Index and length must refer to a location within the string.
          Parameter name: length
          at System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)
          at NinjaTrader.Indicator.TEST_CODE.OnBarUpdate()

          Comment


            #6
            I think it is length of string

            when the close is say 1400.00 i think the string is 1400 so it is only 4 characters long rather than 7 counting the decimal...

            how do i fix that?

            THanks

            Comment


              #7
              // this is the only way i could get it to work.. there must be a better way..

              Print("");
              Print("");
              Print(Close[0] + "------------------------------------");

              string CLOSE_VALUE_STR = Convert.ToString(Close[0] + .01); // add 0.01 to preserve the decimal places

              // Print (CLOSE_VALUE_STR);

              int CLOSE_VALUE_STR_LENGTH = CLOSE_VALUE_STR.Length;

              // Print(CLOSE_VALUE_STR_LENGTH);

              // Print ("---" +CLOSE_VALUE_STR + "---");

              var CLOSE_VALUE_HUNDREDS_STR = CLOSE_VALUE_STR.Remove(2);

              double CLOSE_VALUE_HUNDREDS = Double.Parse(CLOSE_VALUE_HUNDREDS_STR);

              Print(CLOSE_VALUE_HUNDREDS);

              var CLOSE_VALUE_ONES_STR = CLOSE_VALUE_STR.Substring(2, 5);

              double CLOSE_VALUE_ONES = (Double.Parse(CLOSE_VALUE_ONES_STR) - 0.01); // remove the 0.01

              Print(CLOSE_VALUE_ONES);

              Comment


                #8
                will

                round to whole # ( 1400.00 /100 ) = 14

                (14 * 100 ) - 1400.00 = 00.00 ?



                where 1400.00 is the input #

                so if x = 1400.00

                round to whole # ( x /100 ) = 14

                (14 * 100 ) - x = 00.00 ?




                Originally posted by darkspeed View Post
                // this is the only way i could get it to work.. there must be a better way..

                Print("");
                Print("");
                Print(Close[0] + "------------------------------------");

                string CLOSE_VALUE_STR = Convert.ToString(Close[0] + .01); // add 0.01 to preserve the decimal places

                // Print (CLOSE_VALUE_STR);

                int CLOSE_VALUE_STR_LENGTH = CLOSE_VALUE_STR.Length;

                // Print(CLOSE_VALUE_STR_LENGTH);

                // Print ("---" +CLOSE_VALUE_STR + "---");

                var CLOSE_VALUE_HUNDREDS_STR = CLOSE_VALUE_STR.Remove(2);

                double CLOSE_VALUE_HUNDREDS = Double.Parse(CLOSE_VALUE_HUNDREDS_STR);

                Print(CLOSE_VALUE_HUNDREDS);

                var CLOSE_VALUE_ONES_STR = CLOSE_VALUE_STR.Substring(2, 5);

                double CLOSE_VALUE_ONES = (Double.Parse(CLOSE_VALUE_ONES_STR) - 0.01); // remove the 0.01

                Print(CLOSE_VALUE_ONES);
                Last edited by sledge; 09-29-2012, 05:40 PM. Reason: using round of course

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                649 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                370 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                109 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                574 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                576 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X