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

DrawDot not compiling

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

    DrawDot not compiling

    I am attempting to draw a dot next to my stop orders in order to see where it is placing them. I have placed the following Dot code, but I keep getting errors. With this code I am getting:

    1.) The best overloaded method match for 'NinjaTrader.Strategy.StrategyBase.DrawDot(string, bool,int,double,System.Drawing.Color)' has some invalid arguments
    2.) Argument '4': cannot convert from 'NinjaTrader.Cbi.IOrder' to double.

    So this is referring to "LongEntry" which is an IOrder object. Can I not use IOrder objects if I want to DrawDots? Is there a way to convert this Y price from that to a double so that I do not need to write the equation with every order?

    I am using the debugging sample from: http://www.ninjatrader.com/support/f...ead.php?t=3418

    Code:
    				if (direction == TrendDirection.Up)
    				{
    					if (LongEntry == null
    						&& Time[0] > endRange
    						&& Time[0] < removeOrderTime
    						&& restrictTrade == false)
    					{
    						LongEntry = EnterLongStop(0, true, positionSize, rangeHigh + pipBuffer, "BreakoutLong");
    						DrawDot("Stop", true, 0, LongEntry, Color.Orange);
    					}
    				}

    #2
    jg123, would expect since an IOrder object is not a double value which you would need to specify when drawing your dot. It would this way not know which property you want to use from the order object, could be definitely multiple things so you will need to be more exact. I think you would want to draw at the LongEntry.StopPrice value instead once the order is in accepted state?

    Easiest from OnBarUpdate() would be drawing at your rangeHigh + pipBuffer as well, since that is the price the order will use as well.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks

      Yea, that is kind of what I figured, but wanted to confirm.

      But....no dots are being drawn. haha Here is what I have:

      Code:
      				if (direction == TrendDirection.Up)
      				{
      					if (LongEntry == null
      						&& Time[0] > endRange
      						&& Time[0] < removeOrderTime
      						&& restrictTrade == false)
      					{
      						LongEntry = EnterLongStop(0, true, positionSize, rangeHigh + pipBuffer, "BreakoutLong");
      						DrawDot("EnterLongStop" + CurrentBar, true, 0, rangeHigh + pipBuffer, Color.Orange);
      					}
      				}
      				
      				else if (direction == TrendDirection.Down)
      				{
      					if (ShortEntry == null
      						&& Time[0] > endRange
      						&& Time[0] < removeOrderTime
      						&& restrictTrade == false)
      					{
      						ShortEntry = EnterShortStop(0, true, positionSize, rangeLow - pipBuffer, "BreakoutShort");
      						DrawDot("EnterShortStop", true, 0, rangeLow - pipBuffer, Color.Orange);
      					}
      				}
      Checking each of the parameters and it is definitely after the endRange time & before the removeOrderTime time and the restrictTrade is, by default, set to false. I have tried it with TrendDirection.Up and TrendDirection.Down.

      Do you have any other ideas of what could be causing this to not draw?

      Comment


        #4
        I would try commenting out conditons until you see the dots / order appearing, this way you know exactly which one is creating the issues by not evaluating as you would expect.

        Also you create just one dot and modify for the short side, as you only use one tag id. Which is in contrast to what you do for the long side...so here you create a new dot on each new condition hit to draw thus making available the history of the condition hitting to be seen...
        BertrandNinjaTrader Customer Service

        Comment


          #5
          I didn't quite understand what you mean by this.
          Originally posted by NinjaTrader_Bertrand View Post
          Also you create just one dot and modify for the short side, as you only use one tag id. Which is in contrast to what you do for the long side...so here you create a new dot on each new condition hit to draw thus making available the history of the condition hitting to be seen...
          Originally posted by NinjaTrader_Bertrand View Post
          I would try commenting out conditons until you see the dots / order appearing, this way you know exactly which one is creating the issues by not evaluating as you would expect.
          Thanks, this worked like a charm - and the problem was nothing at all what I was thinking.
          Here is the code with the problem area in Red.

          Code:
          				else if (direction == TrendDirection.Down)
          				{
          					if (ShortEntry == null
          						[COLOR="Red"]//&& Time[0] > endRange[/COLOR]
          						&& Time[0] < removeOrderTime
          						&& restrictTrade == false)
          					{
          						ShortEntry = EnterShortStop(0, true, positionSize, rangeLow - pipBuffer, "BreakoutShort");
          						DrawDot("EnterShortStop", true, 0, rangeLow - pipBuffer, Color.Orange);
          					}
          And a pic of what was produced when this was commented out is attached.

          My goal was simply to check to see if the current bar is after a certain time (9 am German time) and before a certain time (22:00 German time). But this clearly is not able to test to see if it is after 9:00. How would I adjust this?
          Attached Files

          Comment


            #6
            jg123, for the tag id comment, please compare you tag id's used in your DrawDot calls for the long and short side, for the long side you ament CurrentBar to the string used for the short side this is not the case. This has the result that for the short you only maintain one draw object really and update the object when conditions are met to do so.

            More background and a dedicated sample could be found here on this topic - http://www.ninjatrader.com/support/f...ead.php?t=3419

            How do you define endRange then? Time[0] is a Datetime object, you may want to work with ToTime to make comparisons more direct -

            BertrandNinjaTrader Customer Service

            Comment


              #7
              ok, i seem to have screwed everything up...lol

              i started making changes to ToTime and one error seemed to lead to another error to another and to another until now I don't even know where everything is. haha

              could you take a look at this? It is saying that there are errors some places that were never errors before, etc.....

              the only way that i could even get it to compile was to comment out everything! lol I tried commenting out various sections which then gave me other sets of errors, etc

              Code:
              /*#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.Gui.Chart;
              using NinjaTrader.Strategy;
              #endregion
              
              // This namespace holds all strategies and is required. Do not change it.
              namespace NinjaTrader.Strategy
              {
                  /// <summary>
                  /// Basic London Breakout - Manually Defined Inputs
                  /// </summary>
                  [Description("Basic London Breakout - Manually Defined Inputs")]
                  public class LondonBreakout : Strategy
                  {
                      #region Variables
              		// Range Variables
                      private DateTime startRange = DateTime.Today.AddHours(2); // Hour that the range will start
                     	private int endRange = 180000; // Hour that the range will end
              		private DateTime removeOrderTime = DateTime.Today.AddHours(18); // Hour that unfilled orders will be removed
              		private double rangeHigh; // High of range
              		private double rangeLow; // Low of range
              		
              		// Trend Variables
              		private TrendDirection direction = TrendDirection.NoTrend; // holds direction of trend to determine direction of trade
              		private string noTrend; // user defined stating no trend
              		private string up; // user defined stating Up Trend 
              		private string down; // user defied stating Down Trend
              
              		// Misc. Variables
              		private int positionSize = 1; // Default setting for PositionSize
              		private double pipBuffer = 0.0000; // distance from range that trade will be placed
              		private bool restrictTrade = false;
              		
              		// Order Management Variables
              		private IOrder LongEntry = null;
              		private IOrder ShortEntry = null;
              		private IOrder LongTarget= null;
              		private IOrder LongStop = null;
              		private IOrder ShortTarget = null;
              		private IOrder ShortStop = null;
              		private IOrder LongEntryOCO = null;
              		private IOrder ShortEntryOCO = null;
              		private IOrder LongTargetOCO = null;
              		private IOrder LongStopOCO = null;
              		private IOrder ShortTargetOCO = null;
              		private IOrder ShortStopOCO = null;
                      #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 = false;
              			TraceOrders = true;
              			
              			if (Time[0] > startRange
              				&& Time[0] < endRange)
              			{
              				restrictTrade = false;
              			}
                      }
              
                      /// <summary>
                      /// Called on each bar update event (incoming tick)
                      /// </summary>
                      protected override void OnBarUpdate()
                      {
              			if (CurrentBar != Bars.GetBar(endRange))
              				return;
              						
              			// Setting overnight range
              			rangeHigh = HighestBar(High, CurrentBar-Bars.GetBar(startRange));
              			rangeLow = LowestBar(Low, CurrentBar-Bars.GetBar(startRange));
              			
              				// Submitting Long Only, Short Only, & OCO Entry Orders
              				if (direction == TrendDirection.Up)
              				{
              					if (LongEntry == null
              						&& Time[0] > endRange
              						&& Time[0] < removeOrderTime
              						&& restrictTrade == false)
              					{
              						LongEntry = EnterLongStop(0, true, positionSize, rangeHigh + pipBuffer, "BreakoutLong");
              						DrawDot("EnterLongStop" + CurrentBar, true, 0, rangeHigh + pipBuffer, Color.Orange);
              					}
              				}
              				
              				else if (direction == TrendDirection.Down)
              				{
              					if (ShortEntry == null
              						&& ToTime((Time[0]) > endRange)
              						&& Time[0] < removeOrderTime
              						&& restrictTrade == false)
              					{
              						ShortEntry = EnterShortStop(0, true, positionSize, rangeLow - pipBuffer, "BreakoutShort");
              						DrawDot("EnterShortStop", true, 0, rangeLow - pipBuffer, Color.Orange);
              					}
              				}
              				
              				if (direction == TrendDirection.NoTrend)
              				{
              					if (LongEntryOCO == null
              						&& ShortEntryOCO == null
              						&& Time[0] > endRange
              						&& Time[0] < removeOrderTime
              						&& restrictTrade == false)
              					{
              						LongEntryOCO = EnterLongStop(0, true, positionSize, rangeHigh + pipBuffer, "BreakoutLongOCO");
              						ShortEntryOCO = EnterShortStop(0, true, positionSize, rangeLow - pipBuffer, "BreakoutShortOCO");
              					}
              					
              				}
              				// Cancel Entry Orders if not filled by certain time
              				if (Time[0] >= removeOrderTime
              					&& LongEntry == null)
              				{
              					CancelOrder(LongEntry);
              				}
              				if (Time[0] >= removeOrderTime
              					&& ShortEntry == null)
              				{
              					CancelOrder(ShortEntry);
              				}
              				if (Time[0] >= removeOrderTime
              					&& LongEntryOCO == null)
              				{
              					CancelOrder(LongEntryOCO);
              				}
              				if (Time[0] >= removeOrderTime
              					&& ShortEntryOCO == null)
              				{
              					CancelOrder(ShortEntryOCO);
              				}
              				
              
              		}
              		protected override void OnExecution(IExecution execution)
              		{
              			// Setting Stop Loss & Profit Target (Limit) Orders -- Long Only & Short Only
              			if (execution.Order.OrderState != OrderState.Filled)
              				return;
              			
              			if (LongEntry != null
              				&& LongEntry == execution.Order)
              			{
              				LongStop = ExitLongStop((rangeLow - pipBuffer),"LongStop", "BreakoutLong");
              				LongTarget = ExitLongLimit(LongEntry.AvgFillPrice + (LongEntry.AvgFillPrice - (rangeLow - pipBuffer)), "LongTarget", "BreakoutLong");
              				restrictTrade = true;
              			}
              			
              			if (ShortEntry != null
              				&& ShortEntry == execution.Order)
              			{
              				ShortStop = ExitShortStop((rangeHigh + pipBuffer),"ShortStop", "BreakoutShort");
              				ShortTarget = ExitShortLimit(ShortEntry.AvgFillPrice - ((rangeHigh + pipBuffer) - ShortEntry.AvgFillPrice), "ShortTarget", "BreakoutShort");
              				restrictTrade = true;
              			}
              			
              			// Setting Stop Loss & Profit Target for OCO orders &&
              			// Cancel Short Entry Order if Long Entry Order is filled & vice versa
              			if (LongEntryOCO != null
              				&& LongEntryOCO == execution.Order)
              			{
              				LongStopOCO = ExitLongStop((rangeLow - pipBuffer),"LongStopOCO","BreakoutLongOCO");
              				LongTargetOCO = ExitLongLimit(LongEntryOCO.AvgFillPrice + (LongEntryOCO.AvgFillPrice - (rangeLow - pipBuffer)), "LongTargetOCO", "BreakoutLongOCO");
              				CancelOrder(ShortEntryOCO);
              				restrictTrade = true;
              			}
              			
              			if (ShortEntryOCO != null
              				&& ShortEntryOCO == execution.Order)
              			{
              				ShortStopOCO = ExitShortStop((rangeHigh + pipBuffer), "ShortStopOCO", "BreakoutShortOCO");
              				ShortTargetOCO = ExitShortLimit(ShortEntryOCO.AvgFillPrice - ((rangeHigh + pipBuffer) - ShortEntry.AvgFillPrice), "ShortTargetOCO", "BreakoutShortOCO");
              				CancelOrder(LongEntryOCO);
              				restrictTrade = true;
              			}
              			
              
              		
              		}
              }
              				
              				
              
              		
              
                      #region Properties
              		[Description("Direction")]
              		[GridCategory("Parameters")]
              		[Gui.Design.DisplayName("4 Direction")]
              		public TrendDirection Direction
              		{
              			get { return direction; }
              			set { direction = value; }
              		}
              
              		
                      [Description("Position Size of Trade")]
                      [GridCategory("Parameters")]
              		[Gui.Design.DisplayName("5 Position Size")]
                      public int PositionSize
                      {
                          get { return positionSize; }
                          set { positionSize = Math.Max(1, value); }
                      }
              
                      [GridCategory("Parameters")]
              		[Gui.Design.DisplayName("1 Start Range")]
                      public DateTime StartRange
                      {
                          get { return startRange; }
                          set { startRange = value; }
                      }
              		
                      [Description("Range End Hour")]
                      [GridCategory("Parameters")]
              		[Gui.Design.DisplayName("2 End Range")]
                      public int EndRange
                      {
                          get { return endRange; }
                          set { endRange = value; }
                      }
              
                      [Description("Hour to Remove Orders")]
                      [GridCategory("Parameters")]
              		[Gui.Design.DisplayName("3 Remove Order")]
                      public DateTime RemoveOrderHour
                      {
                          get { return removeOrderTime; }
                          set { removeOrderTime = value; }
                      }
              		
              		[Description("Pip Buffer")]
              		[GridCategory("Parameters")]
              		[Gui.Design.DisplayName("6 Pips")]
              		public double PipBuffer
              		{
              			get { return pipBuffer; }
              			set { pipBuffer = Math.Max(0.0001, value); }
              		}
                      #endregion 
                  
              
              
              public enum TrendDirection
              {
              	NoTrend,
              	Up,
              	Down
              }
              
              }
              */

              Comment


                #8
                You will need to be real careful with your edits and just go methodical one by one in debugging, otherwise it's easy to introduce additional issues or roadblocks. The code attached would at least get you back to a compilable version of the script. I have blocked out the restrictTrade logic as it makes no sense doing that in the Initialize(). I would further debug / amend from here now.
                Attached Files
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  Oh, thank you very much. That was rally really nice

                  Comment


                    #10
                    I am methodically going through to change the startRange & the removeOrderTime variables to ToTime. I have not yet done the startRange. WhenI did the removeOrderTime, the strategy stopped Enabling.

                    The Output window is not producing anything. The Log file says, "Error on calling 'OnBarUpdate' method for strategy 'XXX': Object reference not set to an instance of an object."

                    At this point, the only thing that I have changed from the corrected file that you sent me is changing removeOrderTime from a DateTime to an int.

                    Here is the code for OnBarUpdate() with each of the removeOrderTime variables highlighted in Red:

                    Code:
                            protected override void OnBarUpdate()
                            {
                    //			if (CurrentBar != Bars.GetBar(endRange))
                    //				return;
                    			
                    //			if (Time[0] > startRange
                    //				&& Time[0] < endRange)
                    //			{
                    //				restrictTrade = false;
                    //			}
                    						
                    			// Setting overnight range
                    			rangeHigh = HighestBar(High, CurrentBar-Bars.GetBar(startRange));
                    			rangeLow = LowestBar(Low, CurrentBar-Bars.GetBar(startRange));
                    			
                    				// Submitting Long Only, Short Only, & OCO Entry Orders
                    				if (direction == TrendDirection.Up)
                    				{
                    					if (LongEntry == null
                    						&& ToTime(Time[0]) > endRange
                    						[COLOR="Red"]&& ToTime(Time[0]) < removeOrderTime[/COLOR]
                    						&& restrictTrade == false)
                    					{
                    						LongEntry = EnterLongStop(0, true, positionSize, rangeHigh + pipBuffer, "BreakoutLong");
                    						DrawDot("EnterLongStop" + CurrentBar, true, 0, rangeHigh + pipBuffer, Color.Orange);
                    						Print("Sell Stop");
                    					}
                    				}
                    				
                    				else if (direction == TrendDirection.Down)
                    				{
                    					if (ShortEntry == null
                    						&& ToTime(Time[0]) > endRange
                    						[COLOR="red"]&& ToTime(Time[0]) < removeOrderTime[/COLOR]
                    						&& restrictTrade == false)
                    					{
                    						ShortEntry = EnterShortStop(0, true, positionSize, rangeLow - pipBuffer, "BreakoutShort");
                    						DrawDot("EnterShortStop", true, 0, rangeLow - pipBuffer, Color.Orange);
                    					}
                    				}
                    				
                    				if (direction == TrendDirection.NoTrend)
                    				{
                    					if (LongEntryOCO == null
                    						&& ShortEntryOCO == null
                    						&& ToTime(Time[0]) > endRange
                    						[COLOR="red"]&& ToTime(Time[0]) < removeOrderTime[/COLOR]
                    						&& restrictTrade == false)
                    					{
                    						LongEntryOCO = EnterLongStop(0, true, positionSize, rangeHigh + pipBuffer, "BreakoutLongOCO");
                    						ShortEntryOCO = EnterShortStop(0, true, positionSize, rangeLow - pipBuffer, "BreakoutShortOCO");
                    					}
                    					
                    				}
                    				// Cancel Entry Orders if not filled by certain time
                    				if ([COLOR="red"]ToTime(Time[0]) >= removeOrderTime[/COLOR]
                    					&& LongEntry == null)
                    				{
                    					CancelOrder(LongEntry);
                    				}
                    				if ([COLOR="red"]ToTime(Time[0]) >= removeOrderTime[/COLOR]
                    					&& ShortEntry == null)
                    				{
                    					CancelOrder(ShortEntry);
                    				}
                    				if ([COLOR="red"]ToTime(Time[0]) >= removeOrderTime[/COLOR]
                    					&& LongEntryOCO == null)
                    				{
                    					CancelOrder(LongEntryOCO);
                    				}
                    				if ([COLOR="red"]ToTime(Time[0]) >= removeOrderTime[/COLOR]
                    					&& ShortEntryOCO == null)
                    				{
                    					CancelOrder(ShortEntryOCO);
                    				}
                    				
                    
                    		}
                    Are you able to see where my error is?

                    Comment


                      #11
                      I think that would be coming due to accessing an IOrder object / property that's null so empty.

                      Probably here -

                      if (ToTime(Time[0]) >= removeOrderTime
                      && LongEntry == null)
                      {
                      CancelOrder(LongEntry);
                      }

                      Why would you cancel this order if it's null?
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        Oh, right.

                        my goal for writing that was more that, "If LongEntry order has not triggered and is still pending, then cancel it at xyz time."

                        Thinking through it now, it sees that I should be doing something with the OrderState as pending or something like that. Can you show me what to look at in order to correctly write this part of the code?

                        Comment


                          #13
                          I would just look into changing the check to be not null, so that you have an active LongEntry IOrder object. You only want to send the cancel if there's active order and the time is over your boundary.
                          BertrandNinjaTrader Customer Service

                          Comment


                            #14
                            Ah, that is a good point. I have changed that.

                            It is now enabling, so that is great - but I am not seeing my dots.

                            The log is not showing anything out of place (well, it is, but that is a different topic and will post that in another thread) and the output window appears that everything is looking good. Here is what the output widow is saying

                            6/17/2014 2:54:55 PM CancelAllOrders: BarsInProgress=0
                            **NT** Disabling NinjaScript strategy 'LondonBreakout/98944cfab77b449a944f06fe10a29894'
                            **NT** Enabling NinjaScript strategy 'LondonBreakout/98944cfab77b449a944f06fe10a29894' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True CalculateOnBarClose=False MaxRestarts=4 in 5 minutes
                            but there are no dots on my chart.

                            Here is the code again:

                            Code:
                            #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.Gui.Chart;
                            using NinjaTrader.Strategy;
                            #endregion
                            
                            // This namespace holds all strategies and is required. Do not change it.
                            namespace NinjaTrader.Strategy
                            {
                                /// <summary>
                                /// Basic London Breakout - Manually Defined Inputs
                                /// </summary>
                                [Description("Basic London Breakout - Manually Defined Inputs")]
                                public class LondonBreakout : Strategy
                                {
                                    #region Variables
                            		// Range Variables
                                    private DateTime startRange = DateTime.Today.AddHours(2); // Hour that the range will start
                                   	private int endRange = 180000; // Hour that the range will end
                            		private int removeOrderTime = 2200; // Hour that unfilled orders will be removed
                            		private double rangeHigh; // High of range
                            		private double rangeLow; // Low of range
                            		
                            		// Trend Variables
                            		private TrendDirection direction = TrendDirection.NoTrend; // holds direction of trend to determine direction of trade
                            		private string noTrend; // user defined stating no trend
                            		private string up; // user defined stating Up Trend 
                            		private string down; // user defied stating Down Trend
                            
                            		// Misc. Variables
                            		private int positionSize = 1; // Default setting for PositionSize
                            		private double pipBuffer = 0.0000; // distance from range that trade will be placed
                            		private bool restrictTrade = false;
                            		
                            		// Order Management Variables
                            		private IOrder LongEntry = null;
                            		private IOrder ShortEntry = null;
                            		private IOrder LongTarget= null;
                            		private IOrder LongStop = null;
                            		private IOrder ShortTarget = null;
                            		private IOrder ShortStop = null;
                            		private IOrder LongEntryOCO = null;
                            		private IOrder ShortEntryOCO = null;
                            		private IOrder LongTargetOCO = null;
                            		private IOrder LongStopOCO = null;
                            		private IOrder ShortTargetOCO = null;
                            		private IOrder ShortStopOCO = null;
                                    #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 = false;
                            			TraceOrders = true;
                                    }
                            
                                    /// <summary>
                                    /// Called on each bar update event (incoming tick)
                                    /// </summary>
                                    protected override void OnBarUpdate()
                                    {
                            //			if (CurrentBar != Bars.GetBar(endRange))
                            //				return;
                            			
                            //			if (Time[0] > startRange
                            //				&& Time[0] < endRange)
                            //			{
                            //				restrictTrade = false;
                            //			}
                            						
                            			// Setting overnight range
                            			rangeHigh = HighestBar(High, CurrentBar-Bars.GetBar(startRange));
                            			rangeLow = LowestBar(Low, CurrentBar-Bars.GetBar(startRange));
                            			
                            				// Submitting Long Only, Short Only, & OCO Entry Orders
                            				if (direction == TrendDirection.Up)
                            				{
                            					if (LongEntry == null
                            						&& ToTime(Time[0]) > endRange
                            						&& ToTime(Time[0]) < removeOrderTime
                            						&& restrictTrade == false)
                            					{
                            						LongEntry = EnterLongStop(0, true, positionSize, rangeHigh + pipBuffer, "BreakoutLong");
                            						DrawDot("EnterLongStop" + CurrentBar, true, 0, rangeHigh + pipBuffer, Color.Orange);
                            						Print("Sell Stop");
                            					}
                            				}
                            				
                            				else if (direction == TrendDirection.Down)
                            				{
                            					if (ShortEntry == null
                            						&& ToTime(Time[0]) > endRange
                            						&& ToTime(Time[0]) < removeOrderTime
                            						&& restrictTrade == false)
                            					{
                            						ShortEntry = EnterShortStop(0, true, positionSize, rangeLow - pipBuffer, "BreakoutShort");
                            						DrawDot("EnterShortStop", true, 0, rangeLow - pipBuffer, Color.Orange);
                            					}
                            				}
                            				
                            				if (direction == TrendDirection.NoTrend)
                            				{
                            					if (LongEntryOCO == null
                            						&& ShortEntryOCO == null
                            						&& ToTime(Time[0]) > endRange
                            						&& ToTime(Time[0]) < removeOrderTime
                            						&& restrictTrade == false)
                            					{
                            						LongEntryOCO = EnterLongStop(0, true, positionSize, rangeHigh + pipBuffer, "BreakoutLongOCO");
                            						ShortEntryOCO = EnterShortStop(0, true, positionSize, rangeLow - pipBuffer, "BreakoutShortOCO");
                            						DrawDot("EnterLongStopOCO", true, 0, rangeHigh + pipBuffer, Color.Orange);
                            						DrawDot("EnterShortStopOCO", true, 0, rangeLow - pipBuffer, Color.Orange);
                            					}
                            					
                            				}
                            				// Cancel Entry Orders if not filled by certain time
                            				if (ToTime(Time[0]) >= removeOrderTime
                            					&& LongEntry != null)
                            				{
                            					CancelOrder(LongEntry);
                            				}
                            				if (ToTime(Time[0]) >= removeOrderTime
                            					&& ShortEntry != null)
                            				{
                            					CancelOrder(ShortEntry);
                            				}
                            				if (ToTime(Time[0]) >= removeOrderTime
                            					&& LongEntryOCO != null)
                            				{
                            					CancelOrder(LongEntryOCO);
                            				}
                            				if (ToTime(Time[0]) >= removeOrderTime
                            					&& ShortEntryOCO != null)
                            				{
                            					CancelOrder(ShortEntryOCO);
                            				}
                            				
                            
                            		}
                            		protected override void OnExecution(IExecution execution)
                            		{
                            			// Setting Stop Loss & Profit Target (Limit) Orders -- Long Only & Short Only
                            			if (execution.Order.OrderState != OrderState.Filled)
                            				return;
                            			
                            			if (LongEntry != null
                            				&& LongEntry == execution.Order)
                            			{
                            				LongStop = ExitLongStop((rangeLow - pipBuffer),"LongStop", "BreakoutLong");
                            				LongTarget = ExitLongLimit(LongEntry.AvgFillPrice + (LongEntry.AvgFillPrice - (rangeLow - pipBuffer)), "LongTarget", "BreakoutLong");
                            				restrictTrade = true;
                            			}
                            			
                            			if (ShortEntry != null
                            				&& ShortEntry == execution.Order)
                            			{
                            				ShortStop = ExitShortStop((rangeHigh + pipBuffer),"ShortStop", "BreakoutShort");
                            				ShortTarget = ExitShortLimit(ShortEntry.AvgFillPrice - ((rangeHigh + pipBuffer) - ShortEntry.AvgFillPrice), "ShortTarget", "BreakoutShort");
                            				restrictTrade = true;
                            			}
                            			
                            			// Setting Stop Loss & Profit Target for OCO orders &&
                            			// Cancel Short Entry Order if Long Entry Order is filled & vice versa
                            			if (LongEntryOCO != null
                            				&& LongEntryOCO == execution.Order)
                            			{
                            				LongStopOCO = ExitLongStop((rangeLow - pipBuffer),"LongStopOCO","BreakoutLongOCO");
                            				LongTargetOCO = ExitLongLimit(LongEntryOCO.AvgFillPrice + (LongEntryOCO.AvgFillPrice - (rangeLow - pipBuffer)), "LongTargetOCO", "BreakoutLongOCO");
                            				CancelOrder(ShortEntryOCO);
                            				restrictTrade = true;
                            			}
                            			
                            			if (ShortEntryOCO != null
                            				&& ShortEntryOCO == execution.Order)
                            			{
                            				ShortStopOCO = ExitShortStop((rangeHigh + pipBuffer), "ShortStopOCO", "BreakoutShortOCO");
                            				ShortTargetOCO = ExitShortLimit(ShortEntryOCO.AvgFillPrice - ((rangeHigh + pipBuffer) - ShortEntry.AvgFillPrice), "ShortTargetOCO", "BreakoutShortOCO");
                            				CancelOrder(LongEntryOCO);
                            				restrictTrade = true;
                            			}
                            			
                            
                            		
                            		}
                            
                                    #region Properties
                            		[Description("Direction")]
                            		[GridCategory("Parameters")]
                            		[Gui.Design.DisplayName("4 Direction")]
                            		public TrendDirection Direction
                            		{
                            			get { return direction; }
                            			set { direction = value; }
                            		}
                            
                            		
                                    [Description("Position Size of Trade")]
                                    [GridCategory("Parameters")]
                            		[Gui.Design.DisplayName("5 Position Size")]
                                    public int PositionSize
                                    {
                                        get { return positionSize; }
                                        set { positionSize = Math.Max(1, value); }
                                    }
                            
                                    [GridCategory("Parameters")]
                            		[Gui.Design.DisplayName("1 Start Range")]
                                    public DateTime StartRange
                                    {
                                        get { return startRange; }
                                        set { startRange = value; }
                                    }
                            		
                                    [Description("Range End Hour")]
                                    [GridCategory("Parameters")]
                            		[Gui.Design.DisplayName("2 End Range")]
                                    public int EndRange
                                    {
                                        get { return endRange; }
                                        set { endRange = value; }
                                    }
                            
                                    [Description("Hour to Remove Orders")]
                                    [GridCategory("Parameters")]
                            		[Gui.Design.DisplayName("3 Remove Order")]
                                    public int RemoveOrderHour
                                    {
                                        get { return removeOrderTime; }
                                        set { removeOrderTime = value; }
                                    }
                            		
                            		[Description("Pip Buffer")]
                            		[GridCategory("Parameters")]
                            		[Gui.Design.DisplayName("6 Pips")]
                            		public double PipBuffer
                            		{
                            			get { return pipBuffer; }
                            			set { pipBuffer = Math.Max(0.0001, value); }
                            		}
                                    #endregion 
                                
                            
                            
                            public enum TrendDirection
                            {
                            	NoTrend,
                            	Up,
                            	Down
                            }
                            
                            }
                            }
                            I just posted everything in case there is something causing it to not show up and is in an area that I would not have expected.

                            Thanks for your help

                            Comment


                              #15
                              jg123, the dots will only print if your conditions for doing so are satisfied, for long that is :

                              if (LongEntry == null
                              && ToTime(Time[0]) > endRange
                              && ToTime(Time[0]) < removeOrderTime
                              && restrictTrade == false)

                              Thus it would be a stepwise isolation now needed to understand while condition is preventing you from seeing a trigger as you expect.

                              As aside for Down and NoTrend you still use a unique tag id only, so meaning you only create one object and update it.
                              BertrandNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by WHICKED, Today, 02:02 PM
                              1 response
                              3 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Started by selu72, Today, 02:01 PM
                              0 responses
                              0 views
                              0 likes
                              Last Post selu72
                              by selu72
                               
                              Started by f.saeidi, Today, 12:14 PM
                              8 responses
                              21 views
                              0 likes
                              Last Post f.saeidi  
                              Started by Mikey_, 03-23-2024, 05:59 PM
                              3 responses
                              49 views
                              0 likes
                              Last Post Sam2515
                              by Sam2515
                               
                              Started by Russ Moreland, Today, 12:54 PM
                              1 response
                              7 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Working...
                              X