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 sjsj2732, Yesterday, 04:31 AM
            0 responses
            28 views
            0 likes
            Last Post sjsj2732  
            Started by NullPointStrategies, 03-13-2026, 05:17 AM
            0 responses
            284 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            281 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            132 views
            1 like
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            90 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Working...
            X