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

How can I Flatten Everything on NT8

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

    How can I Flatten Everything on NT8

    Hello Guys,

    I start my trading with $100 000 and I have a daily profit objective of $1000, so basically I write this code to stop trading once the NetLiquidation amount reaches 100k+1k

    HTML Code:
    MasterInstrument mi = Bars.Instrument.MasterInstrument;
    commPerUnit = this.Account.Commission.ByMasterInstrument[mi].PerUnit;
    
    Print(Convert.ToString(Instrument.MasterInstrument .Name));
    
    if (Account.Get(AccountItem.NetLiquidation, Currency.UsDollar) >= (StartingAccountBalance + DailyTargetProfit)) {
    
    Print("I exceeded the daily target profit");
    myAccount.Flatten(new [] { Instrument.GetInstrument('"' + Convert.ToString(Instrument.MasterInstrument.Name) + '"') });
    }
    The Print() method shows the message "I exceeded the daily target profit" at the right moment, but when the code moves to flatten, it gives an error and abort the entire strategy


    Thanks for your help

    #2
    Hi Mohammed, thanks for posting.

    It looks like the myAccount object is never initialized. See here for an example on how to initialize a custom Account object:



    Kind regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hello Chris, Thnx for your reply, what do u mean not initialized, do u mean declaration ?

      a the beginning of course I have
      HTML Code:
      private Account myAccount;
      is that what you mean or something else ?

      plz give me straight code is possible, Thnx a lot

      Comment


        #4
        Hi Mohammed, thanks for your reply.

        Please see the code example I linked on my previous reply, this shows how you initialize the Account object within the code. Specificaly, this line in State.SetDefaults:

        // Find our Sim101 account
        lock (Account.All)
        myAccount = Account.All.FirstOrDefault(a => a.Na me == "Sim101");

        Kind regards,
        -ChrisL
        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by terofs, Yesterday, 04:18 PM
        1 response
        21 views
        0 likes
        Last Post terofs
        by terofs
         
        Started by CommonWhale, Today, 09:55 AM
        1 response
        3 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by Gerik, Today, 09:40 AM
        2 responses
        7 views
        0 likes
        Last Post Gerik
        by Gerik
         
        Started by RookieTrader, Today, 09:37 AM
        2 responses
        12 views
        0 likes
        Last Post RookieTrader  
        Started by alifarahani, Today, 09:40 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X