Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

AccountValue Query

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

    AccountValue Query

    Hi Support,
    I need my strategy to define the Quantity for each trade as function of capital at risk (e.i. 1%) and the stop loss I apply (e.i. 0.05 ticks) on each trade in live trading. I am wondering if this code could work:

    Code:
    #region Variables
    accountSize = 10000; // initial capital
    stopLoss = 0.050; // stop loss in tick size
    #endregion
    
    On BarUpdate()
    If(Close[0] > Close[1])
    {
    if(!Historical) AccountSize= GetAccountValue(AccountItem.CashValue) == 0 ? AccountSize : GetAccountValue(AccountItem.CashValue); 
    positionSize = accountSize x 0.01 / stopLoss;
    
    EnterLongLimit(0,false,(double)positionSize,Low[0],"Buy");
    }
    Also please could you advisee if it's best defining accountSize in the Variables section or in the Initialize() void

    Thanks

    #2
    Hello yades,

    That should work, but I would change the name of your Variable as it is the same as the "AccountSize" Variable built into the Strategy Class.



    The "AccountSize" Variable inside of the Strategy class is not meant to be dynamically changed, so a defined variable will work like you have, but to avoid conflicting with it you may just want to name it differently.

    Happy to be of further assistance.
    JCNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    648 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    369 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    108 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    572 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    573 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X