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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    111 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    158 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    78 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    125 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    79 views
    0 likes
    Last Post PaulMohn  
    Working...
    X