Next, I stop the Market Replay and refresh the Ninja Script (I'm aware once you refresh the chart, that all bars left of the chart has just become historical data), then all the historical trades pop up. So I guess the question would be: Why is the script not taking live trades during playback or live sessions, but when I refesh the script, will then show historically where the trades should been executed?
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Strategy not taking live trades but showing historical trades
Collapse
X
-
Strategy not taking live trades but showing historical trades
Im backtesting using Market replay to test a simple signal (go short when High[0] > High[1]). When I first enable the strategy, I see the historical trades, but when I begin to play Market Replay, there are zero trade exuctions, and there should be because High[0] > High[1] will produce a signal.
Next, I stop the Market Replay and refresh the Ninja Script (I'm aware once you refresh the chart, that all bars left of the chart has just become historical data), then all the historical trades pop up. So I guess the question would be: Why is the script not taking live trades during playback or live sessions, but when I refesh the script, will then show historically where the trades should been executed?Tags: None
-
Hello AdeptistJune,
I would find this interesting, and there is code that can be added that would force the script to only evaluate historically such as if (State == State.Historical) return;.
If the expected trade(s) are not appearing, this would indicate that the condition to place the order is not evaluating as true and the order is not being submitted, or the order is being ignored for other reasons, or the order is being cancelled.
To understand why the script is behaving as it is, such as placing orders or not placing orders or drawing objects when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.
In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar.
Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).
Also, enable TraceOrders which will let us know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.
I am happy to assist you with analyzing the output from the output window.
Run or backtest the script and when the output from the output window appears save this by right-clicking the output window and selecting Save As... -> give the output file a name and save -> then attach the output from both computers to your reply.
Below is a link to a forum post that demonstrates using prints to understand behavior and includes a link to a video recorded using the Strategy Builder to add prints.
https://ninjatrader.com/support/foru...121#post791121
Please let me know if I may further assist with analyzing the output or if you need any assistance creating a print or enabling TraceOrders.Chelsea B.NinjaTrader Customer Service
-
Hi Chelsea,
If I'm just testing High[0] > High[1], when I do string.format, do I just test High[0] > High[1] in the prints?Last edited by AdeptistJune; 12-20-2021, 02:14 PM.
Comment
-
Here is the print results. It ran the script on Market Replay, and it still didn't take a live trade, but it show it historically.
Comment
-
I ran it in real time. But it doesn't execute in real time, and when I refresh the script, it will then show where the trades would have taken place..
The only state Im checking is this:
else if (State == State.Configure)
{
AddDataSeries(instrumentName: Instrument.FullName,
barsPeriod: new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, MarketDataType = Data.MarketDataType.Last, Value = 1 },
tradingHoursName: "CME US Index Futures RTH", isResetOnNewTradingDay: false);
AddDataSeries(instrumentName: Instrument.FullName,
barsPeriod: new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, MarketDataType = Data.MarketDataType.Last, Value = 1 },
tradingHoursName: "Overnight", isResetOnNewTradingDay: false);
AddDataSeries(instrumentName: Instrument.FullName,
barsPeriod: new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, MarketDataType = Data.MarketDataType.Last, Value = 1 },
tradingHoursName: "CME US Index Futures RTH", isResetOnNewTradingDay: false);
}
Comment
-
Hello AdeptistJune,
Something in OnBarUpdate is preventing this print from appearing in real-time.
Is the print at the top of OnBarUpdate()?
What conditions are in OnBarUpdate()?
What are the hours of the Overnight trading hours template?
Are all the TradingHours in session while real-time bars are closing?Chelsea B.NinjaTrader Customer Service
Comment
-
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1
|| CurrentBars[1] < 1
|| CurrentBars[2] < 1
|| CurrentBars[3] < 1)
return;
noTrade[0] = ((High[0] > OvernightLevels1.ONOpen[0]) && (Low[0] < OvernightLevels1.ONOpen[0])) ? true : false;
Print(string.Format("{0} | State: {1} | High[0]: {2} > High[1]: {3}", Time[0], State, High[0], High[1]));
if (High[0] > High[1])
{
Print("condition true");
}
// Set 1 Rth trading session
// Just testing the levels to make sure they work
if ((Position.MarketPosition == MarketPosition.Flat)
//&& (Times[0][0].TimeOfDay >= new TimeSpan(8, 30, 00) && Times[0][0].TimeOfDay < new TimeSpan(15, 00, 0))
&& (High[0] > High[1])
//&& (CrossBelow(Low, EMA1, 1))
)
{
EnterShort(Convert.ToInt32(DefaultQuantity), "Set 1");
}
}
Comment
-
The hours of the Overnight Trading hours are: Monday 5:00pm - Tuesday 8:30am EOD, Tuesday 5:00pm - Wednesday 8:30am EOD, Wednesday 5:00pm - Thursday 8:30am EOD, Thursday 5:00pm - Friday 8:30am EOD, Sunday 5:00pm - Monday 8:30am EOD,
Comment
-
Are all the TradingHours in session while real-time bars are closing? I don't understand the question.
Comment
-
Okay. I started from scratch and rewrote the script, and I found that the problem has something to do with the overnight session. When I add the Overnight data series to the script, trades will show historically, but we not execute live.
AddDataSeries(instrumentName: Instrument.FullName,
barsPeriod: new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, MarketDataType = Data.MarketDataType.Last, Value = 1 },
tradingHoursName: "Overnight", isResetOnNewTradingDay: false);Last edited by AdeptistJune; 12-21-2021, 04:51 AM.
Comment
-
Hello AdeptistJune,
All the TradingHours have to be in session. Meaning the time of the bar has to be while the sessions are open.
The trading session is the hours defined in the TradingHours template.
Sounds like you added a series that does not define hours while the market is open.Chelsea B.NinjaTrader Customer Service
Comment
-
Thanks Chelsea,
So how do I plot the levels for the overnight session, and use those levels during RTH?
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Yesterday, 05:17 AM
|
0 responses
64 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
139 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
75 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
45 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
50 views
0 likes
|
Last Post
|

Comment