logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
mastermedea  
#1 Posted : Tuesday, August 14, 2007 5:00:27 AM(UTC)
mastermedea

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 6/26/2007(UTC)
Posts: 12

Dear senior users, how can I create an exploration using both daily and weekly data? For example, I want to sort out those stocks offering oversold signals in daily charts and are on weekly uptrends. Thanks for any help1
amory  
#2 Posted : Tuesday, August 14, 2007 7:42:02 AM(UTC)
amory

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 4/18/2007(UTC)
Posts: 99
Location: sydney australia

for a start, how do you define the weekly uptrend, by what criteria?
mastermedea  
#3 Posted : Wednesday, August 15, 2007 8:57:28 AM(UTC)
mastermedea

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 6/26/2007(UTC)
Posts: 12

Well, my idea is to search for stocks that have weekly MACD up, or increasing 26w MA. Then from these stocks I look for those that have daily RSI/ Stochastics just crossing up from oversold levels. Not sure if this exploration helps, I am just studying into technical analysis and want to use Metastock to practice each strategy.
amory  
#4 Posted : Thursday, August 16, 2007 3:06:06 AM(UTC)
amory

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 4/18/2007(UTC)
Posts: 99
Location: sydney australia

don't know that it can't be done (using daily & weekly in one explo) but you can always change the weekly into daily by multiplying 26*5. example, something like

mov(macd(),130,e)>ref(mov(macd(),130,e),-5)

should give you the 26-wk avg, up on 26-week avg a week ago. only guessing, not sure if it solves the problem.

Justin  
#5 Posted : Thursday, August 16, 2007 9:14:51 AM(UTC)
Justin

Rank: Advanced Member

Groups: Registered, Registered Users, Unverified Users
Joined: 9/13/2004(UTC)
Posts: 673
Location: Salt Lake City, UT

Here is a Weekly MACD using Daily data with 12, 26, and 9 for the exponential calculations. This is not something I wrote but figured I'd pass it along.

friday:=DayOfWeek()=5;

newweek:=ROC(DayOfWeek(),1,$)<0 AND

Ref(DayOfWeek(),-1)<>5;

p1:=0.15;

p2:=0.075;

p3:=0.2;

px1:=If(friday,(p1*C)+((1-p1)*PREV),

If(newweek,(p1*Ref(C,-1))+((1-p1)*PREV),PREV));

px2:=If(friday,(p2*C)+((1-p2)*PREV),

If(newweek,(p2*Ref(C,-1))+((1-p2)*PREV),PREV));

px3:=If(friday,(p3*(px1-px2))+((1-p3)*PREV),

If(newweek,(p3*(px1-px2))+((1-p3)*PREV),PREV));

px1-px2

mstt  
#6 Posted : Thursday, August 16, 2007 4:12:14 PM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)

Here's my version of a weekly MACD for daily charts. Any exploration using this formula requires around 600 daily bars to produce an accurate result from the 26 week EMA module (variable X). With 3 PREV-based variables in the formula this makes for a rather slow exploration. The 26 week EMA formula has only 1 PREV-based variable so it runs a little faster but also requires around 600 daily bars. Note that both MACD and EMA formulas use the Forum DLL.

Roy

MetaStock Tips & Tools

{Weekly MACD}

{This indicator uses the Equis Forum DLL}

{Roy Larsen, 2004-2007}

{User settings}

N:=Input("Weekly MACD Signal Periods",1,19,9);

Q:=Input("Mode, 0=Static 1=Dynamic 2=Delayed",0,2,0);

{0, update on last bar of current frame}

{1, update on each new bar}

{2, update on first bar of new frame}

{Weekly frame timing}

{* Day counter from metastock@wabbit.com.au}

M:=Month();A:=Int((14-M)/12);D:=DayOfMonth();

Y:=Year()+4800-A;B:=M+(12*A)-3;

