Very Good.
Share the AFL here.
Let the everyone here think about the changes
// Raft Channel two Std Dev w Zig
// adaptation by reinsley
// Linear Regression Line with 2 Standard Deviation Channels Plotted from Last Zig's Swing
// zig HiLo
SetChartOptions( 0, chartShowArrows | chartShowDates );
_SECTION_BEGIN( "Zig Hi Lo" );
// ZIG hilo version by Joris Schuller
// from ZigZag Hi Lo.afl : simplified version
pltzig = ParamToggle( "Plot ZigHL ", "Off|On", 1 );
change = Param( "ZigZag-HL %", 0.47, 0.01, 3, 0.01 );
za2 = 0;
Title = EncodeColor( 4 ) + _DEFAULT_NAME() + "; " + EncodeColor( 1 ) + StrFormat( "{{NAME}} - {{INTERVAL}}; {{DATE}}; \nO=%g, \nH=%g, \nL=%g, \nC=%g (%.1f%%){{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) );
pk = PeakBars( H, change ) == 0;
tr = TroughBars( L, change ) == 0;
pkbars = PeakBars( H, change );
trbars = TroughBars( L, change );
zHi = Zig( H, change );
zLo = Zig( L, change );
HLAvg = ( zHi + zLo ) / 2;
zp2 = IIf( pk, zHi, IIf( tr, zLo, IIf( pkbars <= trbars, L, H ) ) );//Modified zp to reduce occasional erroneous Pk/Tr connections at very small ZigPerc values
za2 = Zig( zp2, change );
if ( pltzig == 1 )
{
Plot( za2, "\nZig HiLo", 11, 5 | styleNoLabel );//Zig H-L Modified
}
_SECTION_END();
// 123 Pattern
// shapedigit display
_SECTION_BEGIN( "123 Pattern" );
procedure PlotShapeAt( x, y, shape, shift )
{
PlotShapes( IIf( BarIndex() == x, shape, 0 ), colorWhite, 0, y, shift );
}
bi = BarIndex();
sbi = SelectedValue( bi );
upshift = Param( "upshift ", 30, 1, 100, 1 );
if ( SelectedValue( PeakBars( za2 , Change ) < TroughBars( za2 , Change ) ) )
{
pt3 = PeakBars( za2 , Change, 1 ) == 0 ;
pt2 = TroughBars( za2 , Change, 1 ) == 0 ;
ydigit1 = H;
ydigit2 = L;
ydigit3 = H;
}
else
{
pt3 = TroughBars( za2 , change, 1 ) == 0 ;
pt2 = PeakBars( za2 , change, 1 ) == 0 ;
ydigit1 = L;
ydigit2 = H;
ydigit3 = L;
upshift = -upshift;
}
bpt1 = SelectedValue( ValueWhen( pt3, bi ) ); // x axis
bpt2 = SelectedValue( ValueWhen( pt2, bi ) );
bpt3 = SelectedValue( ValueWhen( pt3, bi , 2 ) );
pltdigit = ParamToggle( "Plot 123 Digit ", "Off|On", 1 );
if ( pltdigit == 1 )
{
PlotShapeAt( bpt1, ydigit3 , shapeDigit3, upshift );
PlotShapeAt( bpt2, ydigit2 , shapeDigit2, -upshift );
PlotShapeAt( bpt3, ydigit1 , shapeDigit1, upshift );
}
_SECTION_END();
Plot( C, "", colorWhite, styleThick + styleCandle );
_SECTION_BEGIN( "Xspace" );
xspace = Param( "GraphXSpace ", 10, 1, 20, 1 );
GraphXSpace = xspace;
_SECTION_END();
//The following is written by Patrick Hargus, with critical hints from Marcin Gorzynski, Amibroker.com
LastSwingBars = bi - SelectedValue(ValueWhen( pt3, bi ));
P = ParamField( "Price field", -1 );
Daysback = LastValue( LastSwingBars ) + 1 ;//Param( "Period for Liner Regression Line", 21, 1, 240, 1 );
shift = Param( "Look back period", 0, 0, 240, 1 );
// =============================== Math Formula ================================================== ===========
x = Cum( 1 );
lastx = LastValue( x ) - shift;
aa = LastValue( Ref( LinRegIntercept( p, Daysback ), -shift ) );
bb = LastValue( Ref( LinRegSlope( p, Daysback ), -shift ) );
y = Aa + bb * ( x - ( Lastx - DaysBack + 1 ) );
// ==================Plot the Linear Regression Line ================================================== ========
LRColor = ParamColor( "LR Color", colorCycle );
LRStyle = ParamStyle( "LR Style" );
LRLine = IIf( x > ( lastx - Daysback ) AND BarIndex() < Lastx, y, Null );
pltMidReg = ParamToggle( "Plot Mid Reg Line ", "Off|On", 1 );
if ( pltMidReg == 1 )
{
Plot( LRLine , "\nLinReg", LRCOLOR, LRSTYLE ); // styleDots );
}
// ========================== Plot 1st SD Channel ================================================== =============
// ========================== Plot 2d SD Channel ================================================== =============
_SECTION_BEGIN("Price1");
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();
_SECTION_BEGIN("SAR");
acc = Param("Acceleration", 0.02, 0, 1, 0.001 );
accm = Param("Max. acceleration", 0.2, 0, 1, 0.001 );
Plot( SAR( acc, accm ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style", styleDots | styleNoLine, maskDefault | styleDots | styleNoLine ) );
_SECTION_END();
_SECTION_BEGIN("BandStop");
/* Done by Rajandran R */
/* Author of
www.marketcalls.in */
// BBands_Stop_v1.mq4 by
[email protected]
// translation in Amibroker AFL, E.M.Pottasch, 2011
// Modified By KelvinHand
Length=Param("Length",20, 2); // Bollinger Bands Period
Deviation=Param("Deviation",2);
// Deviation was 2
MoneyRisk=Param("Money Risk", 1);
LineStyle=ParamToggle("Display line mode", "No|Yes", 1); // Display line mode: 0-no,1-yes
cUpTrendLine = ParamColor("UpTrendLine", ColorRGB(65,105,225));
cDnTrendLine = ParamColor("DownTrendLine", colorRed);
// Offset Factor
TurnedUp=Nz(StaticVarGet("TurnedUp"));
TurnedDown=Nz(StaticVarGet("TurnedDown"));
SoundON = ParamToggle("Sound","Off|On",1);
procedure CalcTrend_proc(bbtop,bbbot,Length,MoneyRisk,SoundON,TurnedUp,TurnedDown)
{
global UpTrendLine;
global DownTrendLine;
global smax;
global smin;
UpTrendLine=Null;
DownTrendLine=Null;
smax=Null;
smin=Null;
trend=0;
for (i=Length+1; i<BarCount; i++)
{
smax
=bbtop;
smin=bbbot;
if (C>smax[i-1]) trend=1;
if (C<smin[i-1]) trend=-1;
if(trend>0 && smin<smin[i-1]) smin=smin[i-1];
if(trend<0 && smax>smax[i-1]) smax=smax[i-1];
bsmax=smax+0.5*(MoneyRisk-1)*(smax-smin);
bsmin=smin-0.5*(MoneyRisk-1)*(smax-smin);
if(trend>0 && bsmin<bsmin[i-1]) bsmin=bsmin[i-1];
if(trend<0 && bsmax>bsmax[i-1]) bsmax=bsmax[i-1];
if (trend>0)
{
UpTrendLine=bsmin;
if (SoundON==True && !TurnedUp && i==BarCount-1 && IsEmpty(UpTrendLine[i-1]))
{
Say("Bollinger Bands going Up");
TurnedUp=StaticVarSet("TurnedUp",1);
TurnedDown=StaticVarSet("TurnedDown",0);
}
}
if (trend<0)
{
DownTrendLine=bsmax;
if (SoundON==True && !TurnedDown && i==BarCount-1 && IsEmpty(DownTrendLine[i-1]))
{
Say("Bollinger Bands going Down");
TurnedUp=StaticVarSet("TurnedUp",0);
TurnedDown=StaticVarSet("TurnedDown",1);
}
} //if (trend<0)
} //for
} //procedure
bbtop=BBandTop(C,Length,Deviation);
bbbot=BBandBot(C,Length,Deviation);
CalcTrend_proc(bbtop,bbbot,Length,MoneyRisk,SoundON,TurnedUp,TurnedDown);
UpTrendSigNal=UpTrendLine AND IsEmpty(Ref(UpTrendLine,-1));
DownTrendSigNal=DownTrendLine AND IsEmpty(Ref(DownTrendLine,-1));
DisplayStyle = styleNoLabel|styleDots|styleNoTitle;
if(LineStyle == 0) DisplayStyle |= styleNoLine;
Plot(UpTrendLine,"UPTRENDLINE",cUpTrendLine,DisplayStyle);
Plot(DownTrendLine,"DOWNTRENDLINE",cDnTrendLine,DisplayStyle) ;
PlotShapes(IIf(UpTrendSignal,shapeCircle,shapeNone),cUpTrendLine,0,bbbot,0);
PlotShapes(IIf(DownTrendSignal,shapeCircle,shapeNone),cDnTrendLine,0,bbtop,0);
_SECTION_END();