Need help with Simple EMA+MACD AFL

#11
Hello Singhboy,

You can try following...

B1 = Cross (C, EMA(C,50));
S1 = Cross (EMA(C,50),C);
B1 = Flip(B1,S1);
B2 = MACD() > Signal();
B2 = ExRem(B2,S1);

Buy = B1 AND B2;

Feel free if you need any further help.

Thanks for replying. But this also doesnt work. Ok let me explain again. Take a example of 5 mint chart. Price cross up 50 EMA at 1.00 PM and MACD is grater than signal line then buy signal will appear. Or Price cross up 50 EMA at 1.00 PM and Macd Cross up Signal Line at 1.30 PM , then a buy signal would appear.
Now suppose price remains above 50 EMA but at 1.45 PM Macd cross Down Signal Line , and then at 2 PM, it again cross up Signal Line. Because price is already above 50 ema , then a double buy signal will appear at 2 PM. Now there will be two buy signals, one which generated at 1.30 PM, 2nd which generated at 2 PM.

What I want that there should be only one buy signal for the fresh cross of macd above signal line, after the price crossed above 50 ema.

Now lets talk abt your afl . I copy pasted your afl conditions as following

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates,colorRed);

Plot(C,"Price",IIf(C>O,colorSeaGreen,colorBrown),styleCandle);

_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
if( ParamToggle("Tooltip shows", "All Values|Only Prices" ) )
{
ToolTip=StrFormat("Open: %g\nHigh: %g\nLow: %g\nClose: %g (%.1f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1 )));
}


Plot(EMA(Close,50),"50EMA",colorRed,style=styleThick);

_SECTION_END();


B1 = Cross (C, EMA(C,50));
S1 = Cross (EMA(C,50),C);
B1 = Flip(B1,S1);
B2 = MACD() > Signal();
B2 = ExRem(B2,S1);

Buy = B1 AND B2;



AddColumn(Close,"Close",1.4);
AddColumn(Buy,"buy",1.2);

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorBlue, 0, L, Offset=-20);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorBlue, 0,L, Offset=-30);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-25);


Just watch Nifty futures on 29th July 2011, on 1.05 PM Nifty Future closed above 50 ema, and Macd was above signal line. There should be a Buy signal. But no buy signal appeared. Then price crossed up 50 ema again at 1.25 PM and 1.45 PM while MACD was above signal line but again no buy signal apperaed. Im attaching image

 

myamit

Well-Known Member
#12
Thanks for replying. But this also doesnt work. Ok let me explain again.
Hello SinghBoy,

I'm not sure you really need all those signals as that will be too many. But anyway... use following to achieve your results...

B1 = Cross (C, EMA(C,50));
S1 = Cross (EMA(C,50),C);
B2 = Cross (MACD(), Signal());
S2 = Cross (Signal(), MACD());

EMAUP = Flip(B1,S1);
MACDUP = Flip(B2,S2);

Buy = (B1 AND MACDUP) OR (B2 AND EMAUP);

Do let me know if you need more help.
 
#13
Thanks for replying mate but you didnt get what I want actually. There are double buy signals in this afl. As i have said earlier that If price cross up 50 ema and macd is abv signal line, a buy signal should appear. But if price remains above 50 ema and macd cross down signal line and then again cross up signal line , then once again a double buy signal will appear. Similarly If macd remain above signal line and price cross down 50 ema and then again cross up 50 ema, then again a double buy signal will appear. And thats what happens in ur afl. I dont want that. Buy signal should appear one time only ,thats whenever 2 condtions of 50 ema and macd are met. When both price and macd cross down and once again cross up, only that time another buy signal should appear. I hope this time you understand what i want exactly. Thanks. Im attaching image

 

myamit

Well-Known Member
#14
Thanks for replying mate but you didnt get what I want actually. Buy signal should appear one time only ,thats whenever 2 condtions of 50 ema and macd are met. When both price and macd cross down and once again cross up, only that time another buy signal should appear.
Hello Singhboy,

Hopefully I got you correct this time. Check the code below & let me know.

B1 = Cross (C, EMA(C,50));
S1 = Cross (EMA(C,50),C);
B2 = Cross (MACD(), Signal());
S2 = Cross (Signal(), MACD());

EMAUP = Flip(B1,S1);
MACDUP = Flip(B2,S2);

BSig = EMAUP AND MACDUP;
SSig = (NOT EMAUP) AND (NOT MACDUP);

BSig = ExRem(Bsig,Ssig);
SSig = ExRem(Ssig,Bsig);

Buy = Bsig;
 

singhboy

Active Member
#15
Oh yes Master , this time its absolutely right. Thanks alot for giving your time.:thanx:
 

rajsumi121

Well-Known Member
#16
Hello Singhboy,

Hopefully I got you correct this time. Check the code below & let me know.

B1 = Cross (C, EMA(C,50));
S1 = Cross (EMA(C,50),C);
B2 = Cross (MACD(), Signal());
S2 = Cross (Signal(), MACD());

EMAUP = Flip(B1,S1);
MACDUP = Flip(B2,S2);

BSig = EMAUP AND MACDUP;
SSig = (NOT EMAUP) AND (NOT MACDUP);

BSig = ExRem(Bsig,Ssig);
SSig = ExRem(Ssig,Bsig);

Buy = Bsig;

Please attach this complete afl
 

Similar threads