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

Rounding shares traded

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

    Rounding shares traded

    If I have $1000 for each trade, I'm looking for it to calculate the rounded amount of shares to enter long with below. I'm getting an error message cannot convert double to string. I guess I can't put shares in the EnterLong function below. So how can I go about doing this?...

    protected override void OnBarUpdate()
    {
    double shares = Math.Round(1000/Close[0]);

    if (Close[0] > Open[0] + (Open[0] * .15)) ;

    {
    EnterLong(shares);
    }
    }

    #2
    you need an integer.




    EnterLong()



    Definition
    Generates a buy market order to enter a long position.



    Method Return Value

    An IOrder read-only object that represents the order. Reserved for experienced programmers, additional information can be found within the Advanced Order Handling section.



    Syntax

    EnterLong()
    EnterLong(string signalName)

    EnterLong(int quantity)

    EnterLong(int quantity, string signalName)




    Originally posted by zachj View Post
    If I have $1000 for each trade, I'm looking for it to calculate the rounded amount of shares to enter long with below. I'm getting an error message cannot convert double to string. I guess I can't put shares in the EnterLong function below. So how can I go about doing this?...

    protected override void OnBarUpdate()
    {
    double shares = Math.Round(1000/Close[0]);

    if (Close[0] > Open[0] + (Open[0] * .15)) ;

    {
    EnterLong(shares);
    }
    }

    Comment


      #3



      Originally posted by zachj View Post
      If I have $1000 for each trade, I'm looking for it to calculate the rounded amount of shares to enter long with below. I'm getting an error message cannot convert double to string. I guess I can't put shares in the EnterLong function below. So how can I go about doing this?...

      protected override void OnBarUpdate()
      {
      double shares = Math.Round(1000/Close[0]);

      if (Close[0] > Open[0] + (Open[0] * .15)) ;

      {
      EnterLong(shares);
      }
      }

      Comment


        #4
        So this seems to work...

        EnterLong(Convert.ToInt32(Math.Round(1000/Close[0])));

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by zstheorist, Today, 07:52 PM
        0 responses
        3 views
        0 likes
        Last Post zstheorist  
        Started by pmachiraju, 11-01-2023, 04:46 AM
        8 responses
        149 views
        0 likes
        Last Post rehmans
        by rehmans
         
        Started by mattbsea, Today, 05:44 PM
        0 responses
        5 views
        0 likes
        Last Post mattbsea  
        Started by RideMe, 04-07-2024, 04:54 PM
        6 responses
        33 views
        0 likes
        Last Post RideMe
        by RideMe
         
        Started by tkaboris, Today, 05:13 PM
        0 responses
        5 views
        0 likes
        Last Post tkaboris  
        Working...
        X