I noticed that there is a grey button on the right at the bottom of the middle and bottom indicator windows. When pressed it displays the scale of the next indicator.
I don't suppose there is currently a way of aligning different indicators to one and the same scale in the same indicator window?
|
Thank you both guys.
To say that you went above and beyond the call of duty on this one is an understatement, to say the least. Busteremus posts are educational. I'll be sure to look them up for other gems.
I read your posts yesterday and was swept off my feet. Needless to say, most of the things you presented initially went over my head.
After I collected myself, and after having re-read the posts, I implemented busteremu's suggestions in Maple on my own to see what I come up with. Also because in the future I may want do this on my own for any MACD periods.
I managed to get the same formula after several hours of careful effort ( but then I am totally new to this ).
Now I finally find that Bruce's result coincides to my own. Bruce, I am curious if you used Maple, Excel or some other method to derive this? You seem to have got there fast.
I am presenting excerpts from what I did in Maple in the hope that maybe you would be willing to share your method. And for general benefit to anyone reading this.
Thanks once again.
----------------------------- ----------------------------- explanation of variables below: -------------------------------
position = position of macd, ema etc in a sequence say 1..10 range = for the purpose of implementing difference equations, equals 10 in this instance. period = averaging period for ema inner, outer = inner and outer periods in cascading EMA as in EMA(EMA(price,inner),outer)
------------------------------- the code, copied line by line ------------------------------
with(LinearAlgebra): with(VectorCalculus): with(ArrayTools):
prices := vector([C, C1, C2, C3, C4, C5, C6, C7, C8, C9])
a := proc ( x ) options operator, arrow; ( x-1 )/( x+1 ) end proc
xavgc := proc (period, range, position) options operator, arrow; piecewise(range < position, 0, position = range, XAVGC(period, position-1), position < range, a(period)*xavgc(period, range, position+1)+(1-a(period))*prices[position]) end proc
xavgcxavgc := proc (inner, outer, range, position) options operator, arrow; (inner-1)*xavgc(inner, range, position)/(inner-outer)+(outer-1)*xavgc(outer, range, position)/(outer-inner) end proc
macdhistogram := proc (short, long, signal, position) options operator, arrow; xavgc(short, signal, position)-xavgc(long, signal, position)-xavgcxavgc(short, signal, signal, position)+xavgcxavgc(long, signal, signal, position) end proc
X := vector([seq(position, position = 1 .. 10)]) Y := vector([seq(macdhistogram(21, 50, 10, 11-position), position = 1 .. 10)])
regressionSlope := proc (range) options operator, arrow; ((sum(X[position]*Y[position], position = 1 .. range))-(sum(X[position], position = 1 .. range))*(sum(Y[position], position = 1 .. range))/range)/((sum(X[position]^2, position = 1 .. range))-(sum(X[position], position = 1 .. range))^2/range) end proc
regressionSlope(10)
evalf(regressionSlope(10))
--------- simplified pseudo code of above: -----------
// prices prices[10] = [C,...,C9]
// used in moving average difference eq a( x ) = ( x-1 )/( x+1 )
// piecewise moving average difference equation xavgc(period,range,position)= 0 , for position > range XAVGC(period, position-1) , for position = range a(period)*xavgc(period, range, position+1)+(1-a(period))*prices[position]) , for position < range
// linear cascade of moving average xavgcxavgc(inner,outer,range,position) = (inner-1)*xavgc(inner, range, position)/(inner-outer)+(outer-1)*xavgc(outer, range, position)/(outer-inner)
// macd histogram formula using above elements macdhistogram(short,long,signal,position)=xavgc(short, signal, position)-xavgc(long, signal, position)-xavgcxavgc(short, signal, signal, position)+xavgcxavgc(long, signal, signal, position)
// inputs to regression slope equation X := vector([seq(position, position = 1 .. 10)]) Y := vector([seq(macdhistogram(21, 50, 10, 11-position), position = 1 .. 10)])
---------
|
It seems the formulas match.
On further investigation I have found that on its own, the formula takes approximately a second to load when 200 exponential moving average is not in the upper window with the prices.
However once the 200 EMA is plotted in the upper window and the formula together with its MACD21,50,10 in the middle window, then at zoom five I had on average 5 seconds and more. Whereas with 200MA on its own or with the formula on its own, the lag was not significant.
|
Bruce, the original formula was
(0 -9*XAVGC21.9+ 9*XAVGC50.9- 7*XAVGC21.8+ 7*XAVGC50.8- 5*XAVGC21.7+ 5*XAVGC50.7- 3*XAVGC21.6+ 3*XAVGC50.6- XAVGC21.5+ XAVGC50.5+ 9*XAVG(XAVGC21.9, 10)- 9*XAVG(XAVGC50.9, 10)+ 3*XAVG(XAVGC50.3, 10)+ 9*XAVGC21- 9*XAVGC50- 7*XAVG(XAVGC21.1, 10)+ 7*XAVG(XAVGC50.1, 10)- 9*XAVG(XAVGC21, 10)+ 7*XAVG(XAVGC21.8, 10)- 7*XAVG(XAVGC50.8, 10)- 5*XAVG(XAVGC21.2, 10)+ 5*XAVG(XAVGC50.2, 10)+ 5*XAVG(XAVGC21.7, 10)+ 3*XAVG(XAVGC21.6, 10)- 3*XAVG(XAVGC50.6, 10)- 5*XAVG(XAVGC50.7, 10)+ XAVGC21.4-XAVGC50.4+ 3*XAVGC21.3- 3*XAVGC50.3+ 5*XAVGC21.2- 5*XAVGC50.2+ 7*XAVGC21.1- 7*XAVGC50.1- XAVG(XAVGC21.4, 10)+ XAVG(XAVGC50.4, 10)+ XAVG(XAVGC21.5, 10)- XAVG(XAVGC50.5, 10)+ 9*XAVG(XAVGC50, 10)- 3*XAVG(XAVGC21.3, 10))/165
I do not know if it is the correct one for 50,21,10 histogram, I used the delayed PCF formulas for MACD histogram as elements.
X[10]= [1,2,3,4,5,6,7,8,9,10] Y[10]= [XAVGC21.9-XAVGC50.9-XAVG(XAVGC21.9,10)+XAVG(XAVGC50.9,10),...,XAVGC21-XAVGC50-XAVG(XAVGC21,10)+XAVG(XAVGC50,10)]
Then plugged X and Y into a formula for regression slope for 10 elements. The above formula was the result.
I do hope there is a better approach that produces a fast curve. When I plot the formula as a custom indicator and then switch charts there is a several seconds lag on chart switch.
|
I have derived a formula for MACD 50,21,10 regression slope over 10 days.
It has 40 terms involving moving averages and their averages. It was slow when charts were being loaded. Few seconds per new chart. I guess the scanning of 7000 stocks would suffer if I attempted it.
I used a generic regression formula involving X,Y and I put X = [1, 2, ..., 9, 10] Y = [MACD 10 days ago,...,MACD today] for my formula data.
Then I optimized the formula by having 10 days of Y data as before, but replacing every second day with its immediate neighbour.
This reduced the formula to (8/165)* ( 0-2*XAVGC21.9+ 2*XAVGC50.9- XAVGC21.7+ XAVGC50.7+ 2*XAVGC21- 2*XAVGC50+ XAVGC21.3- XAVGC50.3+ 2*XAVG(XAVGC50, 10)+ 2*XAVG(XAVGC21.9, 10)- 2*XAVG(XAVGC50.9, 10)+ XAVG(XAVGC21.7, 10)- XAVG(XAVGC50.7, 10)- XAVG(XAVGC21.3, 10)+ XAVG(XAVGC50.3, 10)- 2*XAVG(XAVGC21, 10))
The curve was almost identical and I must have speeded it up a bit ( hard to measure as a user ).
The above formula still has repeating terms.
Can further optimization can be done in this instance? Is there a more optimal regression slope formula and approach?
This also brings me to a few related questions regarding optimizing telechart: 1. If I have indicators on a chart that I have made invisible are they being calculated in the background? 2. Does TC PCF engine cache repeating terms internally so that they are calculated once? For example above, most terms repeat at least once; once on their own and once as part of further averaging.
|
I added the 5 period EMA as a child of custom MACD previously. The same only lined up to the custom EMA formulas when the custom formulas were further smoothed by 5 exponentially.
I did not exactly understand the scaling issues. Is the following correct?
1. The 'XAVG(XAVGC10,5)-XAVG(XAVGC21,5)' formula produces the actual accurate raw exponential moving average of the MACD indicator. Plotted without smoothing it is exactly as its underlying values. 2. The 5 period EMA child of custom MACD or any custom indicator is by default plotted as a smoothed version of itself, the smoothing factor being the EMA period.
I wanted my scan PCFs to be accurate and to match the visual indicators.
|
Thanks for clearing that up.
There is one more practical issue.
When I plot MACD as a custom formula XAVGC10 - XAVGC21 and then add exponential moving average to it with the period of 5,
then plot two more custom indicators that ought to represent the same exponential moving average, a) XAVG(XAVGC10,5) - XAVG(XAVGC21,5) center zero line and b) XAVG(XAVGC5,10) - XAVG(XAVGC21,5) center zero line
a) and b) are identical, however they both differ from the original moving average.
The shape is similar, but there are offsets between them.
Which one is the correct one? Should I scale/offset the formula to get a more accurate version? If so, how?
Thanks.
|
I would appreciate some further explanations regarding moving averages in PCFs.
I viewed the Understanding MACD videos Understanding MACD and I gather that the MACD histogram is MACD - 'exponential moving average of MACD for signal periods' = MACD(long,short) - EMA( MACD(long,short), signal )
which in PCF language translates to ( XAVGCshort - XAVGClong ) - ( XAVG(XAVGCsignal,short) - XAVG(XAVGClong,signal) )
This formula seems to be more or less consistent with the MACD plotted by the software.
For the sake of understanding, so that I may successfully create my own PCF's without bothering the trainers too much, I would appreciate the explanation of the following:
I would appreciate the mathematical explanation of
1. Why does the formula ( XAVG(XAVGCsignal,short) - XAVG(XAVGClong,signal) ) represent the exponential moving average of MACD?
2. Would the similar formula for a simple moving average of MACD be AVG(AVGCsignal,short) - AVG(AVGClong,signal) or AVG(AVGCshort,signal) - AVG(AVGClong,signal)?
3. If I had a custom indicator with several terms such as term1 + term2 + ... + termN what would be its moving average and exponential moving average? Could I approximate those moving averages by say reducing the terms to two terms termA + termB and then using the above formulas?
Thanks.
|
Heh, just pasted the definition, did not realize that '( x )' was an emoticon. Sorry, I'll be sure to use preview next time.
|
True, my error.
Sgn(0) is undefined but can be either 0 or 1. Other undefined values are undefined.
signum
or signum function, n. the real function, denoted sgn or sg, that assigns the sign of a nonzero number to that number; alternatively, sgn can be defined as +1 for positive x and -1 for negative x. The term is also used for the corresponding function that sends x to x / || x || for any nonzero x, in any normed space, and especially complex numbers. sgn(0) is generally undefined, but it can be assigned a complex number of absolute value 0 or 1.
|
|