Rank: Member
Groups: Registered, Registered Users, Subscribers Joined: 4/30/2005(UTC) Posts: 13
|
I want to program a smoothing constant called a % trend on price data. The formula is;
20 % trend = (.20*today's price close)+(0.80*yesterday's % trend value)
Thanks!!!
|
|
|
|
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)
|
What you are really trying to program here is an exponential moving average. Have a look in your MS user manual for the moving averages under the Interpretation of Indicators and Line Studies, towards the back of the book.
If you really want to program this function that is already built in, may I suggest you have a look at Jose Silva's excellent site at http://www.metastocktools.com/#metastock
Hope this helps.
wabbit :D
|
|
|
|
Rank: Member
Groups: Registered, Registered Users, Subscribers Joined: 4/30/2005(UTC) Posts: 13
|
Wabbit,
It is like a moving average but the results are different. I put the % trend, simple and EMA and the results were different for all three. I am afraid I am going to have to calculate this for an indicator that I am building. It is more like a smoothing constant if that helps.
TC
|
|
|
|
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)
|
How were you comparing the values of the %trend, SMA and EMA?
There shouldn't be any difference between your %trend indicator and the EMA if the EMA periods are computed thus:
For the 20%trend, pct=0.2
Periods = (2 / pct) - 1 = (2 / 0.2) -1 = 10 - 1 = 9 day EMA
There should not be any differences between your 20%trend indicator and the 9 day EMA.
Any differences between the 20%trend indicator and the 9 day EMA will (probably) be caused by the number of bars used in the calculation. The EMA will have 'remnants' of the very first bar in the chart, whereas your indicator might have a different seed? (Maybe Patrick or Jose might be able to provide a more precise answer here, but this is what I believe the problem might be!) If you compare the values for a chart with a lot of history (loaded) any differences will be minute.
Hope this helps.
wabbit :D
P.S. I also question the validity of any system that is soooo sensitive to such minor differences. You might like to have a look again at the logic of your system; do a simple SWOT analysis (strengths, weaknesses, opportunities and threats) and I think you will find the sensitivity is a major threat to your analysis.
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers Joined: 9/8/2004(UTC) Posts: 2,266
Was thanked: 1 time(s) in 1 post(s)
|
That one is for Jose oz_pdt_01;
I can't explain Math, but I agree with Wabbit.
Patrick :D
|
|
|
|
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)
|
OK I will try to explain the seeding concept, by example.
Lets say we program the %trend indicator as:
(0.2*CLOSE)+(0.8*PREV)
and compare this against the 9 day EMA.
Starting with the very first bar for BHP:
Date Close %trend Moving Average
02 01 87 2.6884
05 01 87 2.7408 0.9783
06 01 87 2.7757 1.3378
07 01 87 2.7975 1.6297
08 01 87 2.7757 1.8589
09 01 87 2.7888 2.0449
12 01 87 2.8411 2.2041
13 01 87 2.8237 2.328
14 01 87 2.732 2.4088 2.7697
15 01 87 2.7626 2.4796 2.7682
16 01 87 2.7626 2.5362 2.7671
You can see that the %trend indicator is not defined on the first day as the PREV value is undefined on bar 1. On bar 2, when PREV is defined, the %trend indicator is also defined, BUT the EMA is not defined until the 9th bar.
In the very short term, at the very beginning of a chart there will be differences between the indicators, sometimes called seeding discrepancies. These discrepancies, in many instances such as this one, become insignificant.
[An example of when a seeding discrepancy may be significant might be if we were to look at a modified OBV; if the 'proper' OBV began with a value of zero on day 1 and a modified OBV bagan with a value of, say, 100000 on day 1, then this seeded discrepancy would be significant for the entire duration of the chart.]
The values for these indicators at the end of the chart are:
Date Close %trend Moving Average
10 05 05 16.7 16.5916 16.5916
11 05 05 16.43 16.5593 16.5593
12 05 05 16.29 16.5055 16.5054
13 05 05 15.95 16.3944 16.3944
16 05 05 15.55 16.2255 16.2255
17 05 05 15.71 16.1224 16.1224
18 05 05 15.93 16.0839 16.0839
19 05 05 16.2 16.1071 16.1071
20 05 05 15.88 16.0617 16.0617
You can see that over a long period, some 4600 bars in this case, the differences between the %trend and the 9 day EMA are not significant (at 4 decimal places!)
Hope this goes some way to explain what seeding means.
wabbit :D
|
|
|
|
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)
|
btw....
the difference between the %trend and the 9 day EMA becomes insignificant (0.0000) after 56 bars!
wabbit :D
|
|
|
|
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)
|
..and for my first attempt to attach an image....
failed
|
|
|
|
Rank: Member
Groups: Registered, Registered Users, Subscribers Joined: 4/30/2005(UTC) Posts: 13
|
Yup you are right Wabbit! Thanks for points that out to me..... IF you want to post an image try down loading to this site and posting the link. Thanks again!
http://www.ttrader.com/mycharts/
TC
|
|
|
|
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.