.

Accurate Heikin Ashi Middle Band - Amibroker AFL Code

Click Image To Enlarge. Please Rate And Comment.

Accurate Heikin Ashi Middle Band

//---- heikin ashi
HaClose = (O+H+L+C)/4; 
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 ); 
HaHigh = Max( H, Max( HaClose, HaOpen ) ); 
HaLow = Min( L, Min( HaClose, HaOpen ) ); 
xDiff = (HaHigh - Halow) * IIf(StrFind(Name(),"JPY"),100,10000);
barcolor = IIf(HaClose >= HaOpen,colorGreen,colorRed);
PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "", barcolor, styleCandle ); 
// Plot(EMA(HaClose,9),"",colorWhite, styleLine);
// Plot(EMA(HaClose,18),"",colorBlack, styleLine);

//---- pivot points
DayH = TimeFrameGetPrice("H", inDaily, -1);  // yesterdays high
DayL = TimeFrameGetPrice("L", inDaily, -1);  //    low
DayC = TimeFrameGetPrice("C", inDaily, -1);  //    close
DayO = TimeFrameGetPrice("O", inDaily);   // current day open

// woodies FIB pivots
if ( False )
{
R = DayH - DayL;   // range
PP = (DayH + DayL + DayO + DayO) / 4 ;
R1 = PP + (R * 0.38);
R2 = PP + (R * 0.62);
S1 = PP - (R * 0.38);
S2 = PP - (R * 0.62);
}

// woodies pivots
if ( True )
{
PP = (DayH + DayL + DayO + DayO) / 4 ;
R1  =  (2 * PP) - DayL;
S1  =  (2 * PP) - DayH;
R2  =  PP + (DayH - DayL);
S2  =  PP - (DayH - DayL);
}

// regular pivots
if ( False )
{
PP = (DayL + DayH + DayC)/3 ;
R1  =  (2 * PP) - DayL;
S1  =  (2 * PP)  - DayH;
R2  =  (PP - S1) + R1;
S2  =  PP - (R1 - S1);
}

Plot(R1, "",colorWhite,styleDots+styleNoLine+styleNoLabel);
Plot(S1, "",colorDarkBlue,styleDots+styleNoLine+styleNoLabel);
Plot(R2, "R2",colorWhite,styleDots+styleNoLine+styleNoLabel);
Plot(S2, "S2",colorDarkBlue,styleDots+styleNoLine+styleNoLabel);
Plot(PP, "",colorYellow,styleLine+styleNoLabel);
//----
Title = Name()+" Heikin Ashi "+Date();

_SECTION_BEGIN("Keltner Bands");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1 );
Width = Param("Width", 2, 0, 10, 0.05 );

Width = 0.5 ;

Color = ParamColor("Color", colorCycle );
Style = ParamStyle("Style");

CenterLine = MA( P, Periods );
KTop = CenterLine + Width * ATR( Periods );
KBot = CenterLine - Width * ATR( Periods );

Plot( KTop, "KBTop" + _PARAM_VALUES(), Color, Style ); 
Plot( KBot, "KBBot" + _PARAM_VALUES(), Color, Style ); 

Plot( MA( P, 15 ), "", colorBlack, styleLine , styleThick); 

PlotOHLC(KTop,KTop,KBot,KBot,"", colorLightBlue,styleCloud ) ;
//PlotOHLC(ACDHigh,ACDHigh,ACDLow,ACDLow,"",colorLig htBlue,styleCloud );


_SECTION_END();

_SECTION_BEGIN("Background");
//SetChartBkGradientFill( ParamColor("BgTop", colorLavender),ParamColor("BgBottom", colorCustom3));
SetChartBkColor(colorWhite); // color of outer border 
SetChartBkGradientFill( ColorRGB(175,175,239), colorLavender, titlebkcolor = colorWhite ); 
//color of inner panel
_SECTION_END();

_SECTION_BEGIN("Gann 1 bar Swing new ");
/* Gann Swing chart v4 */
/* Last modified 24 Feb 2001 */
/* AFL implementation by */
/* (C)2001 Tomasz Janeczko */
/* one and two - bar reversal version */

/* Change this to 1 for two-bar mode */
twobarmode = 0;

outsidebar = Outside();
insidebar = H <= Ref( H, -1 ) AND L >= Ref( L, -1 ); // built-in inside() works with < > instead of <= >=

upbar = H > Ref( H, -1 ) AND L >= Ref( L, -1 );
downbar = L < Ref( L, -1 ) AND H <= Ref( H, -1 );

upbar2 = upbar OR ( outsidebar AND Ref( downbar, 1 ) ) ;
downbar2 = downbar OR ( outsidebar AND Ref( upbar, 1 ) );

