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

Multi Time Frame, Multi Instrument Strategy - Exit Trigger from a lower time frame

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

    Multi Time Frame, Multi Instrument Strategy - Exit Trigger from a lower time frame

    Hello,

    I am implementing a multi time frame, multi instrument strategy in NT7 based on examples provided and the wealth of information on the forums. I have hit a road block and need some help please.

    I work with a daily chart in which the strategy 'buy order' is generated on some logic in the daily chart, however I want to exit based on a trigger from a different instrument on a lower time frame such as 5 mins.

    The behavior I am struggling with the strategy is that it doesn't execute ExitLong("", "") from the 5 min section of the code in (BarsInProgress==2) even though via printf I've confirmed the logic is triggered but ExitLong doesn't execute. I can exit on the daily just fine in BarsSInProgress==0 but the exit is time sensitive. Price changes quite a bit waiting for the next day.

    Did I understand correctly from the posts in the forums that in historical data exits can only be made from BarsSInProgress==0?

    Some help will be appreciated, thanks.

    #2
    Hello remorim,

    Thanks for your post.

    You would need to use the advanced order method for ExitLong() where you will need to specify the BarsInProgress index that you place the entry order on. From the help guide:

    ExitLong(int barsInProgressIndex, int quantity, string signalName, string fromEntrySignal)
    Parameters

    signalName - User defined signal name identifying the order generated. Max 50 characters.

    fromEntrySignal - The entry signal name. This ties the exit to the entry and exits the position quantity represented by the actual entry.

    quantity - Entry order quantity.

    barsInProgressIndex - The index of the Bars object the order is to be submitted against. See the BarsInProgress property. This determines what instrument the order is submitted for.


    References:

    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks Paul.

      I did refer to those examples and now why they did not work for me.

      My case;
      BIP=0 --- 1 day chart
      BIP=2 --- 60 min chart

      When I buy long from (BarsInProgress) BIP=0 into a lower time frame via EnterLong(2,DefaultQuantity,"LowerTFBuy") then this signal wasn't appearing on the primary chart BIP=0 which led me to believe it was not working but debugging further showed that long position was bought into on the next BIP=2 iteration but the lower time frame orders don't appear on the primary chart.

      Another observation, if EnterLong(DefaultQuantity,"HigherTFBuy") is used in BIP=0, then Position.MarketPosition turns out to be 'Flat' in BIP=2.

      If EnterLong(2,DefaultQuantity,"LowerTFBuy") is used in BIP=0, then Position.MarketPosition turns out to be 'Flat' in BIP=0 but appears 'Long' in BIP=2 but for only 1 iteration and then for all subsequent iterations of BIP=2, .Position.MarketPosition is showing as 'Flat'.

      The logic continues to trigger buy orders via EnterLong(2,DefaultQuantity,"LowerTFBuy"), they are all verified in the 1st iteration of BIP=2 as Position.MarketPosition=Long but in all subsequent iterations on BIP=2 they appear as Position.MarketPosition=Flat.

      Is there an explanation to this behavior or how can I troubleshoot it? Is there some code I can put in OnExecution(IExecution execution) to figure out why the position is going flat in the absence of an ExitLong order?

      Comment


        #4
        Originally posted by remorim View Post
        EnterLong(2,DefaultQuantity,"LowerTFBuy")
        This will create a long position on the instrument associated with BIP=2.

        Originally posted by remorim View Post
        EnterLong(<BIP>, DefaultQuantity,"HigherTFBuy")
        Wait, why no BIP argument?

        Mixing and matching is not recommended.

        Don't do this, otherwise, you'll be playing useless 'check-the-BIP' or 'guess-the-BIP' games.

        That's a waste of your time. Just nip it in the bip (uh, I mean, bud ) and be done
        with it. No mess, no fuss, always specify the BIP ... even for BIP=0.

        Why?
        If you wish to enter the world of MTF programming, in every case that allows it, for
        every overload that provides it -- you've now reached that level of programming where
        you should always specify the BIP argument (or the BIP index, such as Closes[0][0]).

        Down the mix-n-match coding style many headaches await thee.

        Just my 2˘.

        Comment


          #5
          The BIP police caught me red handed, guilty as charged The advice is much appreciated.

          Those orders weren't used simultaneously, in testing I commented one out to test the other to experiment with different order types and understanding their behaviors.

          The order you pointed out is what I used, but why the strategy is exiting long without an explicit trigger is eluding me and I am trying to find out how to debug this scenario. Any help will be appreciated.

          Thanks.

          Comment


            #6
            Hello remorim,

            Thanks for your reply.

            I agree with members bltdavid's reply/advise. Once you go MTF it will be a better practice to use the advanced order methods where you are providing the BIP.

            Please review the link previously provided on Multi time frame.

            Also, I would recommend using Positions[] and in this case always use Positions[0] as shown in the referenced section: https://ninjatrader.com/support/help...?positions.htm
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              "Position" is always representative of the BarsInProgress context.

              See attached, study the paragraph outlined in red.
              Attached Files

              Comment


                #8
                Originally posted by remorim View Post
                Another observation, if EnterLong(DefaultQuantity,"HigherTFBuy") is used in BIP=0, then Position.MarketPosition turns out to be 'Flat' in BIP=2.
                Yep, and that is expected.

                To guarantee you are looking at the Position on BIP=0, then use,

                Code:
                Positions[0].MarketPosition
                which works regardless of the BIP context you're currently processing.

                Comment


                  #9
                  I am surprised learning and reading up on the forums for weeks about MTFs I did not come across 'Positions'. I'll start learning and testing it, thanks.

                  Comment


                    #10
                    Yeah, lots of folks use MTF programming in their technical analysis,
                    but I suspect fewer people take the more advanced step of managing
                    multiple positions in more than one instrument in the same strategy.

                    What you're doing is very advanced and, IMHO, very rare.

                    Comment


                      #11
                      bltdavid Pardon my illusions , all my poor soul is trying to accomplish is buy in on the daily time frame and exit at lower time frame triggers from different instruments.
                      Working & debugging with Positions[0] did not solve the problem but I've started another thread since the problem seems to be stemming not in the logic but rather how NT is processing events.
                      The thread is at https://ninjatrader.com/support/foru...-close-problem

                      Thank you for all your help.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Haiasi, 04-25-2024, 06:53 PM
                      2 responses
                      17 views
                      0 likes
                      Last Post Massinisa  
                      Started by Creamers, Today, 05:32 AM
                      0 responses
                      5 views
                      0 likes
                      Last Post Creamers  
                      Started by Segwin, 05-07-2018, 02:15 PM
                      12 responses
                      1,786 views
                      0 likes
                      Last Post Leafcutter  
                      Started by poplagelu, Today, 05:00 AM
                      0 responses
                      3 views
                      0 likes
                      Last Post poplagelu  
                      Started by fx.practic, 10-15-2013, 12:53 AM
                      5 responses
                      5,408 views
                      0 likes
                      Last Post Bidder
                      by Bidder
                       
                      Working...
                      X