this is generic version of AMA AFL. by default it will show for the chart TF.
in param usetf = YES and tf = 1440 to get daily band for swing
tf = 15min for intraday
colors of band and MAs you can change suitably so that you can differentate which is intra and which swing
in param usetf = YES and tf = 1440 to get daily band for swing
tf = 15min for intraday
colors of band and MAs you can change suitably so that you can differentate which is intra and which swing
Code:
datamode = ParamToggle("Data Mode", "No|Yes", 0) ;
showintitle = ParamToggle("Show in Title", "No|Yes", 0) ;
showlabel = ParamToggle("Show Label", "No|Yes", 1) ;
usetf = ParamToggle("Use TF", "No|Yes", 0) ;
tf = Param("TF", 6, 1, 100000, 1) ;
isexpandLast = ParamToggle("Expand Mode", "First|Last", 1) ;
expandmode = IIf(isexpandLast, expandLast, expandFirst) ;
period = Param("Period", 30, 1, 100, 1) ;
noiseperiod = Param("Noise Period", 5, 1, 100, 1) ;
Clr = ParamColor("AMA Color", colorLightOrange) ;
ClrClose = ParamColor("AMA Close Color", colorOrange) ;
MAwidthper = Param("MA Width %", 0.005, 0, 10, 1) ;
MAwidth = SelectedValue(C) * MAwidthper /100 ;
showasband = ParamToggle("Show as band", "No|Yes", 1) ;
Onlyclose = ParamToggle("Show Only Close", "No|Yes", 0) ;
showclosebias = ParamToggle("Show Close Bias", "No|Yes", 0) ;
Closebiasht = Param("Close bias Ht", 4, 0, 100) ;
Clrbiasup = ParamColor("Color Bias Up", colorSkyblue) ;
Clrbiasdn = ParamColor("Color Bias Down", colorRose) ;
Clrbiasnone = ParamColor("Color Bias None", colorLavender) ;
Clrband = ParamColor("Color Band", colorGold) ;
bandlevel = Param("Level Band", -1, -5, 5, 1) ;
tradearr = ParamToggle("Show Trade Arrow", "No|Yes", 0) ;
triggertypepvt = ParamToggle("Trigger Type", "Bar|Pvt", 0) ;
Onbody= ParamToggle("BO style", "H-L|Body", 1) ;
datamodestyle = styleNoRescale ;
if (NOT showintitle)
datamodestyle |= styleNoTitle ;
if (NOT showlabel)
datamodestyle |= styleNoLabel ;
if (datamode)
datamodestyle = styleNoDraw|styleNoTitle|styleNoLabel|styleNoRescale ;
onlyClosestyle = 0 ;
if (Onlyclose)
OnlyClosestyle = styleNoDraw ;
tfs = tf *in1Minute ;
if (usetf)
TimeFrameSet(tfs) ;
tfma = int(Interval()/60) ;
if (usetf AND tfs >= Interval())
tfma = tf ;
strtf = NumToStr(tfma, 8.0)+"min" ;
Refo = ParamField("TF Open", 0) ;
Refh = ParamField("TF High", 1) ;
Refl = ParamField("TF Low", 2) ;
Refc = ParamField("TF Close", 3) ;
//Refbi = ParamField("BI", 4) ;
//Plot(EMA( Close, period ), "", colorRed) ;
fast = 2/(2+1);
slow = 2/(period+1);
dir=abs(Refc -Ref(Refc ,-noiseperiod ));
vol=Sum(abs(Refc -Ref(Refc,-1)),noiseperiod );
ER=dir/vol;
sc =( ER*(fast-slow)+slow)^2;
amaplotcx = AMA( Refc, sc );
dirh=abs(Refh -Ref(Refh ,-noiseperiod ));
volh=Sum(abs(Refh -Ref(Refh,-1)),noiseperiod );
ERh=dirh/volh;
sch =( ERh*(fast-slow)+slow)^2;
amaplothx = AMA( Refh, sch );
dirl=abs(Refl -Ref(Refl ,-noiseperiod ));
voll=Sum(abs(Refl -Ref(Refl,-1)),noiseperiod );
ERl=dirl/voll;
scl =( ERl*(fast-slow)+slow)^2;
amaplotlx = AMA( Refl, scl );
amaplotc = amaplotcx ;
amaploth = amaplothx ;
amaplotl = amaplotlx ;
if (usetf)
{
amaplotc = TimeFrameExpand(amaplotcx, tfs, expandmode) ;
amaploth = TimeFrameExpand(amaplothx, tfs, expandmode) ;
amaplotl = TimeFrameExpand(amaplotlx, tfs, expandmode) ;
TimeFrameRestore() ;
}
showoncrb = ParamToggle("Show On CRB", "No|Yes", 0) ;
Refo = ParamField("CRB Open", 7+0) ;
Refh = ParamField("CRB High", 7+1) ;
Refl = ParamField("CRB Low", 7+2) ;
Refc = ParamField("CRB Close", 7+3) ;
Refbi = ParamField("CRB BI", 7+4) ;
Refcrbbars = ParamField("CRB Bars", 7+5) ;
Refnbars = ParamField("TF Bars", 7+6) ;
Refdt = ParamField("CRB DT", 7+7) ;
if (showoncrb)
{
diffbars = Refnbars -Refcrbbars -1 ;
// convert to crb
Refamaploth = Ref(amaploth, -diffbars) ;
Refamaplotc = Ref(amaplotc, -diffbars) ;
Refamaplotl = Ref(amaplotl, -diffbars) ;
// RefClre = Ref(Clr, -diffbars) ;
k = 0 ;
for ( i = Crbst ; i < BarCount ; i++)
{
Refbar = Refbi[i];
Refamaploth[i] = amaploth[Refbar] ;
Refamaplotc[i] = amaplotc[Refbar] ;
Refamaplotl[i] = amaplotl[Refbar] ;
// RefClre[i] = Clr[Refbar];
k++;
}
}
else
{
Refamaploth = amaploth ;
Refamaplotc = amaplotc ;
Refamaplotl = amaplotl ;
// RefClre = Clre ;
}
Plot(Refamaplotc, strtf+"AMA close"+NumToStr(period, 1.0)+" "+ NumToStr(noiseperiod , 1.0), ClrClose, styleThick|datamodestyle) ;
Plot(Refamaploth, strtf+"AMA high"+NumToStr(period, 1.0)+" "+ NumToStr(noiseperiod , 1.0), Clr, styleThick|datamodestyle|OnlyClosestyle) ;
Plot(Refamaplotl, strtf+"AMA low"+NumToStr(period, 1.0)+" "+ NumToStr(noiseperiod , 1.0), Clr, styleThick|datamodestyle|OnlyClosestyle) ;
if (MAwidth > 0)
PlotOHLC(Refamaplotc+MAwidth, Refamaplotc+MAwidth, Refamaplotc-MAwidth, Refamaplotc-MAwidth, "", ClrClose , styleCloud|styleNoLabel|datamodestyle) ;
if (showasband)
{
PlotOHLC(Refamaploth, Refamaploth, Refamaplotl, Refamaplotl, "", Clrband, styleCloud|styleNoLabel|datamodestyle|OnlyClosestyle, 0, 0, 0, bandlevel) ;
}
if (showclosebias)
{
upside = Refamaploth-(Refamaploth-Refamaplotl)/3 ;
dnside = Refamaplotl+(Refamaploth-Refamaplotl)/3 ;
up = Refamaplotc >= upside ;
dn = Refamaplotc <= dnside ;
Clr = IIf(up, Clrbiasup, IIf(dn, Clrbiasdn,Clrbiasnone)) ;
Plot(Closebiasht, "", Clr, styleArea|styleNoLabel|styleOwnScale, 0, 100) ;
}
showparam = ParamToggle("Show Key Param", "No|Yes", 0) ;
if (showparam)
{
y = (SelectedValue(Refamaploth)+ SelectedValue(Refamaplotl)) /2 ;
tfsd = tfs ;
if (tfsd < Interval())
tfsd = Interval() ;
str = "TF="+NumToStr(tfsd/in1Minute, 1.0) + " P=" + NumToStr(period, 1.0)+"-"+ NumToStr(noiseperiod, 1.0);
PlotText(str, BarCount+2, y, colorBlack) ;
}
showrib = ParamToggle("Show Ribbon", "No|Yes", 0) ;
barht = Param("Bar Ht", 4, 1, 100) ;
Refo = ParamField("Open", 0) ;
Refh = ParamField("High", 1) ;
Refl = ParamField("Low", 2) ;
Refc = ParamField("Close", 3) ;
if (showrib)
{
Buy = Refc > Max(Refamaplotc, Refamaploth) ;
Short = Refc < Min(Refamaplotc, Refamaplotl) ;
up = Flip(Buy, Short) ;
dn = Flip(Short, Buy) ;
Clr = IIf(up, colorBlue, colorRed) ;
Plot(barht, "", Clr, styleArea|styleNoLabel|styleOwnScale, 0, 100) ;
}
isemapvts = ParamToggle("Pvt Type", "H-L|EMA", 0) ;
if (tradearr)// AND NOT datamode)
{
avgP = (Refh+refl+Refc)/3 ;
p1 = Param("Fast", 1, 1, 100, 1) ;
p2 = Param("Slow", 3, 1, 100, 1) ;
ismph = H-H ;
ismpl = L-L ;
if (isemapvts)
{
EMA1 = EMA(avgP, p1) ;
EMA2 = EMA(avgP, p2) ;
upcross = Cross(EMA1, EMA2) ;
downcross = Cross(EMA2, EMA1) ;
bi = BarIndex() ;
mphbar = HighestSinceBars(upcross, Refh) ;
mplbar = LowestSinceBars(downcross, Refl) ;
mphbi = ValueWhen(downcross, bi, 0) - ValueWhen(downcross, mphbar, 0) ;
ismph = mphbi == bi ;
mplbi = ValueWhen(upCross, bi, 0) - ValueWhen(upCross, mplbar, 0) ;
ismpl = mplbi == bi ;
ismph = IIf(downCross AND mphbar == 0, True, ismph) ;
ismpl = IIf(upcross AND mplbar == 0, True, ismpl) ;
}
else
{
ismph = H >= Ref(H, -1) AND H > Ref(H, 1) ;
ismpl = L <= Ref(L, -1) AND L < Ref(L, 1) ;
/*
ismph = ExRem(ismph, ismpl) ;
ismpl = ExRem(ismpl, ismph) ;
isbmph = ExRem(isbmph, isbmpl) ;
isbmpl = ExRem(isbmpl, isbmph) ;
*/
}
showminor = ParamToggle("Show Minor Pvts", "No|Yes", 1) ;
showminorlvls = ParamToggle("Show Minor Levels", "No|Yes", 1) ;
issquare = ParamToggle("Pvt style", "Circle|Square", 0) ;
pvtmarker = IIf(issquare, shapeSmallSquare, shapeSmallCircle) ;
if (showminor)
{
PlotShapes(ismph*pvtmarker , colorRed, 0, Refh, 12) ;
PlotShapes(ismpl*pvtmarker , colorGreen, 0, Refl, -12) ;
}
mph = ValueWhen(ismph, Refh) ;
mpl = ValueWhen(ismpl, Refl) ;
if (showminorlvls)
{
x = LineArray(0, SelectedValue(mph), (BarCount-1), SelectedValue(mph));
Plot(x, "", colorGold, styleDashed);
x = LineArray(0, SelectedValue(mpl), (BarCount-1), SelectedValue(mpl));
Plot(x, "", colorGold, styleDashed);
}
Reflow = Refl ;
Refhigh = Refh ;
if (Onbody)
{
Reflow = Min(Refo, Refc) ;
Refhigh = Max(Refo, Refc) ;
}
if (triggertypepvt)
{
Buy = ismph AND mph > AMAploth ;
Short = ismpl AND mpl < AMAplotl ;
}
else
{
Buy = avgP > AMAploth ;
Short = avgP < AMAplotl ;
}
Buy = ExRem(Buy, Short OR (C < AMAploth AND NOT C < AMAplotl ) ) ;
Short = ExRem(Short, Buy OR C < (AMAplotl AND NOT C > AMAploth ) ) ;
PlotShapes(Buy*shapeUpTriangle, colorGreen, 0, Refh, 12) ;
PlotShapes(Short*shapeDownTriangle, colorBrown, 0, Refl, 12) ;
}
Along with excellent coding abilities , you have also excellent sharing abilities.
Hats off to you !!!
:clapping::clapping::clapping: