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 argusthome, 03-08-2026, 10:06 AM
    0 responses
    80 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    46 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    29 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    32 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    66 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X