Friday 27 February 2015

Very useful afl for Amibroker

Very useful afl for Amibroker



///asfatul.alam@yahoo.com

_SECTION_BEGIN("Small Triggers");
p1 = Param("TL 1 Periods", 20, 5, 50, 1);
p2 = Param("TL 2 Periods", 5, 3, 25, 1);
TL1 = LinearReg(C, p1);
TL2 = EMA(TL1, p2);
Col1 = IIf(TL1 > TL2, ParamColor("TL Up Colour", colorBrightGreen), ParamColor("TL Dn Colour", colorCustom12));
//Plot(TL1, "TriggerLine 1", Col1, styleLine|styleThick|styleNoLabel);
_SECTION_END();


XNAME = Name();
VAL_EXISTS = 0;
T2= "";
Prd1=Param("ATR Period",4,1,20,1);
Prd2=Param("Look Back",8,1,20,1);
green = HHV(LLV(L,Prd1)+ATR(Prd1),Prd2);
red = LLV(HHV(H,Prd1)-ATR(Prd1),Prd2);

HighClosePercent = (H - C)*100/H;
HighLowPercent = MA((H - L)*100/H,25);
Smooth = Param("Smoothness",14,2,100,1);
Length = 20; Num_ATRs = 2;

Mov_Avg = MA((H+L+C)/3,Length);
KUP = Mov_Avg + Num_ATRs * ATR(Length);
KDOWN = Mov_Avg - Num_ATRs * ATR(Length);


Plot (MA(KUP,smooth),"KUP",colorGreen,styleLine);
Plot (MA(KDown,smooth), "Kdown",colorOrange,styleDashed);
Plot (MA(Mov_Avg,smooth),"Mov_Avg",colorGrey40, styleLine);

_SECTION_BEGIN("HA");


tchoice=Param("Title Selection ",2,1,2,1);

Q=Param("% Change",2.1,1,10,1);
Z= Ref(Zig(C ,q ),-1) ;
HH=Ref(((Z<Ref(Z,-1) AND Ref(Z,-1) > Ref(Z,-2)) AND (Peak(z,q,1 ) >Peak(Z,q,2))),-1);
LH=Ref(((Z<Ref(Z,-1) AND Ref(Z,-1) > Ref(Z,-2)) AND (Peak(Z,q,1 ) <Peak(Z,q,2))),-1);
HL=Ref(((Z>Ref(Z,-1) AND Ref(Z,-1) < Ref(Z,-2)) AND (Trough(Z,q,1 ) >Trough(Z,q,2))),-1);
LL=Ref(((Z>Ref(Z,-1) AND Ref(Z,-1) < Ref(Z,-2)) AND (Trough(Z,q,1 ) <Trough(Z,q,2))),-1);
GraphXSpace = 5;
dist = 0.5*ATR(20);

for( i = 0; i < BarCount; i++ )
{
if( HH[i] ) PlotText( "HH", i, H[ i ]+dist[i], colorCustom12 );
if( LH[i] ) PlotText( "LH", i, H[ i ]+dist[i], colorCustom12 );
if( HL[i] ) PlotText( "HL", i, L[ i ]-dist[i], colorWhite );
if( LL[i] ) PlotText( "LL", i, L[ i ]-dist[i], colorWhite );

}

TimeFrameSet(inHourly);
Hh=HHV (L,24);
Ll =LLV (H,24);
TimeFrameRestore();
Hh1=(TimeFrameExpand( Hh, inHourly));
Ll1=(TimeFrameExpand( Ll, inHourly));

_SECTION_BEGIN("Magnified Market Price");
FS=Param("Font Size",30,11,100,1);
GfxSelectFont("Times New Roman", FS, 700, True );
GfxSetBkMode( colorWhite ); 
GfxSetTextColor( ParamColor("Color",colorGold) );
Hor=Param("Horizontal Position",970,1,1200,1);
Ver=Param("Vertical Position",50,1,830,1);
GfxTextOut(""+C, Hor , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSelectFont("Times New Roman", 11, 700, True );
GfxSetBkMode( colorWhite ); 
GfxSetTextColor(ParamColor("Color",colorWhite) );
GfxTextOut(""+DD+"  ("+xx+"%)", Hor , Ver+45 );

_SECTION_END();

_SECTION_BEGIN("swing2");
no=22;
res=HHV(H,no);
sup=LLV(L,no);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
supres=IIf(avn==1,sup,res);
a=Cross(C,supres);
b=Cross(supres,C);
style = a * styleStaircase + b * styleStaircase;
//PlotShapes(a,style, IIf(a,colorGreen,colorRed), 0, IIf(a,Low,High));
//Plot(SUPRES,"Stop Loss",colorCustom1,styleDots);
    _SECTION_END();
SL = ( HHV( H, 26 ) + LLV( L, 26) )/2;
TL = ( HHV( H, 9 ) + LLV( L, 9 ) )/2;
DL = Ref( C, 26 );
Span1 = (( SL + TL )/2);
Span2 = (HHV( H, 52) + LLV(L, 52))/2;
Sp1=Ref((SL+TL)/2,-25);
Sp2=Ref((HHV(H,52)+LLV(L,52))/2,-25);
Plot(DL,"",colorLightBlue,styleThick);


pd = Param("Periods",13,5,144,1);
pds = 2*pd-1;
aa = Close-Ref(Close,-1);
uu = EMA(Max(0,aa),pds);
dd=  EMA((Max(0,0-aa)),pds);

rf = IIf(C>2,1000,10000);

c1 = Param("Upper Level",70,50,90,1);
qq1 =100/(100-c1)-1;
ff1 = qq1*dd-uu;
ff2 = ff1/qq1;
f1 = Max(ff1,ff2);
UL = Close + f1*(pds-1)/2;
UL = IIf(UL>C,floor(UL*rf),ceil(UL*rf))/rf;

c2 = Param("Equilibrium",50,50,50,0);
qq2 =100/(100-c2)-1;// [=1]
ff = dd-uu;
MM = Close + ff*(pds-1)/2;
MM = IIf(MM>C,floor(MM*rf),ceil(MM*rf))/rf;

c3 = Param("Lower Level",30,10,50,1);
qq3 =100/(100-c3)-1;
ff1 = qq3*dd-uu;
ff2 = ff1/qq3;
f3 = Min(ff1,ff2);
LL = Close + f3*(pds-1)/2;
LL = IIf(LL>C,floor(LL*rf),ceil(LL*rf))/rf;


Plot(UL,"",colorRed,1,styleThick|styleNoLabel);
Plot(MM,"",colorWhite,32);
Plot(LL,"",colorGreen,1,styleThick|styleNoLabel);



PlotOHLC( Open, High, Low, Close, "", colorYellow, styleBar | styleThick );
_SECTION_END();


//Plot (SL,"Standard",colorGreen);
//Plot (TL,"Turning",colorRed);
PlotOHLC (Sp1,Sp1,Sp2,Sp2,"Cloud",IIf(Sp1>Sp2,colorSeaGreen,colorDarkGrey),styleCloud);
Title = Name() + "  -  RSI(" + WriteVal(pd,0.0) + ")  -  Close=" +  WriteVal(Close,0.3) + "    UL=" +  WriteVal(UL,0.4) + "    MM=" +  WriteVal(MM,0.4) + "    LL=" +  WriteVal(LL,0.4);

No comments:

Post a Comment

Thanks