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

Creating Time Based Breakout Range

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

    #16
    Hi jg123,

    What line of code is causing the error?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #17
      I will just post the whole thing and highlight what seems to be causing the error. I have changed a couple of variable names

      Code:
          public class LondonBreakout : Strategy
          {
              #region Variables
              private double positionSize = 1; // Default setting for PositionSize
              private DateTime startRange; // Hour that the range will start
             	private DateTime endRange; // Hour that the range will end
      		private DateTime removeOrderHr = 18; // Hour that unfilled orders will be removed
      		private double rangeHigh = 0; // High of overnight range
      		private double rangeLow = 0; // Low of overnight range
      		private double pipBuffer = 0.0000; // distance from range that trade will be placed
      		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
              #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;
              }
      
              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {
      
      			
      				if (direction == TrendDirection.Up)
      				{
      					[B]if (Time[0] > endRange
      						&& Time[0] < removeOrderHr)[/B]
      					{}
      				}
      				
      				else if (direction == TrendDirection.Down)
      				{
      					[B]if (Time[0] > endRange
      						&& Time[0] < removeOrderHr)[/B]
      					{}
      				}
      				
      				else if (direction == TrendDirection.NoTrend)
      				{
      					[B]if (Time[0] > endRange
      						&& Time[0] < removeOrderHr)[/B]
      					{}
      				}
      			
      			
      		}
      
              #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 double PositionSize
              {
                  get { return positionSize; }
                  set { positionSize = Math.Max(1, value); }
              }
      
              [Description("1 Start Time")]
              [GridCategory("Parameters")]
      		[Gui.Design.DisplayName("1 Start Range")]
              public int StartTime
              {
                  get { return startRange; }
                  set { startRange = Math.Max(1, value); }
              }
      		
              [Description("Range End Hour")]
              [GridCategory("Parameters")]
      		[Gui.Design.DisplayName("2 End Range")]
              public int EndTime
              {
                  get { return endRange; }
                  set { endRange = Math.Max(1, value); }
              }
      
              [Description("Hour to Remove Orders")]
              [GridCategory("Parameters")]
      		[Gui.Design.DisplayName("3 Remove Order")]
              public int RemoveOrderHour
              {
                  get { return removeOrderHr; }
                  set { removeOrderHr = Math.Max(1, 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


        #18
        jg123,

        endRange is a integer. You are comparing Time[0] which is a datetime object with endRange which is a integer.

        You can compare
        ToTime(Time[0]) > endRange

        Before you had an endTime that was a datetime object that you could compare with.
        Time[0] > endTime.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #19
          Thank you

          Here is the update to what I am running into now:

          Code:
          				if (direction == TrendDirection.Up)
          				{
          					if (ToTime((Time[0]) > endRange
          						&& ToTime(Time[0]) < removeOrderHr))
          					{}
          				}
          				
          				else if (direction == TrendDirection.Down)
          				{
          					if (ToTime((Time[0]) > endRange
          						&& ToTime(Time[0]) < removeOrderHr))
          					{}
          				}
          				
          				else if (direction == TrendDirection.NoTrend)
          				{
          					if (ToTime(Time[0]) > endRange
          						&& ToTime(Time[0]) < removeOrderHr)
          					{}
          				}
          And I am getting this error:
          Operator '>' cannot be applied to operands of type 'System.DateTime' and 'int'

          I have tried doing startRange, endRange and removeOrderHr as "private int" and as "private DateTime"

          Comment


            #20
            I finally figured out what was going wrong.

            It had to do with what I had written in the variables. I did not have the rest of the variable written

            for example, I only had

            private DateTime startRange;

            but what I should have had was

            private DateTime startRange = DateTime.Today.AddHours(2);

            or something similar to that. As soon as I changed that, and changed the rest of the code accordingly, then it all lined compiled.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by FishTrade, Today, 11:11 PM
            0 responses
            5 views
            0 likes
            Last Post FishTrade  
            Started by Austiner87, Today, 03:42 PM
            1 response
            21 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by cshox, Today, 11:11 AM
            2 responses
            16 views
            0 likes
            Last Post cshox
            by cshox
             
            Started by algospoke, Today, 06:53 PM
            0 responses
            11 views
            0 likes
            Last Post algospoke  
            Started by mlprice12, 12-21-2021, 04:55 PM
            3 responses
            299 views
            0 likes
            Last Post paypachaysa  
            Working...
            X