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

Input string was not in a correct format

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

    Input string was not in a correct format

    I'm getting the following print error from lines same as below Test2

    Test0 : 97.04
    Test1 : 96.48
    Test2 : 56.0000000000002
    Indicator 'Testa': Error on calling 'OnBarUpdate' method on bar 505: Input string was not in a correct format.
    PHP Code:
    Print("Test0 : " Crude.MasterInstrument.RoundToTickSize(SMA(20)[0]).ToString());
    Print(
    "Test1 : " Crude.MasterInstrument.RoundToTickSize(CLSeries[0] ).ToString());
    Print(
    "Test2 : " + (Math.Abs(Crude.MasterInstrument.RoundToTickSize(CLSeries[0]) - Crude.MasterInstrument.RoundToTickSize(SMA(20)[0])) / Crude.MasterInstrument.TickSize).ToString()); 

    What's the error about? Thanks!

    #2
    Hello PaulMohn,

    The error relates to a string, without debugging the code I wouldn't know from which line. The print got to test 2 so those lines are not the problem, you have not included the code which may be a problem or the code after test2.

    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello Jesse, it seems to be working now, needed simpler syntax as
      PHP Code:
      Print("Test2 : " + (Math.Abs(Crude.MasterInstrument.RoundToTickSize(CLSeries[0] - SMA(20)[0])) / Crude.MasterInstrument.TickSize).ToString()); 
      instead of
      PHP Code:
      Print("Test2 : " + (Math.Abs(Crude.MasterInstrument.RoundToTickSize(CLSeries[0]) - Crude.MasterInstrument.RoundToTickSize(SMA(20)[0])) / Crude.MasterInstrument.TickSize).ToString()); 

      I got new issue

      Testa : 97.1
      Test0 : 97.1010565
      Test1 : 0.007835
      Test2 : 194186435
      PHP Code:
      Print("Testa : " Crude.MasterInstrument.RoundToTickSize(SMA(20)[0]).ToString());
      Print(
      "Test0 : " YEN.MasterInstrument.RoundToTickSize(SMA(20)[0]).ToString());
      Print(
      "Test1 : " YEN.MasterInstrument.RoundToTickSize(YENSeries[0] ).ToString());
      Print(
      "Test2 : " + (Math.Abs(YEN.MasterInstrument.RoundToTickSize(YENSeries[0] - SMA(20)[0])) / YEN.MasterInstrument.TickSize).ToString()); 

      As you can see the SMA(20)[0] for Testa (Crude) and Test0 (YEN) are both 97.1 (the CL 20 SMA since the indicator is set on the CL chart.

      I need the correct SMA for YEN (not the CL one), how do I get it?

      I mean why isn't it returning the YEN 20 SMA despite the instrument code for Test0 (i.e. YEN.MasterInstrument.RoundToTickSize(... )

      Same with Test2, i.e. what do i need to specify next for it to get the YEN 20 SMA (on the CL Chart as well).
      The previous way (with redundant syntax)

      PHP Code:
      Print("Test2 : " + (Math.Abs(YEN.MasterInstrument.RoundToTickSize(YENSeries[0]) - YEN.MasterInstrument.RoundToTickSize(SMA(20)[0])) / YEN.MasterInstrument.TickSize).ToString()); 

      still returns the error Input string was not in a correct format

      Please provide the answer with details so I can understand for next time. Thanks!
      Last edited by PaulMohn; 04-25-2022, 12:10 PM.

      Comment


        #4
        I did some more prints

        Print("Testz : " + Crude.MasterInstrument.TickSize.ToString());
        Print("Testx : " + YEN.MasterInstrument.TickSize.ToString());
        Print("Testa : " + Crude.MasterInstrument.RoundToTickSize(SMA(20)[0]).ToString());
        Print("Test0 : " + YEN.MasterInstrument.RoundToTickSize(SMA(20)[0]).ToString());
        Print("Test1 : " + YEN.MasterInstrument.RoundToTickSize(YENSeries[0]).ToString());
        Print("Test2 : " + (Math.Abs(YEN.MasterInstrument.RoundToTickSize(YEN Series[0] - SMA(20)[0])) / YEN.MasterInstrument.TickSize).ToString());
        Print("Test3 : " + (Math.Abs(YEN.MasterInstrument.RoundToTickSize(YEN Series[0]) - YEN.MasterInstrument.RoundToTickSize(SMA(20)[0])) / YEN.MasterInstrument.TickSize).ToString());

        PHP Code:
        Testz 0.01
        Testx 
        5E-07
        Testa 
        100.7
        Test0 
        100.6973685
        Test1 
        0.007861
        Test2 
        201379015
        Test3 
        201379015 

        Testx (YEN.MasterInstrument.TickSize.ToString()) returns 5E-07

        which should equate to 0.0000005
        https://calculator.name/scientific-n...o-decimal/5e-7


        So I have isolated the issue but I still don't know/can't find the answer. How can I get Test0 to returns the YEN 20 SMA value instead of the CL 20 SMA value (CL is the instrument the indictor is on) ?

        I used this syntax which seems right
        PHP Code:
        Print("Test0 : " YEN.MasterInstrument.RoundToTickSize(SMA(20)[0]).ToString()); 

        If the syntax should be another, what would that be? Thanks!

        Comment


          #5
          Hello PaulMohn,

          Which specific line/syntax is having the actual error? The string tests you provided aren't helpful to me to see what line is having an actual error. If you are trying to parse the string and its not in a correct format then you would get that error.

          I would suggest to remove all the prints that you have and comment out some lines to better isolate which specific line and syntax within that line is throwing the error.


          JesseNinjaTrader Customer Service

          Comment


            #6
            Hello Jesse, thanks for the reply. There's no more error now.
            The problem I have is not an error.
            The problem is:
            This print statement returns 100.6973685 for Test0 / YEN.MasterInstrument.RoundToTickSize(SMA(20)[0]

            Print("Test0 : " + YEN.MasterInstrument.RoundToTickSize(SMA(20)[0]).ToString());
            Test0 : 100.6973685

            Yen CANNOT HAVE A 100.6973685 as SMA 20 (Yen is the FX Futures with subdecimal price therefore the YEN 20 SMA should be < 0.00... )


            100.6973685 is the SMA 20 value for CL.

            My indicator has a YEN added series. My indicator is added to a CL chart, and that's why it picks up the CL 20 SMA value for YEN.MasterInstrument.RoundToTickSize(SMA(20)[0]

            Why YEN.MasterInstrument.RoundToTickSize(SMA(20)[0] doesn't return the YEN SMA(20)[0] value instead of the CL one?
            How to make it return the YEN SMA(20)[0] (NOT THE CL ONE!)

            Please understand the problem, or please forward my question/ask advice to a second NT advisor. Thanks!


            Comment


              #7
              Hello PaulMohn,

              I would suggest to simplify what you are trying here for the purpose of the forum post question. You have provided quite a few prints and it seems your script may have multiple series. This also does not relate to your original question about the format error so we really should move this into a separate forum post for a new question.

              Do you still see a problem using a single series script applied directly to the Yen? If so then we could cover that directly.




              JesseNinjaTrader Customer Service

              Comment


                #8
                Thanks Jesse for the suggestions.
                Chelsea got the solution here

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Spank, Yesterday, 04:32 AM
                1 response
                6 views
                0 likes
                Last Post NinjaTrader_Jason  
                Started by onlinebusiness, Today, 02:31 AM
                0 responses
                9 views
                0 likes
                Last Post onlinebusiness  
                Started by kainermy, Today, 02:08 AM
                0 responses
                8 views
                0 likes
                Last Post kainermy  
                Started by bomberone3, 10-16-2017, 12:16 PM
                11 responses
                2,096 views
                0 likes
                Last Post Spank
                by Spank
                 
                Started by BQuinton, Yesterday, 11:06 PM
                0 responses
                36 views
                0 likes
                Last Post BQuinton  
                Working...
                X