• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Tìm hiểu thêm.

Stochastic for Amibroker

traders

Administrator
Thành viên BQT
Tham gia ngày
29/4/17
Bài viết
224
Thích
3
Điểm
18
Website
traders.vn
#1
_SECTION_BEGIN("Period");

SetBarsRequired( 1000, 1000);
prc = ( High + Low ) / 2;
Cyclepart = 0.7 ;
pi=4*atan(1);
RTD=180/pi;
DTR=pi/180;

Smooth[0] = Detrender[0] = I1[0] = Q1[0] = jI[0] = jQ[0] = I2[0] = I3[0] = Q3[0] = Q2[0] = Re[0] = Re1[0] =Im[0] = Im1[0] = 0;
Period[0] = Period1[0] = alpha = cycle = SmoothPeriod[0] = imagpart[0] = realpart[0] = DCPhase[0] = 0;
for ( i = 6; i < BarCount; i++ )
{
Smooth = ( 4 * prc + 3 * prc[i-1] + 2 * prc[i-2] + prc[i-3] ) / 10;
Cycle = ((1-0.5*alpha)^2)*(Smooth - 2*Smooth[i-1] + Smooth[i-2]) + 2*(1-alpha)*Cycle[i-1] - ((1-alpha)^2)*Cycle[i-2];
AmpCorr = 0.075 * Period[i-1] + 0.54;
Detrender = ( 0.0962 * Smooth + 0.5769 * Smooth[i-2] - 0.5769 * Smooth[i-4] - 0.0962 * Smooth[i-6] ) * AmpCorr;
Q1 = ( 0.0962 * Detrender + 0.5769 * Detrender[i-2] - 0.5769 * Detrender[i-4] - 0.0962 * Detrender[i-6] ) * AmpCorr;
I1 = Detrender[i-3];
jI = ( 0.0962 * I1 + 0.5769 * I1[i-2] - 0.5769 * I1[i-4] - 0.0962 * I1[i-6] ) * AmpCorr;
jQ = ( 0.0962 * Q1 + 0.5769 * Q1[i-2] - 0.5769 * Q1[i-4] - 0.0962 * Q1[i-6] ) * AmpCorr;
I2 = I1 - jQ;
Q2 = Q1 + jI;
I3 = 0.2 * I2 + 0.8 * I3[i-1];
Q3 = 0.2 * Q2 + 0.8 * Q3[i-1];
Re = I3 * I3[i-1] + Q3 * Q3[i-1];
Im = I3 * Q3[i-1] - Q3 * I3[i-1];
Re1 = 0.2 * Re + 0.8 * Re1[i-1];
Im1 = 0.2 * Im + 0.8 * Im1[i-1];
{
if ( Im1 != 0 AND Re1 != 0 ) Period1 = 360*DTR / atan( Im1 / Re1 );
else
Period1 = Period1[i-1];
}
{
if ( Period1 > 1.5 * Period1[i-1] ) Period2 = 1.5 * Period1[i-1];
else
{
if ( Period1 < 0.67 * Period1[i-1] ) Period2 = 0.67 * Period1[i-1];
else
Period2 = Period1;
}
}
{
if ( Period2 < 6 ) Period3 = 6;
else
{
if ( Period2 > 50 ) Period3 = 50;
else
period3=Period2;
}
}
Period = 0.2 * Period3 + 0.8 * Period[i-1];
SmoothPeriod = 0.33 * Period + 0.67 * SmoothPeriod[i-1];
DCPeriod = int(SmoothPeriod+0.5);
}

_SECTION_END();
_SECTION_BEGIN("Stochastic - Adaptive Stochastic");
SetChartOptions(0,chartShowArrows|chartShowDates);
hh = HHV(H, DCPeriod) ;
ll = LLV(L, DCPeriod) ;
stoch = IIf ((hh-ll) > 0 ,((Close - ll)/(hh - ll)) * 100,0); ;
stochma =EMA(Stoch,3);
stochmb =EMA(Stochma,3);
UL=Param("UPPER LIMIT",70,60,90,1);
Ll=Param("LOWER LIMIT",30,10,40,1);
R=stochma;
Plot(stochma,"", ParamColor("Plot Color",colorLightOrange),ParamStyle("Plot Style",styleNoLabel));
GraphXSpace=10;
PlotOHLC( R,R,50,r, _DEFAULT_NAME(), IIf( R > 50, colorLightGrey , colorSeaGreen ), styleCloud | styleClipMinMax, LL, UL );
_SECTION_END();

_SECTION_BEGIN("Price");
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", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END(); Stochastic for Amibroker.png
 
Top