NinjaTrader Support Forum  
X

Attention!

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


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 07-15-2007, 10:45 AM   #1
whitmark
Certified NinjaScript Consultant
 
Join Date: Nov 2005
Location: Virginia, USA
Posts: 441
Thanks: 0
Thanked 12 times in 7 posts
Send a message via Skype™ to whitmark
Default BarsInProgress > 0 DataSeries Operations

I am working on a multiple-timeframe strategy that uses three timeframes in all and has some fairly envolved logic for each. Once I resolve each timeframe's partial trading signal, I hope to push this value (or related values) to its own data series such that I can evaluate the conditions (for the current bar and previous bars) across all timeframes before submitting a trade as follows:

Code:
...
if (BarsInProgress == 0)
{
    if (ThisComplexTimeFrame0LogicTrue)
        MTF1signal.Set(1);
}
if (BarsInProgress == 1)
{
    if (ThisComplexTimeFrame1LogicTrue)
        MTF2signal.Set(1);
}
if (BarsInProgress == 2)
{
    if (ThisComplexTimeFrame2LogicTrue)
        MTF3signal.Set(1);
}
...
if (BarsInProgress == 0)
{
     if (MTF1signal[0] == 1 &&
         MTF1signal[1] !=  1 &&
         MTF2signal[0] == 1 &&
         MTF2signal[1] !=  1 &&
         MTF3signal[0] == 1 &&
         MTF3signal[1] !=  1 )
     {
        EnterLong();
     }
}
...
In this context, I would think that the reference to MTF3signal[0] would be the last value I set when BarsInProgress == 2. However, I am getting results that suggest that DataSeries collections are only available for the BarsArray[0] series. Please confirm.

While in a BarsInProgress = 0 event, is there a way to get dataseries values that where set during other BarsInProgress events? if I can't get this to work, I will likely substitute the dataseries with private variables, arrays, or queues.

Regards,

Whitmark
Last edited by whitmark; 07-15-2007 at 10:51 AM.
whitmark is offline  
Reply With Quote
Old 07-16-2007, 02:00 AM   #2
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

How have you created the MTF1Signal data series?
NinjaTrader_Dierk is offline  
Reply With Quote
Old 07-16-2007, 02:40 AM   #3
whitmark
Certified NinjaScript Consultant
 
Join Date: Nov 2005
Location: Virginia, USA
Posts: 441
Thanks: 0
Thanked 12 times in 7 posts
Send a message via Skype™ to whitmark
Default

Yes, please see below. I have since moved on and used private variables as substitutes for these signal dataseries, but would like to understand how this can work for future reference when the signal lookback might be more than just one bar back. Thanks.

Whitmark

Code:
#region Variables
...
DataSeries MTF1signal;
DataSeries MTF2signal;
DataSeries MTF3signal;
...
#endregion

protected override void Initialize()
{
     ...
     MTF1signal = new DataSeries(this);
     MTF2signal = new DataSeries(this);
     MTF3signal = new DataSeries(this);
     ...
}
whitmark is offline  
Reply With Quote
Old 07-16-2007, 02:51 AM   #4
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

I see. The CurrentBar index of the series then is in sync with BarsArray[0], meaning MTF3signal[0] "points" to the same index as BarsArray[0][0].
NinjaTrader_Dierk is offline  
Reply With Quote
Old 07-16-2007, 03:00 AM   #5
whitmark
Certified NinjaScript Consultant
 
Join Date: Nov 2005
Location: Virginia, USA
Posts: 441
Thanks: 0
Thanked 12 times in 7 posts
Send a message via Skype™ to whitmark
Default

Okay . . . so how do I synchronize a dataseries with a BarsArray series other than 0? An example would be apprecated.
whitmark is offline  
Reply With Quote
Old 07-16-2007, 03:01 AM   #6
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

You can't.
NinjaTrader_Dierk is offline  
Reply With Quote
Old 07-16-2007, 03:52 AM   #7
whitmark
Certified NinjaScript Consultant
 
Join Date: Nov 2005
Location: Virginia, USA
Posts: 441
Thanks: 0
Thanked 12 times in 7 posts
Send a message via Skype™ to whitmark
Default

Alright . . . for clarification then, if I am setting signal values into MTF2signal and MTF3signal dataseries when BIP = 1 and BIP = 2 occur respectively . . . and then comes a long a BIP = 0 event, do the previously set values for MTF2signal and MTF3signal get pushed to the [1] slot when the next BarArray[0] bar prints?

If so, in the example context, would this suggest the modified composit trade signal logic would be more appropriate realizing that it is synchronized to BarArray[0]?

Code:
...
if (BarsInProgress == 0)
{
     if (MTF1signal[0] == 1 &&
         MTF1signal[1] !=  1 &&
         MTF2signal[1] == 1 &&
         MTF2signal[2] !=  1 &&
         MTF3signal[1] == 1 &&
         MTF3signal[2] !=  1 )
     {
        EnterLong();
     }
}
...
Clearly, the modified code above is not what I had originally intended but hopefully useful to fleshout the point. Do you recommend the use of an alternative data collection type that allows the same FIFO value setting capability, supports bars ago referencing for a limited lookback period, and can be synchronized (or set) to each BIP event? Just looking for a directional answer on this one. Thanks.

Regards,

Whitmark
whitmark is offline  
Reply With Quote
Old 07-16-2007, 03:58 AM   #8
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

Let me try to clarify: There is a CurrentBar "pointer" for any bar series and your data series below is just in sync with the the "primary" bar series: whenever the CurrentBar "pointer" for the primary series is moved, then the CurrentBar "pointer" for your series is moved.
NinjaTrader_Dierk 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
Exposing non dataseries variable tquinn General Programming 10 05-17-2007 04:12 PM
Meaning of Message: Order was placed in incorrect 'BarsInProgress' context? plipa Strategy Development 9 04-22-2007 08:54 AM
Hiding a plotted DataSeries in an indicator tquinn Indicator Development 7 01-13-2007 11:42 AM
Exposing a non DataSeries property in an indicator tquinn Indicator Development 4 01-11-2007 02:29 PM


All times are GMT -6. The time now is 12:34 PM.