PDA

View Full Version : indicator values multi vs single timeframe


ceesvh
09-19-2007, 04:51 AM
Hello,

I was changing my singletime frame to a multitimeframe strategy and I encountered some problems I could note explain. So I wrote the most simple script printing the value of the EMA(34).
The first script is a single time frame running on a 5 min timeframe.
Value1=EMA(34)[0];
Print("Script1"+" "+Value1.ToString()):

The second script is a multitime frame. The primary timeframe is a 1 min and the secondary timeframe is a 5 min time frame on the same instrument
if(BarsInProgress==1)
{
Value1=EMA(34)[0];
Print("script2"+" "+Value1.ToString());
}

Then I had both scripts running simultaneously on live charts of the dax this morning.

The outcome of this test is that the values of the EMA's are different.
To my understanding both ema's should be the same.
Is there an explanation?

NinjaTrader_Ray
09-19-2007, 07:05 AM
They should be the same provided that the range settings are the same on the chart. We will run some tests today and report back our findings.

ceesvh
09-19-2007, 07:47 AM
Ray,

Thanks for your quick reply.
I would like to go a little further
I have extended the multitimeframe script further. My goal is (I know it will be implemented in the next release) to issue orders from the two timeframes.
My thought was that the barclose of bar 5 of the 1 min bars should coincide with barclose of the 5min bar. So it is a matter of barcounting of the 1 min bar.

if(BarsInProgress==0)
{
Barcount=Barcount+1;
if( Barcount==5)
{
SMA1=EMA(34)[0];
Print("test2a"+" "+"ĖMA"+" "+SMA1.ToString());
}
}
if(BarsInProgress==1)
{
SMA1=EMA(34)[0];
Print("test2b"+" "+"ĖMA"+" "+SMA1.ToString());
Barcount=0;
}

My original idea was that these ema's are also the same but they are not the same and differ from the ema in the single timeframe strategy.

Is it possible to workaround in such a away that it is possible to trade from both timeframes? Apparently the above approach is not the correct one.

NinjaTrader_Josh
09-19-2007, 09:11 PM
Hi ceesvh,

I ran tests on your original post, but could not reproduce the problem. Script 1 and Script 2 were printing the same EMA values on my end. Please try my attached strategies and see if they work. I used the simulator on 1sec (primary) and 5sec (secondary) charts. Run Test1 on a 5second chart and run Test2 simultaneously on a 1second chart.

About your second issue, I believe the EMAs are actually suppose to be different the way your code is setup. Adding the barcounter only tells it to print the EMA(34) of the 1min bars period every fifth 1min bar. It does not tell it to calculate the EMA(34) on a 5min bar spacing. When you call the EMA(34)[0] it is still on the 1min bars and it does its calculations based on 1min. If you wanted to get the 5min EMA while in the 1min BarsInProgress you will need to do something like
EMA(BarsArray[1], 34)[0]