buy at low sell at high for Amibroker (AFL)
_SECTION_BEGIN("FastStoch FullStochK");
pds = Param("Periods",13,2,20);
slw = Param("Slow StochK",3,1,14); ;
slwd = Param("Slow StochD",3,1,14);
ob = Param("Overbought",83,65,88);
os = Param("Oversold",24,20,50);
FSK = 100*(C-LLV(L,pds))/(HHV(H,pds)-LLV(L,pds)); // FASTSTOCHK
FLSK = MA( FSK, slw ); // FULLSTOCHK
FLSD = MA( FLSK, slwd ); // FULLSTOCHD
MaxGraph = 6;
Graph0 = FSK;
Graph0Color = ParamColor("Fast K",colorGreen);
Graph1 = FLSK;
Graph1Color = ParamColor("Full K",colorRed);
Graph2 = FLSD;
Graph2Color = ParamColor("Full D",colorAqua);
Graph0Style = ParamStyle("FastStoch K",styleThick,maskAll);
Graph1Style = ParamStyle("FullStoch K",styleThick,maskAll);
Graph2Style = ParamStyle("FullStoch D",styleThick,maskAll);
Graph3 = FLSD;
Graph3BarColor =
IIf (Graph3 > ob, colorRed,
IIf (Graph3 < os, colorBrightGreen, colorGrey40));
Graph4 = ob;
Graph4Color = 4;
Graph5 = os;
Graph5Color = colorBrightGreen;
Graph3Style =ParamStyle("BAR 1",styleHistogram | styleThick,maskHistogram );
Graph4Style = Graph5Style =1;// ParamStyle("style");
Title = Name()+" - "+FullName()+
EncodeColor(Graph0Color)+" FastStochK="+
StrFormat("%1.4g ",fsk)+EncodeColor(Graph1Color)+
" FullStochK="+StrFormat("%1.4g ",flsk)+
EncodeColor(Graph2Color)+" FullStochD="+
StrFormat("%1.4g ",flsd);
whengoup = FLSD < os AND Cross(FSK,os) AND FLSK >= Ref(FLSK,-1) AND FLSD >= Ref(FLSD,-1) OR Cross(FLSD,os) AND //...next line
FSK >= Ref(FSK,-1) AND FLSK >= Ref(FLSK,-1) ;
whengodown = IIf(BarsSince(Cross(os,FSK))==1 AND FLSK < os ,1,0) OR Cross(os,FSK) AND FLSK < Ref(FLSK,-1) OR FLSK < ob //...next line
AND FLSK > os AND FLSK <= Ref(FLSK,-1) OR FSK > ob AND FLSK > ob AND FLSD > ob AND FSK < Ref(FSK,-1) AND FLSK < Ref(FLSK,-1) //...next line
AND FLSD <= Ref(FLSD,-1) OR FSK > ob AND FLSK > ob AND FLSD > ob AND Cross(ob,FLSK);
Buy = whengoup;
Sell = whengodown;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
_SECTION_END();_SECTION_BEGIN("Stochastic");
periods = Param( "Periods", 15, 1, 200, 1 );
Ksmooth = Param( "%K avg", 3, 1, 200, 1 );
Dsmooth = Param( "%D avg", 3, 1, 200, 1 );
myStochD=StochD( periods , Ksmooth, DSmooth );
myStochK=StochK( periods , Ksmooth);
Overbought=80;
Oversold=20;
Buy = Cross(myStochK, myStochD );
Sell = Cross( myStochD, myStochK );
Plot( myStochD, "Stochastic %D"+_PARAM_VALUES(), ParamColor( "ColorD", colorRed ), ParamStyle("StyleD") );
Plot( myStochK, "Stochastic %K", ParamColor( "ColorK", colorGreen ), ParamStyle("StyleK") );
PlotShapes(IIf(Sell, shapeHollowDownArrow , shapeNone), colorRed);
PlotShapes(IIf(Buy, shapeHollowUpArrow , shapeNone), colorBlue);
Plot(Overbought,"Overbought Level",colorRed);
Plot(Oversold,"Oversold Level",colorGreen);
PlotOHLC( myStochK,myStochK,50,myStochK, "", colorRed, styleCloud | styleClipMinMax, 20, 80 );
PlotOHLC( myStochD,myStochD,50,myStochD, "", colorYellow, styleCloud | styleClipMinMax, 20, 80 );
PlotOHLC( Null,myStochD,myStochK,Null, "", colorBlue, styleCloud);
_SECTION_END();
No comments:
Post a Comment
Thanks