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
Historical keyword in Replay mode
Collapse
X
-
Historical keyword in Replay mode
The Historical keyword does not seem to work correctly in Replay mode. It returns true for all bars. I would expect it to work as if you were in live mode, and be set to true for all but the last bar. What is the best way to tell if you are running on the last bar in all modes? Also, from an indicator, how can you tell if Replay is running?Tags: None
-
aslane,
This is unsupported, but you could try something like this – that’s in our Bartimer indicator.
Code:private DateTime Now { get { DateTime now = (Bars.MarketData.Connection.Options.Provider == Cbi.Provider.Replay ? Bars.MarketData.Connection.Now : DateTime.Now); if (now.Millisecond > 0) now = Cbi.Globals.MinDate.AddSeconds((long) System.Math.Floor(now.Subtract(Cbi.Globals.MinDate).TotalSeconds)); return now; } }
Code:Bars.MarketData.Connection.Options.Provider == Cbi.Provider.Replay
Adam P.NinjaTrader Customer Service
Comment
-
I'm lost on this one.
I've used:
Code:protected override void OnBarUpdate() { if (Historical) return; .... }
What am I not understanding about this post? NT 7.0.1000.8... 32 bit.
Edit: I'm referring my usage for Strategies. Not indicators. Maybe that is the difference you speak of
Originally posted by aslane View PostThe Historical keyword does not seem to work correctly in Replay mode. It returns true for all bars. I would expect it to work as if you were in live mode, and be set to true for all but the last bar. What is the best way to tell if you are running on the last bar in all modes? Also, from an indicator, how can you tell if Replay is running?
Comment
-
I have written a simple test for Historical, and it does seem to work in a trivial indi in replay mode. Unfortunately, it does not always work in complex code. I must be doing something to cause the issue, but I find it strange that I could cause the issue from my side of the fence. I'll try to isolate more.
Comment
-
Originally posted by aslane View PostI have written a simple test for Historical, and it does seem to work in a trivial indi in replay mode. Unfortunately, it does not always work in complex code. I must be doing something to cause the issue, but I find it strange that I could cause the issue from my side of the fence. I'll try to isolate more.
I am out of guesses without seeing some code that isolates and is reproduceable.
Comment
-
Please take a look at my post in this older thread and provide your comments about it as a possible solution. I have a similar need. Do you think it is viable? It's certainly not optimal, but can you think of any reason why it would fail?
Thanks.
Scott
Comment
-
Historical stays 'true' for referenced indicator on phantom bar if updated
Hello!
I have studied the Historical property in Replay mode and found that 'Historical' for a referenced indicator will not switch to 'false' on the phantom bar that NT injects on the first real time tick if the callee is updated on every bar. But if you skip the call to update the referenced indicator on the phantom bar, then 'Historical ' switches to false also for the referenced indicator. Is this behaviour expected?
I have attached 2 simple indicators where you can reproduce my print statments below if you run the Caller in Replay mode. (The injected phantom bar is nr 81 my example below.)
Best Regards
poseidon
Case 1: Calle updated on every bar
TestHistoricalCaller:
*******************************************
CurrentBar: 80
CalculateOnBarClose: False
Historical: True
TestHistoricalCallee:
----------------------------------------------
CurrentBar: 80
CalculateOnBarClose: False
Historical: True
TestHistoricalCaller:
*******************************************
CurrentBar: 81
CalculateOnBarClose: False
Historical: False (Historical changes to False on phantom bar)
TestHistoricalCallee:
----------------------------------------------
CurrentBar: 81
CalculateOnBarClose: False
Historical: True (Historical stays TRUE for the referenced indicator on the phantom bar)
Case 2: Calle updated on every bar except for the injected phantom bar
TestHistoricalCaller:
*******************************************
CurrentBar: 80
CalculateOnBarClose: False
Historical: True
TestHistoricalCallee:
----------------------------------------------
CurrentBar: 80
CalculateOnBarClose: False
Historical: True
TestHistoricalCaller:
*******************************************
CurrentBar: 81
CalculateOnBarClose: False
Historical: False
TestHistoricalCallee:
----------------------------------------------
CurrentBar: 81
CalculateOnBarClose: False
Historical: FalseLast edited by poseidon_sthlm; 03-16-2015, 08:45 AM.
Comment
-
I understand the basic concept of the Historical property. My question relates to the specific situation when NT injects a phantom bar where historical data ends and real time data begins. As I have shown below, the property Historical on the injected phantom bar is TRUE for the calling indicator (Caller) but FALSE for the referenced indicator (Callee) , unless you skip the update call on this phantom bar. Isn't this an inconsistent behaviour?
/PoseidonLast edited by poseidon_sthlm; 03-16-2015, 10:39 AM.
Comment
-
Hello again,
My key point is that this inconsistency for the Historical property on the phantom bar is caused by the update call. So my work around here is to skip the update call in the Caller on the phantom bar. Why is this work around required to make the Historical property FALSE also for the referenced indicator on the first real time tick?
The code is simple an I have attached the indicators in post #11.
Code:public class TestHistoricalCaller : Indicator { /// Variables int alt = 1; bool historicalCurrentBar = true; bool historicalPrevBar = true; TestHistoricalCallee myTestHistoricalCallee; protected override void OnStartUp() { myTestHistoricalCallee = TestHistoricalCallee(); /// Instantiate Indicator } protected override void OnBarUpdate() { if ( FirstTickOfBar ) { Print(""); Print("TestHistoricalCaller:"); Print("*******************************************"); Print("CurrentBar: " + CurrentBar); Print("CalculateOnBarClose: " + CalculateOnBarClose); Print("Historical: " + Historical); historicalPrevBar = historicalCurrentBar; historicalCurrentBar = Historical; switch(alt) { case 1: /// Update calle on every bar double v1 = myTestHistoricalCallee[0]; break; case 2: /// Don't update calle on the injected phantom bar if ( historicalPrevBar == historicalCurrentBar ) { double v2 = myTestHistoricalCallee[0]; } break; } Print(""); } } #region Properties [GridCategory("Parameters")] public int Alt { get { return alt; } set { alt = Math.Max(value, 1); } } #endregion }
Code:public class TestHistoricalCallee : Indicator { protected override void OnBarUpdate() { if ( FirstTickOfBar ) { Print(""); Print("TestHistoricalCallee:"); Print("----------------------------------------------"); Print("CurrentBar: " + CurrentBar); Print("CalculateOnBarClose: " + CalculateOnBarClose); Print("Historical: " + Historical); } } }
Last edited by poseidon_sthlm; 03-17-2015, 04:36 AM.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by carnitron, Today, 08:42 PM
|
0 responses
2 views
0 likes
|
Last Post
by carnitron
Today, 08:42 PM
|
||
Started by strategist007, Today, 07:51 PM
|
0 responses
3 views
0 likes
|
Last Post Today, 07:51 PM | ||
Started by StockTrader88, 03-06-2021, 08:58 AM
|
44 responses
3,969 views
3 likes
|
Last Post
by jhudas88
Today, 06:59 PM
|
||
Started by rbeckmann05, Today, 06:48 PM
|
0 responses
5 views
0 likes
|
Last Post
by rbeckmann05
Today, 06:48 PM
|
||
Started by rhyminkevin, Today, 04:58 PM
|
4 responses
58 views
0 likes
|
Last Post
by dp8282
Today, 06:13 PM
|
Comment