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 ageeholdings, Today, 07:43 AM
      0 responses
      7 views
      0 likes
      Last Post ageeholdings  
      Started by pibrew, Today, 06:37 AM
      0 responses
      4 views
      0 likes
      Last Post pibrew
      by pibrew
       
      Started by rbeckmann05, Yesterday, 06:48 PM
      1 response
      14 views
      0 likes
      Last Post bltdavid  
      Started by llanqui, Today, 03:53 AM
      0 responses
      6 views
      0 likes
      Last Post llanqui
      by llanqui
       
      Started by burtoninlondon, Today, 12:38 AM
      0 responses
      12 views
      0 likes
      Last Post burtoninlondon  
      Working...
      X