![]() |
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
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Mar 2007
Location: , ,
Posts: 225
Thanks: 1
Thanked 2 times in 2 posts
|
I'm following the example "Exposing indicator values that are not plots" that's been provided but get compile errors.
In the example they apply the line: Add(SampleBoolSeries()) in the "SampleBoolSeriesStrategy". In my application I do the same adding the line: Add(SwingOne()) in my strategy. When I do this I get a compile error: "No overload for method 'SwingOne' takes '0' arguments" If I add instead the line: Add(SampleBoolSeries()) I get no compile errors. So the sample indicator code compiles OK but mine does not. My question: Is my coding error in my strategy or in the referenced indicator? I'm not sure where to begin to track down this problem. Regards, taddypole... |
|
|
|
|
|
#2 |
|
Senior Member
Join Date: Mar 2007
Location: , ,
Posts: 225
Thanks: 1
Thanked 2 times in 2 posts
|
To add more detail to my previous post:
I'm trying to access the pivots or swings from the swing indicator. So I created a copy of the swing indicator and called it SwingOne. Then I added variables for the SwingHighs and SwingLows so they could be referenced in my Strategy. I made these variables exposed as per the example since they are doubles and not dataseries values. Everything was going good until I added that line in the strategy. Add(SwingOne()) I just can't figure out what the error message might be telling me. |
|
|
|
|
|
#3 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,392
Thanks: 252
Thanked 968 times in 951 posts
|
Your custom indicator likely needs inputs like DataSeries and parameters to be specified, please use Intellisense to see what the compiler would expect.
You can just use the per default exposed Swing indicator methods - http://www.ninjatrader.com/support/h.../nt7/swing.htm
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Mar 2007
Location: , ,
Posts: 225
Thanks: 1
Thanked 2 times in 2 posts
|
I've attached my SwingOne indicator.
I've added in the variables section: private double exposedCurrentSwingHigh; // Exposed variables private double exposedCurrentSwingLow; // Exposed variables I've added in the Initialize section: double exposedCurrentSwingHigh = 0.0; // Exposed variables double exposedCurrentSwingLow = 0.0; // Exposed variables In the OnBarUpdate section, I've added: exposedCurrentSwingHigh = currentSwingHigh; // exposed Swing High exposedCurrentSwingLow = currentSwingLow; // exposed Swing Low and in the Properties section I've added: [Browsable(false)] [XmlIgnore()] public double ExposedCurrentSwingHigh { // We need to call the Update() method to ensure our exposed variable is in up-to-date. get { Update(); return exposedCurrentSwingHigh; } } [Browsable(false)] [XmlIgnore()] public double ExposedCurrentSwingLow { // We need to call the Update() method to ensure our exposed variable is in up-to-date. get { Update(); return exposedCurrentSwingLow; } } As far as I can tell, this follows the example closely. Any suggestions? Thanks, taddypole... |
|
|
|
|
|
#5 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,392
Thanks: 252
Thanked 968 times in 951 posts
|
The code compiles fine here, but why the work to expose those values when they are already available directly by accessing the respecive plots?
double mySwingHigh = Swing(5).SwingHigh[0];
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Mar 2007
Location: , ,
Posts: 225
Thanks: 1
Thanked 2 times in 2 posts
|
ok.. I think we are down to the point I don't understand.
So are you saying: if I put: double mySwingHigh = Swing(5).SwingHigh[0]; in my strategy, I will have access to those plots within my strategy? Does SwingOne indicator need to be applied to that chart also? And yes, that code compiled fine, it was the line in the strategy: Add(SwingOne()); that produced the compile error when compiling my strategy. Thanks Bertrand... |
|
|
|
|
|
#7 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,392
Thanks: 252
Thanked 968 times in 951 posts
|
Correct, that's what I meant - Plots are exposed from any indicator per default, so there's no custom exopse needed as for internal DataSeries and / or variables, so you were basically taking the hard route to get those values.
The Add() did not work out, as it would expect parameters - Add(SwingOne(5)); >> this should compile as well, but not needed
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#8 |
|
Senior Member
Join Date: Mar 2007
Location: , ,
Posts: 225
Thanks: 1
Thanked 2 times in 2 posts
|
ok... one more point of clarification:
Am I correct in saying, that if I apply an indicator to a chart, it then becomes exposed to a strategy applied to that same chart? If this is true, is it also more efficient from a CPU loading point of view to use values from indicators rather than recomputing them in the strategy? |
|
|
|
|
|
#9 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,392
Thanks: 252
Thanked 968 times in 951 posts
|
No, the indicator does not have to load on the chart to offer it's plots for value access - the strategy would start an indicator instance (if not already cached from another call) to you can call it's values for your calcs.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#10 |
|
Senior Member
Join Date: Mar 2007
Location: , ,
Posts: 225
Thanks: 1
Thanked 2 times in 2 posts
|
ok... and the last point... is it more efficient?
If the indicator is already running on the chart, is accessing the indicator value from within a strategy more efficient than doing all the code for the indicator in the strategy? |
|
|
|
|
|
#11 |
|
Senior Member
Join Date: Mar 2007
Location: , ,
Posts: 225
Thanks: 1
Thanked 2 times in 2 posts
|
I've attached a chart that shows the difference of calculating the Swing indicator by either the COBC true or false. As you can see the swing lines turn out differently.
The problem i'm now having is, when i access the swing values from within my strategy which is calculated with COBC = false I don't get the same values as when calculated with COBC = true. I"ve tried many many things but can't get those correct values. I can get close to those values but not exactly. How do i access those values that are based on COBC = true when my strategy is running on COBC = false? The most obvious was to limit just those calculations for the swing values in the strategy to only fire on the close of the bar but that still didn't yield the correct results. How do I sync the calculation updates to only get the swing values which are calculated on COBC = true conditions? Thanks, taddypole... |
|
|
|
|
|
#12 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,392
Thanks: 252
Thanked 968 times in 951 posts
|
Yes, accessing the indicator instance would be more efficient than rerunning indicator cals in the strategy, since NT would attempt to cache instances with the same parameters used.
For realtime use you could look into this sample, showing how to work with FirstTickOfBar to use onbarclose and on tick calcs in the same script - http://www.ninjatrader.com/support/f...ad.php?t=19387
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#13 |
|
Senior Member
Join Date: Mar 2007
Location: , ,
Posts: 225
Thanks: 1
Thanked 2 times in 2 posts
|
thanks Bertrand,
I now have all that working. Next I want to get the highest/lowest pivot or swing of the last 3 If SwingLow is a dataseries, I thought of using: MIN(SwingLow,3)[0]; but this only gives me the lowest swing of the last 3 bars and not the last 3 swings. How can I get the max/min of the last 3 dataseries objects? Thank you for all your help. taddypole... |
|
|
|
|
|
#14 |
|
Senior Member
Join Date: Mar 2007
Location: , ,
Posts: 225
Thanks: 1
Thanked 2 times in 2 posts
|
Never mind...
I've figured it out. |
|
|
|
|
|
#15 | |
|
Senior Member
Join Date: Nov 2004
Location: Switzerland
Posts: 540
Thanks: 23
Thanked 12 times in 11 posts
|
Quote:
Hi I'm also using the Swing indicator and I want to integrate it into my strategy but when I compile with the line that you offered, I get the following error message: " An object reference is required for the non-static field, ethod or property 'NinjaTrader.Strategy.Strategy.Swing(int)' What am I missing? |
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| My strategy needs to access a 2 plots of an indicator | dcmdp | Strategy Development | 1 | 03-17-2011 01:40 PM |
| Access an indicator var from a strategy? | marynja | Strategy Development | 3 | 01-30-2011 01:19 PM |
| access Strategy object from indicator | pbcah | Indicator Development | 4 | 06-07-2010 12:28 AM |
| Can a strategy access the SMA indicator | Turtle Trader | Strategy Development | 3 | 04-07-2010 04:27 AM |
| Can I access Public Indicator Variables from Strategy | rrv1980 | Strategy Development | 13 | 08-24-2008 05:31 PM |