The Grand AFL Collection Thread

NTrader42

Well-Known Member
#11
NTrader42, good one to begin with. But if possible we are looking to have some comment on the afls right here so that it gets well documented.
Hello sudris

We are all counting on you to do that, i just gave you material to get started with, here is something more for you, after you are through with organizing and commenting on Linkon's stuff, Enjoy :thumb:

AFL Thread by Zultan


:clap:
 

sudris

Well-Known Member
#12
Below afl will show the last tick price as a horizontal line across the price chart, similar to what is seen in Metatrader.

Just drag and drop on your price chart. default color is black so in case your chart background is black, you would have to right click and go to parameters and select suitable color for "Last Price Line"

Code:
_SECTION_BEGIN("Last Price Line");
//Plots the last tick price as a horizontal line across the price chart.
//By Sudris.
PlotGrid(LastValue(C),ParamColor("Last Price Line Color", colorBlack));
_SECTION_END();
Disclaimer: Not sure if this is posted before. if posted earlier, credit to the Original Author.
 

trash

Well-Known Member
#13
Different method of price line that in addition draws that line just for the current day only. So this function is suitable for intra-day data.

Code:
_SECTION_BEGIN("CDL");
//by trash
function CDL( array, doy )
{ 
  Lastdoy = doy == LastValue( doy );
  Dayline = array * Lastdoy;

  return IIf( Dayline, Dayline, Null );
}

priceline = CDL( LastValue(Close), DayOfYear() );

Plot(priceline, "", ParamColor("Last Price Line Color", colorRed), styleBar|styleNorescale);
_SECTION_END();
stylebar can be changed to styleline or styledashed.
array of the CDL function can be whatever you want i.e., high of the day or low of the day or Bid price or Ask price or ....
You get Bid/Ask price this way

BidPrice = GetRTData("Bid");
AskPrice = GetRTData("Ask");

And for Bid or Ask you don't need to use Lastvalue() function within CDL function. Example:
Code:
_SECTION_BEGIN("CDL");
//by trash
function CDL( array, doy )
{ 
  Lastdoy = doy == LastValue( doy );
  Dayline = array * Lastdoy;

  return IIf( Dayline, Dayline, Null );
}


BidPrice = GetRTData("Bid");
AskPrice = GetRTData("Ask");

doy = DayOfYear();
bidline = CDL( BidPrice, doy );
askline = CDL( AskPrice, doy );

Plot(bidline, "", ParamColor("Bid Price Line Color", colorRed), styleBar|styleNorescale);
Plot(askline, "", ParamColor("Ask Price Line Color", colorBlue), styleBar|styleNorescale);
_SECTION_END();
And Bid/Ask GetRTData functions work with real-time data only.
 
Last edited:
#14
i think moving the line to the right is better idea


_SECTION_BEGIN("Price1");
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("CDL");
//by trash
function CDL( array, doy )
{
Lastdoy = doy == LastValue( doy );
Dayline = array * Lastdoy;

return IIf( Dayline, Dayline,Null);
}

priceline = CDL( LastValue(Close), DayOfYear() );

Plot(priceline, "", ParamColor("Last Price Line Color", colorWhite),Null|styleNoRescale,Null,Null,4);
_SECTION_END();
 

trash

Well-Known Member
#17
i think moving the line to the right is better idea


_SECTION_BEGIN("Price1");
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("CDL");
//by trash
function CDL( array, doy )
{
Lastdoy = doy == LastValue( doy );
Dayline = array * Lastdoy;

return IIf( Dayline, Dayline,Null);
}

priceline = CDL( LastValue(Close), DayOfYear() );

Plot(priceline, "", ParamColor("Last Price Line Color", colorWhite),Null|styleNoRescale,Null,Null,4);
_SECTION_END();

If you want it to be extended to the right then here is a better solution, IMO. In addition it's all inclusive (three length versions).

Code:
_SECTION_BEGIN("CDL advanced");
//by trash
function CDL( array, doy )
{ 
  Lastdoy = doy == LastValue( doy );
  Dayline = array * Lastdoy;

  return IIf( Dayline, Dayline, Null );
}

ext       = Param("Extend Last Price Line to the Right", 50, 1, 50, 1); 
Linemode  = ParamList("Choose Line length", "Shortest|Current Day|Full Length");
Linecol   = ParamColor("Last Price Line Color", colorRed);
Line0     = EndValue( C );
FinishL0  = EndValue( BarIndex() - ext); 
Shortest  = LineArray(FinishL0, Line0, FinishL0 - ext, Line0, 1);
priceline = CDL( Line0, DayOfYear() );
Linestyle = styleDashed|styleNoRescale|styleNoLabel;

if(Linemode == "Shortest")
 Plot(Shortest, "", Linecol, Linestyle, 0, 0, ext);
else if (Linemode == "Current Day")
{
 Plot(Shortest, "", Linecol, Linestyle, 0, 0, ext);
 Plot(priceline, "", Linecol, Linestyle);
}
else if (Linemode == "Full Length")
 PlotGrid(Line0,  Linecol);
_SECTION_END();
 
#18
this my way also you can have the pric appear next exacly to the candle

_SECTION_BEGIN("Price1");
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();

