Saturday 4 July 2015

Right Time Right Seclection AFL For Amibroker



// asfatul.alam@yahoo.com


_SECTION_BEGIN("VOLUME_Hight of Volume Bars Control");


PlotVOL = ParamToggle( "plot Volume?","No| Yes",0);

VolColor = (C>O OR (C==O AND
(H-C)<=(C-L) ))*ParamColor( "VUpColor" ,colorGreen) +

(C<O OR (C==O AND
(H-C)>(C-L)) )*ParamColor( "VDnColor" ,colorRed) ;

VolScale = Param("1/Vol. Height (TimeBar chart)(fraction of window) 5=1/5=20%",10, 2, 100, 1.0) ; // Timebars

if (PlotVOL >0)

{

Vheight = VolScale;

Plot(Prec(Volume ,0),"V",VolColor,
styleNoTitle| styleOwnScale| styleNoLabel| styleThick| ParamStyle( "VStyle", styleHistogram,maskHistogram| styleNoLabel) ,Vheight ); }
//Plot(MA(Volume,50),"",colorLightBlue,styleLine);



_SECTION_BEGIN("Stochastic_45-4-2_833");
periods = Param( "Periods", 20, 1, 200, 1 );

//Plot( StochK( periods , K1smooth), _DEFAULT_NAME(), colorCustom3, styleNoLabel | styleThick | styleDots);


periods = Param( "Periods", 20, 1, 200, 1 );
K1smooth = Param( "%K1 avg", 4, 1, 200, 1 );
D1smooth = Param( "%D1 avg", 2, 1, 200, 1 );
//Plot( StochD( periods , K1smooth, D1Smooth ), _DEFAULT_NAME(), colorCustom3, styleNoLabel | styleThick | styleDots);



A = StochK( periods , K1smooth);
B = StochD( periods , K1smooth, D1Smooth );




//PlotOHLC( 100, 100 , 95 , 95 , "", IIf( a < 20 OR a > 80,colorBlack,IIf(A>B ,colorBrightGreen,colorRed)), styleCloud | styleNoLabel);
//PlotOHLC( 5, 5 , 0 , 0 , "", IIf( a < 20 OR a > 80,colorBlack,IIf(A<B ,colorRed,colorBrightGreen)), styleCloud | styleNoLabel);

periods = Param( "Periods", 8, 1, 200, 1 );
K1smooth = Param( "%K1 avg", 3, 1, 200, 1 );



periods = Param( "Periods", 8, 1, 200, 1 );
K2smooth = Param( "%K1 avg", 3, 1, 200, 1 );
D2smooth = Param( "%D1 avg", 3, 1, 200, 1 );

M = StochK( periods , K2smooth);
N = StochD( periods , K2smooth, D2Smooth );

ColorK=IIf(A>B,colorBrightGreen,colorRed);

//Plot( M,"StoK", ColorK, styleNoLabel|styleThick);
//Plot( N,"StoD", colorDarkYellow, styleNoLabel|styleDashed);

style = Param("candle = yes",1,0,1,1);
Plot(Close,"",IIf(A > B ,colorBrightGreen,colorRed),IIf(style==1,styleCandle,styleLine));
//PlotOHLC( O, H , L , C , "Cloud", IIf(A > B ,colorDarkGreen,colorDarkRed), styleCloud | styleNoLabel);


_SECTION_END();


_SECTION_BEGIN("Tüm hedefler");

TimeFrameSet( inDaily );
DH=(H+Ref(H,-1))/2;
DL=(L+Ref(L,-1))/2;
DC=(C+Ref(C,-1))/2;
DR=DH-DL;
DCDHF=DH-DC;
DCDLF=DC-DL;

pd = (O+ DH+ DL + DC )/4;
sd1 = (2*pd)-DH;
sd2 = pd -(DH - DL);
sd3 = Sd1 - (DH-DL);
rd1 = (2*pd)-DL;
rd2 = pd +(DH -DL);
rd3 = rd1 +(DH-DL);

L4 =DC-(DR*130) / 100 ;
L3 =DC-(DR*120) / 100 ;
L2 =DC-DR;
L1 = DC-(DR*78) / 100;
SAT=DC-(DR*52/100);
STLS=DC-(DR*12.5)/100;
AL=DC+(DR*7.5)/100;
H1 = DC+(DR*37.5/100);
H2 = DC+(DR*78)/100;
H3 = DC+(DR*90)/100;
H4 = DC+(DR*120)/100 ;

Plot(SelectedValue(AL),"AL",colorGreen,styleDots);

Plot(SelectedValue(STLS),"STLS",colorYellow,styleDots);

Plot(SelectedValue(SAT),"SAT",colorCustom12,styleDots);

Plot(SelectedValue(H1),"H1",colorCustom15,styleDashed);
Plot(SelectedValue(H2),"H2",colorCustom11,styleDashed);

