Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

setting stop loss and target from account balance

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

    setting stop loss and target from account balance

    //double currentAccountBalance = Account.Get(Account.Name).Get(AccountItem.CashValu e, Currency.UsDollar);


    im getting a error with this code

    im trying to set stoploss and target based off % of balance of account, could i get some help with the correct code to do that.

    Thanks in Advance , Anton



    #2
    Hello Anton,

    Thanks for your post.

    In the code you shared you are using Account.Get().Get(); which is invalid syntax.

    Further, you would need to define the account in a class-level variable, such as private Account myAccount, and then use myAccount.Get(AccountItem.CashValue, Currency.UsDollar); in the script.

    For example:

    //class level variable
    private Account myAccount;

    //OnStateChange() State.SetDefaults
    lock (Account.All)
    myAccount = Account.All.FirstOrDefault(a => a.Name == "Sim101");

    //OnBarUpdate()
    ​double currentAccountBalance = myAccount.Get(AccountItem.CashValue, Currency.UsDollar);


    See the help guide documentation below for more information and sample code:

    Account: https://ninjatrader.com/support/help...ount_class.htm
    <Account>.Get(): https://ninjatrader.com/support/helpGuides/nt8/get.htm
    AccountItem: https://ninjatrader.com/support/help...ccountitem.htm
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      thanks for the info

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      80 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      40 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      63 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      63 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      54 views
      0 likes
      Last Post CarlTrading  
      Working...
      X