Need Help for Composite MACD

#11
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.
I enclose following
1) sample chart.
2) compo macd test rev2
In my chart I have used this formula. Instead of ema's, I have used ma's. Jose also has used ma's.
Also, instead of 200ma of emacomp, I have used 200ma of pkvaltrvalavg field. This gives middle line better. In the charts enclosed by you, look is different ---may be due to lot of price variation?. Please check on ntpc chart. Look may be similar to as posted by you earlier.
Regards
 
Last edited:

hitesh

Active Member
#12
Thanks a lot.

In the chart forwarded by you, it gives perfect reading. But when I copy formula and plot into chart it gives different effect.

I am attaching chart of VSNL (3 minutes), the chart of same scrip attahced by you.

In the chart forwarded by you, these three lines never meets each other, whereas in this case, there is a overlapping.

May I request you to forward me the formula you are using as it is?

Regards.
 
Last edited:
#13
hitesh,
1) your present afl is ok, but it needs to be modified as follows.
2) In my afl formula, I have given colorwhite for following (to make them invisible)
Plot(pkval ,"pkval",colorWhite) ;
Plot(trval ,"trval",colorWhite) ;
Plot(pkvaltrvalavg ,"pkvaltrvalavg",colorWhite) ;

You have modified them as colorblack. Modify them back as colorwhite. Do
not delete them as they are required to calculate ma's as mentioned below.
With this, these fields will remain in chart but as invisible.
3) Now drag and drop three 200ma's (not ema's) in this indicator pane, one each for pkval,trval
and pkvaltrvalavg and modify their color( other than white), field, period from parameters.
as done earlier.
Now your chart will be similar to mine.

Regards
 
Last edited:

hitesh

Active Member
#14
:) Thanks a lot Sir, :)

It is coming perfectly. And visual effect is also as metastock.

I am relived. Thank you very much once again.
Regards
 

beginner_av

Well-Known Member
#16
No friends,
I cant help much. I got the following already with parameters. But I just cant understand what the hell is Cum(pkVal)/Cum(pkVal), cos it alwats gives 1...
************************
// Composite MACD
// Incorporating automatic overbought/oversold levels
// Copyright 2005 Jose Silva
//Modified to adapt for amibroker

Plot1 = Param("1M 2Hist", 1, 1, 2, 0.5);
Plot2 = Param("1M Hist, 2Norm", 1, 1, 2, 0.5);
pds = Param("Sig Hist EMApds", 2, 2, 260, 21);

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,pds);
hist = emaComp - s;

//MacdH = IIf(Plot1 = 1, emaComp, hist);

if (Plot1 = 1)
{
MacdH = emaComp;
}
else
if (Plot1 = 2)
{
MacdH = hist;
}
//{ Normalized MACD/Histogram }
normMod = Highest(MacdH)- Lowest(MacdH);
normMod = IIf(normMod = 0, .000001, normMod);
MacdHnorm = ((MacdH- Lowest(MacdH))/normMod-.5)*200;

//{ Choose standard/normalized }
//MacdComp = IIf(Plot2 = 1, MacdH, MacdHnorm);

if (Plot2 = 1)
{
MACDComp = MacdH;
}
else
if (Plot2 = 2)
{
MACDComp = MacdHnorm;
}

s = EMA(MacdComp,pds);
//{ MACD/Hist average }
//MACDComp0check = IsTrue(MACDComp);
//if (MACDComp0check = 1)
//{
Avg1 = Cum(MacdComp)/Cum(MacdComp);
//}
//else
//{}
//;


//{ MACD/Hist auto boundaries }
pk = Ref(MacdComp,-1)> MacdComp AND Ref(MacdComp,-1) > Ref(MacdComp,-2)
AND Ref(MacdComp,-1)> Avg1;

pkVal = ValueWhen(pk, Ref(MacdComp,-1), 1);

tr = Ref(MacdComp,-1)<MacdComp AND Ref(MacdComp,-1)<Ref(MacdComp,-2)
AND Ref(MacdComp,-1) < Avg1;

trVal = ValueWhen(tr,Ref(MacdComp,-1), 1);


pkVal0check = IsTrue(pkVal);
//if (pkVal0check = 1)
//{
Obought = Cum(pkVal)/Cum(pkVal);
//}
//else
//{};
Osold = Cum(trVal)/Cum(trVal);



//{ Plot in own window }
Plot(Obought, "overbought", colorRed);
Plot(Avg1, "Average", colorLightGrey);
Plot(Osold, "oversold", colorBlue);
p1 = IIf(Plot1 = 1, s, Avg1);
Plot(p1, "Chosen signal/average", colorGreen );
Plot(MacdComp, "MACD Composite", colorBlack);
 
#17
biginner_av,
Thank you for your help. Presently, hitesh"s problem is solved with my afl.
Formula Obought = Cum(pkVal)/Cum(pkVal);
should be Obought = Cum(pkVal)/Cum(pk);

But cum(pkval) does not give correct value ---which I too did not understand.
Regards.
 

hitesh

Active Member
#18
Dear beginner_av,,

Thank you for your help. Presently kgsirasangi has help me out to solve the problem.

In metastock, there is a term called IsDefined. The meaning of which is as follows:- Returns 1 if all data necessary to calculate the formula is available, 0 if not.

I was stucked there only.In the formula, IsDefined is used three times. For calculating MACD/Hist average, Obought and Osold. The original formula is as follows:-
Obought:=Cum(pkVal)/Cum(IsDefined(pkVal));
Osold:=Cum(trVal)/Cum(IsDefined(trVal));


In denominator, the value should be 1 or 0 depending on value available.(so far I understand)
Regards and Thanks
Hitesh
 

casoni

Well-Known Member
#19
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.
.....................................................................
add this it will plot signals as above mentioned condition....
Buy= Cross (x ,s) AND x> MA(pkval,periods);
Sell= Cross (x ,s) AND x<MA(trval,periods);
Cover = Cross (x , MA(pkval,periods)) AND x> s ;
Short = Cross( MA(trval,periods),x) AND x<s ;

PlotShapes( shapeSmallCircle*Buy, colorBrightGreen);
PlotShapes( shapeSmallCircle*Sell, colorYellow);
PlotShapes( shapeUpArrow*Cover, colorBlue, -10 );
PlotShapes( shapeDownArrow*Short, colorRed, -10 );
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Cover=ExRem(Cover,Short);
Short=ExRem(Short,Cover);
..................lets hope i have done it right.....waiting for your responce...............thanks
 

Similar threads