M:=D+Int((2+153*B)/5)+(365*Y)+Int(Y/4)-Int(Y/100)+Int(Y/400)-32045;

{*}I:=Int(M/7);

I:=I-ValueWhen(2,1,I);

G:=LastValue(Lowest(Sum(I>0,5))=5);

M:=G+I;F:=G+(M=0)*ExtFml("Forum.Sum",Ref(I,1),1);

A:=LastValue(Cum(1)-1)=Cum(1);

B:=Alert(A,2)*(A=0);

J:=If(F,1,If(Alert(F,2)=0 AND M,2,0));

J:=If(A+LastValue(J)>2 OR B+(Q=1)=2,1,J);

J:=If(G,1,If(Q=2 OR Cum(J)<=1,M*2,J));

{Weekly CLOSE}

K:=ValueWhen(1,J,If(J=1,C,ValueWhen(2-G,1,C)));

{Calculate and plot weekly MACD and signal line}

X:=0.15; Y:=0.075; N:=2/(N+1); J:=J>0;

X:=If(Cum(J)=1,K,PREV*If(J,1-X,1)+J*K*X);

Y:=If(Cum(J)=1,K,PREV*If(J,1-Y,1)+J*K*Y);

R:=X-Y;

Z:=If(Cum(J)=1,R,PREV*If(J,1-N,1)+J*R*N);

Z; {Weekly MACD signal line}

R; {Weekly MACD}

{end}

{Weekly EMA - Close}

{This indicator uses the Equis Forum DLL}

{Roy Larsen, 2004-2007}

{User settings}

N:=Input("Weekly EMA / Close, Periods",1,99,26);

Q:=Input("Mode, 0=Static 1=Dynamic 2=Delayed",0,2,1);

{0, update at last bar of current frame}

{1, update on each new bar}

{2, update on first bar of new frame}

{Weekly frame timing}

{* Day counter from metastock@wabbit.com.au}

M:=Month();A:=Int((14-M)/12);D:=DayOfMonth();

Y:=Year()+4800-A;B:=M+(12*A)-3;

M:=D+Int((2+153*B)/5)+(365*Y)+Int(Y/4)-Int(Y/100)+Int(Y/400)-32045;

{*}I:=Int(M/7);

I:=I-ValueWhen(2,1,I);

G:=LastValue(Lowest(Sum(I>0,5))=5);

M:=G+I;F:=G+(M=0)*ExtFml("Forum.Sum",Ref(I,1),1);

A:=LastValue(Cum(1)-1)=Cum(1);

B:=Alert(A,2)*(A=0);

J:=If(F,1,If(Alert(F,2)=0 AND M,2,0));

J:=If(A+LastValue(J)>2 OR B+(Q=1)=2,1,J);

J:=If(G,1,If(Q=2 OR Cum(J)<=1,M*2,J));

{Weekly CLOSE}

K:=ValueWhen(1,J,If(J=1,C,ValueWhen(2-G,1,C)));

{Calculate and plot weekly EMA of CLOSE }

N:=2/(1+N);J:=J>0;

If(Cum(G+J>0)<3-G,K,PREV*If(J,1-N,1)+J*K*N);

{end}

wabbit  
#7 Posted : Thursday, August 16, 2007 9:18:10 PM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
Notwithstanding the excellent posts above, I think the fastest solution and easiest to implement is to have multiple explorations and use the results of the previous exploration in the subsequent explorations; after all that is why the functionality exists!

e.g.

Code:
{myExploration - Part 1}
{weekly data}
{filter}
x:=MACD();
y:=x > mov(x,9,e);
y and alert(y=0,2);


{myExploraton - Part 2}
{daily data}
{use results from previous exploration}
{filter}
ROC(Mov(C,30,S),1,$)>0;


This will return all stocks where the weekly MACD has moved up through the trigger line, and the daily 30 day SMA is rising.

Hope this helps.

wabbit [:D]

