Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order Quantity Error

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

    Order Quantity Error

    Hi,
    I'm attempting to set the order Quantity relative to whatever my cash value is at the moment. ( Essentially Cash value divided by the current asking price, rounded to a whole number would be the number of shares I'd like to execute on each long)

    In Initialize() I have AccountSize = 40000

    then for OnBarUpdate() at the end of my code I have my conditions and the line to long the stock as seen below:
    EnterLong("",math.round(GetAccountValue(AccountIte m.CashValue)/Ask[0]), "");

    When I run the script it just orders 1 share every time, so its clearly not working...
    Could someone assist me, I'm not sure if my logic is correct. I might be going about this all wrong.

    Cheers,
    Mike

    #2
    Originally posted by mwait View Post
    Hi,
    I'm attempting to set the order Quantity relative to whatever my cash value is at the moment. ( Essentially Cash value divided by the current asking price, rounded to a whole number would be the number of shares I'd like to execute on each long)

    In Initialize() I have AccountSize = 40000

    then for OnBarUpdate() at the end of my code I have my conditions and the line to long the stock as seen below:
    EnterLong("",math.round(GetAccountValue(AccountIte m.CashValue)/Ask[0]), "");

    When I run the script it just orders 1 share every time, so its clearly not working...
    Could someone assist me, I'm not sure if my logic is correct. I might be going about this all wrong.

    Cheers,
    Mike
    Before your EnterLong - let's see what's actually being computed.

    Code:
    Print (" GetAccountValue(AccountIte m.CashValue)=" + GetAccountValue(AccountIte m.CashValue) );
    Print ( "Ask[0]=" + Ask[0] );
    Print ( "The division=" + (GetAccountValue(AccountIte m.CashValue)/Ask[0]))  );
    Print ( "The rounding=" + math.round(GetAccountValue(AccountIte m.CashValue)/Ask[0]))  );
    Whatever your issue is, it should be clear now.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Tim-c, Today, 02:10 PM
    1 response
    7 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by Taddypole, Today, 02:47 PM
    0 responses
    2 views
    0 likes
    Last Post Taddypole  
    Started by chbruno, 04-24-2024, 04:10 PM
    4 responses
    50 views
    0 likes
    Last Post chbruno
    by chbruno
     
    Started by TraderG23, 12-08-2023, 07:56 AM
    10 responses
    400 views
    1 like
    Last Post beobast
    by beobast
     
    Started by lorem, Yesterday, 09:18 AM
    5 responses
    25 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Working...
    X