Announcement

Collapse
No announcement yet.

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

    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

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        89 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        135 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        68 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        119 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        69 views
        0 likes
        Last Post PaulMohn  
        Working...
        X