mastermedea  
#8 Posted : Friday, August 17, 2007 4:50:32 AM(UTC)
mastermedea

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 6/26/2007(UTC)
Posts: 12

Thanks everyone, I need another help and rather post it here instead of creating a new topic to save forum space. I want to return the C value on the day nth periods ago when a condition is met. Example:

nth:=barssince(c>ref(c,-1));

Now how I get C nth periods ago? The formula ref(c,-1*nth) does not work as it requires a constant, not a formula or variable.

Any advice is very much appreciated, mastermedea

wabbit  
#9 Posted : Friday, August 17, 2007 10:12:36 AM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
have a look for the ValueWhen() function in the MS Users Manual.


wabbit [:D]


mastermedea  
#10 Posted : Saturday, August 18, 2007 4:15:06 AM(UTC)
mastermedea

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 6/26/2007(UTC)
Posts: 12

Really don't know why the valuewhen() function doesn't work when the expression is peak() or trough(). I have tried the following: valuenwhen(1,peak(1,c,5),v) , valuewhen(1,peak(1,c,5),macd()) but it just returns the current value of V and MACD. It works when the expression is something like c>mov(c,26,e).

By the way, no other way to track the value of a data array n bars ago, where n is not a constant but results from a formula?

wabbit  
#11 Posted : Saturday, August 18, 2007 10:08:43 PM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
mastermedea wrote:
Really don't know why the valuewhen() function doesn't work when the expression is peak() or trough(). I have tried the following: valuenwhen(1,peak(1,c,5),v) , valuewhen(1,peak(1,c,5),macd()) but it just returns the current value of V and MACD.

MS Users Manual wrote:
SYNTAX valuewhen ( Nth, EXPRESSION, DATA ARRAY )

FUNCTION Returns the value of the DATA ARRAY when the EXPRESSION was true on the Nth most recent occurrence. This includes all data loaded in the chart.

MS Users Manual wrote:
SYNTAX peak( Nth, DATA ARRAY, % MINIMUM CHANGE )

FUNCTION Plots the value of DATA ARRAY Nth peak(s) ago. This uses the Zig Zag function (see Zig Zag) to determine the peaks. N=1 would return the value of the most recent peak. N=2 would return the value of the 2nd most recent peak. Etc.

The ValueWhen() function evaluates an expression as either TRUE or FALSE. A TRUE condition is any value <>0 and FALSE is any value =0. If we look at the Peak/Trough functions, they return values of the DATA ARRAY when the Peak/Trough condition was x-recently met. If applying this to your price data then it is most unlikely the value returned here will be zero, so the non-zero value is indicating a TRUE condition. As you are now returning a TRUE condition on every bar since a Peak/Trough was formed, the ValueWhen() function is correctly returning the value of the VOLUME, or MACD() or whatever you are attempting.

You need to make sure the expression in the ValueWhen() function can be evaluated as TRUE or FALSE:
Code:
ValueWhen(1,C=Peak(1,C,5),v);

mastermedea wrote:
It works when the expression is something like c>mov(c,26,e).

Really? I doubt it. Maybe you have achieved a result you want, but this will be due more to good luck than good coding and good logic!

mastermedea wrote:
By the way, no other way to track the value of a data array n bars ago, where n is not a constant but results from a formula?

You could achieve a similar result using the PeakBars/TroughBars functions and the variable lookback Ref() function found in the free Forum.dll
Code:
prd:=PeakBars(1,C,1);
data:=extfml("Forum.Ref",VOLUME,prd);
{return}
data;

There has been much written in the Forum about these functions and achieving similar goals. A careful perusal of the Form posts and the MS Users Manual will reveal even more information!

Also, make sure you are FULLY aware of the limitations of the dynamic nature of the Peak/Trough/Zig/LastValue etc functions.


Hope this helps.

wabbit [:D]

Users browsing this topic
Guest (Hidden)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.