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 NullPointStrategies, Today, 05:17 AM
        0 responses
        50 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        126 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        69 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        42 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X