Go Back   NinjaTrader Support Forum > Application Technical Support > Charting

Charting Support for NinjaTrader Advanced Charting.

Reply
 
Thread Tools Display Modes
Old 07-26-2012, 01:23 AM   #1
laocoon
Senior Member
 
Join Date: Nov 2004
Posts: 709
Thanks: 32
Thanked 42 times in 28 posts
Default Using the Swing Indicator

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.
laocoon is offline  
Reply With Quote
Old 07-26-2012, 04:16 AM   #2
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 553 times in 545 posts
Default

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);
	}
}
The above code draws an arrow if the current swing value equals the value of the swing 10 bars back.
NinjaTrader_Joydeep is offline  
Reply With Quote
Old 07-26-2012, 05:03 AM   #3
laocoon
Senior Member
 
Join Date: Nov 2004
Posts: 709
Thanks: 32
Thanked 42 times in 28 posts
Default

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.
laocoon is offline  
Reply With Quote
Old 07-26-2012, 05:22 AM   #4
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 553 times in 545 posts
Default

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;
InOnBarUpdate

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;
}
NinjaTrader_Joydeep is offline  
Reply With Quote
Old 07-26-2012, 09:19 AM   #5
laocoon
Senior Member
 
Join Date: Nov 2004
Posts: 709
Thanks: 32
Thanked 42 times in 28 posts
Default

Looks good so far, thanks a lot for helping out Joydeep!
laocoon is offline  
Reply With Quote
The following user says thank you to laocoon for this post:
Old 07-26-2012, 09:22 AM   #6
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 553 times in 545 posts
Default

Hello laocoon,
Thanks for your note.
Please let me know if I can assist you any further.
NinjaTrader_Joydeep is offline  
Reply With Quote
Old 07-30-2012, 09:03 AM   #7
laocoon
Senior Member
 
Join Date: Nov 2004
Posts: 709
Thanks: 32
Thanked 42 times in 28 posts
Default

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
Attached Images
File Type: jpg FDAX 09-12 (10 Min) 30_07_2012.jpg (39.9 KB, 65 views)
laocoon is offline  
Reply With Quote
Old 07-30-2012, 09:36 AM   #8
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 553 times in 545 posts
Default

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);
http://www.ninjatrader.com/support/h...urence_mro.htm
NinjaTrader_Joydeep is offline  
Reply With Quote
Old 07-31-2012, 07:49 AM   #9
laocoon
Senior Member
 
Join Date: Nov 2004
Posts: 709
Thanks: 32
Thanked 42 times in 28 posts
Default

Thanks Joydeep, I'll look into it.

Regards
laocoon is offline  
Reply With Quote
The following user says thank you to laocoon for this post:
Old 08-02-2012, 04:52 AM   #10
laocoon
Senior Member
 
Join Date: Nov 2004
Posts: 709
Thanks: 32
Thanked 42 times in 28 posts
Default

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
laocoon is offline  
Reply With Quote
Old 08-02-2012, 05:10 AM   #11
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 553 times in 545 posts
Default

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.
NinjaTrader_Joydeep is offline  
Reply With Quote
Old 08-02-2012, 05:58 AM   #12
koganam
Senior Member
 
Join Date: Feb 2008
Location: http://omegasigmaindicators.com
Posts: 4,790
Thanks: 31
Thanked 1,984 times in 1,622 posts
Send a message via Skype™ to koganam
Default

Quote:
Originally Posted by laocoon View Post
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
So why not just determine the actual Swing bar? Once you know the bar number, you can reference it any way that you want.

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.
koganam is offline  
Reply With Quote
The following user says thank you to koganam for this post:
Old 08-02-2012, 06:25 AM   #13
laocoon
Senior Member
 
Join Date: Nov 2004
Posts: 709
Thanks: 32
Thanked 42 times in 28 posts
Default

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
laocoon is offline  
Reply With Quote
Old 08-02-2012, 06:35 AM   #14
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 553 times in 545 posts
Default

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
}
@koganam - thanks for the pointer.
NinjaTrader_Joydeep is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Joydeep for this post:
Old 08-03-2012, 05:59 AM   #15
laocoon
Senior Member
 
Join Date: Nov 2004
Posts: 709
Thanks: 32
Thanked 42 times in 28 posts
Default

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.
laocoon is offline  
Reply With Quote
The following user says thank you to laocoon for this post:
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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 11:48 AM
Howard Indicator and Pesavento Pattern Swing Indicator DORAIRAJ_S@HOTMAIL.COM Indicator Development 1 11-12-2007 01:28 AM


All times are GMT -6. The time now is 05:35 PM.

FULL RISK DISCLOSURE: Futures trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.