AFL coding help requested

#1
Hello Members
Request coding help for Buy / Sell signal based on

Buy Condition:
Close > EMA(5) and
AccDist > MA(AccDist,15)

Sell Condition:
Close < EMA(C,5) and
MA(AccDist,15) < AccDist

Note : Buy / Sell arrows to be in a single window which shows price and EMA(5) only. Also, SCAN/EXPLORE option, if possible, in the same AFL would be highly appreciated.

I tried combining 2 separate AFL's into one, which did not work - as follows :
_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", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

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

_SECTION_BEGIN("AccDist");
//Plot( AccDist(), _DEFAULT_NAME(), ParamColor("Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();


CandleBuy = Cross(Close, EMA(Close,50));
CandleSell = Cross(EMA(Close,50), Close);

AccDistSell = Cross(AccDist(), MA(AccDist(),15));
AccDistBuy = Cross(MA(AccDist(),15), AccDist());


PlotShapes(IIf((CandleSell and AccDistSell)==1, shapeDownArrow, shapeNone), colorRed, 0,High, Offset=-15);
PlotShapes(IIf((CandleBuy and AccDistBuy)==1, shapeUpArrow , shapeNone), colorGreen, 0,Low, Offset=-15);
 

Romeo1998

Well-Known Member
#3
Hello Members
Request coding help for Buy / Sell signal based on

Buy Condition:
Close > EMA(5) and
AccDist > MA(AccDist,15)

Sell Condition:
Close < EMA(C,5) and
MA(AccDist,15) < AccDist

Note : Buy / Sell arrows to be in a single window which shows price and EMA(5) only. Also, SCAN/EXPLORE option, if possible, in the same AFL would be highly appreciated.

I tried combining 2 separate AFL's into one, which did not work - as follows :
_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", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

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

_SECTION_BEGIN("AccDist");
//Plot( AccDist(), _DEFAULT_NAME(), ParamColor("Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();


CandleBuy = Cross(Close, EMA(Close,50));
CandleSell = Cross(EMA(Close,50), Close);

AccDistSell = Cross(AccDist(), MA(AccDist(),15));
AccDistBuy = Cross(MA(AccDist(),15), AccDist());


PlotShapes(IIf((CandleSell and AccDistSell)==1, shapeDownArrow, shapeNone), colorRed, 0,High, Offset=-15);
PlotShapes(IIf((CandleBuy and AccDistBuy)==1, shapeUpArrow , shapeNone), colorGreen, 0,Low, Offset=-15);
Dear Mam A Bhapkar,
( just now had a look at ur profile, hence calling Mam :) )
the following afl will fulfill the given buy n sell conditions
it will also plot arrows on chart when buy or sell condition is fulfilled (u can toggle them On or Off from parameters)
u can use this code in exploration too
Note -- AccDist uses volume, so if ur symbol doesnt have volume data , arrows wont b shown on chart n exploration wont show any results
here is the code :happy:
Code:
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", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );

t = ParamToggle("ShowArrows","Yes|No",1);
Plot(EMA(C,5),"EMA5",colorLightBlue,styleLine);

buycond = Cross (C,EMA(C,5)) AND Cross (AccDist(),MA(AccDist(),15));
sellcond = Cross(EMA(C,5),C)  AND  Cross (MA(AccDist(),15),AccDist());

if(t)
{
PlotShapes(IIf(buycond,shapeupArrow,shapeNone),coloryellow,0,L,-15);
PlotShapes(IIf(sellcond,shapedownArrow,shapeNone),colorwhite,0,H,-15);
}

Filter = buycond OR sellcond;

AddColumn(IIf(buycond,1,Null),"Buy",1,-1,IIf(buycond,colorLightYellow,Null));
AddColumn(IIf(buycond,AccDist(),Null),"AccDist",1.2,-1,IIf(buycond,colorLime,Null));
AddColumn(IIf(buycond,MA(AccDist(),15),Null),"MA_AccDist_15",1.2,-1,IIf(buycond,colorLightOrange,Null));
AddColumn(IIf(buycond,EMA(C,5),Null),"EMA_5",1.2,-1,IIf(buycond,colorAqua,Null));
AddColumn(IIf(buycond,c,Null),"Close",1.2,-1,IIf(buycond,colorLightBlue,Null));

AddColumn(IIf(sellcond,1,Null),"Sell",1,-1,IIf(sellcond,colorLightYellow,Null));
AddColumn(IIf(sellcond,AccDist(),Null),"AccDist",1.2,-1,IIf(sellcond,colorLime,Null));
AddColumn(IIf(sellcond,MA(AccDist(),15),Null),"MA_AccDist_15",1.2,-1,IIf(sellcond,colorLightOrange,Null));
AddColumn(IIf(sellcond,EMA(C,5),Null),"EMA_5",1.2,-1,IIf(sellcond,colorAqua,Null));
AddColumn(IIf(sellcond,c,Null),"Close",1.2,-1,IIf(sellcond,colorLightBlue,Null));
:happy:
 
Last edited:
#5
Romeo Sir
Found some issues in your AFL (since there is a slight modification in the AFL logic and requesting your support for the same). Also, in your earlier AFL the arrows were not coming properly. Have enclosed herewith a 50EMA and MACD only Buy / Sell signals expected places. Ideally, priority should be for MACD crossover as first priority and then the 50EMA crossover as the second priority - as mentioned in the attached pic.
Request you to please help with the login
warm regards- A Bhapkar
 

Attachments

Similar threads