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

Notification

Icon
Error

Options
Go to last post Go to first unread
annonymous  
#1 Posted : Thursday, December 2, 2010 8:02:37 AM(UTC)
annonymous

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 9/5/2009(UTC)
Posts: 18

Hello,

I would like to compute an arithmetic average of volume exchanged on a minute by minute basis only for those minutes where the close value changed from the previous minute's close. I need to use the result of this average to build an indicator.

I know there is no loop mechanism and I was thinking of an workaround. Is there a way to remove from the volume array those values for which close(crt)<=close(crt-1) and then compute the average for the remaining array. For the average I was thinking of using a simple mov, if there is a function that tells me the length of an array.

Can somebody point out a way to do this in metastock?

Regards,
Mihaela
vienna  
#2 Posted : Thursday, December 2, 2010 8:49:38 AM(UTC)
vienna

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 12/14/2009(UTC)
Posts: 140
Location: Austria

Hi,
I have no intraday data and so I currently haven't used minutes data in metastock, but I think it should work like with daily data?

Try this code and play around with it:

Code:

n:=Input("Period:",1,3600,10);

sumVol:=Sum(If(C>Ref(C,-1),V,0),n);
m:=Sum(If(C>Ref(C,-1),1,0),n);

x:=sumVol/m;
x;

annonymous  
#3 Posted : Saturday, December 4, 2010 4:13:04 AM(UTC)
annonymous

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 9/5/2009(UTC)
Posts: 18

Hey and thanks for the interest to help.

What I need is something that computes once an average for a part of the graph, but this formula plots a chart based on previous values.

Let's say I have one chart composed of three weeks of daily data. I need to calculate the average daily volume for a week, but in this average computation i will only include the volume for the days when close was bigger than the day before. So this would be a formula that computes the volume average in one week. In your example, the sum takes into account only the last 'n' values, while I need the whole week.

After this, I will go over every day in the chart and compare its volume to the average volume.
Using the formula you provided for one day, let's say wednesday, it will compute an average based only on past values, I can't use it to compute an average for this whole week.

PS I am asking these questions because I am trying to compute Pascal Willain indicators described in Value in Time: Better trading through Effective Volume (and mentioned first in Alexander Elder's Entries and Exits), but as I am having difficulties plotting even the Large Effective Volume, I am wondering if there is an available Metastock plugin for this or if someone is willing to do it for money.


vienna  
#4 Posted : Monday, December 6, 2010 6:08:16 AM(UTC)
vienna

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 12/14/2009(UTC)
Posts: 140
Location: Austria

If I understood you right than the code below can be a sample- it's not very elegant - but calculates only the sum (average) of volume only for the the week of every calculation.
(This means on monday only the value for monday if close was higher than the day before;
on tuesday the sum of monday and tuesday; on wednesday the sum of all three days; and so on)

Code:

n:=DayOfWeek();

mycount:=If(C>Ref(C,-1),1,0);
myvol:=If(C>Ref(C,-1),V,0);

sumVol:=If(n=1,Sum(myvol,1),0);
sumVol:=If(n=2,Sum(myvol,2),sumVol);
sumVol:=If(n=3,Sum(myvol,3),sumVol);
sumVol:=If(n=4,Sum(myvol,4),sumVol);
sumVol:=If(n=5,Sum(myvol,5),sumVol);

m:=If(n=1,Sum(mycount,1),0);
m:=If(n=2,Sum(mycount,2),m);
m:=If(n=3,Sum(mycount,3),m);
m:=If(n=4,Sum(mycount,4),m);
m:=If(n=5,Sum(mycount,5),m);
m;


x:=sumVol/m;
x;


Another way would be to use the lastvalue(n+prev-prev) trick, but this didn't display the indicator correctly on my chart and so I changed it back to the if statements...
annonymous  
#5 Posted : Saturday, December 11, 2010 6:41:06 AM(UTC)
annonymous

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 9/5/2009(UTC)
Posts: 18

Because I'm not very familiar with the Metastock formula language and I don't know how I can use your code so that on a Thursday I can compare the volume with the average volume for the whole week (average only of the volume that corresponds to a price inflection).

Further help would be kindly appreciated.

Thank you,
Mihaela
vienna  
#6 Posted : Monday, December 13, 2010 2:09:37 AM(UTC)
vienna

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 12/14/2009(UTC)
Posts: 140
Location: Austria

should be something like this:

Code:


n:=DayOfWeek();

mycount:=If(C>Ref(C,-1),1,0);
myvol:=If(C>Ref(C,-1),V,0);

sumVol:=If(n=4,Sum(myvol,4),0);
m:=If(n=4,Sum(mycount,4),0);
thuVol:=If(n=4,V,0);

avgVol:=If(m=0,0,sumVol/m);

If(avgVol=0,0,thuVol/avgVol-1);


In this example the result is greater than 0 if the thursday volume is higher than the average, less than 0 if the average volume is greater than thursday volume.
annonymous  
#7 Posted : Monday, December 13, 2010 4:51:55 AM(UTC)
annonymous

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 9/5/2009(UTC)
Posts: 18

1. But if you use this:
Sum(myvol,4) and Sum(mycount,4)
doesn't it mean that you do the calculation for the last 4 days ? Meaning that if it's Thursday, the average will be for Monday, Tuesday, Wednesday and Thursday, leaving out Friday ?

2. Just to make sure I understand correctly, from
mycount:=If(C>Ref(C,-1),1,0);
I get it that mycount is a scalar, not a vector right ? So when you do this: Sum(mycount,4) does it take the last 4 values computed for mycount (the current one and the previous 3 iterations) ?

vienna  
#8 Posted : Monday, December 13, 2010 9:41:23 AM(UTC)
vienna

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 12/14/2009(UTC)
Posts: 140
Location: Austria

1:
You are right. Sorry my english is not as good as it should be - I understood that you want the average for only for the same week (starting from monday). If you want to include the friday of the last week you have to use Sum(myvol,5) and Sum(mycount,5)

2:
mycount:=If(C>Ref(C,-1),1,0); checks if the close of today is greater than the close of yesterday and sets mycount=1. If the close of today is less than close of yesterday it would be 0.
The same calculation is done for all the days before.

Sum(mycount,5) counts up for how many days the close was greater than the close of the day before. This will you need to calculate the average, because you have to divide the volume through the number of day's (which is only 5 when every day's close was greater than the day before).
annonymous  
#9 Posted : Monday, December 20, 2010 7:15:34 AM(UTC)
annonymous

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 9/5/2009(UTC)
Posts: 18

