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
Replace values of plot in history
Collapse
X
-
Replace values of plot in history
I am working on an indicator which changes the period of indicators in response to some market action. Is there a way to change the values of the plot of an indicator on previous bars? For example, if i were plotting an indicator that is the equivalent of the RSI(14) on the chart and I wanted to change the period to 24 because of some market data that just came into NT8. ThanksTags: None
-
Hello,
Thank you for the question.
You would have to account for this change with your own logic.
You can set previous plot values using a BarsAgo index, if you were to re-iterate through the bars you could likely reset the values as needed. A For loop could be used to iterate the bars and from there you could get data as needed from the indicators.
Code:protected override void OnStateChange() { if (State == State.SetDefaults) { AddPlot(Brushes.Red, "Plot0"); } } protected override void OnBarUpdate() { if(State == State.Historical) { Value[0] = Close[0]; } else if (State == State.Realtime) { for(int i = 0; i < Count -2; i++) { Value[i] = 120; } } }
I look forward to being of further assistance.JesseNinjaTrader Customer Service
-
Jesse,
Thanks for this information. I was able to make the data replacement work for the realtime situation. However, when I try to insert the logic into the historical calculation, the calculation works, but takes forever. Is there a way to ignore going through the change of RSI(n) in the Value array until the last historical bar?
Thanks.
Comment
-
Hello,
Thank you for the reply.
Yes, you could either wait for Realtime, or if you want to do this in historical you would need to check the CurrentBar against the Count.
Code:if(Historical) return;
Code:if(CurrentBar < Count - 2) return;
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Comment
-
Jesse,
Thanks for that information. I was able to make that work. Last thing, I hope. I'm trying to provide a displayName that mimics a standard RSI or MACD or whatever. Because the periods are changing underneath, I would like the displayname to update when the periods change. I tried overriding the display name as follows:
Code:public override string DisplayName { get { return Name + "( " + this.Instrument.FullName + " (" + Bars.BarsPeriod + "), " + Period + ")" ; } }
Thanks again!
Comment
-
Hello,
In this case because the Instrument is not yet know, the object would be null. Instrument would be null until the indicator is actually added to the chart, so you would likely need to modify the logic to use a variable. Other items may also cause this, so I would suggest for any NinjaScript specific property, to use a variable instead to prevent nulls.
Here is one example:
Code:private string myInstrument = "Some Placeholder Text"; protected override void OnStateChange() { if (State == State.Historical) { myInstrument = Instrument.FullName; } } public override string DisplayName { get { return Name + "( " + myInstrument + " , " + Period + ")" ; } }
JesseNinjaTrader Customer Service
Comment
-
Unhandled Exception
Hello Jesse,
Thanks for your help so far. I've the code "mostly" working. It plots correctly. However, for a reason that I can't figure out, sometimes when I return to the ninjatrader chart window from another application, the indicator's plot is empty. If I hit F5 to refresh, I get an unhandled exception indicating that an object was expected. It doesn't say what object was expected. I suspect I'm not reinitializing something when the window becomes active again. The code for bar generation is below. It relies on RSI and a custom indicator. I have not experienced this behavior with either RSI or ACPDominantCycle on their own.
TIA
Code:if((State == State.Historical && CurrentBar == Count - 2) || State == State.Realtime ) { double temp = ACPDominantCycle(100,true)[0]; int NewPeriod = Convert.ToInt32(temp); int theEnd = (Period == NewPeriod)?1:Count-2; Period = NewPeriod; myName = Name + "( " + this.Instrument.FullName + " (" + Bars.BarsPeriod + "), " + Period + ", "+ Convert.ToInt32(temp*SmoothingRatio) + ")" ; for(int i = 0; i < theEnd; i++) { Value[i] = RSI(Convert.ToInt32(temp),Convert.ToInt32(temp*SmoothingRatio))[i]; Values[1][i] = RSI(Convert.ToInt32(temp),Convert.ToInt32(temp*SmoothingRatio)).Avg[i]; } }
Comment
-
Hello SkiMajor,
Thanks for your reply.
IsSuspendedWhileInactive was added in Ninjatrader8 as a performance improvement option that is set true by default. From the helpguide: "Prevents real-time market data events from being raised while the indicator's hosting feature is in a state that would be considered suspended and not in immediate use by a user. Enabling this property in your indicator helps save CPU cycles while the hosting feature is suspended and not in use by a user. Once the hosting feature is in a state that would no longer be considered suspended, the historical OnBarUpdate() events will be replayed allowing the indicator to catch up to current real-time values."
Full Link: http://ninjatrader.com/support/helpG...leinactive.htmPaul H.NinjaTrader Customer Service
Comment
-
IsSuspendedWhileInactive
Hi Paul,
Thanks for your reply. IsSuspendedWhileInactive seems like a very useful feature in NT8. However, can you help me understand what it is about my code that is causing an unhandled exception as described in the OP when IsSuspendedWhileInactive = true?
Thanks.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by rbeckmann05, Yesterday, 06:48 PM
|
1 response
12 views
0 likes
|
Last Post
by bltdavid
Today, 05:43 AM
|
||
Started by llanqui, Today, 03:53 AM
|
0 responses
6 views
0 likes
|
Last Post
by llanqui
Today, 03:53 AM
|
||
Started by burtoninlondon, Today, 12:38 AM
|
0 responses
10 views
0 likes
|
Last Post Today, 12:38 AM | ||
Started by AaronKoRn, Yesterday, 09:49 PM
|
0 responses
15 views
0 likes
|
Last Post
by AaronKoRn
Yesterday, 09:49 PM
|
||
Started by carnitron, Yesterday, 08:42 PM
|
0 responses
11 views
0 likes
|
Last Post
by carnitron
Yesterday, 08:42 PM
|
Comment