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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    84 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    46 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    66 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    69 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    58 views
    0 likes
    Last Post CarlTrading  
    Working...
    X