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

FlattenEverything

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

    FlattenEverything

    Hello,
    If I have several strategies working on different charts (all on the same real account) and in one of these strategies I call "Account.FlattenEverything", are the positions of all the products/charts closed?

    #2
    Hello soyjesus

    The Account.Flatten() accepts an instrument would flatten everything on the account for that instrument. For any strategies with open positions this would cause them to be disabled.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks Chelsea B., but which is the difference between "Account.Flatten()" and "FlatenEverything()"?

      Comment


        #4
        Hello soyjesus,

        The Account.Flatten() method is a documented method in the help guide of which I can assist with using. FlattenEverything() is not a documented method and we do not have a specific expectation for its use.

        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello,

          I'm using Account.Flatten() and the problem is that it closes the positions in the actual Account and in the rest of accounts too. And I want to close positions only in the Account in which I have inserted the strategy.

          Comment


            #6
            Hello soyjesus,

            I am not able to reproduce this behavior.

            To test I have created Sim102 account and opened a long position on both Sim101 and Sim102.

            Then in an indicator, I have called
            Account myAccount = Account.All.FirstOrDefault(a => a.Name == "Sim102");
            myAccount.Flatten(new [] { Instrument.GetInstrument("ES 12-21") });

            Only the position on the Sim102 account was flattened.

            Below is a link to a video of the test.
            https://drive.google.com/file/d/1_E7...w?usp=drivesdk

            This indicates that <Account>.Flatten() does work as intended.


            If you are wanting to flatten only the strategy position in a NinjaScript Strategy. Call ExitLong() and ExitShort() in the strategy.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Question, While using the flatten() with a collection is using only realtime data required in all strategies to keep historical trades adding to tally.

              Comment


                #8
                Hello JLSwin,

                The Flatten would be in relation to the Account position and not the strategy position. Any strategies running on those instruments that have a position open would be disabled.

                Accounts positions are real-time.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_ChelseaB View Post
                  Hello soyjesus,

                  I am not able to reproduce this behavior.

                  To test I have created Sim102 account and opened a long position on both Sim101 and Sim102.

                  Then in an indicator, I have called
                  Account myAccount = Account.All.FirstOrDefault(a => a.Name == "Sim102");
                  myAccount.Flatten(new [] { Instrument.GetInstrument("ES 12-21") });

                  Only the position on the Sim102 account was flattened.

                  Below is a link to a video of the test.
                  https://drive.google.com/file/d/1_E7...w?usp=drivesdk

                  This indicates that <Account>.Flatten() does work as intended.


                  If you are wanting to flatten only the strategy position in a NinjaScript Strategy. Call ExitLong() and ExitShort() in the strategy.
                  Hello Chelsea and thanks for that helpful demo.

                  I'm wondering how to make the Flatten() method apply to whatever instrument of the chart the indicator is loaded on instead of a predefined string.

                  I can't find the syntax in the doc

                  How would it work? Thanks!
                  Last edited by PaulMohn; 06-13-2022, 09:25 AM.

                  Comment


                    #10
                    Hello PaulMohn,

                    You would the Instrument of the Indicator class instead of Instrument.Get().


                    Try printing the instrument
                    Print(Instrument.ToString());
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Ok thanks a lot, so simply get it as string
                      PHP Code:
                      myAccount.Flatten(new [] { Instrument.GetInstrument(Instrument.ToString()) }); 

                      It compiles ok. I'll test is asa. Thanks!

                      Comment


                        #12
                        Hello PaulMohn,

                        myAccount.Flatten(new [] { Instrument });
                        Chelsea B.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by usazencort, Today, 01:16 AM
                        0 responses
                        1 view
                        0 likes
                        Last Post usazencort  
                        Started by kaywai, 09-01-2023, 08:44 PM
                        5 responses
                        603 views
                        0 likes
                        Last Post NinjaTrader_Jason  
                        Started by xiinteractive, 04-09-2024, 08:08 AM
                        6 responses
                        22 views
                        0 likes
                        Last Post xiinteractive  
                        Started by Pattontje, Yesterday, 02:10 PM
                        2 responses
                        20 views
                        0 likes
                        Last Post Pattontje  
                        Started by flybuzz, 04-21-2024, 04:07 PM
                        17 responses
                        230 views
                        0 likes
                        Last Post TradingLoss  
                        Working...
                        X