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 01-05-2011, 01:07 PM   #1
trader2be
Member
 
Join Date: Nov 2007
Posts: 63
Thanks: 0
Thanked 0 times in 0 posts
Default Referencing DataSeries with multi timeframe indicators

Hello everyone,

I have read every single existing thread on this topic but I still have not found a solution to my problem.

Here it is: I have created a multi-timeframe indicator called ContextAnalyzer. This indicator performs an analysis of two timeframes and populates a DataSeries object (myContextSeries) with the results of the analysis (a single value for each bar of the primary data series). I have completely tested this indicator and it works like a charm when applied to a chart. I have even done as far as printing the CurrentBar and myContextSeries[0] for each bar of the primary series to verify the logic. So far, so good....

myContextSeries is exposed publicly via the following code:

[Browsable(false)]
[XmlIgnore()]
public DataSeries ContextMOM
{
get { return myContextSeries; }
}

So far I assume that all is good...

I would now like to use the values of the DataSeries referenced above in another indicator, let's call it ContextConsumer. Here is my test code for this:

Code:
    public class ContextConsumer: Indicator
    {
        private ContextAnalyzer myContext;

        protected override void Initialize()
        {
            Overlay                = true;
        }

        protected override void OnStartUp()
        {
            myContext = ContextAnalyzer(PeriodType.Minute,3);
        }
        protected override void OnBarUpdate()
        {

            double dContext = myContext.ContextMOM[0];

            if (dContext == -2) BarColor = Color.Red;
            if (dContext == -1) BarColor = Color.Magenta;
            if (dContext == 1) BarColor = Color.LightBlue ;
            if (dContext == 2) BarColor = Color.Blue ;

        }
The problem with all this is that the values returned by dContext are completely out of whack with the values produced by ContextAnalyzer. I can't quite diagnose the problem and have no idea as to what is going on.

Any help is greatly appreciated.
trader2be is offline  
Reply With Quote
Old 01-05-2011, 01:46 PM   #2
NinjaTrader_Brett
NinjaTrader Customer Service
 
NinjaTrader_Brett's Avatar
 
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,499
Thanks: 109
Thanked 291 times in 280 posts
Default

Hello,

Thanks for your forum post.

When using multi series and data series objects. You must sync the data series to the object it will be tracking. Please see this guide:

http://www.ninjatrader.com/support/f...ead.php?t=3572

Let me know if I can be of further assistance.
NinjaTrader_Brett is offline  
Reply With Quote
Old 01-05-2011, 02:16 PM   #3
trader2be
Member
 
Join Date: Nov 2007
Posts: 63
Thanks: 0
Thanked 0 times in 0 posts
Default

Hi Brett,

I have already read that post several times and my code is in line with it.

The DataSeries myContextSeries is correctly synchronized to the primary series in ContextAnalyzer. I didn't create a secondary series for the other timeframe since I didn't have any use for it.

Is any synchronization required in the calling indicator "ContextConsumer" required?

David
trader2be is offline  
Reply With Quote
Old 01-05-2011, 04:21 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

David,

Not exactly sure what you are doing. We do not support this "ContextAnalyzer" object you are calling nor would have any idea what it is. DataSeries are only able to sync to DataSeries as outlined in the reference sample. You can do one of the following:

1. In Initialize() you call someDataSeries = new DataSeries(this);
The "this" reference syncs it to the primary bars.

2. In OnBarUpdate() you can sync to a secondary bars series.
someDataSeries = new DataSeries(SMA(BarsArray[1], 50));
The BarsArray[1] is what the someDataSeries is synced to.

You are doing neither of the above.
NinjaTrader_Josh is offline  
Reply With Quote
Old 01-05-2011, 08:18 PM   #5
trader2be
Member
 
Join Date: Nov 2007
Posts: 63
Thanks: 0
Thanked 0 times in 0 posts
Default

Josh - there is a similar thread here: http://www.ninjatrader.com/support/f...622#post213622

ContextAnalyzer is simply my indicator, mentioned in this thread as an example. This indicator uses a second timeframe to perform an analysis and saves the results of this analysis in a DataSeries object. This works perfectly fine. The problem that I am facing however, is when trying to use this DataSeries from yet another indicator that only has primary bars. When doing this, the values returned by the DataSeries of ContextAnalyzer are all wrong. In the other thread, snaphook seems to be experiencing the exact same problem. I do not believe that the example that you provide with the secondary dataseries that is synced in OnBarUpdate() has any bearing on this problem.
trader2be is offline  
Reply With Quote
Old 01-06-2011, 06:35 AM   #6
NinjaTrader_Brett
NinjaTrader Customer Service
 
NinjaTrader_Brett's Avatar
 
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,499
Thanks: 109
Thanked 291 times in 280 posts
Default

Trader,

Just so that I understand correctly. Your trying to use variables from another indicator in another indicator or strategy? Therefor your trying to do communication between strategies/indicators?

I look forward to assisting you further.
NinjaTrader_Brett 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
Dataseries problem in Multi-timeframe strategy bridenour Automated Trading 2 07-25-2009 05:06 AM
Multi timeframe dataseries astrolobe Strategy Development 1 06-17-2009 05:47 AM
Multi-timeframe indicator referencing LazKz Strategy Development 3 03-18-2009 07:24 AM
DataSeries on supplementary series in multi-timeframe strategy DavidD99 Strategy Development 1 11-30-2008 03:39 AM
Referencing DataSeries elements in Multi-timeframe Strategies dbw451 Strategy Development 2 09-06-2008 09:17 AM


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