AFL writing guide for new user

KelvinHand

Well-Known Member
hi friends,

please help how to change chart background color in afl

SetChartBkColor(ParamColor("bkcolor",ColorRGB(0,0, 0)));

I want to change ColorRGB to ColorLavender, it is showing error

please help
Change ColorRGB(0,0, 0) to ColorLavender
OR
Use ColorRGB(230,230, 250)
 
Last edited:

vu22rps

Active Member
Adding Volume in this scan

Hello,

I wrote this small afl which plots moving averages of 56 period of High, Low and Close, the buy signal is generated when the price cuts the high from bottom and the reverse for for sell signal.

Now I've tried to add Volume bot no luck, the idea was to include the 56 period of volume also into consideration to generate a buy or sell signal. Can any one correct me on this. The Bolinger Band is just an additional indicator I included.

Thanks in advance..


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();

//EMA1= EMA(H,56);
//EMA2=EMA(L,56);
//EMA3=EMA(C,56);

Buy= Cross(Close, EMA( H, 56 ));
Sell= Cross(EMA( L, 56 ),Close);

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

PlotShapes(shapeUpArrow*Buy,colorGreen);
PlotShapes(shapeDownArrow*Sell,colorRed);


Plot( EMA( H,56), "56 EMA High",ParamColor("EMA 56 Color", colorBlue ),styleNoRescale);
Plot( EMA( C,56), "56 EMA Close",ParamColor("EMA 56 Color", colorRed ),styleNoRescale);
Plot( EMA( L,56), "56 EMA Low",ParamColor("EMA 56 Color", colorGreen ),styleNoRescale);

_SECTION_END();

_SECTION_BEGIN("Bollinger Bands");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 100, 1 );
Width = Param("Width", 2, 0, 10, 0.05 );
Color = ParamColor("Color", colorLightGrey );
Style = ParamStyle("Style", styleLine | styleNoLabel ) | styleNoLabel;
Plot( bbt = BBandTop( P, Periods, Width ), "BBTop" + _PARAM_VALUES(), Color, Style );
Plot( bbb = BBandBot( P, Periods, Width ), "BBBot" + _PARAM_VALUES(), Color, Style );
PlotOHLC( bbt, bbt, bbb, bbb, "", ColorBlend( Color, colorWhite, 0.9 ), styleNoLabel | styleCloud | styleNoRescale, Null, Null, Null, -1 );
_SECTION_END();
 
Sear Friend,
Try with leading indicator,MA ia lagging indicator and will not getting price what exactly will take entry....
Pls work out with this and share the information


AFL FOR "VISUAL ARROW" FOR EMA CROSS OVER SYSTEM

Well we have have plotted our price and desired ema in the chart. Now may be we want to put an arrow in the chart. This will help us to recognize our signal better. How can I do this? Here is the code for it.

_SECTION_BEGIN("visual arrow ema cross over");
SetChartOptions(0,chartShowArrows|chartShowDates);
Plot( Close, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );

Buy= Cross(EMA( C, 20 ), EMA( C, 50 ));
Sell= Cross(EMA( C, 50 ), EMA( C, 20 ));

PlotShapes(IIf(Sell==1, shapeDownArrow, shapeNone), colorRed, 0,High, Offset=-20);
PlotShapes(IIf(Buy==1, shapeUpArrow , shapeNone), colorGreen, 0,Low, Offset=-20);

Plot( EMA( C,20), "20 EMA Close",ParamColor("EMA 20 Color", colorGreen ),styleNoRescale);
Plot( EMA( C,50), "50 EMA Close",ParamColor("EMA 50 Color", colorRed ),styleNoRescale);
_SECTION_END();


here Plot function is making this arrow.
Plot( EMA( C,20), "20 EMA Close",ParamColor("EMA 20 Color", colorGreen ),styleNoRescale);
Plot( EMA( C,50), "50 EMA Close",ParamColor("EMA 50 Color", colorRed ),styleNoRescale);


here is the output
 
I guess it is too late to thank Debarghya now for his above EXREM post. But I am having repeat signals (Buy-Buy) even when there are EXREM codes. Can anyone tell me why? I assume DM is not available in this thread frequently so I ask all.
 
Hi, I would be grateful if you could add two lines, as shown in the image below, right after the crossover occurs, please code it in such a way that emas can be modified, and the lines comes into view only after the buy signal occurs.. The lines should represent High & Low points of the bar on which the crossover occured..


