NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 04-06-2010, 06:41 PM   #1
vegasfoster
Member
 
Join Date: Dec 2009
Posts: 77
Thanks: 0
Thanked 0 times in 0 posts
Default 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.
vegasfoster is offline  
Reply With Quote
Old 04-07-2010, 06:48 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,555
Thanks: 261
Thanked 1,013 times in 994 posts
Default

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
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 04-07-2010, 03:54 PM   #3
vegasfoster
Member
 
Join Date: Dec 2009
Posts: 77
Thanks: 0
Thanked 0 times in 0 posts
Default

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 Files
File Type: zip MovingSwingCenter.zip (5.1 KB, 12 views)
Last edited by vegasfoster; 04-07-2010 at 03:59 PM.
vegasfoster is offline  
Reply With Quote
Old 04-07-2010, 04:09 PM   #4
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

Print() will print to the Output Window the moment the code reaches that line. If you are not reaching that line then nothing will be printed. I suggest you check your Control Center logs for any runtime errors that may have halted your script.
NinjaTrader_Josh is offline  
Reply With Quote
Old 04-07-2010, 09:17 PM   #5
vegasfoster
Member
 
Join Date: Dec 2009
Posts: 77
Thanks: 0
Thanked 0 times in 0 posts
Default

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.
vegasfoster is offline  
Reply With Quote
Old 04-08-2010, 04:00 AM   #6
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,555
Thanks: 261
Thanked 1,013 times in 994 posts
Default

Thanks for posting your solution and great you got it working.
NinjaTrader_Bertrand is offline  
Reply With Quote
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
array values from indicator are "0" Sleeping Troll Strategy Development 3 03-29-2010 06:26 AM
DrawDiamond("My swing" , true, 1, Swing(10).SwingHighBar(10, 1, 50), Color.Blue duck_CA Strategy Development 3 03-14-2009 12:00 PM
summary of "strategy realized" is not equal "account performance, total net profit"" Fragolino Miscellaneous Support 1 02-19-2009 04:12 AM
Indicator Values not "sticking" Bannor Indicator Development 3 01-13-2009 08:46 AM
Problem with opening application and trying to preserve prior "workspace" Greg1 Miscellaneous Support 8 04-14-2007 01:49 PM


All times are GMT -6. The time now is 07:01 PM.