Experiments in Technical Analysis

A

amarnath

Guest
Digital Filters

Digital filters are intended for signal processing (filtration) presented as time series. We will exaime only line digital filters (hereinafter DF), as thier methods of calculating exist for a long time, both of filters themselves and their characteristics. Besides, they are mostly often used by traders, although traders do not know this themselves.


I will give some examples:

Simple moving average (SMA). As it is known, it is calculated as an average value of final N elements of time series. This is an example of DF with final impulse response (FIR-filter).

Triangular and weighted average (Triangular & Weighted). These moving averages are calculated in the same way as simple average, but members of time series are taken with different weight. For triangular average weight the triangle is made, so middle elements have the largest weight, and last elements - the smallest. For weighted average the last row elements are the most important, unimportant - the most old elements. They are examples of FIR-filters, but with other characteristics.

Here we can add such well-known indicators and their combinations as Momentum, ROC, MACD, TRIX, difference of two moving averages with different periods or taken in different moments of time and many others. I will not describe them in details now. All of them are digital filters and come to a sum (finite or infinte) of input row members taken with some weight or to finite sum of some last members of input row and it is possible that some members of output row taken with some weight. The set of weight defines filters qualities. So we came to a formular of line digital filter, it is written in the following way:

Y = B[0] X + B[1] X[i-1] + .... - A[1] Y[i-1] - A[2] Y[i-2] - ....

Here X input time series, Y output row, A and B sets of weight coefficients.
 

kkseal

Well-Known Member
Re: Digital MACD

Hi all,

First i like to say i am not a stupid lover of MACD but if some one like take it and make to to get working your self if it works well for u, below i added a code of digital MACD if like make it on u r favourite AB codes or MS as you ppls wish

btw this macd looks smoother and reduce little lag and i prefer smoother equity curve than smooth indicators :d


Code:
#property indicator_separate_window 
#property indicator_buffers 2 
#property indicator_color1 Blue 
#property indicator_color2 Red 

//---- buffers 
double FTLMBuffer[]; 
double STLMBuffer[]; 
double value1; 
double value2; 
double value3; 
double value4; 
//+------------------------------------------------------------------+ 
//| Custom indicator initialization function | 
//+------------------------------------------------------------------+ 
int init() 
{ 
string short_name; 
//---- indicator line 
IndicatorBuffers(2); 
SetIndexStyle(0,DRAW_LINE); 
SetIndexBuffer(0,STLMBuffer); 
SetIndexStyle(1,DRAW_LINE); 
SetIndexBuffer(1,FTLMBuffer); 
SetIndexDrawBegin(0,90); 
SetIndexDrawBegin(1,43); 
//---- 
return(0); 
} 
int start() 
{ 
int shift,counted_bars=IndicatorCounted(); 
if(counted_bars<43) 
{ 
for(shift=1;shift<=0;shift++) FTLMBuffer[Bars-shift]=0.0; 
for(shift=1;shift<=0;shift++) STLMBuffer[Bars-shift]=0.0; 
} 
//---- 
shift=Bars-43-1; 
if(counted_bars>=43) shift=Bars-counted_bars-1; 
while(shift>=0) 
{ 
value1 = 
0.112952*Close[shift+0] 
+0.111644*Close[shift+1] 
+0.109058*Close[shift+2] 
+0.105254*Close[shift+3] 
+0.100320*Close[shift+4] 
+0.094368*Close[shift+5] 
+0.087532*Close[shift+6] 
+0.079966*Close[shift+7] 
+0.071834*Close[shift+8] 
+0.063313*Close[shift+9] 
+0.054575*Close[shift+10] 
+0.045801*Close[shift+11] 
+0.037159*Close[shift+12] 
+0.028809*Close[shift+13] 
+0.020898*Close[shift+14] 
+0.013548*Close[shift+15] 
+0.006870*Close[shift+16] 
+0.000944*Close[shift+17] 
-0.004166*Close[shift+18] 
-0.008428*Close[shift+19] 
-0.011828*Close[shift+20] 
-0.014378*Close[shift+21] 
-0.016112*Close[shift+22] 
-0.017080*Close[shift+23] 
-0.017348*Close[shift+24] 
-0.016998*Close[shift+25] 
-0.016118*Close[shift+26] 
-0.014806*Close[shift+27] 
-0.013156*Close[shift+28] 
-0.011270*Close[shift+29] 
-0.009238*Close[shift+30] 
-0.007152*Close[shift+31] 
-0.005090*Close[shift+32] 
-0.003120*Close[shift+33] 
-0.001302*Close[shift+34] 
+0.000322*Close[shift+35] 
+0.001714*Close[shift+36] 
+0.002858*Close[shift+37] 
+0.003744*Close[shift+38] 
+0.004372*Close[shift+39] 
+0.004754*Close[shift+40] 
+0.004910*Close[shift+41] 
+0.004864*Close[shift+42] 
+0.004646*Close[shift+43] 
+0.004288*Close[shift+44] 
+0.003824*Close[shift+45] 
+0.003288*Close[shift+46] 
+0.002712*Close[shift+47] 
+0.002124*Close[shift+48] 
+0.001548*Close[shift+49] 
+0.001010*Close[shift+50] 
+0.000522*Close[shift+51] 
+0.000098*Close[shift+52] 
-0.000254*Close[shift+53] 
-0.000530*Close[shift+54] 
-0.000734*Close[shift+55] 
-0.000866*Close[shift+56] 
-0.000934*Close[shift+57] 
-0.000948*Close[shift+58] 
-0.000914*Close[shift+59] 
-0.000844*Close[shift+60] 
-0.000750*Close[shift+61] 
-0.000638*Close[shift+62] 
-0.000520*Close[shift+63] 
-0.000922*Close[shift+64]; 

value2 = 
0.038953*Close[shift+0] 
+0.042502*Close[shift+1] 
+0.045773*Close[shift+2] 
+0.048702*Close[shift+3] 
+0.051237*Close[shift+4] 
+0.053326*Close[shift+5] 
+0.054931*Close[shift+6] 
+0.056018*Close[shift+7] 
+0.056566*Close[shift+8] 
+0.056566*Close[shift+9] 
+0.056018*Close[shift+10] 
+0.054931*Close[shift+11] 
+0.053326*Close[shift+12] 
+0.051237*Close[shift+13] 
+0.048702*Close[shift+14] 
+0.045773*Close[shift+15] 
+0.042502*Close[shift+16] 
+0.038953*Close[shift+17] 
+0.035190*Close[shift+18] 
+0.031281*Close[shift+19] 
+0.027295*Close[shift+20] 
+0.023298*Close[shift+21] 
+0.019357*Close[shift+22] 
+0.015532*Close[shift+23] 
+0.011880*Close[shift+24] 
+0.008451*Close[shift+25] 
+0.005287*Close[shift+26] 
+0.002424*Close[shift+27] 
-0.000112*Close[shift+28] 
-0.002305*Close[shift+29] 
-0.004142*Close[shift+30] 
-0.005624*Close[shift+31] 
-0.006758*Close[shift+32] 
-0.007558*Close[shift+33] 
-0.008042*Close[shift+34] 
-0.008240*Close[shift+35] 
-0.008177*Close[shift+36] 
-0.007890*Close[shift+37] 
-0.007415*Close[shift+38] 
-0.006786*Close[shift+39] 
-0.006041*Close[shift+40] 
-0.005219*Close[shift+41] 
-0.004349*Close[shift+42] 
-0.003466*Close[shift+43] 
-0.002596*Close[shift+44] 
-0.001764*Close[shift+45] 
-0.000991*Close[shift+46] 
-0.000294*Close[shift+47] 
+0.000318*Close[shift+48] 
+0.000835*Close[shift+49] 
+0.001254*Close[shift+50] 
+0.001575*Close[shift+51] 
+0.001801*Close[shift+52] 
+0.001937*Close[shift+53] 
+0.001993*Close[shift+54] 
+0.001978*Close[shift+55] 
+0.001902*Close[shift+56] 
+0.001777*Close[shift+57] 
+0.001616*Close[shift+58] 
+0.001428*Close[shift+59] 
+0.001228*Close[shift+60] 
+0.001020*Close[shift+61] 
+0.000816*Close[shift+62] 
+0.000622*Close[shift+63] 
+0.000445*Close[shift+64] 
+0.000287*Close[shift+65] 
+0.000154*Close[shift+66] 
+0.000045*Close[shift+67] 
-0.000040*Close[shift+68] 
-0.000100*Close[shift+69] 
-0.000139*Close[shift+70] 
-0.000159*Close[shift+71] 
-0.000161*Close[shift+72] 
-0.000672*Close[shift+73]; 

value3 = 
0.0729811286*Close[shift+0] 
+0.0727839290*Close[shift+1] 
+0.0721970455*Close[shift+2] 
+0.0712248998*Close[shift+3] 
+0.0698810899*Close[shift+4] 
+0.0681787637*Close[shift+5] 
+0.0661384062*Close[shift+6] 
+0.0637836328*Close[shift+7] 
+0.0611379416*Close[shift+8] 
+0.0582328720*Close[shift+9] 
+0.0551006677*Close[shift+10] 
+0.0517729856*Close[shift+11] 
+0.0482864520*Close[shift+12] 
+0.0446761673*Close[shift+13] 
+0.0409807341*Close[shift+14] 
+0.0372349199*Close[shift+15] 
+0.0334766035*Close[shift+16] 
+0.0297389677*Close[shift+17] 
+0.0260572889*Close[shift+18] 
+0.0224620500*Close[shift+19] 
+0.0189846476*Close[shift+20] 
+0.0156508337*Close[shift+21] 
+0.0124844115*Close[shift+22] 
+0.0095064451*Close[shift+23] 
+0.0067348956*Close[shift+24] 
+0.0041825353*Close[shift+25] 
+0.0018620649*Close[shift+26] 
-0.0002214306*Close[shift+27] 
-0.0020618579*Close[shift+28] 
-0.0036612349*Close[shift+29] 
-0.0050199184*Close[shift+30] 
-0.0061460477*Close[shift+31] 
-0.0070453847*Close[shift+32] 
-0.0077311361*Close[shift+33] 
-0.0082154598*Close[shift+34] 
-0.0085069196*Close[shift+35] 
-0.0086364464*Close[shift+36] 
-0.0086063959*Close[shift+37] 
-0.0084385053*Close[shift+38] 
-0.0081544217*Close[shift+39] 
-0.0077720532*Close[shift+40] 
-0.0073096701*Close[shift+41] 
-0.0067829639*Close[shift+42] 
-0.0062100031*Close[shift+43] 
-0.0056056555*Close[shift+44] 
-0.0049866671*Close[shift+45] 
-0.0043657084*Close[shift+46] 
-0.0037560684*Close[shift+47] 
-0.0031670013*Close[shift+48] 
-0.0026079202*Close[shift+49] 
-0.0020858529*Close[shift+50] 
-0.0016064640*Close[shift+51] 
-0.0011734916*Close[shift+52] 
-0.0007908741*Close[shift+53] 
-0.0004588212*Close[shift+54] 
-0.0001790390*Close[shift+55] 
+0.0000510113*Close[shift+56] 
+0.0002315881*Close[shift+57] 
+0.0003671215*Close[shift+58] 
+0.0004595615*Close[shift+59] 
+0.0005144014*Close[shift+60] 
+0.0005345365*Close[shift+61] 
+0.0005256791*Close[shift+62] 
+0.0028871340*Close[shift+63]; 

value4 = 
0.0077174463*Close[shift+0] 
+0.0093613543*Close[shift+1] 
+0.0110760659*Close[shift+2] 
+0.0128488828*Close[shift+3] 
+0.0146643234*Close[shift+4] 
+0.0165073564*Close[shift+5] 
+0.0183605871*Close[shift+6] 
+0.0202076529*Close[shift+7] 
+0.0220298758*Close[shift+8] 
+0.0238101118*Close[shift+9] 
+0.0255293260*Close[shift+10] 
+0.0271702104*Close[shift+11] 
+0.0287147044*Close[shift+12] 
+0.0301471980*Close[shift+13] 
+0.0314517917*Close[shift+14] 
+0.0326129335*Close[shift+15] 
+0.0336190364*Close[shift+16] 
+0.0344584557*Close[shift+17] 
+0.0351210901*Close[shift+18] 
+0.0356004564*Close[shift+19] 
+0.0358898494*Close[shift+20] 
+0.0359870888*Close[shift+21] 
+0.0358898494*Close[shift+22] 
+0.0356004564*Close[shift+23] 
+0.0351210901*Close[shift+24] 
+0.0344584557*Close[shift+25] 
+0.0336190364*Close[shift+26] 
+0.0326129335*Close[shift+27] 
+0.0314517917*Close[shift+28] 
+0.0301471980*Close[shift+29] 
+0.0287147044*Close[shift+30] 
+0.0271702104*Close[shift+31] 
+0.0255293260*Close[shift+32] 
+0.0238101118*Close[shift+33] 
+0.0220298758*Close[shift+34] 
+0.0202076529*Close[shift+35] 
+0.0183605871*Close[shift+36] 
+0.0165073564*Close[shift+37] 
+0.0146643234*Close[shift+38] 
+0.0128488828*Close[shift+39] 
+0.0110760659*Close[shift+40] 
+0.0093613543*Close[shift+41] 
+0.0077174463*Close[shift+42] 
+0.0061560794*Close[shift+43] 
+0.0046876404*Close[shift+44] 
+0.0033209857*Close[shift+45] 
+0.0020624135*Close[shift+46] 
+0.0009181866*Close[shift+47] 
-0.0001091877*Close[shift+48] 
-0.0010167048*Close[shift+49] 
-0.0018053597*Close[shift+50] 
-0.0024753283*Close[shift+51] 
-0.0030306241*Close[shift+52] 
-0.0034740883*Close[shift+53] 
-0.0038122332*Close[shift+54] 
-0.0040510538*Close[shift+55] 
-0.0041947730*Close[shift+56] 
-0.0042586429*Close[shift+57] 
-0.0042438250*Close[shift+58] 
-0.0041610379*Close[shift+59] 
-0.0040209559*Close[shift+60] 
-0.0038324095*Close[shift+61] 
-0.0036044078*Close[shift+62] 
-0.0033446882*Close[shift+63] 
-0.0030621605*Close[shift+64] 
-0.0027641559*Close[shift+65] 
-0.0024589320*Close[shift+66] 
-0.0021527365*Close[shift+67] 
-0.0018521222*Close[shift+68] 
-0.0015616524*Close[shift+69] 
-0.0012859688*Close[shift+70] 
-0.0010285368*Close[shift+71] 
-0.0007921495*Close[shift+72] 
-0.0005786502*Close[shift+73] 
-0.0003899810*Close[shift+74] 
-0.0002262453*Close[shift+75] 
-0.0000882844*Close[shift+76] 
+0.0000251537*Close[shift+77] 
+0.0001141964*Close[shift+78] 
+0.0001810281*Close[shift+79] 
+0.0002266104*Close[shift+80] 
+0.0002536520*Close[shift+81] 
+0.0002635807*Close[shift+82] 
+0.0002592130*Close[shift+83] 
+0.0014236495*Close[shift+84]; 


STLMBuffer[shift] = value3-value4; 
FTLMBuffer[shift] = value1-value2; 

shift--; 
} 
return(0); 
} 
//+------------------------------------------------------------------+
Not sure what is being plotted Is it FTLM - STLM?

Anyway, that's s-o much better than the ranting Mr Amarnath :)

Regards,
Kalyan.
 

kkseal

Well-Known Member
Interesting to see what would correspond to the above method if we were using a traditional IIR filter (EMA)

fpd = fast period (default 12), spd = slow period (default 26)

value1 = EMA(C, fpd)
value2 = EMA(value1, fpd)
value3 = EMA(C, spd)
value4 = EMA(value3, spd)

FTLM = value1 - value2
STLM = value3 - value4

MACD = FTLM - STLM (This last line needs confirmation)

Incidentally, this MACD would actually be a second derivative (acceleration) of price and not the (usual) first (velocity/momentum).

Regards,
Kalyan.
 
Last edited:

kkseal

Well-Known Member
Toh Kahan maar kha gaya India ?

Lag? (No big deal Zero-lag is possible even with FIR filters)
Phase Distortion? (Wouldn't happen with FIR/IIR filters)
It's actually the Amplitude Distortion (due to overshoot)

Another issue is the Cycle adaptiveness (there are ways however - not perfect though)

Regards,
Kalyan.
 
A

amarnath

Guest
Re: Digital MACD

Not sure what is being plotted Is it FTLM - STLM?

Anyway, that's s-o much better than the ranting Mr Amarnath :)

Regards,
Kalyan.
Ranting at me doesn't even generate penny to a traders trading account :) what i asked before was a justification for 1000s of post to find old bicycle MACD :D
 

sudoku1

Well-Known Member
Re: Digital MACD

Ranting at me doesn't even generate penny to a traders trading account :) what i asked before was a justification for 1000s of post to find old bicycle MACD :D
if macd has 1000 posts 2 prove that only macd can spin money....traders would had bought stakes in nse & bse.......:D
 

kkseal

Well-Known Member
Re: Digital MACD

Ranting at me doesn't even generate penny to a traders trading account :) what i asked before was a justification for 1000s of post to find old bicycle MACD :D
It's not just about the 'bicycle' or 'Harley-Davidson' MACD Mr Amarnath - it's the concept of Convergence-Divergence. Where's the harm in exploring it a bit? Why, perhaps a Convergence-Divergence (not necessarily MA-cd)of your short and medium term trend indicators can be attempted to merge them into a single indicator (one which can also be confirmatory for your 3rd indicator).

BTW, it's a misnomer to call the indicator you've posted a MACD as it's not really based on MAs.

Hope to see you as a valuable contributor to the thread (rather than just a critic) Will help us losers.

Regards,
Kalyan.

P.S. Was i right about what is being plotted?
 

Similar threads