![]() |
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Member
Join Date: Dec 2009
Posts: 77
Thanks: 0
Thanked 0 times in 0 posts
|
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.
|
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,555
Thanks: 261
Thanked 1,013 times in 994 posts
|
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
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: Dec 2009
Posts: 77
Thanks: 0
Thanked 0 times in 0 posts
|
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) );
Last edited by vegasfoster; 04-07-2010 at 03:59 PM.
|
|
|
|
|
|
#4 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
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.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Member
Join Date: Dec 2009
Posts: 77
Thanks: 0
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,555
Thanks: 261
Thanked 1,013 times in 994 posts
|
Thanks for posting your solution and great you got it working.
Bertrand
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |