//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
No announcement yet.
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.
Is there something wrong with my code, is it perhaps a bug, or is there another way to have NT always start flat?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.
<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
50 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
126 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
69 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
42 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
46 views
0 likes
|
Last Post
|

Comment