![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| Charting Support for NinjaTrader Advanced Charting. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Nov 2004
Location: Switzerland
Posts: 540
Thanks: 23
Thanked 12 times in 11 posts
|
Hello
I'm using the standard Ninja Swing indicator and I'd like to add a very simple functionality to it: Basically, whenever the Swing Line is rather long (let's say, 10+ candles), I want the indicator to draw an arrow next to the Swing Line, in order to highlight its importance (I'm using a Swing Line with a value of 5). I've played around with the DrawArrowUp/Down function but it only lets me draw an arrow above/below a candle, not next to another element on the chart like the Swing line. How should I go about this? Thanks in advance for your suggestions.
Last edited by laocoon; 07-26-2012 at 01:57 AM.
|
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
Hello laocoon,
A very simple code will be like Code:
protected override void OnBarUpdate()
{
if (CurrentBar < 10) return;
if (this.Swing(5)[0] == Swing(5)[10])
{
this.DrawArrowUp("swing" + CurrentBar, false, 0, Swing(5)[0], Color.Blue);
}
}
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Nov 2004
Location: Switzerland
Posts: 540
Thanks: 23
Thanked 12 times in 11 posts
|
Hello Joydeep
Thanks a lot for your reply and the code snippet. I'd like to use the code for both the Upper Swing Line and the Lower Swing Line but when I apply the following modification Old: this.DrawArrowUp("swing" + CurrentBar, false, 0, Swing(5)[0], Color.Blue); New: this.DrawArrowUp("swingUpper" + CurrentBar, false, 0, SwingHigh(5)[0], Color.Blue); this.DrawArrowDown("swingLower" + CurrentBar, false, 0, SwingLow(5)[0], Color.Blue); it doesn't work (I get an error message although I'm using SwingHigh & SwingLow in another context and they work perfectly. Also, I'd like the arrow to appear only ONCE per Swing Line and not on every candle. Thanks again. |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
Hello laocoon,
NinjaTrader natively does not comes with any SwingHigh or SwingLow indicator. To access the Swing high value you can use the following code for example Code:
Swing(5).SwingHigh[0]; Please try this modified code, which will draw only one arrow, In variable region Code:
bool onlyOnce = true; Code:
if (CurrentBar < 10) return;
if (Swing(5).SwingHigh[0] != Swing(5).SwingHigh[10])
{
onlyOnce = true;
}
if (onlyOnce && this.Swing(5).SwingHigh[0] == Swing(5).SwingHigh[10])
{
this.DrawArrowUp("swing" + CurrentBar, false, 0, Swing(5).SwingHigh[0], Color.Blue);
onlyOnce = false;
}
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Nov 2004
Location: Switzerland
Posts: 540
Thanks: 23
Thanked 12 times in 11 posts
|
Looks good so far, thanks a lot for helping out Joydeep!
|
|
|
|
|
The following user says thank you to laocoon for this post: |
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
Hello laocoon,
Thanks for your note. Please let me know if I can assist you any further.
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Nov 2004
Location: Switzerland
Posts: 540
Thanks: 23
Thanked 12 times in 11 posts
|
Hello Joydeep
I have a quick follow-up question regarding the Swing Indicator: how can I address an "older" Swing line, ie not the most recent one but the one before? (See attached chart for clarification) The Swing Line I'd like to address in my code is highlighted by a blue arrow. Thanks a lot. Regards |
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
Hello laocoon,
You can use the MRO method to do it. A sample code will be like: Code:
if (CurrentBar < 100) return;
int m = MRO(delegate {return Swing(5)[0] != Swing(5)[1]; }, 1, 50);
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Nov 2004
Location: Switzerland
Posts: 540
Thanks: 23
Thanked 12 times in 11 posts
|
Thanks Joydeep, I'll look into it.
Regards |
|
|
|
|
The following user says thank you to laocoon for this post: |
|
|
|
#10 |
|
Senior Member
Join Date: Nov 2004
Location: Switzerland
Posts: 540
Thanks: 23
Thanked 12 times in 11 posts
|
Sorry to bother you again with this, Joydeep, but I have two issues with the solution you suggested:
1. In the online support section it is written (about MRO) that "This method will NOT work on multi-instrument or multi-time frame strategies." Unfortunately my strategy IS multi-time frame. 2. I understand this snippet: int m = MRO(delegate {return Swing(5)[0] != Swing(5)[1]; }, 1, 50); but the problem I have with it is the following: the most recent Swing Line is obviously easy to address with "Swing(5)[0]" because it is drawn above/below the most recent candle. But now it gets a little more tricky because in order to address the *second* most recent Swing Line (the one highlighted by a blue arrow in the attached chart in one of my previous posts) I need to know how many candles back it was drawn and this value will almost never be the same. In the example on the chart it is "Swing(5)[6]", but the next one might be at "Swing(5)[9]" etc. To sum it all up: all I'm looking to achieve is to address the *second* most recent Swing Line in order to be able to compare it to the most recent one. Thanks again. Regards |
|
|
|
|
|
#11 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
Hello laocoon,
Unfortunately the MRO function works on single series scripts only as you rightly pointed out. Unfortunately there are no native functions to do it. You have to further custom code to get the 2nd most swing value.
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
#12 | |
|
Senior Member
|
Quote:
![]() From the NT Help: Syntax - Bars Ago High Bar Swing(int strength).SwingHighBar(int barsAgo, int instance, int lookBackPeriod) Swing(IDataSeries input, int strength).SwingHighBar(int barsAgo, int instance, int lookBackPeriod) Low Bar Swing(int strength).SwingLowBar(int barsAgo, int instance, int lookBackPeriod) Swing(IDataSeries input, int strength).SwingLowBar(int barsAgo, int instance, int lookBackPeriod) Return Value An int value representing the number of bars ago. Returns a value of -1 if a swing point is not found within the look back period. |
|
|
|
|
|
The following user says thank you to koganam for this post: |
|
|
|
#13 |
|
Senior Member
Join Date: Nov 2004
Location: Switzerland
Posts: 540
Thanks: 23
Thanked 12 times in 11 posts
|
Thanks for your reply Joydeep. I was hoping that there would be an easy solution to my problem but apparently that's not the case. Will have to look further.
Regards |
|
|
|
|
|
#14 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
Hello laocoon,
My apologies, kognams solution should get you going. A sample code will be like Code:
if (CurrentBar < 20) return;
int i = Swing(5).SwingHighBar(0, 2, 20);
if (i > 0)
{
//do something
}
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
The following user says thank you to NinjaTrader_Joydeep for this post: |
|
|
|
#15 |
|
Senior Member
Join Date: Nov 2004
Location: Switzerland
Posts: 540
Thanks: 23
Thanked 12 times in 11 posts
|
Thank you very much Koganam & Joydeep for your help, much appreciated!
I'm currently working on implementing your suggested solution and will let you know how it goes. Thanks again & have a nice weekend. |
|
|
|
|
The following user says thank you to laocoon for this post: |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Swing indicator | Dervakon | General Programming | 3 | 05-03-2011 03:07 PM |
| Swing indicator | Stephan123 | Indicator Development | 1 | 05-02-2011 09:41 AM |
| strategy that shows broken Swing high and Swing low? | MoreYummy | Strategy Development | 1 | 06-06-2010 10:16 PM |
| Swing Indicator | wcmaria | Indicator Development | 1 | 12-04-2008 10:48 AM |
| Howard Indicator and Pesavento Pattern Swing Indicator | DORAIRAJ_S@HOTMAIL.COM | Indicator Development | 1 | 11-12-2007 12:28 AM |