Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      thanks for the info

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by burtoninlondon, Today, 12:38 AM
      0 responses
      9 views
      0 likes
      Last Post burtoninlondon  
      Started by AaronKoRn, Yesterday, 09:49 PM
      0 responses
      14 views
      0 likes
      Last Post AaronKoRn  
      Started by carnitron, Yesterday, 08:42 PM
      0 responses
      11 views
      0 likes
      Last Post carnitron  
      Started by strategist007, Yesterday, 07:51 PM
      0 responses
      13 views
      0 likes
      Last Post strategist007  
      Started by StockTrader88, 03-06-2021, 08:58 AM
      44 responses
      3,983 views
      3 likes
      Last Post jhudas88  
      Working...
      X