Announcement

Collapse
No announcement yet.

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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        152 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        87 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        131 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        127 views
        1 like
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        106 views
        0 likes
        Last Post CarlTrading  
        Working...
        X