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 Barry Milan, Today, 10:35 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by WeyldFalcon, 12-10-2020, 06:48 PM
        14 responses
        1,428 views
        0 likes
        Last Post Handclap0241  
        Started by DJ888, Yesterday, 06:09 PM
        2 responses
        9 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by jeronymite, 04-12-2024, 04:26 PM
        3 responses
        40 views
        0 likes
        Last Post jeronymite  
        Started by bill2023, Today, 08:51 AM
        2 responses
        16 views
        0 likes
        Last Post bill2023  
        Working...
        X