![]() |
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Nov 2008
Posts: 95
Thanks: 0
Thanked 0 times in 0 posts
|
Hi,
I have finished programming an indicator. The indicator basically contains a bunch of conditions and outputs some bool type variables to indicate entry/exit. Now I'm programming a strategy. I wonder if you can briefly teach me how to put some functions that output bool type in a separate file, and let my indicator refer to it. That way if I need to change my method, I don't need to change both indicator and strategy files. |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 4,858
Thanks: 162
Thanked 579 times in 570 posts
|
You will need to expose these bools publicly which can then be read directly from the strategy. You would not need to write to a separate file with this method.
Please see our Reference Sample on Exposing indicator values that are not plots http://www.ninjatrader.com/support/f...ead.php?t=4991
Matthew
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: Nov 2008
Posts: 95
Thanks: 0
Thanked 0 times in 0 posts
|
Hi Thanks for reply.
I tried the same as the example below. Code:
Add(MACD(12, 26, 9));
Add(SampleBoolSeries());
I can only add indicator to the primary data series, but can't add to my secondary data series. Is there a way to work around this? |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,568
Thanks: 261
Thanked 1,017 times in 998 posts
|
Hi Leon, what you experience is expected - if you wish to Add() an indicator working on another series, please do those calcs in the added indicator itself.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#5 | |
|
Member
Join Date: Nov 2008
Posts: 95
Thanks: 0
Thanked 0 times in 0 posts
|
Quote:
So say if I firstly added a secondary series by: Add(PeriodType.Ticks, 500); Then how do I run the indicator SampleBoolSeries() on that secondary series? |
|
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 4,858
Thanks: 162
Thanked 579 times in 570 posts
|
Hello,
The Add() method would only be used for visual charting purposes. If you wanted to visualize this indicator on the chart from a secondary data series, you would need to manually add the indicator to your chart. However you can still reference the indicator methods in your strategy and specify which data series it is being calculated from Taking the SampleBoolSeries for example, the conditional logic would read: Code:
if(SampleBoolSeries(BarsArray[1]).BullIndication[0]) EnterLong(); More information on BarsArray can be found below: http://www.ninjatrader.com/support/h.../barsarray.htm
Matthew
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Member
Join Date: Nov 2008
Posts: 95
Thanks: 0
Thanked 0 times in 0 posts
|
Hi I think my question would really be: how to build a strategy and indicator referencing a external library? Is there an example for it?
|
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 4,858
Thanks: 162
Thanked 579 times in 570 posts
|
Hello,
It is possible to have your indicator or strategy read from an external file. Please see our Reference Sample on Using StreamReader to read from a text file http://www.ninjatrader.com/support/f...ead.php?t=3476
Matthew
NinjaTrader Customer Service |
|
|
|
|
|
#9 | |
|
Member
Join Date: Nov 2008
Posts: 95
Thanks: 0
Thanked 0 times in 0 posts
|
Quote:
Code:
protected override void Initialize()
{
// Add our indicators to the strategy for charting purposes
Add(MACD(12, 26, 9));
Add(SampleBoolSeries());
CalculateOnBarClose = true;
}
|
|
|
|
|
|
|
#10 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
Hello leontancfa,
Thanks for your note and I am replying for Matthew. Yes, the strategy will work fine even if you do not Add the indicator in the initialize section of the strategy.
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
#11 |
|
Member
Join Date: Nov 2008
Posts: 95
Thanks: 0
Thanked 0 times in 0 posts
|
what is the benefit of having a private variable,
Code:
#region Variables
private BoolSeries aBC;
#endregion
Code:
public BoolSeries ABC
{
get { return aBC; }
}
|
|
|
|
|
|
#12 | |
|
Senior Member
|
Quote:
ref: http://msdn.microsoft.com/en-us/library/w86s7x04.aspx |
|
|
|
|
|
The following user says thank you to koganam for this post: |
|
|
|
#13 |
|
Member
Join Date: Nov 2008
Posts: 95
Thanks: 0
Thanked 0 times in 0 posts
|
Thank you. so I read that reference. I saw one reason is to let outside the indicator only read, but not set the value of the inner variable.
Did I miss other reasons? |
|
|
|
|
|
#14 | |
|
Senior Member
|
Quote:
"Properties have many uses: they can validate data before allowing a change; they can transparently expose data on a class where that data is actually retrieved from some other source, such as a database; they can take an action when data is changed, such as raising an event, or changing the value of other fields." The funny thing about programming is that you may think at this time that you do not need any of those abilities, so you can dispense with them and just use a public variable. In my experience, however, sooner or later, if one continues development, one will find that he/she wants to do something which would be very easy to do, if only Properties had been used in the first place. Best practices get dubbed as such, because the collective wisdom of those who have come before us, have found out the hard way, that not doing things in that manner, often causes regrets down the road. Just my $0.02. |
|
|
|
|
|
The following user says thank you to koganam for this post: |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Shared Indicator | ScottB | Automated Trading | 2 | 08-04-2011 08:10 AM |
| Trying to update shared file | zacharydw00 | NinjaScript File Sharing Discussion | 7 | 11-02-2009 07:17 AM |
| Can I refer an indicator variables in a strategy ? | blarouche | General Programming | 3 | 07-13-2009 09:09 AM |
| Create methods that are shared by other indicators | xewoox | General Programming | 5 | 02-25-2009 02:09 PM |
| Shared Draww methods only worl in Panel 1 | scjohn | General Programming | 1 | 05-27-2007 12:51 PM |