Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Open Range breakout Strategy

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

    Open Range breakout Strategy

    As a measure to learn Ninjascript, I try to create an open range breakout strategy.
    Step by step I advanced to point where I do not understand why I get these results.
    Until now I only used the Strategy wizard.
    My idea was to implement a 15 minute breakout strategy test. I want to take the highest high and lowest low of the first 15 minutes, and if the breakout occurs within the next 5 minutes, enter a long or short position respectively.

    In the attachments one can see, that the strategy obviously takes a long position where it shouldn't. This strategy is so easy, I don't understand what I can do wrong.
    I just check on bar after the other if there is a new high (or low), then save it in a variable and use this variable afterwards for comparison.
    Can anyone give me a hint? What am I overlooking.

    Best regards,

    Stefan Jung
    Attached Files

    #2
    I found that switching the "calculate bar on close" off seems to solve my problem, as far as I can see. I have not expected this behavior though. Is there good information to find on this subject?

    Comment


      #3
      Hello Stefan,

      Thank you for your post.

      We do have a sample on our forum on how to monitor and trade a breakout that should come in handy -
      http://www.ninjatrader.com/support/f...ead.php?t=3223

      Let me know if I can be of further assistance.
      Cal H.NinjaTrader Customer Service

      Comment


        #4
        Regarding sessions: Am I right that the first bar of a session is the time defined in a template of the session manager? So if I have a session defined for regular trading hours, it starts with, let's say for NASDAQ stocks, at 15:30.

        Comment


          #5
          Stefan,

          This is correct. the session is defined by the session template and how the FirstBarOfSession is determined.
          Cal H.NinjaTrader Customer Service

          Comment


            #6
            You could use an indicator that calculates the opening range and then directly access the upper and lower bounds of the opening range, see chart attached. The indicator is available open source.
            Attached Files

            Comment


              #7
              Where can I find the shaded opening range like in the posted image? Thank you.

              Comment


                #8
                I think you can get it on Big Mikes Trading and look for Fattails....he has a bunch of great indicators. I have this indicator and trade the opening range.....I'm currently looking to have a few plots added to this indicator based on tics above and below the opening range for the A up/downs and C up/downs. It would be nice to be able to have this plotted based on the tics I want per each instrument.

                Comment


                  #9
                  Hi,
                  I tried the sample code for NT7.

                  I have done required changes to get 1st hour Opening Range breakout.

                  My problem is its only taking Long orders ,.. no short orders. Am i doing anything wrong with order placing ? How does it work in ninjaTrader ?
                  Here is the code ,..

                  Code:
                  protected override void OnBarUpdate()
                          {
                              // Resets the highest high at the start of every new session
                              if (Bars.FirstBarOfSession)
                              {
                                  highestHigh = High[0];
                                  lowestLow = Low[0];
                              }
                              // Stores the highest high from the first 12 bars
                              if (Bars.BarsSinceSession < 12 && High[0] > highestHigh)
                                  highestHigh = High[0];
                              if (Bars.BarsSinceSession < 12 && Low[0] < lowestLow)
                                  lowestLow = Low[0];
                              // Entry Condition: Submit a buy stop order one tick above the first 12 bar high. 
                              if (Bars.BarsSinceSession > 12 )
                              {
                                  // EnterLongStop() can be used to generate buy stop orders.
                                  EnterLongStop(highestHigh + TickSize);
                              }
                              if (Bars.BarsSinceSession > 12 )
                              {
                                  EnterShortStop(lowestLow - TickSize);
                              }
                              // Exit Condition: Close positions after 10 bars have passed
                              if (BarsSinceEntry() > 10)
                              {
                                  ExitLong();
                                  ExitShort();
                              }
                  
                          }
                  I have declared variable lowestLow and it compiles successfully. But the order management i dont get. It should place both long and short orders at the same time. Which will eventually work as a stop order in case of one side is filled.

                  Guide me please.
                  Thanks ,..

                  Comment


                    #10
                    Hello hsrad,

                    Thanks for your post.

                    With reference to the help guides section on "Managed approach" you are violating one of the "Internal Order Handling Rules that Reduce Unwanted Positions", specifically, "Methods that generate orders to enter a position will be ignored if: A position is open and an order submitted by an exit method (ExitLongLimit() for example) is active and the order is used to open a position in the opposite direction" https://ninjatrader.com/support/help...d_approach.htm You should check the "log" tab of the control center to see if you have error messages related to this strategy. You can also test this by changing the code order and move the code to place the short entry first which should result in only short trades being taken.

                    What you can do, in the managed approach, in your code, is to monitor the current price relative to the two levels and when price touches those levels to enter an appropriate order.


                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks Paul for reply,..

                      But I need to do put orders this way only.

                      Can i develop to different strategies and deploy on one instrument, like one for short and one for long ?? will that do??

                      if not then can u please show me the way how can i do it like i said putting stop orders on both side ??

                      Comment


                        #12
                        Hello hsrad,

                        Thanks for your reply.

                        In the managed approach as advised you cannot place orders that violate the internal order handling rules. I suggested an alternative way to perform your strategy to accomplish your breakout goal that would place only one entry order, depending on the direction.

                        "Can i develop to different strategies and deploy on one instrument, like one for short and one for long ?? will that do??" You can develop different strategies and they can be employed on the same instrument. I do not know if that will perform as you want but you can certainly test. You will need to make sure you understand that a strategy maintains its own strategy position, so while one strategy would be long and the other strategy goes short, the account position would be flat, once a strategy reaches its stop or profit level it will continue to place those orders live even though the account may be flat or in the other direction. Please review this section of the help guide for further understanding: https://ninjatrader.com/support/help..._account_p.htm

                        If you want to be able to run one strategy and have to place orders "this way only", then you may want to look into using the "UnManaged approach" which allows you the freedom to place orders as you wish with the restrictions of the managed approach. Here is a description of the unmanaged approach: "The Unmanaged approach is reserved for VERY EXPERIENCED programmers. In place of the convenience layer that the Managed approach offered, the Unmanaged approach instead offers ultimate flexibility in terms of order submission and management.". Please see https://ninjatrader.com/support/help...d_approach.htm

                        An alternative would be to have you strategy created for you by a 3rd party professional developer, if this is of interest we can provide you with a link to such developer through the Ninjatrader ecosystem.
                        Last edited by NinjaTrader_PaulH; 12-12-2019, 10:15 AM. Reason: added a word
                        Paul H.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by trilliantrader, 04-18-2024, 08:16 AM
                        4 responses
                        18 views
                        0 likes
                        Last Post trilliantrader  
                        Started by mgco4you, Today, 09:46 PM
                        1 response
                        7 views
                        0 likes
                        Last Post NinjaTrader_Manfred  
                        Started by wzgy0920, Today, 09:53 PM
                        0 responses
                        9 views
                        0 likes
                        Last Post wzgy0920  
                        Started by Rapine Heihei, Today, 08:19 PM
                        1 response
                        10 views
                        0 likes
                        Last Post NinjaTrader_Manfred  
                        Started by Rapine Heihei, Today, 08:25 PM
                        0 responses
                        10 views
                        0 likes
                        Last Post Rapine Heihei  
                        Working...
                        X