Add these lines to your afl
-----
x=LastVisibleValue(DateNum());
Cond=BarsSince(DateNum()<x);
y=Ref(DateNum(),-Cond);
Cond1=BarsSince(DateNum()<LastValue(y));
z=Cond1-Cond;
Hi=Ref(HHV(H,z),-Cond);
Hibar=Ref(HHVBars(H,z),-Cond)+Cond;
x0=BarCount-1-LastValue(Hibar);
x1=BarCount-1;
y0=LastValue(Hi);
y1=y0;
Line = LineArray( x0, y0, x1, y1, 1 );
Plot( Line, "high line", ParamColor("high line", colorGreen),styleThick );
pc=Ref(Close,-Cond);
x10=BarCount-1-LastValue(Cond);
x11=BarCount-1;
y10=LastValue(pc);
y11=y10;
Line1=LineArray( x10, y10, x11, y11, 1 );
Plot( Line1, "Close line", ParamColor("close line", colorWhite),styleThick );
Lo=Ref(LLV(L,z),-Cond);
Lobar=Ref(LLVBars(L,z),-Cond)+Cond;
x00=BarCount-1-LastValue(Lobar);
x01=BarCount-1;
y00=LastValue(Lo);
y01=y00;
Line11=LineArray(x00,y00,x01,y01,1);
Plot(Line11,"Low Line",ParamColor("Low line", colorBlue),styleThick);
------
i am getting error while adding these line to my afl .
SetChartBkColor(colorLightGrey ) ;
_N(Title = StrFormat(EncodeColor( colorBlack) + "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
SetChartOptions(0,chartShowArrows|chartShowDates);
// Quick counting of bars by range selector
if (BeginValue(BarIndex()) != 0 AND EndValue(BarIndex()) != BarCount-1) {
range = EndValue(BarIndex())-BeginValue(BarIndex());
Title += StrFormat("\nRange Bars: %g", range);
}
UpCandleColor = ParamColor("Up Candle Color", colorDarkGreen );
DownCandleColor = ParamColor("Down Candle Color", colorRed );
// set amibroker to display colored bars
Graph0BarColor = IIf( C > O,UpCandleColor ,DownCandleColor);
//Plot( C, "Close", 10,styleLine | ParamStyle("Stylecandle") );
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
//-------------------------------------
_SECTION_BEGIN("VWAP 3Days");
//http://www.***********.com/amibroker/1884-afl-volume-weighted-average-price.html
RequestTimedRefresh( 1 );
nb = Param("ToDay+Number of Bars",151,1,1500,75);
ND = Day() != Ref(Day(), -1);
_SECTION_BEGIN("Magnified Market Price");
FS=Param("Font Size",30,30,100,1);
GfxSelectFont("Arial", FS, 900, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ParamColor("Color",colorBlack) );
Hor=Param("Horizontal Position",100,100,100,100);
Ver=Param("Vertical Position",27,27,27,27);
GfxTextOut(""+C,Hor+60 , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSelectFont("Arial", 12, 100, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
//GfxSetTextColor(ParamColor("Color",colorBlack) );
//GfxTextOut(""+DD+" ("+xx+"%)", Hor+25, Ver+45 );
_SECTION_END();
GraphXSpace=10;
_SECTION_END();
ND = Day() != Ref(Day(), -1);
///// VWAP and SDs /////
P = (H + L) / 2;
VWP = P * V;
BI = BarIndex();
BeginBI = ValueWhen(ND, BI);
BeginBI = BeginBI[BarCount -1];
if(BeginBI < BarCount - 1)
{
InRange = BI >= BeginBI;
CumV = Cum(V * InRange);
CumVWP = Cum(VWP * InRange);
VWAP = CumVWP / CumV;
S = Cum(Ref(CumV, -1) * V * (P - Ref(VWAP, -1))^2 / CumV);
Variance = S / CumV;
SD = sqrt(Variance);
VWAP = IIf(InRange, VWAP, Null);
}
//-----------------------------------
GfxSelectSolidBrush( colorBlack ); // this is the box background color}
//pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
Left = 1100;
width = 310;
x = 5;
x2 = 155;
y = 180;
GfxSelectPen( colorGreen, 1); // broader color
GfxRoundRect( x, y - 168, x2, y , 5, 5 ) ;
GfxSetTextColor( colorGreen );
GfxSelectFont("Times New Roman", 16, 700, True );
GfxTextOut(("SD+3 : " + (Vwap + 3*sd) ), 13,9);
GfxSetTextColor( colorGreen );
GfxSelectFont("Times New Roman", 16, 700, True );
GfxTextOut( ("SD+2 : " + (Vwap + 2*sd) ), 13,26);
GfxSetTextColor( colorGreen );
GfxSelectFont("Times New Roman", 16, 700, True );
GfxTextOut( ("SD+1 : " + (Vwap + sd) ), 13,42);
GfxSetTextColor( colorYellow );
GfxSelectFont("Times New Roman", 16, 700, True );
GfxTextOut( ("vwap : " + Vwap ), 13,60);
GfxSetTextColor( colorRed );
GfxSelectFont("Times New Roman", 16, 700, True );
GfxTextOut( ("SD-1 : " + (Vwap - sd) ), 13,80);
GfxSetTextColor( colorOrange );
GfxSelectFont("Times New Roman", 16, 700, True );
GfxTextOut(("SD-2 : " + (Vwap - 2*sd) ), 13,100);
GfxSetTextColor( colorRed );
GfxSelectFont("Times New Roman", 16, 700, True );
GfxTextOut(("SD-3 : " + (Vwap - 3*sd) ), 13,120);
//----------------
_SECTION_END();
//-----------------------------
//"Anybody tracking/trading on Thomas DeMark's Sequential system ? This system is catching Nifty futures tops and bottoms with remarkable accuracy. On daily chart,it cought Jan 2008 botton a day earlier,July 2008 bottom exactly on the day of the bottom.Also on hourly time frame,it cought NF top on 24th July at 11=00 bar and gave a sell signal at 4458 also cought 29 July 3.00 pm hrly bottom and gave buy signal at 4202." - Smart Trade
_SECTION_BEGIN("TD Systems");
// Parameters
ShowNumbers= ParamToggle("Show 1-8 Numbers","No|Yes");
ShowTDPoints = ParamToggle("Show TD Points", "No|Yes");
ShowTDST = ParamToggle("Show TD Setup Trend", "No|Yes",1);
tdstsa = 0;
tdstba = 0;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//********************************************** TD Points ************************************************** ******************/
function TD_Supply()
{
return ( H > Ref(H, 1) AND H > Ref(H, -1) AND H > Ref(C, -2));
}
function TD_Demand()
{
return ( L < Ref(L, 1) AND L < Ref(L, -1) AND L < Ref(C, -2));
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// *********************************************** TD Sequential ************************************************** **********/
// *** Setup Buy Signal ***
//nine consecutive days closes less than the close four days earlier
Con = C < Ref( C, -4);
Buy9Bars = BarsSince(BarsSince(Con));
Buy9Signal = Buy9Bars == 9;
// *** Requirements ***
//The first day of the nine-day must be preceded by a close day immediately before it that is greater than or equal to the close four days earlier
Con = Ref(C, -9) >= Ref(C, -13);
Buy9Req = Buy9Signal AND Con;
// *** Intersection ***
// the high of either day 8 or day 9 is greater than or equal to the low three, four, five, six, or seven days earlier
Con1 = (H >= Ref(L, -3)) OR ( Ref(H, -1) >= Ref(L, -3));
Con2 = (H >= Ref(L, -4)) OR ( Ref(H, -1) >= Ref(L, -4));
Con3 = (H >= Ref(L, -5)) OR ( Ref(H, -1) >= Ref(L, -5));
Con4 = (H >= Ref(L, -6)) OR ( Ref(H, -1) >= Ref(L, -6));
Con5 = (H >= Ref(L, -7)) OR ( Ref(H, -1) >= Ref(L, -7));
Buy9Intr = Buy9Req AND (Con1 OR Con2 OR Con3 OR Con4 OR Con5);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// *** Setup Sell Signal ***
//nine consecutive days closes greater than the Close four days earlier.
Con = C > Ref( C, -4);
Sell9Bars = BarsSince(BarsSince(Con));
Sell9Signal = Sell9Bars == 9;
// *** Requirements ***
//The first day of the nine-day must be preceded by a Close day immediately before it that is less than the Close four days earlier
Con = Ref(C, -9) < Ref(C, -13);
Sell9Req = Sell9Signal AND Con;
// *** Intersection ***
//the low of either day 8 or day 9 is less than or equal to the high three, four, five, six, or seven days earlier
Con1 = (L <= Ref(H, -3)) OR ( Ref(L, -1) <= Ref(H, -3));
Con2 = (L <= Ref(H, -4)) OR ( Ref(L, -1) <= Ref(H, -4));
Con3 = (L <= Ref(H, -5)) OR ( Ref(L, -1) <= Ref(H, -5));
Con4 = (L <= Ref(H, -6)) OR ( Ref(L, -1) <= Ref(H, -6));
Con5 = (L <= Ref(H, -7)) OR ( Ref(L, -1) <= Ref(H, -7));
Sell9Intr = Sell9Req AND (Con1 OR Con2 OR Con3 OR Con4 OR Con5);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(StrToNum(NumToStr(Buy9Intr))) Sell9Intr = False;
if(StrToNum(NumToStr(Sell9Intr))) Buy9Intr = False;
BuySignal = Flip(Buy9Intr, Sell9Intr);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// *** Buy Countdown ***
//With respect to a pending Buy Signal, the close must be less than the low two days earlier;
Con = C < Ref(L, -2);
Buy13Count = Sum(Con AND BuySignal, BarsSince(Buy9Intr));
Buy13Signal = Buy13Count == 13;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// *** Sell Countdown ***
//with respect to a pending Sell Signal, the Close must be greater than the High two trading days earlier.
Con = C > Ref(H, -2);
Sell13Count = Sum(Con AND NOT BuySignal, BarsSince(Sell9Intr));
Sell13Signal = Sell13Count == 13;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//*********************************************** TD Sequential Plotting area *************************************************/
//Plot(C, "", IIf(O>=C, colorRed, colorGreen), styleCandle);
PlotShapes(IIf(Buy9Intr OR Sell9Intr, shapeDigit9, shapeNone),colorBlue, 0, H, 20);
if(ShowNumbers)
PlotShapes(IIf(Buy9Bars==1, shapeDigit1,
IIf(Buy9Bars==2, shapeDigit2,
IIf(Buy9Bars==3, shapeDigit3,
IIf(Buy9Bars==4, shapeDigit4,
IIf(Buy9Bars==5, shapeDigit5,
IIf(Buy9Bars==6, shapeDigit6,
IIf(Buy9Bars==7, shapeDigit7,
IIf(Buy9Bars==8, shapeDigit8,
IIf(Buy9Bars >9, shapeStar,shapeNone))))))))),colorGreen, 0, H, H*.001);
if(ShowNumbers)
PlotShapes(
IIf(Sell9Bars==1, shapeDigit1,
IIf(Sell9Bars==2, shapeDigit2,
IIf(Sell9Bars==3, shapeDigit3,
IIf(Sell9Bars==4, shapeDigit4,
IIf(Sell9Bars==5, shapeDigit5,
IIf(Sell9Bars==6, shapeDigit6,
IIf(Sell9Bars==7, shapeDigit7,
IIf(Sell9Bars==8, shapeDigit8,
IIf(sell9bars>9, shapeStar,shapeNone))))))))),colorRed, 0, H, H*.001);
Sell = Sell13Signal AND NOT BuySignal;
Buy = Buy13Signal AND BuySignal;
Sell = ExRem(Sell, Buy);
Buy = ExRem(Buy, Sell);
//PlotShapes(Sell*shapeDownArrow, colorYellow, 0, H, -H*.001);
//PlotShapes(Buy*shapeUpArrow, colorBrightGreen, 0, L, -L*.001);
if(StrToNum(NumToStr(BuySignal)))
bgColor = ColorRGB(0,66, 2);
else
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//*********************************************** TD Points Plotting area *************************************************/
if(ShowTDPoints)
{
PlotShapes(TD_Supply()*shapeSmallCircle, colorRed, 0, H, H*.001);
PlotShapes(TD_Demand()*shapeSmallCircle, colorGreen, 0, L, -L*.001);
///////////////////////////////////////////////////////////////////////////
y0 = StrToNum(NumToStr(ValueWhen(TD_Demand(), L)));
x = LineArray(0, y0, (BarCount-1), y0);
Plot(x, "", colorGold, styleDashed);
y0 = StrToNum(NumToStr(ValueWhen(TD_Supply(), H)));
x = LineArray(0, y0, (BarCount-1), y0);
Plot(x, "", colorGold, styleDashed);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//*********************************************** TDST Plotting area *************************************************/
// ---------------->>>> Code from Dave <<<----------------------
//
if(ShowTDST)
{
tdstba =Cum(0);
tdstb = Null;
HHV9 = HHV(H,9);
for (i = 0; i < 10; i++) tdstba
= Null;
for( i = 10; i < BarCount; i++ )
{
if (Buy9Bars == 9)
{
HHV_b = HHV9;
if (HHV_b > C[i-9])
tdstb = HHV_b;
else tdstb = C[i-9];
for (j = 0; j < 9; j++ )
tdstba[i-j] = tdstb;
}
else tdstba = tdstb;
}
tdstsa =Cum(0);
tdsts = Null;
LLV9 = LLV(L,9);
for (i = 0; i < 10; i++) tdstsa = Null;
for( i = 10; i < BarCount; i++ )
{
if (Sell9Bars == 9)
{
LLV_b = LLV9;
if (LLV_b < C[i-9])
tdsts = LLV_b;
else tdsts = C[i-9];
for (j = 0; j < 9; j++ )
tdstsa[i-j] = tdsts;
}
else tdstsa = tdsts;
}
//Plot(tdstba, "TDSTb", colorBlue,styleStaircase | styleThick|styleLine);
//Plot(tdstsa, "TDSTs", colorRed,styleStaircase | styleThick|styleLine);
}
GfxSetTextColor( colorBlue );
GfxSelectFont("Times New Roman", 16, 700, True );
GfxTextOut(("TDSTb: " + (TDSTb) ), 5,140);
GfxSetTextColor( colorRed );
GfxSelectFont("Times New Roman", 16, 700, True );
GfxTextOut(("TDSTs: " + (TDSTs) ), 5,160);
//Peaking Volumes
HiVolume = IIf(V > (2 * MA(V,10)), True, False);
PlotShapes(shapeSmallCircle * HiVolume, IIf(C > O, colorBlack, colorWhite), 0, (O+C)/2, 0);
_SECTION_END();
_SECTION_BEGIN("FRACTALS");
//Fractal up
fUp = (Ref(H,-2) > Ref(H, -4)) AND
(Ref(H,-2) > Ref(H, -3)) AND
(Ref(H,-2) > Ref(H, -1)) AND
(Ref(H,-2) > H);
var1=ValueWhen(fUp ,Ref(H,-2) ,1);
FractalUp=HighestSince(var1 > 0, var1, 1);
//Plot(FractalUp, "F+",ParamColor( "F+ Color", colorCycle ) , styleLine);
FUpBuyPrice = FractalUp ;
FUpHit = FUpBuyPrice <= H AND FUpBuyPrice >= L;
FUpSignalOn = Flip(Ref(FractalUp,-1) != FractalUp, FUpHit);
//Looks into the future. This is done only to display Fractal arrow at the right bar.
//The calculation of the fractal up is done without looking into the future.
PlotShapes(IIf(Ref(FractalUp,2) != Ref(FractalUp,1), shapeSmallCircle, shapeNone), colorLime,0,Ref(FractalUp,2), 10);
//Fractal Down
var2=
(Ref(L,-2) <= Ref(L, -1)) AND
(Ref(L,-2) <= Ref(L, 0)) AND
(Ref(L,-2) <= Ref(L, -3)) AND
(Ref(L,-2) <= Ref(L, -4));
FractalDown=ValueWhen(var2, Ref(L,-2), 1);
FDownSellPrice= FractalDown;
FDownHit = FDownSellPrice <= H AND FDownSellPrice >= L;
FDownSignalOn = Flip(Ref(FractalDown,-1) != FractalDown, FDownHit );
PlotShapes(IIf(Ref(FractalDown,2) != Ref(FractalDown,1), shapeSmallCircle,shapeNone), colorRed,0,Ref(FractalDown,2), 10);
Plot(MA(Close,21), "MA1", colorGreen,styleLine|styleLine|styleThick);