I think I need to rephrase the problem. As you told me you don't work with intraday data, I tried to formulate my 'question' in terms of daily data, but I'm not getting the expected result :)

So let me start over. I have 1-min data and a formula that looks at the volume of shares traded every minute. I compare the volume traded on a certain MINUTE to something called average effective volume.

Average effective volume is an arithmetic average of volumes traded this current DAY. It takes into account only those minutes where there is a price inflection. So, to compute this average:
1. I look at every minute since the day started until the day ended (from 9:30 a.m. to 4 p.m.! NOT last n minutes, NOT all minutes until now, BUT ALL minutes of today).
2. I see if the closing price is different than the close of the previous minute
3. if the close is different, I include this volume in the computation of the average.

I need a way to compute this average so that I can use it inside my formula.

In Metastock language I only saw moving averages computing an average of the last n values of a vector. I found nothing that would be even close to what I described above.

Please if anyone thinks I am not clear enough let me know. I find it very strange that from all the people that use Metastock and frequent this forum and from 900 viewers...nobody knows how to solve this problem, which in other programming languages is something that you do in a 'Hello world' program :)

@viena : let me know if now I was more clear, because it seemed to me that i didn't manage to explain to you very well what i was trying to do.
MS Support  
#10 Posted : Monday, December 20, 2010 4:34:25 PM(UTC)
MS Support

Rank: Advanced Member

Groups: Moderators, Registered, Registered Users, Subscribers
Joined: 10/8/2010(UTC)
Posts: 1,967

Thanks: 93 times
Was thanked: 156 time(s) in 151 post(s)
This request is complicated because it requires data earlier in the day to look some unknown number of bars into the future to sum the volume for that day. MetaStock has a function to search back in time for an event but it does not look forward at "future" data. The Ref() function can look forward a set number of bars but the amount of time to look forward will change throughout the day and that does not work with Ref().

The only way I can see to accomplish this calculation is with an external DLL.
annonymous  
#11 Posted : Tuesday, December 21, 2010 2:09:07 AM(UTC)
annonymous

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 9/5/2009(UTC)
Posts: 18

