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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        562 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        325 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        547 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X