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!
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
NinjaTrader
User Preference for Time
Collapse
X
-
User Preference for Time
I know I can reference time as a condition in the strategy wizard (so only to trade from 9am to 12noon for instance), but can I make the time variable which is definable in the backtest parameters, rather than having to go and change in the main code every time I want to change time?Tags: None
-
Hello,
You can create an integer to create a variable to change the parameter for your time filter.
I have provided an example of how you can achieve this below:
Code:#region Variables private int beginTime = 93000; private int endTime = 113000; #endregion protected override void OnBarUpdate() { if ((ToTime(Time[0]) >= beginTime && ToTime(Time[0]) < endTime) { EnterLong(); } } #region Properties [Description("")] [GridCategory("Parameters")] public int BeginTime { get { return beginTime; } set { myInput0 = Math.Max(1, value); } } [Description("")] [GridCategory("Parameters")] public int EndTime { get { return endTime; } set { myInput0 = Math.Max(1, value); } } #endregion
Cody B.NinjaTrader Customer Service
-
Understood- Am I correct in thinking I can't do this from the strategy wizard? Id prefer not to unlock the code, as I am liking the training wheels.
Originally posted by NinjaTrader_CodyB View PostHello,
You can create an integer to create a variable to change the parameter for your time filter.
I have provided an example of how you can achieve this below:
Code:#region Variables private int beginTime = 93000; private int endTime = 113000; #endregion protected override void OnBarUpdate() { if ((ToTime(Time[0]) >= beginTime && ToTime(Time[0]) < endTime) { EnterLong(); } } #region Properties [Description("")] [GridCategory("Parameters")] public int BeginTime { get { return beginTime; } set { myInput0 = Math.Max(1, value); } } [Description("")] [GridCategory("Parameters")] public int EndTime { get { return endTime; } set { myInput0 = Math.Max(1, value); } } #endregion
Comment
-
Hello,
You would be able to do this within the strategy wizard. You will create user defined inputs for the integer time variables.
When adding the condition you will need to select the user defined input for the right hand side selection to compare against the time of the current bar.
I have attach screenshots of how you could set up the user defined inputs and then compare the time against the input.
If we can be of any other assistance please let us know.Cody B.NinjaTrader Customer Service
Comment
-
When I do this, I get an error message...
Screenshots attached.
Originally posted by NinjaTrader_CodyB View PostHello,
You would be able to do this within the strategy wizard. You will create user defined inputs for the integer time variables.
When adding the condition you will need to select the user defined input for the right hand side selection to compare against the time of the current bar.
I have attach screenshots of how you could set up the user defined inputs and then compare the time against the input.
If we can be of any other assistance please let us know.
Comment
-
-
I´m attempting this in unlocked code mode, as instructed - I used && as it is an additional condition. I have an error code coming up saying that && is invalid expression? (on line 53 which is the ToTime line)
How can I fix this?
Code:// Condition set 1 if (GetCurrentBid() > High[1] && Flip == false) && ToTime(Time[0]) >= startTime && ToTime(Time[0]) < endTime; { ExitShort("", ""); EnterLong(DefaultQuantity, ""); } // Condition set 2
Last edited by ScottieDog; 04-02-2016, 01:18 PM.
Comment
-
Hello,
You would not use the ToTime() method on Time[0]. ToTime() converts an integer value so that it returns a DateTime object. The Time[] series returns a datetime values already.
If you have set startTime and endTime as DateTime variables then you could do a direct comparison of Time[0] to these values, such as if(Time[0] > startTime)
If they are integers you would need to use the ToTime() method on these variables such as if(Time[0] > ToTime(startTime)Cody B.NinjaTrader Customer Service
Comment
-
I was just copying the code you gave as example in #2.
I´m not sure where I have gone wrong.
Code:#region Variables private int beginTime = 93000; private int endTime = 113000; #endregion protected override void OnBarUpdate() { if ((ToTime(Time[0]) >= beginTime && ToTime(Time[0]) < endTime) { EnterLong(); } } #region Properties [Description("")] [GridCategory("Parameters")] public int BeginTime { get { return beginTime; } set { myInput0 = Math.Max(1, value); } } [Description("")] [GridCategory("Parameters")] public int EndTime { get { return endTime; } set { myInput0 = Math.Max(1, value); } } #endregion
Comment
-
Hello,
My apologies upon further review you would use ToTime(Time[0]) to compare to an integer value. http://ninjatrader.com/support/helpG...nt7/totime.htm
Upon further review of the code it would apper that you have a parantheses after Flip == false which end the if Statement before the && expression.Cody B.NinjaTrader Customer Service
Comment
-
-
I made the change and it is compiling without error now, but the time filter is not working for some reason. Strategy is running but totally ignoring the time filter.
Im not sure what to do next? What would be the next step to troubleshoot this?
This time filter works
Code:if (GetCurrentAsk() < Low[1] && Once == false && Flip == true && ToTime(Time[0]) >= ToTime(9, 0, 0) && ToTime(Time[0]) <= ToTime(10, 0, 0) { ExitShort("", ""); EnterLong(DefaultQuantity, ""); DrawDot("My dot" + CurrentBar, false, 0, Low[0] + -10 * TickSize, Color.Green); }
Code:if (GetCurrentAsk() < Low[1] && Once == false && Flip == true && ToTime(Time[0]) >= (startTime) && ToTime(Time[0]) < (endTime)); { ExitShort("", ""); EnterLong(DefaultQuantity, ""); DrawDot("My dot" + CurrentBar, false, 0, Low[0] + -10 * TickSize, Color.Green); }
Last edited by ScottieDog; 04-04-2016, 12:50 PM.
Comment
-
Yes, I have them set as follows::
Thanks for the support!
Code:#region Variables private int profitTarget = 200; // Default setting for ProfitTarget private int stopLoss = 200; // Default setting for StopLoss private bool flip = false; // Default setting for Flip private int startTime = 0900000; // Default setting for StartTime private int endTime = 1000000; // Default setting for EndTime private bool once = false; // Default setting for Once #endregion
Code:#region Properties [Description("Trading Start")] [GridCategory("Parameters")] public int StartTime { get { return startTime; } set { startTime = Math.Max(1, value); } } [Description("Trading End")] [GridCategory("Parameters")] public int EndTime { get { return endTime; } set { endTime = Math.Max(1, value); } } #endregion
Last edited by ScottieDog; 04-04-2016, 01:12 PM.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by pvincent, 06-23-2022, 12:53 PM
|
14 responses
238 views
0 likes
|
Last Post
by Nyman
Today, 12:47 AM
|
||
Started by TraderG23, 12-08-2023, 07:56 AM
|
9 responses
382 views
1 like
|
Last Post
by Gavini
Today, 12:29 AM
|
||
Started by oviejo, Today, 12:28 AM
|
0 responses
1 view
0 likes
|
Last Post
by oviejo
Today, 12:28 AM
|
||
Started by pechtri, 06-22-2023, 02:31 AM
|
10 responses
125 views
0 likes
|
Last Post Today, 12:03 AM | ||
Started by judysamnt7, 03-13-2023, 09:11 AM
|
4 responses
59 views
0 likes
|
Last Post
by DynamicTest
Yesterday, 08:25 PM
|
Comment