Thank you, this is what I was suspecting, but I was waiting for confirmation from somebody who knew better than me. I didn't want to invest into the MDK without being sure I need it.

Is somebody willing to do this in MDK, so that I wouldn't buy the kit for just one formula implementation ? I would like to pay for this, anyone interested ?
vienna  
#12 Posted : Monday, January 3, 2011 7:44:50 AM(UTC)
vienna

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 12/14/2009(UTC)
Posts: 140
Location: Austria

Yes, thanks now it was more clear for me...
do you know how many bars (minutes) will be per day (for your data)?
annonymous  
#13 Posted : Tuesday, January 4, 2011 7:01:03 AM(UTC)
annonymous

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 9/5/2009(UTC)
Posts: 18

The number of minutes in one day should be 60*no_of_trading_hours.

But in the computation of the average effective volume for a single day, I will only take into account those minutes with a price inflection (current close > previous close) and we don't know how many minutes like that there will be in one day (not until we iterate over the Close vector and count them).
vienna  
#14 Posted : Tuesday, January 4, 2011 7:14:13 AM(UTC)
vienna

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 12/14/2009(UTC)
Posts: 140
Location: Austria

Try this code. For variable j use more than number of bars per day but less than number of bars per week. I have tested this code only with intraday test-data I had for some days - so I couldn't really check if it works properly. With variable x I calculate the last available volume (not equal 0) divided by the avg. volume for the day.. (this is only done as example, here you have to change it to your formula/idea)

the last row of the code only shows the result after the last bar of the day...

Code:

{example for average effective volume by vienna}
{j = greater then bars per day, but less than 4x bars per day}
j:=1500;

n:=DayOfWeek();

n;

mycount1:=If(n=1,Sum(If(C<>Ref(C,-1) AND n=1,1,0),j),0);
mycount2:=If(n=2,Sum(If(C<>Ref(C,-1) AND n=2,1,0),j),0);
mycount3:=If(n=3,Sum(If(C<>Ref(C,-1) AND n=3,1,0),j),0);
mycount4:=If(n=4,Sum(If(C<>Ref(C,-1) AND n=4,1,0),j),0);
mycount5:=If(n=5,Sum(If(C<>Ref(C,-1) AND n=5,1,0),j),0);


avgvol1:=If(mycount1=0,0,Sum(If(n=1 AND C<>Ref(C,-1),V,0),j)/mycount1);
avgvol2:=If(mycount2=0,0,Sum(If(n=2 AND C<>Ref(C,-1),V,0),j)/mycount2);
avgvol3:=If(mycount3=0,0,Sum(If(n=3 AND C<>Ref(C,-1),V,0),j)/mycount3);
avgvol4:=If(mycount4=0,0,Sum(If(n=4 AND C<>Ref(C,-1),V,0),j)/mycount4);
avgvol5:=If(mycount5=0,0,Sum(If(n=5 AND C<>Ref(C,-1),V,0),j)/mycount5);

lastV:=If(V=0,PREV,V);

x:=If(n=1,If(avgvol1=0,0,lastV/avgvol1),0);
x:=If(n=2,If(avgvol2=0,0,lastV/avgvol2),x);
x:=If(n=3,If(avgvol3=0,0,lastV/avgvol3),x);
x:=If(n=4,If(avgvol4=0,0,lastV/avgvol4),x);
x:=If(n=5,If(avgvol5=0,0,lastV/avgvol5),x);

x;

If(n<>Ref(n,-1),Ref(x,-1),0);


Try the code and change the colors of the different result-lines, then you will see what it is doing..
annonymous  
#15 Posted : Saturday, January 8, 2011 7:19:33 AM(UTC)
annonymous

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 9/5/2009(UTC)
Posts: 18

I have tried this code with intraday data for various stocks. It always plots only one line; it's value is something around 0; never changes. And when I hover the mouse over any point of the line, there's a little pop-up that says:

Date: 00/00/0000
Time: 12:00


vienna  
#16 Posted : Tuesday, January 11, 2011 1:34:10 AM(UTC)
vienna

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 12/14/2009(UTC)
Posts: 140
Location: Austria

Try to load more data points and try to reduce j to something like j:=96; or j:=200; only for testing purpose.
If it still shows no results, I' m sorry but I can't test it without intraday data. (The only one security for which I have testdata worked with this solution on my pc.)
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.