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 argusthome, Yesterday, 10:06 AM
    0 responses
    14 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    11 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    9 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    4 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    31 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X