Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Convert to INT

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

    Convert to INT

    I have the following variable, Period, cast as int. This compiles fine but on runtime I get the following error. I want "Period" to be an integer. Thanks.

    Period = Convert.ToInt64(StdDev(5));

    Unable to cast object of type 'NinjaTrader.NinjaScript.Indicators.StdDev' to type 'System.IConvertible

    #2
    Originally posted by EthanHunt View Post
    I have the following variable, Period, cast as int. This compiles fine but on runtime I get the following error. I want "Period" to be an integer. Thanks.

    Period = Convert.ToInt64(StdDev(5));

    Unable to cast object of type 'NinjaTrader.NinjaScript.Indicators.StdDev' to type 'System.IConvertible
    Try adding a BarsAgo subscript, like this,

    Code:
    Period = Convert.ToInt64(StdDev(5)[COLOR=Red][0][/COLOR]);

    Comment


      #3
      Hello EthanHunt,

      Thanks for your post.

      Member bltdavid has provided the solution, your statement was trying to convert a series and by adding the bars ago index [] it will be able to convert just the double value that it resolves to.

      Reference: https://ninjatrader.com/support/help...ion_stddev.htm

      Comment


        #4
        NT returns the following error after adding the bars ago index []...

        Cannot implicitly convert type 'long' to 'int'. An explicit conversion exists (are you missing a cast?)


        Originally posted by NinjaTrader_Paul View Post
        Hello EthanHunt,

        Thanks for your post.

        Member bltdavid has provided the solution, your statement was trying to convert a series and by adding the bars ago index [] it will be able to convert just the double value that it resolves to.

        Reference: https://ninjatrader.com/support/help...ion_stddev.htm

        Comment


          #5
          Hello EthanHunt

          Thanks for your reply.

          The Convert.ToInt64() would convert the double to a Long, so in this case, you would need to declare Period as a long:

          To convert the double to an int, please use Convert.ToInt32().

          Comment


            #6
            That worked, thanks.

            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
            573 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