Poi = outsidebar AND Ref( insidebar, 1 );
Poo = outsidebar AND Ref( outsidebar, 1 );
Pooi = Poo AND Ref( insidebar, 2 );
Poio = Poi AND Ref( outsidebar, 2 );
Poii = Poi AND Ref( insidebar, 2 );
Pooo = Poo AND Ref( outsidebar, 2 );
Poooi = Pooo AND Ref( insidebar, 3 );
Pooio = Pooi AND Ref( outsidebar, 3 );
Poioo = Poio AND Ref( outsidebar, 3 );

upbar3 = upbar2 OR ( Poi AND Ref( downbar, 2 ) );
downbar3 = downbar2 OR ( Poi AND Ref( upbar, 2 ) );

upbar4 = upbar3 OR ( Poo AND Ref( upbar, 2 ) );
downbar4 = downbar3 OR ( Poo AND Ref( downbar, 2 ) );

upbar5 = upbar4 OR ( Pooi AND Ref( upbar, 3 ) );
downbar5 = downbar4 OR ( Pooi AND Ref( downbar, 3 ) );

upbar6 = upbar5 OR ( Poio AND Ref( upbar, 3 ) );
downbar6 = downbar5 OR ( Poio AND Ref( downbar, 3 ) );

upbar7 = upbar6 OR ( Poii AND Ref( downbar, 3 ) );
downbar7 = downbar6 OR ( Poii AND Ref( upbar, 3 ) );

upbar8 = upbar7 OR ( Pooo AND Ref( downbar, 3 ) );
downbar8 = downbar7 OR ( Pooo AND Ref( upbar, 3 ) );

upbar9 = upbar8 OR ( Poooi AND Ref( downbar, 4 ) );
downbar9 = downbar8 OR (Poooi AND Ref( upbar, 4 ) );

upbar10 = upbar9 OR ( Pooio AND Ref( downbar, 4 ) );
downbar10 = downbar9 OR ( Pooio AND Ref( upbar, 4 ) );

upbar11 = upbar10 OR ( Poioo AND Ref( downbar, 4 ) );
downbar11 = downbar10 OR ( Poioo AND Ref( upbar, 4 ) );

fupbar = upbar11;
fdownbar = downbar11;

// Two-bar mode handling
fupbar = IIf( twobarmode, fupbar AND Ref( fupbar, 1 ), fupbar );
fdownbar = IIf( twobarmode, fdownbar AND Ref( fdownbar, 1 ), fdownbar );

/* Barcount since most recent up and down swings */
Us = BarsSince( fupbar ); 
Ds = BarsSince( fdownbar ) ;

Sd1 =IIf( Us==0, 1, IIf( Ds==0, -1, 0) );

Sd2 = IIf( Sd1 == 1, IIf( Ref( BarsSince(Sd1==1), -1) > Ref( BarsSince( Sd1 == -1), -1), 1, 0), 
IIf( Sd1 == -1, IIf( Ref( BarsSince(Sd1==1),-1) < Ref( BarsSince( Sd1 == -1),-1), -1, 0), 0 ) ); 

g0 = ValueWhen( Sd2, Sd2 ); /* sample and hold non-zero values */

/* shift back one bar, add one dummy swing at the end and shift forward */
/* to ensure proper handling of the last swing */
lastbar = Cum(1) == LastValue( Cum(1) );
swinglevel = IIf( g0 == -1, HighestSince( Sd2 == 1, H ), LowestSince( Sd2 == -1, L ) );
swinglevel = IIf( lastbar, IIf( g0 == -1, LowestSince( Sd2 == -1, L ), HighestSince( Sd2 == 1, H )), Ref( swinglevel, 1 ) );

/* Gann Swing chart drawn here */
Graph1 = Ref( ValueWhen( Ref( Sd2 != 0, 1 ) OR lastbar, swinglevel , 0 ), -1 );
Graph1Style = 512+1024;
GraphXSpace = 5;
Title = Date() + Name() + " 1 Bar Gann Swing Chart";

/* Colourized price bars drawn here */
/* graph0 = close; */
/* graph0style = 128; */
/* barcolor = IIF( outsidebar, 1, IIF( downbar, 4, IIF( upbar, 5, 0 ) ) ); */
/* graph0barcolor = ValueWhen( barcolor != 0, barcolor ); */
_SECTION_END();

_SECTION_BEGIN("Background");
//SetChartBkGradientFill( ParamColor("BgTop", colorLavender),ParamColor("BgBottom", colorCustom3));
SetChartBkColor(colorWhite); // color of outer border 
SetChartBkGradientFill( ColorRGB(175,175,239), colorLavender, titlebkcolor = colorWhite ); 
//color of inner panel
_SECTION_END();
Previous Post Next Post