Series functions with multiple time frames?

Questions about MultiCharts and user contributed studies.
Xyzzy
Posts: 162
Joined: 19 Mar 2011
Has thanked: 43 times
Been thanked: 79 times

Series functions with multiple time frames?

Postby Xyzzy » 30 Jun 2011

Hi,

I'm working on a strategy that uses both daily bars (as data1) and weekly bars (as data2). The weekly bars are used to determine setups based on the long-term trend, and the daily bars are used to determine specific entry points.

I would like to be able to determine the EMA of both the daily bars and the weekly bars within my signals. The pseudocode is:

Code: Select all

DailyEMA = XAverage( Close of data1, 11 ) ;
WeeklyEMA = XAverage( Close of data2, 11 ) ;
If DailyEMA > X AND WeeklyEMA > Y then begin ...
To do this, the code "WeeklyEMA = XAverage( Close of data2, 11 )" should only be evaluated once per week, rather than on every daily bar. However, MultiCharts will instead evaluate this function by default at the close of every daily bar. This will lead to incorrect results -- rather than calculating the EMA of the last 11 weekly bars, it will instead calculate the EMA based on on the _daily_ closes of the most-recent weekly bars.

I've also tried forcing this code to execute only once per week using the following code:

Code: Select all

If DayOfWeek(Date) = 5 then begin
WeeklyEMA = XAverage( Close of data2, 11 ) ;
end ;
However, this also doesn't seem to work. My understanding is that with series functions like XAverage, the function will be executed at the close of each and every bar, regardless of whether that function is actually called in the code during that bar. Consequently, the code will ignore the "If DayOfWeek..." statement, and calculate the WeeklyEMA result each time regardless, which leads to the same outcome as above.

Is there any way that I'm missing to get the result that I'm looking for -- an EMA of the data2 series, based on the timeframe of the data2 series? I could perhaps code my own EMA function that accomplishes this, but I'm hoping that I don't need to reinvent the wheel. Many thanks in advance.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Series functions with multiple time frames?

Postby TJ » 30 Jun 2011

Hi,

I'm working on a strategy that uses both daily bars (as data1) and weekly bars (as data2). The weekly bars are used to determine setups based on the long-term trend, and the daily bars are used to determine specific entry points.

I would like to be able to determine the EMA of both the daily bars and the weekly bars within my signals. The pseudocode is:

Code: Select all

DailyEMA = XAverage( Close of data1, 11 ) ;
WeeklyEMA = XAverage( Close of data2, 11 ) ;
If DailyEMA > X AND WeeklyEMA > Y then begin ...
To do this, the code "WeeklyEMA = XAverage( Close of data2, 11 )" should only be evaluated once per week, rather than on every daily bar. However, MultiCharts will instead evaluate this function by default at the close of every daily bar. This will lead to incorrect results -- rather than calculating the EMA of the last 11 weekly bars, it will instead calculate the EMA based on on the _daily_ closes of the most-recent weekly bars.

I've also tried forcing this code to execute only once per week using the following code:

Code: Select all

If DayOfWeek(Date) = 5 then begin
WeeklyEMA = XAverage( Close of data2, 11 ) ;
end ;
However, this also doesn't seem to work. My understanding is that with series functions like XAverage, the function will be executed at the close of each and every bar, regardless of whether that function is actually called in the code during that bar. Consequently, the code will ignore the "If DayOfWeek..." statement, and calculate the WeeklyEMA result each time regardless, which leads to the same outcome as above.

Is there any way that I'm missing to get the result that I'm looking for -- an EMA of the data2 series, based on the timeframe of the data2 series? I could perhaps code my own EMA function that accomplishes this, but I'm hoping that I don't need to reinvent the wheel. Many thanks in advance.
see post #5
EasyLanguage / PowerLanguage FAQ
viewtopic.php?f=16&t=6929

sptrader
Posts: 742
Joined: 09 Apr 2010
Location: Texas
Has thanked: 483 times
Been thanked: 274 times
Contact:

Re: Series functions with multiple time frames?

Postby sptrader » 30 Jun 2011

it's also a good idea to add this to the variable:

vars: WeeklyEMA(0,data2);

User avatar
Stan Bokov
Posts: 963
Joined: 18 Dec 2009
Has thanked: 367 times
Been thanked: 302 times

Re: Series functions with multiple time frames?

Postby Stan Bokov » 30 Jun 2011

TJ,

Just so you know, you can click on the orange post number, and you will get a unique link to that post in your navigation bar. You can then post it, so when ppl follow it, it'll jump directly to the post.

Xyzzy
Posts: 162
Joined: 19 Mar 2011
Has thanked: 43 times
Been thanked: 79 times

Re: Series functions with multiple time frames?

Postby Xyzzy » 30 Jun 2011

Thanks everyone! Exactly what I needed. I'll try it this evening.


Return to “MultiCharts”