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 BarUpdate, Entries and Exits

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

    Multi-Time Frame BarUpdate, Entries and Exits

    Hi again everyone,

    I'm wondering, is it possible on a Multi-TimeFrame strategy that employs let's say a 2 minute bar time frame and 20 minute bar time frame to have conditions set on the 2 minute bar OnBarUpdate to Enter a position and on the 20 minute bar, conditions on it's OnBarUpdate set to Exit the previous entries with a set limit of direction to 1?

    What I'd like essentially is to use 1 type of BarObject to specifically trigger Entries and another BarObject type to Exit.

    I cannot seem to get my head around this logic yet with Ninja Script. Any help would be appreciated.

    Thanks

    David

    #2
    Hello David,

    Yes, this would be possible. Please see our Strategy Reference Sample on Entering on one time frame and exiting on another:



    Please let me know if you have additional questions.
    MatthewNinjaTrader Product Management

    Comment


      #3
      Thank you for this, that is excellent, I'm now browsing all the reference strategy guides!

      Just one quick question, is it possible for Ninja Trader to automatically cancel an automated order from a strategy trigger if lets say that order was not filled by x amount of time, x move of bars or x move of price?

      I'm using Ninja Trader with IQFeed as my feed and Interactive Brokers as my online broker.

      Thank you again,

      David

      Comment


        #4
        David,

        Yes, this would also be possible using CancelOrder()



        The help guide will show an example of how to cancel after X number of bars, however, you would also be able to use a DateTime condition if needed.
        MatthewNinjaTrader Product Management

        Comment


          #5
          Nice, it seems like Ninja Trader has thought of everything.

          And I have one more question please. Is it possible to when using Multi-TimeFrames to have lets say triggers set off on the close of the 2 minute bar, CalculateOnBarClose = true, BUT calculations and triggers to be set off by the 20 minute bar by the incoming ticks? e.g. CalculateOnBarclose = false, meaning that calcs and triggers will be calculated for the second time frame as each individual tick arrive?

          Thanks

          David

          Comment


            #6
            David,

            Yes, also possible! There is a reference sample on this subject as well:

            Strategy: Separating logic to either calculate once on bar close or on every tick


            Please let me know if you have any questions on any of these methods or properties.
            MatthewNinjaTrader Product Management

            Comment


              #7
              Seriously, wow! lol, Is there anything that Ninja Trader didn't think of??? I really need to get myself a Lifetime license!

              I hope lastly, consider this

              (MACD(BarsArray[1], 12, 26, 9)[1]

              Firstly, to verify,the last [1] signifies that I am request that value of the MACD for the bar previous to the current bar as the current bar index is [0] right?

              Also, how do I get the MACD Difference value? I'm more interested in the Difference Value rather than the Avg and MACD values.

              Thanks

              David

              Comment


                #8
                David,

                You would need to specify .Diff after the MACD() method:

                MACD(BarsArray[1], 12, 26, 9).Diff[1];

                The snippet above would give you the MACD Difference value of the secondary data series one bar ago.

                More information on the MACD() method can be found below:
                MatthewNinjaTrader Product Management

                Comment


                  #9
                  Thank you for the snippet, very helpful indeed. So if I have set

                  CalculateOnBarClose = false;

                  how do I get the value of the current tick? the current Last Traded Price?

                  Consider that I have 2 objects, 2 minutes and 20 minutes

                  So what I've done is, in my Initialize() I've set CalculateOnBarClose = false; Then in my OnBarUpdate() I test for the

                  if (FirstTickOfBar) //because I only want triggers on close of bars
                  {
                  //Entry
                  if (BarsInProgress == 1) //this would give me my 2 minute bar object
                  {
                  //I want to test current tick price against my intra formed 20 minute bar EMA values, BarsArray[2]
                  //if condition is good EnterLong(1);
                  }
                  //Exit
                  if (BarInProgress == 2)
                  {
                  //On Bar Close Condition
                  //ExitLong(1)
                  }
                  }

                  I'm wondering, is the above possible? Especially the condition for entering the EnterLong(1)

                  Thank you

                  David
                  Last edited by davidt07; 10-04-2011, 09:15 PM.

                  Comment


                    #10
                    David,

                    If you're using Calculate On Bar Close == false, you can just use Close[0] to get the price of the current tick. This can be used and compared to other series you have added to the code
                    MatthewNinjaTrader Product Management

                    Comment


                      #11
                      And the condition of the BarsArray[2] inside the BarsArray[1] is possible?

                      Comment


                        #12
                        Hello,

                        Yes, as long as you are working within the correct BarsInProgress context.

                        Close[0] will give you the close of the first data series. You can compare this do your indicator using BarsArray[1].

                        Please let me know if you need further clarification
                        MatthewNinjaTrader Product Management

                        Comment


                          #13
                          Hi Matthew, well, erm... would it be possible to take a look at my earlier post with some of my pseudo logic code?

                          I think you may find that I maybe in the wrong BarInProgress context? I need your verification.

                          From what you are saying, it seems like Ninja Trader is finally NOT flexible enough to do my simple requirement? Sad :-(

                          Thanks

                          David
                          Last edited by davidt07; 10-04-2011, 11:37 PM.

                          Comment


                            #14
                            David,

                            I see - you can just add another check that you are in BIP 1 and 2 when checking for that entry signal

                            if (BarsInProgress == 1 && BarsInProgress == 2) // this would give you the 2 minute bar and allow you to also check the Bars in the 2nd array as well.

                            Then you could just run a check for if (BarsInProgress == 2) to work only in the context of your exit condition you want to check.
                            MatthewNinjaTrader Product Management

                            Comment


                              #15
                              Okay, I will give that a shot. One thing however about the CurrentTick, if I am using something like RangeBars instead of TimeFrame bars, Close[0] would not get me the CurrentTick price because RangeBars closes due to the CurrentTick being out of Range.

                              How would I get the CurrentTick price in this instance if I am working with RangeBars, Renko or similar type bars?

                              Thanks

                              David

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by zstheorist, Today, 07:52 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post zstheorist  
                              Started by pmachiraju, 11-01-2023, 04:46 AM
                              8 responses
                              149 views
                              0 likes
                              Last Post rehmans
                              by rehmans
                               
                              Started by mattbsea, Today, 05:44 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post mattbsea  
                              Started by RideMe, 04-07-2024, 04:54 PM
                              6 responses
                              33 views
                              0 likes
                              Last Post RideMe
                              by RideMe
                               
                              Started by tkaboris, Today, 05:13 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post tkaboris  
                              Working...
                              X