What line of code is causing the error?
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Creating Time Based Breakout Range
Collapse
X
-
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
-
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
-
Thank you
Here is the update to what I am running into now:
And I am getting this error: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) {} }
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
-
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 Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
671 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
379 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
111 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
575 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
582 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment