Need Help for Composite MACD

hitesh

Active Member
#1
Hi Friends,
Help required for AFL of MACD Composite, originally written by Mr. Jose Silva for Meta Stock.I have taken permission of Mr.Jose Silva regarding the same.


Metastock formula is as under:-
====================
MACD - composite EMA
====================
-----------------------------------------------

{ MACD or Histogram based on multiple EMA's }
{ Incorporating automatic overbought/oversold
levels }
{ Copyright 2005 Jose Silva }
{ http://www.metastocktools.com }

{ User inputs }
plot1:=Input("[1]MACD, [2]Histogram",1,2,1);
plot2:=Input("[1]MACD/Hist, [2]Normalized",
1,2,1);
pds:=Input("Signal/Histogram EMA periods",
2,260,21);

{ Composite-EMA MACD/Histogram }
ema1:=
Mov(C,3,E)
+Mov(C,5,E)
+Mov(C,8,E)
+Mov(C,11,E)
+Mov(C,14,E)
+Mov(C,17,E);
ema2:=
Mov(C,30,E)
+Mov(C,35,E)
+Mov(C,40,E)
+Mov(C,45,E)
+Mov(C,50,E)
+Mov(C,56,E);
emaComp:=ema1-ema2;
signal:=Mov(emaComp,pds,E);
hist:=emaComp-signal;

{ Choose MACD or Histogram }
MacdH:=If(plot1=1,emaComp,hist);

{ Normalized MACD/Histogram }
normMod:=Highest(MacdH)-Lowest(MacdH);
normMod:=If(normMod=0,.000001,normMod);
MacdHnorm:=
((MacdH-Lowest(MacdH))/normMod-.5)*200;

{ Choose standard/normalized }
MacdComp:=If(plot2=1,MacdH,MacdHnorm);
signal:=Mov(MacdComp,pds,E);

{ MACD/Hist average }
avg:=Cum(MacdComp)/Cum(IsDefined(MacdComp));

{ MACD/Hist auto boundaries }
pk:=Ref(MacdComp,-1)>MacdComp
AND Ref(MacdComp,-1)>Ref(MacdComp,-2)
AND Ref(MacdComp,-1)>avg;
pkVal:=ValueWhen(1,pk,Ref(MacdComp,-1));
tr:=Ref(MacdComp,-1)<MacdComp
AND Ref(MacdComp,-1)<Ref(MacdComp,-2)
AND Ref(MacdComp,-1)<avg;
trVal:=ValueWhen(1,tr,Ref(MacdComp,-1));
Obought:=Cum(pkVal)/Cum(IsDefined(pkVal));
Osold:=Cum(trVal)/Cum(IsDefined(trVal));

{ Plot in own window }
Obought; { Red }
avg; { Grey }
Osold; { Blue }
If(plot1=1,signal,avg); { Green }
MacdComp { Black }

Formula of Metastock available at
http://www.metastocktools.com/MetaStock/MACDHcomp.txt also.

I have written part codes covering MACD and Signal in AFL as under:-

// Composite MACD
// Incorporating automatic overbought/oversold levels
// Copyright 2005 Jose Silva

ema1=
EMA(C,3)
+EMA(C,5)
+EMA(C,8)
+EMA(C,11)
+EMA(C,14)
+EMA(C,17);
ema2=
EMA(C,30)
+EMA(C,35)
+EMA(C,40)
+EMA(C,45)
+EMA(C,50)
+EMA(C,56);
emaComp=ema1-ema2;
s=EMA(emaComp,21);

Plot(S , "SIGNAL", colorRed);
Plot(emaComp , "emaComp", colorBlue);
Plot(0,"",colorBlack,styleLine);
---------------------------------------------------

Unable to code for overbought/oversold.

Help requested for the complete code with Overbought/sold levels.

Thanks in advance.
Hitash Pandya
 

hitesh

Active Member
#3
Thank you very much Sir,

I have posted to Amibroker forum but yet not received any response. I have tried Purebyte also.

I am used to this single indicator in Metastock that feeling uncomfortable and unable to work when I don't have the same in Amibroker.

I will be greatful if you help me out.

Thank you very much once again.
 

hitesh

Active Member
#5
I have attached herewith file in Doc, step by step explaination.

I have tried to write afl code. I have also attahced that file in txt form.

Thanks and Regards
 
Last edited:
#6
I am also curious to know about this indicator.Can you please post chart using this indicator? Normally in
http://trader.online.pl/MSZ/!-MSZ-index-en.html
examples of indicators are given but for this indicator, example is not available.
Presuming normalisation same as stochastic, I have plotted stochastic and stochastic of macd in one pane. please check whether your indicator is similar to this. chart is enclosed
 
Last edited:

hitesh

Active Member
#7
Thanks for your posting, but MACD Composite is different than the example you have send.
Pl find here attached chart showing indicator. - Thanks & Regards
 
Last edited:
#8
Thanks for your posting, but MACD Composite is different than the example you have send.
Pl find here attached chart showing indicator. - Thanks & Regards
Thanks for enclosing chart which is quite interesting.
I enclose a text file. In this I have added to your formula ---peak and trough value calculations and buy and sell arrows in the chart.
Further to this, Jose has done cumulative average of peak and trough values at any time and plotting this as historic cumulative overbought and oversold lines. I do not know how to do this.
Hope biginner_av will help us further
Regards
 
Last edited:
#9
Thanks for enclosing chart which is quite interesting.
I enclose a text file. In this I have added to your formula ---peak and trough value calculations and buy and sell arrows in the chart.
Further to this, Jose has done cumulative average of peak and trough values at any time and plotting this as historic cumulative overbought and oversold lines. I do not know how to do this.
Hope biginner_av will help us further
Regards
I enclose following :
a)compo macd test rev1.txt
b) sample chart with above formula.

In the previous formula, some errors were there. I have corrected them.
Pl note following
1)Prepare new afl file with above formula. It gives comp macd indicator.In this indicator panel, drag and drop three 200ema's ---one each for fields emacomp, pkval and trval.You have to select these with suitable colour in the parameters.
With this, you will get similar chart as in the sample.
I could not get historical averages, by formula. Hence instead of that I am using 200ema for above fields.
After using above, please enclose a chart for information. Also, pl inform how you use this indicator, for decision making for buy or sell, for information.
Regards
 
Last edited:

hitesh

Active Member
#10
Thanks for the afl.
I don't know why but visual effect is not same as in Metastock.

Here is how I use the formula:-
1. Buy when MACD crosses upper most line.
2. To add to investment when:-
a. MACD violates signal line and crosses back/again and still both the lines remains above the uppermost line.
3. To sell when MACD comes below 2nd line.
4. To short when MACD comes below lower most line.
5. To add to short when:-
a. MACD crosses signal line in upwards direction and crosses back and still both the line remains below lower most lines.

Example chart attached.
 
Last edited:

Similar threads