Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
How to get indicator value based on another chart timeframe post
Collapse
X
-
Ok, so, are you saying that it's not possible to get the current 5m EMA value on each 1m close? When you say, "...the value from the 5 minute series will be whatever the most recently updated price was for that series", does that mean for each 1m bar close the value of the 5m EMA will be whatever it's previous 5m bar close was and not the current value?
-
And that's what I expect, but it doesn't work, it gives me the value of it's previous 5m post. Can you confirm this?
Comment
-
Thanks for the video. I understand what you're saying, and the 5m values (the current price/value of the building candle) update on every 1m post in realtime, however, it does not show the 5m building candle values on historical data or in the Strategy Analyzer. My main goal here is to get the 5m values at the time of the 1m posts in the Strategy Analyzer. Is this possible? Because, like I've mentioned, in the Strategy Analyzer it's not giving me the current 5m price/values.
Does that make sense? I can provide a video if needed.
Comment
-
Thanks again, and thanks for your patience! However, this does not quite answer my question yet.
Each tick/price change updates the value of, for example, the EMA. So, the value of the 5m EMA on each 1m post is different, most of the time. Getting this value works as expected in realtime, but, in the Strategy Analyzer with TickReplay enabled, it's outputting the value of the 5m EMA at the previous 5m post on each 1m update instead of its current value on those 1m posts.
Comment
-
Hello DawnTreader,
The value will correspond with the timestamp.
In historical there would not be a way to see this visually on the chart as the chart cannot show the value of the 5 minute SMA intra-bar.
However, we can see from the time stamp what bar the value is coming from.
The value is coming from the currently building bar.Chelsea B.NinjaTrader Customer Service
Comment
-
Right, I'm not looking at a chart, I'm looking at the output from the Strategy Analyzer. That's the context. With TickReplay enabled, here is some example output from the script:
------------------------------------------------
6/23/2023 8:50:00 AM
EMA5m[0]: 15711.8688438973
------------------------------------------------
6/23/2023 8:51:00 AM
EMA5m[0]: 15711.9450751178
------------------------------------------------
6/23/2023 8:52:00 AM
EMA5m[0]: 15711.9450751178
------------------------------------------------
6/23/2023 8:53:00 AM
EMA5m[0]: 15711.9450751178
------------------------------------------------
6/23/2023 8:54:00 AM
EMA5m[0]: 15711.9450751178
------------------------------------------------
6/23/2023 8:55:00 AM
EMA5m[0]: 15711.9450751178
------------------------------------------------
6/23/2023 8:56:00 AM
EMA5m[0]: 15708.2060600943
------------------------------------------------
6/23/2023 8:57:00 AM
EMA5m[0]: 15708.2060600943
------------------------------------------------
6/23/2023 8:58:00 AM
EMA5m[0]: 15708.2060600943
------------------------------------------------
6/23/2023 8:59:00 AM
EMA5m[0]: 15708.2060600943
------------------------------------------------
6/23/2023 9:00:00 AM
EMA5m[0]: 15708.2060600943
------------------------------------------------
As you can see, the 5m EMA values are the same for each 1m post, every 5 minutes. In realtime, these would be all different because it's grabbing the intra-bar value, right? I'm expecting/wanting them to be different—to be the actual value on each 1m post.
Comment
-
This output would suggest Tick Replay may not actually be enabled and/or this is being printed from a condition that checks for IsFirstTickOfBar - if this wasn't the case, you would be seeing multiple prints for each 1m timestamp as there would be a print for each tick.
If it would help illustrate what you are doing, provide a video showing where in the code these prints are located, the test in the analyzer, and the resulting output.
Comment
-
Correct, we've already established that I'm using IsFirstTickOfBar because I want to check the value of the 5m EMA on each 1m update. I'm also using Calculate.OnEachTick. I feel like I keep repeating myself, so something must be getting lost in translation here. These are the steps and code:
This is the (simplified) strategy code:
And here is a screenshot of the Strategy Analyzer window:Code:private NinjaTrader.NinjaScript.Indicators.EMA EMA1m; private NinjaTrader.NinjaScript.Indicators.EMA EMA5m; private NinjaTrader.NinjaScript.Indicators.SMA SMA1m; private NinjaTrader.NinjaScript.Indicators.SMA SMA5m; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Get indicator values on multi timeframes"; Name = "MultiTimeframeTest"; Calculate = Calculate.OnEachTick; EntriesPerDirection = 1; EntryHandling = EntryHandling.AllEntries; IsExitOnSessionCloseStrategy = true; ExitOnSessionCloseSeconds = 30; IsFillLimitOnTouch = false; MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix; OrderFillResolution = OrderFillResolution.Standard; Slippage = 0; StartBehavior = StartBehavior.WaitUntilFlat; TimeInForce = TimeInForce.Gtc; TraceOrders = false; RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose; StopTargetHandling = StopTargetHandling.PerEntryExecution; BarsRequiredToTrade = 20; // Disable this property for performance gains in Strategy Analyzer optimizations // See the Help Guide for additional information IsInstantiatedOnEachOptimizationIteration = false; OpenTime = DateTime.Parse("07:00", System.Globalization.CultureInfo.InvariantCulture); CloseTime = DateTime.Parse("09:00", System.Globalization.CultureInfo.InvariantCulture); } else if (State == State.Configure) { AddDataSeries(Data.BarsPeriodType.Minute, 5); } else if (State == State.DataLoaded) { EMA1m = EMA(Close, 9); EMA5m = EMA(BarsArray[1], 9); SMA1m = SMA(Close, 7); SMA5m = SMA(BarsArray[1], 7); } } protected override void OnBarUpdate() { if (BarsInProgress != 0) return; if (CurrentBars[0] < 1 || CurrentBars[1] < 1) return; // 7:30-8:30 Trade Window bool tradeWindow = (Times[0][0].TimeOfDay >= OpenTime.TimeOfDay) && (Times[0][0].TimeOfDay <= CloseTime.TimeOfDay); if (tradeWindow && IsFirstTickOfBar) { Print(Time[0]); Print("Bar: " + CurrentBar); Print("Green candle (Close[0] > Open[0])): " + (Close[0] > Open[0])); Print("EMA on top (EMA1m[0] > SMA1m[0])): " + (EMA1m[0] > SMA1m[0])); Print("1m EMA Value (EMA1m[0]): " + EMA1m[0]); Print("5m EMA Value (EMA5m[0]): " + EMA5m[0]); Print("Open[0]: " + Open[0]); Print("High[0]: " + High[0]); Print("Low[0]: " + Low[0]); Print("Close[0]: " + Close[0]); } } #region Properties [NinjaScriptProperty] [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKey")] [Display(Name="OpenTime", Order=3, GroupName="Parameters")] public DateTime OpenTime { get; set; } [NinjaScriptProperty] [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKey")] [Display(Name="CloseTime", Order=4, GroupName="Parameters")] public DateTime CloseTime { get; set; } #endregion
Can you run this code in the Strategy Analyzer and send me a few minutes of the output?
Here are a few minutes of my output:
------------------------------------------------
6/23/2023 7:27:00 AM
Bar: 6206
Green candle (Close[0] > Open[0])): False
EMA on top (EMA1m[0] > SMA1m[0])): True
1m EMA Value (EMA1m[0]): 15694.7530631982
5m EMA Value (EMA5m[0]): 15703.3749758375
Open[0]: 15693.5
High[0]: 15693.5
Low[0]: 15693.5
Close[0]: 15693.5
------------------------------------------------
6/23/2023 7:28:00 AM
Bar: 6207
Green candle (Close[0] > Open[0])): False
EMA on top (EMA1m[0] > SMA1m[0])): True
1m EMA Value (EMA1m[0]): 15694.9424505586
5m EMA Value (EMA5m[0]): 15703.6749758375
Open[0]: 15694.5
High[0]: 15694.5
Low[0]: 15694.5
Close[0]: 15694.5
------------------------------------------------
6/23/2023 7:29:00 AM
Bar: 6208
Green candle (Close[0] > Open[0])): False
EMA on top (EMA1m[0] > SMA1m[0])): True
1m EMA Value (EMA1m[0]): 15694.3139604469
5m EMA Value (EMA5m[0]): 15703.2749758375
Open[0]: 15693
High[0]: 15693
Low[0]: 15693
Close[0]: 15693
------------------------------------------------
6/23/2023 7:30:00 AM
Bar: 6209
Green candle (Close[0] > Open[0])): False
EMA on top (EMA1m[0] > SMA1m[0])): True
1m EMA Value (EMA1m[0]): 15694.6611683575
5m EMA Value (EMA5m[0]): 15703.7249758375
Open[0]: 15694.25
High[0]: 15694.25
Low[0]: 15694.25
Close[0]: 15694.25
------------------------------------------------
This is really confusing. Now, the 5m EMA values are different, but the OHLC values are the same! Help!!
Comment
-
Hello DawnTreader,
Thank you for your response.
The Open[0], High[0], Low[0], and Close[0] values are the same because you are printing them within your IsFirstTickOfBar condition. This is expected behavior.
IsFirstTickOfBar is true when the incoming tick is the first tick of a new bar. So the price/value of this single tick is only the price/value information that the currently forming (0 bars ago) bar has. Therefore the OHLC of the currently processing bar are all going to have the same value because we only have the price info from a single tick.
Attached is also the test script Chelsea shared, it may help to re-watch the video he made and test this script at the same time so you can follow along. In the code, we print for every update (not just BIP 0) so we can see the 5 minute and 1 minute bars updating and changing. Then, in BIP 1 on the first tick of bar we print Times[2][0] which is the 5 minute bar information.Attached Files
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
37 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
124 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
64 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
41 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