Plot(SelectedValue(H3),"H3",colorCustom10,styleDashed);
Plot(SelectedValue(H4),"H4",colorBlue,styleDashed) ;

Plot(SelectedValue(L1),"L1",colorCustom4,styleDashed);
Plot(SelectedValue(L2),"L2",colorCustom7,styleDashed);

Plot(SelectedValue(L3),"L3",colorCustom8,styleDashed);
Plot(SelectedValue(L4),"L4",colorCustom5,styleLine );

Plot(SelectedValue(pd),"pd",colorBlack,styleDots);



TimeFrameRestore();

tgt_up = L4-L4*5/1000;
tgt_up2 = L4-L4*10/1000;
tgt_dn = H4+H4*5/1000;
tgt_dn2 = H4+H4*10/1000;

Plot(SelectedValue(tgt_up),"hdf",colorWhite,styleDots);
Plot(SelectedValue(tgt_dn),"hdf",colorRed,styleDots);

Title = EncodeColor(colorWhite)+ "" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +" - "
+ WriteIf(Col_action=colorGreen, EncodeColor(colorGreen)+"stay LONG  ","")+ WriteIf(Col_action==colorRed, EncodeColor(colorRed)+"stay SHORT","")+ WriteIf(Col_action=colorBlack, EncodeColor(colorYellow)+"No Trend","")+"\n"
+ "Vol= "+ WriteVal(V) +WriteIf ( V > MA(V,26) ,EncodeColor(colorGreen)+" UP "+ (V/MA(V,26))*100 + " %", EncodeColor(colorRed)+" DOWN "+ (V/MA(V,26))*100 + " %")
+ EncodeColor(colorRed)+ "\n L4 : "+ EncodeColor(colorWhite)+L4+ EncodeColor(colorRed)+ " hdf : "+ EncodeColor(colorWhite)+tgt_up +EncodeColor(colorRed)+ " hdf2 : "+ EncodeColor(colorWhite)+tgt_up2
+ EncodeColor(colorRed)+ "\n L3 : "+ EncodeColor(colorWhite)+L3
+ EncodeColor(colorRed)+ "\n L2 : "+ EncodeColor(colorWhite)+L2
+ EncodeColor(colorRed)+ "\n L1 : "+ EncodeColor(colorWhite)+L1+ EncodeColor(colorGreen)+ "` Yüksek: "+ EncodeColor(colorWhite)+H
+ EncodeColor(colorCustom12)+ "\n SAT : "+ EncodeColor(colorCustom12)+SAT
+ EncodeColor(colorYellow)+ "\n STLS : "+ EncodeColor(colorYellow)+STLS
+ EncodeColor(colorBlack)+ "\n P?VOT : "+ EncodeColor(colorBlack)+pd + EncodeColor(colorYellow)+ "` Aç?l??: "+ EncodeColor(colorWhite)+O+ EncodeColor(colorBlack)+ "Kapan??: "+ EncodeColor(colorBlack)+C
+ EncodeColor(colorBrightGreen)+ "\n AL : "+ EncodeColor(colorBrightGreen)+AL
+ EncodeColor(colorGreen)+ "\n H1 : "+ EncodeColor(colorWhite)+H1+ EncodeColor(colorRed)+ "` Dü?ük: "+ EncodeColor(colorWhite)+L
+ EncodeColor(colorGreen)+ "\n H2 : "+ EncodeColor(colorWhite)+H2
+ EncodeColor(colorGreen)+ "\n H3 : "+ EncodeColor(colorWhite)+H3
+ EncodeColor(colorGreen)+ "\n H4 : "+ EncodeColor(colorWhite)+H4+ EncodeColor(colorGreen)+ " hdf : "+ EncodeColor(colorWhite)+tgt_dn + EncodeColor(colorGreen)+ " hdf2 : "+ EncodeColor(colorWhite)+tgt_dn2
+ EncodeColor(colorYellow)+ "\n DH : "+ EncodeColor(colorYellow)+DH
+ EncodeColor(colorTan)+ "\n DC : "+ EncodeColor(colorTan)+DC
+ EncodeColor(colorYellow)+ "\n DL : "+ EncodeColor(colorYellow)+DL
+ EncodeColor(colorAqua)+ "\n DCDHF : "+ EncodeColor(colorAqua)+DCDHF
+ EncodeColor(colorAqua)+ "\n DCDLF : "+ EncodeColor(colorAqua)+DCDLF
;

_SECTION_END();

Plot(6, "", IIf(PDI(7) > MDI(7) AND PDI(7) > 30,colorGreen,IIf (MDI(7) > PDI(7) AND MDI(7) > 30,colorRed,colorYellow)), styleOwnScale| styleArea|styleNoLabel,-0.5,500);

