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

Math.Round as 'int' not working

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

    Math.Round as 'int' not working

    Hi guys

    In Variables, I've declared:

    Code:
    private double mult = 2.0;
    private int var1 = 2
    private int var2 = 2
    then in OnBarUpdate, I've put:

    Code:
    Var1 = 3*Mult;
    Var2 = Math.Round(2*Mult, 0);
    The Var1 = 3*Mult works OK, but the Var2 = Math.Round(2*Mult, 0) doesn't compile: there's obviously a int/double mismatch. The exact error message is:

    Cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?)
    I need Var2 to be 'int' as I use it later in HMA(Median, Var2).

    Any advice as to how to solve this conundrum will be greatly appreciated.

    #2
    Originally posted by arbuthnot View Post
    Hi guys

    In Variables, I've declared:

    Code:
    private double mult = 2.0;
    private int var1 = 2
    private int var2 = 2
    then in OnBarUpdate, I've put:

    Code:
    Var1 = 3*Mult;
    Var2 = Math.Round(2*Mult, 0);
    The Var1 = 3*Mult works OK, but the Var2 = Math.Round(2*Mult, 0) doesn't compile: there's obviously a int/double mismatch. The exact error message is:

    I need Var2 to be 'int' as I use it later in HMA(Median, Var2).

    Any advice as to how to solve this conundrum will be greatly appreciated.
    Hi arbuthnot,

    Using the NinjaTrader editor, when you type in the following string...

    Var2 = Math.Round(

    When you enter the curved bracket, You will be offered a series of options to complete the statement. Just follow the format you want.

    RJay
    RJay
    NinjaTrader Ecosystem Vendor - Innovative Trading Solutions

    Comment


      #3
      hello arbuthnot,

      you could use the following code to load the integers with the doubles values:
      Code:
       
      Var1 = ([COLOR=blue]int[/COLOR])(3*Mult);
      Var2 = ([COLOR=blue]int[/COLOR])Math.Round(2*Mult,0);
      Marco

      Comment


        #4
        Hi arbuthnot,

        Using the NinjaTrader editor, when you type in the following string...

        Var2 = Math.Round(

        When you enter the curved bracket, You will be offered a series of options to complete the statement. Just follow the format you want.

        RJay
        Thanks very much, RJay. That's a very useful suggestion but it doesn't seem to work on my NT7. Maybe because I'm using XP...

        Comment


          #5
          hello arbuthnot,

          you could use the following code to load the integers with the doubles values:
          Code:
          Var1 = (int)(3*Mult); Var2 = (int)Math.Round(2*Mult,0);
          Marco
          Thanks very much, Marco, I've done as you suggested and that works perfectly. Not for the first time I'm very grateful to you.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by bmartz, 03-12-2024, 06:12 AM
          4 responses
          32 views
          0 likes
          Last Post bmartz
          by bmartz
           
          Started by Aviram Y, Today, 05:29 AM
          4 responses
          12 views
          0 likes
          Last Post Aviram Y  
          Started by algospoke, 04-17-2024, 06:40 PM
          3 responses
          28 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by gentlebenthebear, Today, 01:30 AM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by cls71, Today, 04:45 AM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X