Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Afternoon breakout

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

    Afternoon breakout

    Hi guys, Im trying to put together a system that trades the breakout of the morning session (from open till 1). I made a few adjustments to a ORB strategy to get this. When I set it up, it holds off putting in orders until 1pm as expected but as soon as it hits 1pm, my Interactive Brokers Demo fills up with positions, not waiting to break the highs and lows like it should.
    The daily highs and lows show up correctly in the Output window though.

    Im running 6.5 on windows XP, connected to TWS.
    The ORB that I modified it from works fine....
    any help would be much appreciated.

    Thanks.

    Code:
    // 
    // Copyright (C) 2007, NinjaTrader LLC <[URL="http://www.ninjatrader.com"]www.ninjatrader.com[/URL]>.
    // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
    //
    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Strategy;
    #endregion
    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
        /// <summary>
        /// Simple strategy that monitors for a breakout.
        /// </summary>
        [Description("Simple strategy that monitors for a breakout.")]
        public class AfternoonBreak: Strategy
        {
            #region Variables
      private double highestHigh = 0;
      private double lowestLow = 0; 
            #endregion
            /// <summary>
            /// This method is used to configure the strategy and is called once before any strategy method is called.
            /// </summary>
            protected override void Initialize()
            {
                CalculateOnBarClose = true;
            }
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
       
     
            {
       
       
       // Resets the highest high and lowest low at the start of every new session
       if (Bars.FirstBarOfSession && FirstTickOfBar)
       {
        highestHigh = High[0];
        lowestLow = Low[0];
       }
      
       
       // Stores the highest high from the morning session on a 30 minute chart
       if (Bars.BarsSinceSession < 7 && High[0] > highestHigh)
        highestHigh = High[0];
       // Stores the lowest low from the morning session on a 30 minute chart
       if (Bars.BarsSinceSession < 7 && Low[0] < lowestLow)
        lowestLow = Low[0];
       // Prints details in the output window to follow for confirmation 
        Print(Instrument.FullName + " " + Time[0] + " " + CurrentBar + " " + highestHigh + " " + lowestLow);
        Print(Bars.BarsSinceSession);
       // Draw the bar count on the chart
        DrawText(CurrentBar.ToString(),Bars.BarsSinceSession.ToString(),0,High[0] + (TickSize *3),Color.Blue);
       
       
       
       //Print the symbol and Highs and Lows of the morning session 
       if (Bars.BarsSinceSession == 6 )
        PrintWithTimeStamp(Instrument.FullName + " " + "High" + " " + highestHigh + " " + "Low" + lowestLow);
        
       
      
       
           //Setup the Stop in the direction of  close to the high/low midpoint
        if (Bars.BarsSinceSession >= 6 && Close[0] > (highestHigh + lowestLow)/2)
                    //Enter Long at highest high + 1 of Morning Session.
     
         EnterLongStop(100, highestHigh + TickSize, "");
        //} PrintWithTimeStamp(Instrument.FullName + " " +) 
         
       else if (Bars.BarsSinceSession >= 6 && Close[0] < (highestHigh + lowestLow)/2)
        //Enter Short at lowest low - 1 of Morning Session.
                 
        EnterShortStop(100, lowestLow - TickSize, "");
       
      
      
      
                
      }
      
     }
     
    }

    #2
    maninjapan, from a quick view I think you see this as you already send the order if the close is higher than the midpoint value (no time rule for waiting until 1 PM) - also you would see them expiring after each bar, as this is default order behavior for stop and limit orders where liveUntilCancelled is not explicitly set to 'true'.

    Comment


      #3
      Actually the order does wait until 1pm, usign the following code on a 30 minute chart.
      Code:
       //Setup the Stop in the direction of  close to the high/low midpoint
          if (Bars.BarsSinceSession >= 6 && Close[0] > (highestHigh + lowestLow)/2)
                      //Enter Long at highest high + 1 of Morning Session.
      I would expect it to place a buy stop order above the mid point, but the stop order is for the high o the day + 1 tick. However when the clock hits 1pm, I end up with a bunch of positions Im not expecting. The correct high and low is printed in the output window, but the stop order doesnt seem to follow this.
      Any ideas on where I have the code wrong?

      Thanks.

      Comment


        #4
        maninjapan, then I would suggest working with TraceOrders to debug your order behavior - http://www.ninjatrader-support2.com/...ead.php?t=3627

        Comment


          #5
          Originally posted by NinjaTrader_Bertrand View Post
          maninjapan, then I would suggest working with TraceOrders to debug your order behavior - http://www.ninjatrader-support2.com/...ead.php?t=3627

          Thanks Bertrand, I tried the following but got errors, what is the correct format for this?

          Code:
                  /// <summary>
                  /// This method is used to configure the strategy and is called once before any strategy method is called.
                  /// </summary>
                  protected override void Initialize() 
             TraceOrders = true;

          Comment


            #6
            Please ensure the needed start / end braces for the Initialize() method are kept intact like -

            Code:
             
            protected override void Initialize() 
            [B]{ 
            [/B]    TraceOrders        = true; 
            [B]}[/B]

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            648 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            369 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            108 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            572 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            574 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X