Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Converting double to Int to use as calculation of share quantity

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

    Converting double to Int to use as calculation of share quantity

    I know that C# has a conversion process that is something like this:

    double shareCalc = Math.Floor(unitSize / ((resistance1 - Support1) * winningPercentage));

    int shareQuantity = Convert.ToInt32(shareCalc);


    so that i can use my double value as an int for the purpose of determining and entering share quantity in my order code.


    I keep getting this message:

    **NT** Error on calling 'OnBarUpdate' method for strategy 'BasicPivot/13eb629f4d0544df810a5ccff04f6238': Value was either too large or too small for an Int32.

    Please advise, and thanks in advance.

    Regards,

    Andrew

    #2
    Hello,

    Thanks for the note.

    Can you please try Print(shareCalc); before you try to convert it to an Int so we can take a look at what price we are trying to convert to int.

    It may be we need to use Math.Round() to round the value down so it can be converted.

    -Brett
    BrettNinjaTrader Product Management

    Comment


      #3
      Here is an interesting piece of code printout...hmmm...

      590
      Infinity
      Last edited by NinjaTrader_Brett; 08-23-2012, 07:19 AM.

      Comment


        #4
        Hello,

        Looks like your math action is causing an infinity output which then wont convert to Int.

        Would need to have you check your math there and see what is going wrong.

        -Brett
        BrettNinjaTrader Product Management

        Comment


          #5
          I would like to send you a code snippet privately, may i?

          Comment


            #6
            Hello,

            Yes you can to support at ninjatrader dot com ATTN: Brett. I can take a quick look although I cannot do debugging unfortunately though I can take a quick look to see if I can assist.

            -Brett
            BrettNinjaTrader Product Management

            Comment


              #7
              email has been sent

              Comment


                #8
                Thanks, I replied via email and will follow up there.

                -Brett
                BrettNinjaTrader Product Management

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                61 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                40 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                21 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                23 views
                0 likes
                Last Post TheRealMorford  
                Started by Mindset, 02-28-2026, 06:16 AM
                0 responses
                51 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Working...
                X