• 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

Parse a string into private double.

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

    Parse a string into private double.

    Can you tell me how to paste a string into a double?
    From
    string[] status = GetAtmStrategyEntryOrderStatus(orderId[0]);
    In the Output Window
    I have status[0] 1850.25 store as a string and I need it as a private double in my script.
    Last edited by girda; 02-16-2016, 02:03 PM.

    #2
    https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

    You might want to look up a substring type function too.

    Comment


      #3
      Hi sledge,
      Many thanks for your answer,
      I've hard time writing the proper syntax to paste the string value of status[0] into a double.
      By the way what do you mean by substring type function and where I can find example.

      Comment


        #4
        Hello,

        If you are having trouble with something you are trying, please provide the exact syntax you are using and we could further review what may be happening.

        For a sample of Double.TryParse, sledge had provided that in his reply. On the MSDN page, please see the example listed it shows the following line which is how to parse a string into a double:

        Code:
        Double.TryParse(value, out number)
        You would need to review the MSDN page as this uses a variable and is not the full example, on MSDN the variable is listed and there is documentation.

        Regarding any other C# method you may hear about such as SubString, you could easily find the MSDN documentation for any C# method using google. Simply search "MSDN substring" or "C# substring" and you will get multiple results with multiple examples. Here is the MSDN docs: https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

        Please let me know if I may be of additional assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Following on 'Parse a string into private double.'

          Hi Jesse,
          Thanks for your replay,
          I'm working on a strategy who will establish a recovery zone using ATM strategy from a script.

          Goal is to replace (Low[0] + 10 * TickSize) in orderId[1] by the status[0] a string value who need to parse into a double as it will fix the recoveryzone.
          above and below ZoneRecoveryArea is define in
          #region Variables

          After the condition Double.TryParse(value, out number)
          I can't change Console.WriteLine by other action.
          I got Error Code CS0029
          Cannot implicitly convert type 'string' to 'double'

          The exact syntax is

          if (orderId[0].Length > 0)
          {
          string[] status = GetAtmStrategyEntryOrderStatus(orderId[0]);

          // If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements
          if (status.GetLength(0) > 0)
          {
          // this printFlag is used to only print the status each time it changes instead of on each tick
          if (printFlags[0] != status[2])
          {
          printFlags[0] = status[2];
          // Print out some information about the order to the output window
          Print(Time+"Entry order[0] order state is: " + status[2]);
          Print(Time+"Entry order[0] average fill price is: " + status[0]);
          Print("Entry order[0] filled amount is: " + status[1]);

          //Double.TryParse Method (String, Double)
          if (status[0] == "PartFilled" || status[0] == "Filled")
          {

          string[] values = { status[0] };
          double number;

          foreach (var value in values)
          {
          if (Double.TryParse(value, out number))
          aboveZoneRecoveryArea =( value, number);
          Print("value, number"+number);
          }
          }
          }

          // If the order state is terminal, reset the order id value
          if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
          {
          orderId[0] = string.Empty;
          atmStrategyId[1] = GetAtmStrategyUniqueId();
          orderId[1] = GetAtmStrategyUniqueId();
          AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.StopLimit, (Low[0] + 10 * TickSize), (Low[0] + 10 * TickSize), TimeInForce.Day, orderId[1], "Algo2", atmStrategyId[1]);
          Print(string.Format("{0} | OrderId[0] {1} | submitting orderId[1] & setting orderId[0] to empty", DateTime.Now, status[2]));
          }
          }
          }

          Comment


            #6
            Hello,

            Thank you for the reply.

            I would be unsure with what is provided on what specific line you are getting that error. Because I cant run and see the error as you are, it would be a guess what object is throwing the error.

            The error in general is very specific, you are trying to use a string where a double would be used.

            Can you further isolate this sample to the single line that is listed for the error? In the NinjaScript editor, try double clicking on the error message and see if it is able to take you to the specific line, if so can you provide which specific line is throwing this error? It will likely be more apparent seeing which objects are being used as to why that error is happening.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              The error appear on the line

              foreach (var value in values)

              But only after I changed the Console.WriteLine (value, number); by
              aboveZoneRecoveryArea =( value, number);

              Comment


                #8
                Hello,

                Thank you for providing more information.

                Looking at the line after where you have said the error is showing we see the following:

                aboveZoneRecoveryArea =( value, number);

                This is likely the problem, what type of variable is this, is this defined as a double or a string?

                Also the syntax: =( value, number); is likely the specific problem, were you intending to make aboveZoneRecoveryArea equal number?

                If so the syntax would likely just be:

                aboveZoneRecoveryArea = number;

                the double.TryParse has an out overload which sets the variable used to the parsed value, if you are trying to later use the parsed number, you would just need to use it as number.

                If this is not the case, you may need to attach the script or email us at platform support @ ninjatrader.com for further assistance.

                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Hi Jesse,
                  Thanks a lot for your reply,
                  You solved the error.

                  Comment


                    #10
                    Hi Jesse,
                    Testing the script I found out that the line
                    string[] values = { status[0] };
                    could be wrong as it don't return the string value of status[0]
                    Can you take a look?
                    Last edited by girda; 02-18-2016, 01:33 AM.

                    Comment


                      #11
                      Hello,

                      I am not sure what you mean, you said it does not return the value of status[0], do you mean when you use Print(status[0]); it is a blank string?

                      Could you provide the script for me to see what the error is? I am not sure by the question what may be happening.

                      I look forward to being of further assistance.
                      JesseNinjaTrader Customer Service

                      Comment


                        #12
                        Hi,
                        The Print(Time+"status[0] "+status[0]);
                        isn't show at all in the Output Window.
                        Meaning it couldn't take part of the following logic.
                        What's the best way sending you the script?

                        Comment


                          #13
                          Hello,
                          Yes if you are not getting any output from that statement, it is likely not being called, I would presume the Time would be printed even if the other two were blank stings.

                          If you are ok to share the script on here you could just attach the .cs file from Documents\NinjaTrader 7\bin\Custom\Strategy

                          Otherwise if you want to keep it private please email me at platform support @ ninjatrader.com and include a link to this thread along with attaching the file.

                          I look forward to being of further assistance.
                          JesseNinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by YevhenShynkarenko, Yesterday, 01:22 AM
                          2 responses
                          37 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Started by testingsarasa, 05-20-2018, 02:50 PM
                          11 responses
                          733 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Started by martyn73, Today, 05:27 PM
                          2 responses
                          9 views
                          0 likes
                          Last Post martyn73  
                          Started by MichaelAlexander, 02-22-2017, 05:06 AM
                          5 responses
                          1,402 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Started by walter739, Today, 11:56 AM
                          3 responses
                          11 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Working...
                          X