_SECTION_BEGIN("EMA");
Plot( EMA( Close, 34 ), "", IIf(EMA( Close, 34 ) > Ref(EMA( Close, 34 ),-1),colorGreen,colorRed),styleThick );
Plot( EMA( Close, 33 ), "", IIf(EMA( Close, 34 ) > Ref(EMA( Close, 34 ),-1),colorGreen,colorRed),styleThick+styleNoLabel );
Plot( EMA( Close, 32 ), "", IIf(EMA( Close, 34 ) > Ref(EMA( Close, 34 ),-1),colorGreen,colorRed),styleThick+styleNoLabel );

_SECTION_END();

_SECTION_BEGIN("EMA1");
Plot( EMA( Close, 17 ), "", IIf(EMA( Close, 17 ) > Ref(EMA( Close, 17 ),-1),colorTeal,colorYellow),styleThick );
Plot( EMA( Close, 16 ), "", IIf(EMA( Close, 17 ) > Ref(EMA( Close, 17 ),-1),colorTeal,colorYellow),styleThick+styleNoLabel );
Plot( EMA( Close, 15 ), "", IIf(EMA( Close, 17 ) > Ref(EMA( Close, 17 ),-1),colorTeal,colorYellow),styleThick+styleNoLabel );

_SECTION_END();

_SECTION_BEGIN("EMA2");
Plot( EMA( Close, 55 ), "", IIf(EMA( Close, 55 ) > Ref(EMA( Close, 55 ),-1),colorWhite,colorCustom12),styleThick );
Plot( EMA( Close, 54 ), "", IIf(EMA( Close, 55 ) > Ref(EMA( Close, 55 ),-1),colorWhite,colorCustom12),styleThick+styleNoLabel );
Plot( EMA( Close, 53 ), "", IIf(EMA( Close, 55 ) > Ref(EMA( Close, 55 ),-1),colorWhite,colorCustom12),styleThick+styleNoLabel );
_SECTION_END();


Filter = AL OR STLS OR SAT;
AddColumn( C, "KAPANIS", 1.2, colorDefault, colorLightBlue );
AddColumn( AL, "AL F?YATI", 1.2, colorDefault, colorGreen );
AddColumn( STLS, "STLS AL", 1.2, colorDefault, colorYellow );
AddColumn( SAT, "SAT F?YATI", 1.2, colorDefault, colorRed );

_SECTION_BEGIN("3 color gradient");

priceAxesWidth=0;
dateAxesHeight=0;
TitleHeight=0;

pxwidth = Status("pxwidth");
pxheight = Status("pxheight");

chartwidth = pxwidth-priceAxesWidth;
chartheight = pxheight-dateAxesHeight;

topColor=ParamColor("topColor",ColorRGB(207,254,240) );
centerColor=ParamColor("centerColor", ColorRGB(249,236,164));
botColor=ParamColor("BottomColor", ColorRGB( 253,223,196));
priceAxesColor=ParamColor("priceAxesColor", colorWhite );
dateAxesColor=ParamColor("dateAxesColor", colorWhite);

relPos=Param("centerPosition%",50,0,100,1)/100;
centerHeight=chartheight*Param("centerHeight%",10, 0,100,1)/100;
x0=0;
y0=Max(TitleHeight,chartheight*relPos-centerHeight/2);
x1=chartwidth;
y1=Min(chartheight,chartheight*relPos+centerHeight/2);

GfxSetBkMode( 1 );
GfxSetOverlayMode(1);
GfxGradientRect(0,0,chartwidth,TitleHeight, colorWhite ,colorWhite);
GfxGradientRect(chartwidth,0,pxwidth,pxheight, priceAxesColor
,priceAxesColor);
GfxGradientRect(0,chartheight,chartwidth,pxheight, dateAxesColor
,dateAxesColor);
GfxGradientRect(x0,y0,x1,y1, CenterColor ,CenterColor );
GfxGradientRect(0,TitleHeight,chartwidth, y0,topColor, CenterColor );
GfxGradientRect(0,y1,chartwidth, chartheight, CenterColor ,botColor);

_SECTION_END();


_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",colorGreen) );
Hor=Param("Horizontal Position",1050,1,1200,1);
Ver=Param("Vertical Position",1,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",colorGreen) );
GfxTextOut(""+DD+" ("+xx+"%)", Hor , Ver+45 );
_SECTION_END();


_SECTION_BEGIN("Name");
GfxSetOverlayMode(1);
GfxSelectFont("Tahoma", Status("pxheight")/20 );
GfxSetTextAlign( 6 );// center alignment
GfxSetTextColor( ColorHSB( 130, 240, 180 ) );
GfxSetBkMode(0); // transparent
GfxTextOut( Name(), Status("pxwidth")/2, Status("pxheight")/30 );
GfxSelectFont("Tahoma", Status("pxheight")/50 );


GfxSelectFont("Tahoma", Status("pxheight")/10 );
GfxSelectFont("Tahoma", Status("pxheight")/60 );

_SECTION_END();


_SECTION_BEGIN("Graphics");
GrpPrm=Param("Graphic Space",2,-5,10);
GraphXSpace=GrpPrm;

No comments:

Post a Comment

Thanks