Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Using Swing indicator
Collapse
X
-
Hi,
If I have indicator "ABC" with the code that Patrick provided and want a new indicator "XYZ" to call on the values of "ABC" , will the following be the proper way to do this?... since it's not exactly working out for me.
Thanks in advance .Code:OnBarUpdate() double SwingH = (Swing(5).SwingHigh[CurrentBar - highBarNum]); double SwingL = (Swing(5).SwingLow[CurrentBar - lowBarNum]);
Comment
-
Hello 2Look4me,
I'm not quite sure what you are asking.
However, if you have indicator ABC and want to call XYZ, this would work the same as any indicator call.
double myValue = XYZ()[0];
Patrick is demonstrating that you can call the swing from another indicator.
if (Swing(5).SwingHigh[0] > Swing(5).SwingHigh[6])
This checks that the current swing high is greater than the swing high of 6 bars ago.
If you are getting an error, what is the error?Chelsea B.NinjaTrader Customer Service
Comment
-
Hi ChelseaB,
Thanks for the reply. I'm having the following issues; in using the same code and just changing CalculateOnBarClose from True to False or vice versa, it will plot different results (attachments). Once the chart is refreshed the problem is gone and the plots match.
I used the one minute time frame, but I'm having the same issues with other time frames also.
Code:#region Variables private int switchSwing = 0; private int highBarNum = 0; private int lowBarNum = 0; #endregion /// <summary> /// This method is used to configure the indicator and is called once before any bar data is loaded. /// </summary> protected override void Initialize() { MaximumBarsLookBack = MaximumBarsLookBack.Infinite; CalculateOnBarClose = false; Overlay = true; AutoScale = false; DrawOnPricePanel = true; } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if(CurrentBar <6) return; if(CurrentBar == 0) { highBarNum = CurrentBar; lowBarNum = CurrentBar; } if(Swing(5).SwingHigh[0] > Swing(5).SwingHigh[6] && Swing(5).SwingLow[0] == Swing(5).SwingLow[6]) { highBarNum = CurrentBar; } if(Swing(5).SwingLow[0] < Swing(5).SwingLow[6] && Swing(5).SwingHigh[0] == Swing(5).SwingHigh[6]) { lowBarNum = CurrentBar; } DrawLine("l"+lowBarNum, true, CurrentBar - lowBarNum, Swing(5).SwingLow[CurrentBar - lowBarNum], 0, Swing(5).SwingLow[CurrentBar - lowBarNum], Color.Black, DashStyle.Solid,4); DrawLine("h"+highBarNum, true, CurrentBar - highBarNum, Swing(5).SwingHigh[CurrentBar - highBarNum], 0, Swing(5).SwingHigh[CurrentBar - highBarNum], Color.Black, DashStyle.Solid,4); }
Comment
-
Hello 2Look4me,
When Calculate on bar close is set to True, this means that the script processes once per bar after the bar closes and the bar is complete.
When Calculate on bar close is set to False, this means that the script processes on every tick before the bar closes and before the bar is complete.
This means that you are providing half a bar's information to an indicator and comparing this to the full bars information.
Why are you expecting this to be the same?
I would expect the historical to be the same after this is reloaded, but I would not expect this to be the same when running live.
In your screenshot, is this historical or live data?Chelsea B.NinjaTrader Customer Service
Comment
-
Hello 2Look4me,
May I have an exported example?
(A short example with only that print in it and no other code)
To export your script do the following:- Click File -> Utilities -> Export NinjaScript
- Enter a unique name for the file in the value for 'File name:'
- Select the strategy from the objects list on the left -> click the right facing arrow ">" to add the strategy to the export
- Click the 'Export' button -> click 'yes' to add any referenced indicators to the export -> click OK to clear the export location message
By default your exported file will be in the following location:- (My) Documents/NinjaTrader 7/bin/Custom/ExportNinjaScript/<export_file_name.zip>
Below is a link to the help guide on Exporting NinjaScripts.
http://www.ninjatrader.com/support/h...nt7/export.htmChelsea B.NinjaTrader Customer Service
Comment
-
Chelsea, thanks again.
I'm attaching the script with the changes, but as I call the values from another indicator,
there's a compile error "is inaccessible due to its protection level". I cannot get it to pass on the SwingHighest and SwingLowest values.Code:double SwingH = (aaaTestingSwingHL(5).SwingHighest[0]); double SwingL = (aaaTestingSwingHL(5).SwingLowest[0]);
Attached Files
Comment
-
Hello,
That should be easily fixed. It looks like SwingHighest and SwingLowest currently only exist as private doubles in this script. In order to access them outside of the script, you will need to define public properties, the way you have done for SwingHigh and SwingLow. Note that these will be public double properties, rather than public DataSeries.
Please give that a shot and see if the error is resolved.Dave I.NinjaTrader Product Management
Comment
-
Thanks for the suggestions. As I define them in the properties section
I then get a compile error:Code:[Browsable(false)] [XmlIgnore()] public double SwingHighest { get { Update(); return swingHighest; } } [Browsable(false)] [XmlIgnore()] public double SwingLowest { get { Update(); return swingLowest; } }
NinjaTrader indicator....already contains a definition for SwingHighest
NinjaTrader indicator....already contains a definition for SwingLowest
Comment
-
Hello,
If I remember correctly, didn't your private variables also begin with capital letters? If so, you will now have private variables and public properties with the exact same name. As a good best practice, I recommend beginning your private variables with lowercase letters, and beginning your properties with capital letters.
Let me know if I'm remembering incorrectly, and I'll take a closer look.Dave I.NinjaTrader Product Management
Comment
-
Dave, you are correct about the private variables being in capital letters. I made the changes and also changed the private variable to a public variable
as I call SwingHighest from another indicatorCode:#region Variables public double SwingHighest = 0; #endregion #region properties [Browsable (false)] [XmlIgnore()] public double swingHighest { get { update(); return SwingHighest; } }
there's a compile error: "Cannot apply indexing with [] to an expression of type double"Code:double SwingH = (aaaTestingSwingHL(5).SwingHighest[0]);
Thanks again for your patience.
Comment
-
Hello,
If you are trying to access a double value from another indicator, you can not apply a BarsAgo as you have in your example like it is a dataseries.
This would have an issue compiling:
Because that is the same as saying:Code:double SwingH = (aaaTestingSwingHL(5).SwingHighest[0]);
The [0] would be invalid because that is just a double and not a dataSeries, I believe what you are actually trying to use is a DataSeries.Code:double SwingHighest = 0; Print(SwingHighest[0]);
An example would be accessing the SMA or SMA(12)[0]
In your case, you would need to change the double
toCode:private double SwingHighest = 0; private double SwingLowest = 0;
And create the dataseries in Initialize as you have with the others in your script.Code:private DataSeries SwingHighest; private DataSeries SwingLowest;
The public property would then look like the following:
Finally anywhere in the indicator where you have the SwingHighest or Lowest data series, instead of assiging a value you would useCode:[Browsable(false)] [XmlIgnore()] public DataSeries SwingHighestSeries { get { return Values[5]; // this index is according to the order you have your SwingHighest = new DataSeries(this) } } [Browsable(false)] [XmlIgnore()] public DataSeries SwingLowestSeries { get { return Values[6]; } }
SwingHighest.Set(value);
and anywhere you use the variable SwingHighest in the indicator, you would replace with SwingHighest[0]
Please let me know if I may be of additional assistance.
Comment
-
Hi Jesse,
Thanks for explaining the issues in detail. I made the suggested changes except for those in the 'Properties" region, which I have as:
It all worked as I printed SwingHighest and SwingLowest in the XYZ indicator and indicator ABC as it called on those values.Code:public DataSeries SwingHighest { get { Update(); return swingHighestSeries; } }
The issue is that XYZ will print those values once calculated, but there's a 3-5 minutes lag before ABC will print/access those same values in the XYZ indicator.
Comment
-
Hello 2Look4Me,
When you say 3-5 minutes lag do you mean when you run your ABC and XYZ indicators at the same time, once the XYZ indicator prints a value, the ABC indicator doesn't print that same value for 3-5 minutes afterwards?
Could you please provide a brief example of the code you are using to print in both indicators?
Thank you in advance for clarifying.Michael M.NinjaTrader Quality Assurance
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
605 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
351 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
105 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
560 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
561 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment