Simple Amibroker AFL not working

#1
I am trying to draw simple Buy and Sell arrows in the chart using cross function. However, it is not drawing anything on chart where the two lines are EMA() and Accdist() are crossing. Not sure what is wrong with the code, can anyone help?


_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_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", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();


Periods = Param("PeriodsEMA", 50, 2, 300, 1, 10 );
Plot( EMA( V, Periods ), "EMA", colorRed, styleOwnScale|styleThick );
Plot( AccDist(), "AccDist", colorBlue, styleOwnScale|styleThick );

Sell=Cross( EMA(V,Periods), AccDist()) ;
Buy=Cross(AccDist(),EMA(V,Periods)) ;

Short=Sell;
Cover=Buy;
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);


shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy, Low, High ) );
 

KelvinHand

Well-Known Member
#2
I am trying to draw simple Buy and Sell arrows in the chart using cross function. However, it is not drawing anything on chart where the two lines are EMA() and Accdist() are crossing. Not sure what is wrong with the code, can anyone help?


_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_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", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();


Periods = Param("PeriodsEMA", 50, 2, 300, 1, 10 );
Plot( EMA( V, Periods ), "EMA", colorRed, styleOwnScale|styleThick );
Plot( AccDist(), "AccDist", colorBlue, styleOwnScale|styleThick );

Sell=Cross( EMA(V,Periods), AccDist()) ;
Buy=Cross(AccDist(),EMA(V,Periods)) ;

Short=Sell;
Cover=Buy;
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);


shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy, Low, High ) );
1. Take out the "Price" session, make it as indicator window.
2. Remove the styleOwnScale.
3. Remove the IIf(Buy, Low, High)
 

KelvinHand

Well-Known Member
#4
Hi Kelvin,

I modified the code as instructed, but it is still not showing buy and sell arrows
Code:
Periods = Param("PeriodsEMA", 50, 2, 300, 1, 10 );
a= EMA( V, Periods );
b = AccDist();

Plot( a, "EMA(V)", colorRed, styleThick );
Plot( b, "AccDist", colorBlue, styleThick );

Sell=Cross( a, b) ;
Buy=Cross(b,a) ;

Short=Sell;
Cover=Buy;
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);


shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ));
not all stocks can. try more.

maybe not a good way to scan volume
 
Last edited:
#5
Found out the mistake with your help. the two lines were not crossing.

styleOwnScale was showing crossing lines when in fact they were not.
You had mentioned to remove it, but I guess removed it only from one line plot.

Thanks for your valuable time, really appreciated :)
 
#7
Maybe you want to do this

Code:
Periods = Param("PeriodsEMA", 50, 2, 300, 1, 10 );
a=  AccDist();
b =EMA( a, Periods );

Plot( a, "AccDist", colorRed, styleThick );
Plot( b, "EMA(AccDist)", colorBlue, styleThick );

Sell=Cross(a,b) ;
Buy=Cross(b,a) ;

Short=Sell;
Cover=Buy;
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);


shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ));
The above does not use volume, but trades based on trend in AccDist ratio.

Cheers
::thumb::
 
#8
Hi,
I am also facing some problem using PlotShapes AFL. Even though my sell statement returns false then also the sell shape is plotting on every candle.
This is my code :-

/*This will Plot monthly, weekly, AND daly charts in one chart but different panes. */
SetChartBkGradientFill(colorWhite,colorLightGrey,colorWhite);
Period= ParamList("Base","Daily|Weekly|Monthly|5 Minutes",0);
Period1 = EndValue( BarIndex() ) - BeginValue( BarIndex() );

//For Daily timeset
if(Period=="Daily")
{
TimeFrameSet(inDaily);
PlotOHLC(Open, High, Low, Close, "Daily Price Chart", colorBlack, style = styleCandle );
Plot(Volume, "Volume", colorTeal, styleBar);
//Plot(BarCount, "BarCount", colorTeal, styleBar);

extremeHigh = H[0];
extremeLow = 0;
volumeOnHigh =V[0];
volumeOnLow = 0;

//PlotText("Period@" + Period1, 0, L[0], colorRed );
for( i = 0; i < Period1 - 1; i++ )
{
condSell1 = H[i+1] > extremeHigh;
condSell2 = V[i+1]>= volumeOnHigh;
Sell = condSell1 AND condSell2;

if (Sell == 1)
{
printf( "Sell is ******************* %g\n", Sell );
PlotShapes(shapeDownArrow, colorGreen, 0,High);
}

if (extremeHigh < H[i +1])
{
extremeHigh = H[i+1];
volumeOnHigh = V[i+1];
}
condBuy1 = Low < extremeLow;
condBuy2 = Volume >= volumeOnLow;
Buy = condBuy1 AND condBuy2;
if (extremeLow > L[i+1])
{
extremeLow = L[i+1];
volumeOnLow = V[i+1];
}

}
TimeFrameRestore();

I just want to plot down arrow on sell signal, even though I get sell value as 1 it is showing arrow on all the candles.

Please help!!! :(
 

Similar threads