Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Referencing prior "Swing" Indicator Values
Collapse
X
-
Referencing prior "Swing" Indicator Values
I currently using a moving centerline defined as (high + low)/2 for a specified lookback period to help identify the trend and for entry points, but I think it would work better to use the swing indicator figures for a specified number of prior swing highs and swing lows, e.g. 3, 5, 10 etc. In that manner, the "lookback period" would self adjust separately for highs and lows to the most current swings. Because the number of bars ago that each swing occurred will vary, is there a way to refer to the prior swings other than using a specified number of bars? Thank you.Tags: None
-
Vegasfoster, you could check how many bars ago the swing point occured and then plug this for example in the High / Low indexes to access those swing price values then to compare for the trend structure - http://www.ninjatrader-support.com/H...eV6/Swing.html
-
That's a great start, thank you. I can make it work using the following, but the number of prior swings used in the calculation isn't variable.
Center.Set( (
High[Math.Max(0, Swing(strength).SwingHighBar(0, instances, period))] +
High[Math.Max(0, Swing(strength).SwingHighBar(0, instances - 1, period))] +
High[Math.Max(0, Swing(strength).SwingHighBar(0, instances - 2, period))] +
Low[Math.Max(0, Swing(strength).SwingLowBar(0, instances, period))] +
Low[Math.Max(0, Swing(strength).SwingLowBar(0, instances - 1, period))] +
Low[Math.Max(0, Swing(strength).SwingLowBar(0, instances - 2, period))]
)/6 );
So I am trying the following but it isn't plotting. I tried using Print("AverageHigh") and Print(AverageHigh) but nothing shows in the output window. I am not 100% on how to get data to show in the output window, I added indicator to chart and then recompiled the indicator, but nothing shows, is that the correct way? Not sure how else to troubleshoot. Thanks for any help.
{
if (CurrentBar < period)
{
return;
}
double y = 0;
int number1 = instances;
for (int n1 = 0; n1 < number1; n1++)
{
y = y + (High[Math.Max(0, Swing(strength).SwingHighBar(0, n1, period))]);
}
double AverageHigh = y / instances;
double z = 0;
int number2 = instances;
for (int n2 = 0; n2 < number2; n2++)
{
z = z + (Low[Math.Max(0, Swing(strength).SwingLowBar(0, n2, period))]);
}
double AverageLow = z / instances;
Center.Set( ( (AverageHigh + AverageLow)/2) );Attached FilesLast edited by vegasfoster; 04-07-2010, 03:59 PM.
Comment
-
Ok, it said,
"4/7/2010 1:47:33 PM|3|4|Error on calling the 'OnBarUpdate' method for indicator 'MovingSwingCenter2' on bar 200: Swing.SwingHighBar: instance must be greater/equal 1 but was 0"
So I changed "int number1 = instances;" to "int number1 = instances + 1;" and "for (int n1 = 0; n1 < number1; n1++)" to "for (int n1 = 1; n1 < number1; n1++)" for both the high and low and that fixed the problem. Thanks, learned something new to look at.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
569 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
330 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
548 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
548 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment