![]() |
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Join Date: Mar 2007
Location: , ,
Posts: 17
Thanks: 0
Thanked 0 times in 0 posts
|
Hello, trying to port my 250KLOC EasyLanguage script to NT6 and have come up with a couple of questions.
1) Re: Multi-TimeFrame Strategy: How do I find the "Period" and "PeriodType" for the primary barseries? My strategy utilizes both volume and minute charts and then creates larger time/volume frame charts based upon what period the base chart is running in. Is there a property value somewhere which has this information? 2) Not really a question but a request..... What I would*really* like to do is have the ability toeither resize the volume charts and/or remove/add them at the beginning of the day based upon some average of daily volume and be able to backtest. Any chance this functionality could be supported in the future? Thanks in advance, Best Regards, Jim |
|
|
|
|
|
#2 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
Hi Jim,
1) You can access Bars.Period.Id Bars.Period.Value Id returns a value of PeriodType. So, PeriodType.Volume, PeriodType.Minute etc... Value returns an integer value for the interval. Bars points to the current BarsInProgress (calling the OnBarUpdate) event. So, when BarsInProgess == 0, you will have the primary bars object. Alternatively, you can access BarsArray[0].Period which will always point to the primary bars object. 2) I will add this as a feature request for future consideration. Ray
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Join Date: Mar 2007
Location: , ,
Posts: 17
Thanks: 0
Thanked 0 times in 0 posts
|
Thank You! Got it.
Jim |
|
|
|
|
|
#4 |
|
Join Date: Nov 2006
Location: , ,
Posts: 66
Thanks: 0
Thanked 0 times in 0 posts
|
Can you please describe the usage of PeriodType and PeriodType.Volume, PeriodType.Minute,etc.
Thank you. |
|
|
|
|
|
#5 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
PeriodType is an enum representing the support perdiod/interval type of a bars object.
PeriodType.Minute PeriodType.Seconds PeriodType.Tick etc... Some people may have indicators that set a variable value based on the interval being used.
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#6 |
|
Junior Member
Join Date: Oct 2007
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
|
Hi I've been trying to get BarsArray[0].Period.Id and BarsArray[0].Period.Value and use them to initialize a second time period series.
Essentially I try to do the following Code:
protected override void Initialize()
{
Add(BarsArray[0].Period.Id, BarsArray[0].Period.Value * 2);
}
Is the BarsArray not initialized until after Strategy.Initialize() has returned? |
|
|
|
|
|
#7 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
That is correct. The error message from the log when you do that code is as follows: Failed to call 'Initialize' for strategy 'MultiTimeFrame': 'BarsArray' property can not be accessed from within 'Initialize' method.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#8 | |
|
Junior Member
Join Date: Oct 2007
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
|
Quote:
I've also been trying to plot from two time frames. I notice that if I Add() the same indicator with different parameters, it generates two separate instances. I want to have one indicator plot the results from the primary time frame, and the second plot the results from a second time frame. But since I can't access the BarsArray object in Strategy.Initialize(), how can I achieve this? I've tried doing the following: Code:
#region variables
...
private bool oneTimeFlag = false;
...
#endregion
...
protected override void Initialize()
{
Add(PeriodType.second, 480);
Add(MyIndicator(0));
Add(MyIndicator(1));
}
protected override void OnBarUpdate()
{
if(BarsInProgress == 1) {
if(!oneTimeFlag) {
Indicators[1].Input = BarsArray[1];
oneTimeFlag = true;
}
}
}
Is it possible to plot indicator values from different time frames, and if so, what is the correct way of doing so? Thanks in advance. |
|
|
|
|
|
|
#9 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
I don't think it is possible because of the way the chart would be. One time frame would have more points than the other time frame and plotting something like SMA wouldn't match up. For instance, trying to plot the SMA(5) of a 1-min bar wouldn't work on a 5-min chart simply because where would the extra 4 data points from the 1-min SMA(5) go.
If you want to access values of the different time period's SMA, this is possible. You can do something like Code:
if (SMA(20)[0] > 100 && SMA(BarsArray[1], 20)[0] > 200)
// Do something
The way you have done it seems to be a workaround that fits your bill though. I don't know of a better 'official' way to do it so continuing using your way should be fine. Edit: Actually you might want to check the values on your indicator plots. It might not match up with the values you wanted.
Josh
NinjaTrader Customer Service
Last edited by NinjaTrader_Josh; 10-03-2007 at 12:34 AM.
|
|
|
|
|
|
#10 | ||
|
Junior Member
Join Date: Oct 2007
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
|
Quote:
Heh, but it doesn't really work. NT seems to loose track of the plots after a while. After some digging I found this in Help (here): Quote:
So now I'm just wondering how this affects indicators accessed from within strategies. Say I have a 1 second primary time frame, and add a 5 minute secondary time frame. If I call a custom indicator that sets up its own DataSeries to store series data, when BarsInProgress == 1, does that indicator actually hold datapoints on a second resolution (in sync with the primary time frame)? And when I do something like: Code:
if(BarsInProgress==1) {
MyIndicator theIndicator = MyIndicator(0);
Print(theIndicator.MyDataSeries[5].ToString());
}
And what if my primary time frame has a longer period than my secondary one (e.g. primary is 5 minute period, while secondary is 1 second)? If the indicator has a custom Dataseries that is sync'd to the primary period of 5 minutes, what happens to all the data points for the 1 second time frame?
Last edited by qbit9; 10-03-2007 at 12:50 AM.
Reason: typo
|
||
|
|
|
|
|
#11 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
I believe you would get the value of 5 seconds ago since like the message said, it is only synced to the primary bars. I would think there are no data points for 1-sec when your primary period is 5mins. The indicator isn't run on a 1-sec time frame thus no data points. I have never tried using DataSeries in the manner you are trying for before.
To make things simple, if you don't use DataSeries and just use the indicator itself, you can access the desired time period by various means such as Code:
if (BarsInProgress == 1)
Print(myIndicator()[0].ToString());
Code:
Print(myIndicator(BarsArray[1])[0].ToString());
Josh
NinjaTrader Customer Service
Last edited by NinjaTrader_Josh; 10-03-2007 at 01:25 AM.
|
|
|
|
|
|
#12 |
|
Junior Member
Join Date: Oct 2007
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
|
Hmmm. I guess I need to rethink my implementation. The reason I'm using DataSeries is because I need to do some intermediate calculations on series data. Essentially I'm trying to establish an envelope that is a moving average plus and minus the range. But I need to smooth that envelope exponentially and thus need to store the values in two DataSeries so that I can feed it to EMA. But if the data points are out of sync with the bar numbers, I'm probably getting the wrong results. Arrrgh. Bummer.
|
|
|
|
|
|
#13 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
Hi qbit9,
I ran several tests to see what happens with DataSeries during multi-time frames and the results are promising. You can use them and they will be linked to the proper time frame they were called from (they will be synced with whichever bar). Here are my test files. I tested it with a DataSeries set to take on the values of SMA(14) and when I call it from within a strategy it prints out the proper SMA(14) value across both time frames.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#14 |
|
Junior Member
Join Date: Oct 2007
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
|
Wow, thanks! I'll definitely check them out. I was banging my head against this issue all day!
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|