Regards
bump!!! if someone could help still... thnx in advance...
 
I am new to AFL, can any body help me with multi time frame? I would like to trade and back test, SMA 10 and SMA 20 crossing in 15 mints, while SMA 10 and SMA 20 is crossed in hourly?
 
dear sir,

my requirement is below



BUY CONDITION: ALL BUY SIGNAL ONLY WILL TAKE HIGH+1 OF THE SIGNAL CANDLE .


SELL CONDITION: ALL SELL SIGNAL ONLY WILL TAKE LOW-1 OF THE SIGNAL CANDLE.

PLEASE SEE THE SCREEN SHOT FOR YOUR REF




http://imageshack.com/a/img838/3879/xmn2.jpg
--------------------------------------------------------------------------

PLEASE USE THIS AFL----------




_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("Advanced Trailstop System");



mult=Param("multi", 2.0, 0.1, 10, 0.05);
Aper=Param("ATR period", 7, 2, 100, 1 );
atrvalue=(mult*ATR(aper));

Bs[0]=0;//=L;
L[0]=0;
C[0]=0;

for( i = 9; i < BarCount; i++ )
{
if ( L[ i ] > L[ i - 1 ] AND L[ i ] > L[ i - 2 ] AND L[ i ] > L[ i - 3 ] AND L[ i ] > L[ i - 4 ] AND
L[ i ] > L[ i - 5 ] AND L[ i ] > L[ i - 6 ] AND L[ i ] > L[ i - 7 ] AND L[ i ] > L[ i - 8 ] AND
L[ i ] > L[ i - 9 ] AND C[ i ] > bs[ i - 1 ])
{
bs[ i ] = L[ i ] - ATRvalue[ i ] ;

}
else
{
if ( H[ i ] < H[ i - 1 ] AND H[ i ] < H[ i - 2 ] AND H[ i ] < H[ i - 3 ] AND H[ i ] < H[ i - 4 ] AND
H[ i ] < H[ i - 5 ] AND H[ i ] < H[ i - 6 ] AND H[ i ] < H[ i - 7 ] AND H[ i ] < H[ i - 8 ] AND
H[ i ] < H[ i - 9 ] AND C[ i ] < bs[ i - 1 ] )
{
bs[ i ] = H[ i ] + ATRvalue[ i ];

}
else
{
bs[ i ] = bs[ i - 1];
} }}

//================================================== ==
Mycolor=IIf(C>bs,colorLime,colorRed);
bcolor=IIf(C>bs,colorBlue,colorBlue);
//PlotOHLC( Open, High, Low, Close, "", Mycolor, styleBar| styleThick );
Plot(bs,"ATS",bcolor,1|styleThick);
Buy=Cover=Cross(C,bs);
Sell=Short=Cross(bs,C);
shape=Buy*shapeUpArrow + Sell*shapeDownArrow;
PlotShapes(shapeUpArrow*Buy, colorLime, 0, L, -95 );
PlotShapes(shapeDownArrow*Sell, colorRed, 0, H, -30 );
SellPrice=ValueWhen(Sell,C,1);
BuyPrice=ValueWhen(Buy,C,1);
Long=Flip(Buy,Sell);
Shrt=Flip(Sell,Buy );
_SECTION_END();
Filter= Buy OR Sell OR Short OR Cover;
//=================TITLE============================ ================================================== ==================

_SECTION_BEGIN("Title");
if( Status("action") == actionIndicator )
(
Title = EncodeColor(colorWhite)+ "Advanced Trailstop System " + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +" - "+"\n" +EncodeColor(colorRed) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n"+
EncodeColor(colorLime)+
WriteIf (Buy , " GO LONG / Reverse Signal at "+C+" ","")+
WriteIf (Sell , " EXIT LONG / Reverse Signal at "+C+" ","")+"\n"+EncodeColor(colorWhite)+
WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(C-BuyPrice)+"","")+
WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+(SellPrice-C)+"","")+
WriteIf(Long AND NOT Buy, "Trade : Long - Entry price Rs."+(BuyPrice),"")+
WriteIf(shrt AND NOT Sell, "Trade : Short - Entry price Rs."+(SellPrice),"")+"\n"+
WriteIf(Long AND NOT Buy, "Current Profit/Loss Rs."+(C-BuyPrice)+"","")+
WriteIf(shrt AND NOT Sell, "Current Profit/Loss Rs."+(SellPrice-C)+"",""));
_SECTION_END();
 

Similar threads