Need Help in modifying this AFL - MA200 Crossover and MACDHist Crossover

#1
Hello,

I wanted to know what is wrong in this AFL where arrows are not coming proper in SCAN. There are no BUY Arrows being shown and Multiple SELL arrows are popping up at the WRONG place

Condition:
Buy : Price > 200MA (one candle ago) AND MACDHist > 0 (zero) - on earlier candle, MACDHist was below 0;
Sell : Price < 200MA (one candle ago) AND MACDHist < 0 (zero) - on earlier candle, MACDHist was above 0;

Note: The AFL is for MACD Lines. I'm not sure how to code for MACDHist. Pls modify a bit.
Also requesting addition of line to work in EXPLORE option also


http://imageshack.us/photo/my-images/545/bhartidly.jpg/

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();


_SECTION_BEGIN("Volume1");
Plot( Volume, _DEFAULT_NAME(), ParamColor("Color", colorBlueGrey ), ParamStyle( "Style", styleHistogram | styleOwnScale | styleThick, maskHistogram ), 2 );
_SECTION_END();

_SECTION_BEGIN("MA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

MA_Buy= Cross( C, MA( Close, 200 ) );
MA_Sell= Cross( EMA( Close, 200 ), C );

MACD_Buy = MACD(5,10) > 0;
MACD_Sell = MACD(5,10) < 0;

Buy = MA_Buy AND MACD_Buy == True;
Sell = MA_Sell AND MACD_Sell == True;

shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
Plot( Close, "Price", colorBlack, styleCandle );
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy, Low, High ) );
GraphXSpace = 5;
Short = Sell;
Cover = Buy;
 
#2
I wish i understood you properly.

plz check for the following AFL-

/*Condition:
Buy : Price > 200MA (one candle ago) AND MACDHist > 0 (zero) - on earlier candle, MACDHist was below 0;
Sell : Price < 200MA (one candle ago) AND MACDHist < 0 (zero) - on earlier candle, MACDHist was above 0;
*/


Code:
tog=IIf(Ref(MACD(12,26),-1)<0,False,True);
Buy= C>Ref(EMA(C,200),-1)&& MACD(12,26)>0 && tog==False;
Sell=C<Ref(EMA(C,200),-1) && MACD(12,26)<0 && tog==True;
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=Sell;
Cover=Buy;
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);
PlotShapes(Buy*shapeUpArrow+Sell*shapeDownArrow,IIf(Buy,colorGreen,IIf(Sell,colorRed,Null)),0,IIf(Buy,Low,High));
PlotShapes(Buy*shapeUpArrow+Sell*shapeDownArrow,IIf(Buy,colorBlue,IIf(Sell,colorViolet,Null)),0,IIf(Buy,Low-.03*Low,High+.03*H));
 

Similar threads