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 charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    65 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    149 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    162 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    99 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    286 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Working...
    X