![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Sunday May 26th at 12PM 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 |
|
Member
Join Date: Jun 2011
Posts: 53
Thanks: 7
Thanked 2 times in 2 posts
|
Hi,
I am newish to C# and new to NT and so forgive the question... From within a strategy I would like to access an Indicator by reference. The reason for doing this is so that I do not have to search and replace the name of the indicator in multiple spots within the strategy when I want to use a new indicator (with a different name but same input and output parameters). When using the indicator within the strategy this works fine and passes me back the value of "NewStop1".... exitLongStopT1Price = MyIndicator(orderPrice, BarsSinceEntry(), exitLongStopT1Price, "Long").NewStop1[0]; this does not work.... Indicator.MyIndicator refindicator= new Indicator.MyIndicator(); exitLongStopT1Price = refindicator(orderPrice, BarsSinceEntry(), exitLongStopT1Price, "Long").NewStop1[0]; I get an error saying "refindicator is a Variable but is used like a Method". I have tried several combinations of () and [] to no avail. In the end, I'm stumped. Also, in the MyIndicator, I have the parameters defined as follows. [Description("")] [GridCategory("Parameters")] public double AveragePrice1 { get { return averagePrice1; } set { averagePrice1 = value; } } The Indicator works fine and, again, if I call it directly from within the strategy it works fine. I have not made any out of the ordinary customizations to the Indicator. Any help or sample code would be greatly appreciated. |
|
|
|
|
|
#2 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
joesandyego,
You are accessing a singleton double value from your indicator like that. If you want to do that you need to store it into a double variable. That double value will be the value whatever value the indicator was at the point in time you assigned it its value. If the indicator changes, the variable will not change along with it. If you are trying to just simplify the naming you need to create it as an indicator. private MACD someInd; someInd = MACD(12, 26, 9); Print(someInd.Avg[0]);
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: Jun 2011
Posts: 53
Thanks: 7
Thanked 2 times in 2 posts
|
OK. Thanks for the response. So if I understand you correctly then using your example of MACD, if I need to call MACD multiple times within my strategy using different Fast,Slow and Signal parameters each time it is called then I will need to call MACD directly with each new set of parameters each time. Because even in your example of ' someInd = MACD(12, 26, 9); ' MACD is effectively used directly when assigning someInd.
Users must get around this somehow. Because I think that, for example, many Stop Loss and Exit strategies may need real time parameters related to a specific position (if multiple positions are active) such as AvgPrice. So the Stop Loss/Exit indicator may get called multiple times within a strategy (OnBarUpdate) with different parameters passed each time. If I wanted to change to a new Stop Loss/Exit indicator then I would need to find and replace the name of the Indicator in my strategy which could be multiple instances and then recompile. If I could call the Indicator via reference then I could just have a switch/control that switches easily between Indicators. Again, thanks for your response and I hope that you could just confirm my understanding. |
|
|
|
|
|
#4 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
If you are trying to have dynamic parameters then you have no other option but to call it with the parameters you want. This is not really an issue.
Print(MACD(variable1, variable2, variable3).Avg[0]); Just change the variables to whatever you need them to be and it will be dynamic. There really is not much benefit to creating "references". The only reason people do it is so they can type less in code. If you have to have it dynamic, then you need to do it the way shown above.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Member
Join Date: Jun 2011
Posts: 53
Thanks: 7
Thanked 2 times in 2 posts
|
Thanks for your responses and time. I understand.
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| accessing other indicators or instruments | Stephan123 | Indicator Development | 5 | 05-03-2011 04:53 PM |
| Accessing Properties of other Indicators | WolliWilli | Version 7 Beta General Questions & Bug Reports | 1 | 11-20-2009 06:29 AM |
| Accessing Real-Time Indicators within a Strategy | Prospectus | Strategy Development | 1 | 10-22-2009 06:02 AM |
| accessing indicators | velocity | General Programming | 7 | 02-22-2009 11:17 PM |
| Reference variables for indicators | cls71 | General Programming | 4 | 03-12-2008 01:56 AM |