For example, let's say when the stochastic is above 80 I want it to check for the last time the stochastic was above 80 from the past bars and then if the price on the current bar is lower than the price was on that bar in the past an alert would go out. Please assist.
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
comparing the value of an indicator on different bars
Collapse
X
-
comparing the value of an indicator on different bars
Can somebody tell me the easiest way to compare the value of an indicator on the current bar or 1 bar back to the value of an indicator x bars in the past. This is the type of code you would use to make divergence indicators like a macd or stochastic divergence, etc. I've seen this done using for loops but I'm not sure if that's the only way or even the most efficient way to accomplish this. I'm not going to be looking for a specific bar but scanning bars in the past to find the last bar that closed on a specific indicator level or within a specific zone.
For example, let's say when the stochastic is above 80 I want it to check for the last time the stochastic was above 80 from the past bars and then if the price on the current bar is lower than the price was on that bar in the past an alert would go out. Please assist.Tags: None
-
Hello gordongekko,
Thanks for your post.
One way to accomplish your goal would be to save the bar number in an int variable when the stochastic value is > 80. For example:
if (Stochastics(7, 14, 3).D[0] >= 80)
{
if (High[0] < High[CurrentBar - prev80bar]) // check against previous high
{
Alert(...)
}
prev80bar = CurrentBar;
}Paul H.NinjaTrader Customer Service
-
Hi Paul,
Thanks for the reply. Can you explain how to do this using 2 different price data series. For example, how do I make an alert for when the current 1m bar closes above the high of the previous daily bar. I'm assuming I would make a double for the previous days high but how do I reference the daily data series because if i use current bar etc it will think I'm taking about the main data series.
Comment
-
Hello gordongekko,
Thanks for your reply.
There would be a couple of ways to do this.
In Ninjascript (or strategy builder) You can add a daily bar series and then reference the Highs[1][1] which points to the added daily bar high of yesterday (depending on Calculate setting). This would be creating a multi time frame script which causes references to change and you would want to fully review this section of the helpguide: https://ninjatrader.com/support/help...nstruments.htm
Alternatively, you can add the indicator PriorDayOHLC and access the previous day High value. Prior day uses the intraday data. You can add it to a chart to see what that results in. Please see: https://ninjatrader.com/support/help...r_day_ohlc.htm
Alternatively, if all you need is an alert, you can create a chart alert using Current price and the indicator PriorDayOHLC's High line. Reference: https://ninjatrader.com/support/help...us/?alerts.htmPaul H.NinjaTrader Customer Service
Comment
-
I followed the instructions in the support guide but I'm getting a "Method name expected" error on this line when trying to compile the code:
if(Close[0] > High[1](BarsArray[1]) || Close[0] > Low[1](BarsArray[1]))
Comment
-
I'm assuming you mean High[1][1] referring to data series 1 the array and the previous bar in that data series. Is this correct?
I added this data series to the state configure
AddDataSeries(BarsPeriodType.Day, 1);
i just need to see the correct syntax for this line comparing the main data series to the 1 data series in the barsarray.
This is obviously incorrect because it wont compile:
if(Close[0] > High[1](BarsArray) || Close[0] > Low[1](BarsArray[1]))
What I want to say is "if the close of the main data series (e.g.1m) closes above the high of the previous days bar or if the main data series closes above the low of the previous days bar" then run the methodLast edited by gordongekko; 12-05-2017, 03:50 PM.
Comment
-
Hello gordongekko,
Thanks for your reply.
If you are running the code with Calculate.OnBarClose then you would use:
if (Closes[0][0] > Highs[1][0] || Closes[0][0] < Lows[1][0])
Please note that with reference to the helpguide: https://ninjatrader.com/support/help...nstruments.htm you will want to isolate to BarsInProgress == 0 and you will need to ensure at least 1 day bar has been loaded before trying to access that statement (review CurrentBars[] check in https://ninjatrader.com/support/help...urrentbars.htm)Paul H.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Padan, Today, 02:02 AM
|
1 response
8 views
0 likes
|
Last Post Today, 07:56 AM | ||
Started by Mestor, Today, 03:15 AM
|
1 response
8 views
0 likes
|
Last Post Today, 07:41 AM | ||
Started by RaygunWizzle, Yesterday, 08:52 PM
|
1 response
9 views
0 likes
|
Last Post Today, 07:40 AM | ||
Started by Mestor, 03-10-2023, 01:50 AM
|
13 responses
314 views
0 likes
|
Last Post Today, 07:29 AM | ||
Started by Lele2k24, Yesterday, 11:24 AM
|
7 responses
25 views
0 likes
|
Last Post Today, 07:25 AM |
Comment