Discussions
»
Product and Service Development
»
Formula Assistance
»
Formula to calculate average for negative % price changes
Rank: Newbie
Groups: Registered, Registered Users Joined: 1/24/2006(UTC) Posts: 3
|
Hi -- I am a total newbie, although I have mastered the basics of writing formulas thanks to the Formula Primer.
I have a fairly simple question:
How do I write a formula to calculate the average daily percent (%) decrease in the closing price for a period N, i.e. calculate the average negative daily percent price change for the period N, ignoring any positive changes (increases) in the same period.
I would like to set up a buy signal for when the % change in the latest closing price versus the previous close is smaller than the average daily percent decrease in the closing price for the previous N days.
Any ideas? Perhaps there is a formula/system already in existence along these lines?
Thanks in advance,
Trevor
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 1/19/2005(UTC) Posts: 1,065 Location: Koh Pha-Ngan, Earth
Was thanked: 2 time(s) in 2 post(s)
|
Try this:
[code:1:6af4051840]Nperiods:=21;
DailyChange:=ROC(C,1,%);
AvgDailyCh:=Mov(DailyChange,Nperiods,S);
short:=DailyChange<AvgDailyCh;
long:=DailyChange>AvgDailyCh;
long-short
[/code:1:6af4051840]
jose '-)
|
|
|
|
Rank: Newbie
Groups: Registered, Registered Users Joined: 1/24/2006(UTC) Posts: 3
|
Thanks for the quick reply Jose!
That gets me halfway there; the problem is that I don't believe that
AvgDailyCh:=Mov(DailyChange,Nperiods,S);
includes only negative ROC values in the average. The price will move up and down over the period in question, but I want to exclude the upward ROC values when calculating the average...
Can this be done relatively easily?
Cheers,
Trevor
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 1/19/2005(UTC) Posts: 1,065 Location: Koh Pha-Ngan, Earth
Was thanked: 2 time(s) in 2 post(s)
|
trevor_richter wrote:the problem is that I don't believe
Oh no... you must believe in MetaStock! :?
Ok, try this:
[code:1:fd83878679]Nperiods:=21;
DailyChange:=ROC(C,1,%);
UpDailyChange:=ROC(C,1,%)*(ROC(C,1,%)>0);
{DownDailyChange:=ROC(C,1,%)*(ROC(C,1,%)<0);}
AvgDailyUpCh:=Mov(UpDailyChange,Nperiods,S);
short:=UpDailyChange<AvgDailyUpCh;
long:=UpDailyChange>AvgDailyUpCh;
long-short
[/code:1:fd83878679]
jose '-)
|
|
|
|
Rank: Newbie
Groups: Registered, Registered Users Joined: 1/24/2006(UTC) Posts: 3
|
ok Jose, I've settled for this...
Nperiods:=21;
DailyChange:=ROC(C,1,%);
DownDailyChange:=ROC(C,1,%)*(ROC(C,1,%)<0);
AvgDownDailyChange:=Mov(DownDailyChange,Nperiods,S);
short:=DailyChange<AvgDownDailyChange;
long:=DailyChange>AvgDownDailyChange;
long-short
Agree?
Thanks for the help,
Trevor
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 1/19/2005(UTC) Posts: 1,065 Location: Koh Pha-Ngan, Earth
Was thanked: 2 time(s) in 2 post(s)
|
Oh, so now you want the down daily changes, eh?
And to think it only took you three posts for me to catch on... :)
jose '-)
|
|
|
|
Users browsing this topic |
Guest (Hidden)
|
Discussions
»
Product and Service Development
»
Formula Assistance
»
Formula to calculate average for negative % price changes
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.