//Historical is a bool that is false when live and true when backtesting. #region Trading?? //LIVE if ((State == State.Historical && !Historical && ToTime(Time[0]) < ToTime(startTime)) || Time[0].Date < DateTime.Today.AddDays(0) || Close[0] < 2 || Close[0] > 200) return; //BACKTESTING if ((State == State.Historical && Historical && Time[0].Date < DateTime.Today.AddDays(0)) || Close[0] < 2 || Close[0] > 200) return; if (CurrentBars[1] < BarsRequiredToTrade) {return;} if (BarsInProgress != 0) return; #endregion
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
Do 0 Calculations Before live
Collapse
X
-
Do 0 Calculations Before live
Hi there. I was looking to see if there was a way to have NT8 do 0 calculations before the strategy goes live. Currently I'm using the following block of code at the beginning of my strategy but it will still (rarely) say it's already in a long or short position when the strategy becomes active and therefore not execute a future trade that it should.
Code:Tags: None
-
Hello magnatauren,
Thank you for your post.
It seems that your conditions may allow for historical orders to happen between certain time frames.
The simplest way to start flat is to modify your script so that it only places orders if the data is real-time data. To do this you will need to edit the code of your script directly, as the Historical property is not available to the Strategy Builder.
The code needed would be something like:
if (State != State.Realtime) return;
This condition checks to see if the script is not processing real-time data (meaning it is processing historical data) and if true will stop any code appearing after it in the same method from evaluating.
Here is a link to the Help Guide on the 'State' NinjaScript property — http://ninjatrader.com/support/helpG...n-us/state.htm
Also, here is a link to a NinjaTrader Forum post with more information — https://ninjatrader.com/support/foru...541#post811541
Please let us know if we may further assist.
Brandon H.NinjaTrader Customer Service
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by pmachiraju, 11-01-2023, 04:46 AM
|
8 responses
147 views
0 likes
|
Last Post
by rehmans
Today, 06:44 PM
|
||
Started by mattbsea, Today, 05:44 PM
|
0 responses
5 views
0 likes
|
Last Post
by mattbsea
Today, 05:44 PM
|
||
Started by RideMe, 04-07-2024, 04:54 PM
|
6 responses
33 views
0 likes
|
Last Post
by RideMe
Today, 05:31 PM
|
||
Started by tkaboris, Today, 05:13 PM
|
0 responses
5 views
0 likes
|
Last Post
by tkaboris
Today, 05:13 PM
|
||
Started by GussJ, 03-04-2020, 03:11 PM
|
16 responses
3,282 views
0 likes
|
Last Post
by Leafcutter
Today, 04:14 PM
|
Comment