numbars = SelectedValue(Cum(Status("barvisible")));
fraction= IIf(StrRight(Name(),3) == "",3.2,3.2);
hts = Param ("Text Shift", -50,-100,100,10);
PlotText("-----------" + WriteVal(C,fraction),
SelectedValue(BarIndex())-(numbars/hts),SelectedValue(C),2);


 

trash

Well-Known Member
#19
Ok, pal. Here is last version with Bid Ask plot. Here you need real-time data.

Code:
//by trash
function CDL( array, doy )
{ 
  Lastdoy = doy == LastValue( doy );
  Dayline = array * Lastdoy;
  return IIf( Dayline, Dayline, Null );
}

ext       = Param("Extend Last Price Line to the Right", 10, 1, 50, 1); 
Linemode  = ParamList("Choose Line length", "Shortest|Current Day|Full Length");
Linecol   = ParamColor("Bid Price Line Color", colorRed);
Askcol    = ParamColor("Ask Price Line Color", colorBlue);
Line0     = GetRTData("Bid");
Lineask   = GetRTData("Ask");
FinishL0  = EndValue( BarIndex() - ext); 
Shortest  = LineArray(FinishL0, Line0, FinishL0 - ext, Line0, 1);
ShortAsk  = LineArray(FinishL0, Lineask, FinishL0 - ext, Lineask, 1);
priceline = CDL( Line0, DayOfYear() );
Linestyle = styleDashed|styleNoRescale|styleNoLabel;

if(Linemode == "Shortest")
{
 Plot(Shortest, "", Linecol, Linestyle, 0, 0, ext);
 Plot(ShortAsk, "", Askcol, Linestyle, 0, 0, ext);
}
else if (Linemode == "Current Day")
{
 Plot(Shortest, "", Linecol, Linestyle, 0, 0, ext);
 Plot(ShortAsk, "", Askcol, Linestyle, 0, 0, ext);
 Plot(priceline, "", Linecol, Linestyle);
}
else if (Linemode == "Full Length")
{
 Plot(ShortAsk, "", Askcol, Linestyle, 0, 0, ext);
 Plot(Line0, "", Linecol, Linestyle, 0, 0, ext);
}

PlotText( "Bid  " + WriteVal(Line0, 1.4), BarCount+ext+2, LastValue(Line0)- TickSize, Linecol);
PlotText( "Ask "  + WriteVal(Lineask, 1.4), BarCount+ext+2, LastValue(Lineask)+ 0.01 * TickSize, Askcol );
 

Attachments

Last edited:
#20
Dear Coders,

plz help in this volume oscillator afl.both lines are same colour.can the change of colour of the crossover line?one blue & the other one is red.

/* Volume Oscillator */
/* Indicator, system, and exploration */

PlusDM= IIf(High>Ref(High,-1) AND Low>=Ref(Low,-1), High-Ref(High,-1),
IIf(High>Ref(High,-1) AND Low<Ref(Low,-1)
AND High-Ref(High,-1)>Ref(Low,-1)-Low,
High-Ref(High,-1),0));

Vm=log(EMA(V,3));

Buy= (C-L)*Vm+ (H-O)*Vm +
IIf(C>O,(C-O)*Vm,0) + PlusDM*Vm +
IIf(Ref(C,-1)<O,(O-Ref(C,-1))*Vm,0);

MinDM = IIf(Low<Ref(Low,-1) AND High<=Ref(High,-1), Ref(Low,-1)-Low,
IIf(High>Ref(High,-1) AND Low<Ref(Low,-1)
AND High-Ref(High,-1)<Ref(Low,-1)-Low, Ref(Low,-1)-Low, 0));

Sell= (H-C)*Vm + (O-L)*Vm +
IIf(C<O,(O-C)*Vm,0) + MinDM*Vm +
IIf(Ref(C,-1)>O,(Ref(C,-1)-O)*Vm,0);

Wm=Wilders(Wilders(Buy,3)-Wilders(Sell,3),3);

Buy=Cross(Wm,0);
Sell=Cross(0,Wm);


Graph1=Wm;
/*Graph2=Wilders(Wm,30);*/
Graph2=MA(Wm,8);

Graph0=0;
Graph0Style=Graph1Style=Graph2Style=5;
Graph2Color=6;


Filter= (Buy==1) ;
NumColumns = 6;
Column0 =Ref(C+0.065,-1);
Column0Format = 1.2;
Column0Name = "Trigger Price";WriteVal(C+0.065);
Column1 = C;
Column1Name = "Close ";WriteVal(C);
Column1Format = 1.2;
Column2 = MA(V,17);
Column2Name = "17 Ma Vol ";WriteVal(MA(V,17) );
Column2Format = 1.0;
Column3 = MA(C,17)/MA(C,50);
Column3Name = "% 17/50 ";WriteVal( MA(C,17)/MA(C,50) );
Column3Format = 1.2;
Column3Format = 1.2;
Column4= MA(C,17);
Column4Name="17 C ma"; WriteVal( MA(C,17) );
Column4Format = 1.2;
Column4= MA(C,50);
Column4Name="50 C ma"; WriteVal( MA(C,50) );
Column4Format = 1.2;
Column5=Wm;
Column5Name="Vol Osc"; WriteVal(Wm);
Column5Format=1.2;

/* End of Exploration Code. */
 

Similar threads