Stock Portfolio Organizer

The ultimate porfolio management solution.

Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
For Portfolio Manager Click Here

WiseTrader Toolbox

#1 Selling Amibroker Plugin featuring:

Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
Find Out More Here

NIFTY SPECIAL for Amibroker (AFL)

Copy & Paste Friendly
_SECTION_BEGIN("Background");
	SetChartOptions(0,chartShowArrows|chartShowDates);
	SetChartBkColor(ParamColor("Outer panel",colorGrey40)); // color of outer border 
	SetChartBkGradientFill( ParamColor("Inner panel
upper",colorGrey40),ParamColor("Inner panel lower",colorGrey40));
	tchoice=Param("Title Selection ",2,1,2,1);

Plot(C, "", IIf(O>=C, colorOrange, colorGreen), ParamStyle("Price
Style",styleCandle,maskPrice));
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

//Magnified Market Price

	SetChartOptions(0,chartShowArrows|chartShowDates);
	SetChartBkColor(ParamColor("Outer panel",colorGrey40)); // color of outer border 
	SetChartBkGradientFill( ParamColor("Inner panel
upper",colorGrey40),ParamColor("Inner panel lower",colorGrey40));
	tchoice=Param("Title Selection ",2,1,2,1);

Plot(C, "", IIf(O>=C, colorOrange, colorGreen), ParamStyle("Price
Style",styleCandle,maskPrice));
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

_SECTION_BEGIN("Magnified Market Price");
FS=Param("Font Size",12,11,100,1);
GfxSelectFont("Times New Roman", FS, 700, True ); 
GfxSetBkMode( colorWhite );  
GfxSetTextColor( ParamColor("Color",colorYellow) ); 
Hor=Param("Horizontal Position",547,1,1200,1);
Ver=Param("Vertical Position",1,1,830,1); 
GfxTextOut("http://chartiscafe.com 9255191643", Hor , Ver );
GfxTextOut(""+Name(), Hor+30 , 20 );
GfxTextOut(""+C, Hor+50 , 40);
_SECTION_END();

_SECTION_BEGIN("Title");
if( Status("action") == actionIndicator ) 
(
Title = EncodeColor(colorWhite)+ "ajit " + " - " +  Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
 "  - " + Date() +" - "+"\n" +EncodeColor(colorYellow) +"Op-"+O+"  "+"Hi-"+H+"  "+"Lo-"+L+"  "+
"Cl-"+C+"  "+ "Vol= "+ WriteVal(V)+"\n"+ 
EncodeColor(colorLime));
_SECTION_END();


//INDICATORS
_SECTION_BEGIN("Mid BB");

P = ParamField("Price");
Type = ParamList("Type", "Simple,Exponential,Double Exponential,Tripple Exponential,Wilders,Weighted,Len Reg,Time Shift,AMA,Median");
 
 
Periods = Param( "period ", 20, 1, 500, 1 );
Width = Param("Width", 2.000, 0, 10, 0.0001 );
s = Param("shift", 0, -10, 10, 1 );
 
Var   = Param("AMA var", 0.03, 0, 10, 0.001 );
 
m = 0;
 
if( Type == "Simple" )                  m = MA( P, Periods );
if( Type == "Exponential" )             m = EMA( P, Periods );
if( Type == "Double Exponential" )  m = DEMA( P, Periods );
if( Type == "Tripple Exponential" )     m = TEMA( P, Periods );
if( Type == "Wilders" )                 m = Wilders( P, Periods );
if( Type == "Weighted" )                m = WMA( P, Periods );
if( Type == "Len Reg" )                 m = LinearReg( P, Periods );
if( Type == "Time Shift" )              m = TSF( P, Periods );
if( Type == "AMA" )                         m = AMA( P, Var );
if( Type == "Median" )                  m = Median(P,Periods );
sma=m;
Plot( sma, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style",styleDashed|styleThick) | styleNoRescale );

_SECTION_END();

_SECTION_BEGIN("MA");
ppl = ParamToggle("","Off|On",1);
P = ParamField("Price");
Type = ParamList("Type", "Simple,Exponential,Double Exponential,Tripple Exponential,Wilders,Weighted,Len Reg,Time Shift,AMA,Median");
 
 
Periods = Param( "period ", 34, 1, 500, 1 );
Width = Param("Width", 1.000, 0, 10, 0.0001 );
s = Param("shift", 0, -10, 10, 1 );
 
Var   = Param("AMA var", 0.03, 0, 10, 0.001 );
 
m = 0;
 
if( Type == "Simple" )                  m = MA( P, Periods );
if( Type == "Exponential" )             m = EMA( P, Periods );
if( Type == "Double Exponential" )  m = DEMA( P, Periods );
if( Type == "Tripple Exponential" )     m = TEMA( P, Periods );
if( Type == "Wilders" )                 m = Wilders( P, Periods );
if( Type == "Weighted" )                m = WMA( P, Periods );
if( Type == "Len Reg" )                 m = LinearReg( P, Periods );
if( Type == "Time Shift" )              m = TSF( P, Periods );
if( Type == "AMA" )                         m = AMA( P, Var );
if( Type == "Median" )                  m = Median(P,Periods );
sma=m;
if(ppl==0) {
Plot( sma, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") | styleNoRescale );
}
_SECTION_END();


_SECTION_BEGIN("BBands1");
P = ParamField("Price field",-1);
Periods = Param("Periods", 20, 2, 100, 1 );
Width = Param("Width", 2, 0, 10, 0.05 );
Color = ParamColor("Color", colorDarkGrey );
Style = ParamStyle("Style") | styleNoRescale;;
Plot( bbt = BBandTop( P, Periods, Width ), "BBTop" + _PARAM_VALUES(), Color, Style|styleDashed|styleThick  ); 
Plot( bbb = BBandBot( P, Periods, Width ), "BBBot" + _PARAM_VALUES(), Color, Style|styleDashed|styleThick ); 
PlotOHLC( bbt, bbt, bbb, bbb, "", ColorBlend( Color, colorWhite, 0.9), styleCloud | styleNoRescale, Null, Null, Null, -1 );
_SECTION_END();

_SECTION_BEGIN("BBands2");
ppl = ParamToggle("","Off|On",1);
P = ParamField("Price field",-1);
Periods = Param("Periods", 20, 2, 100, 1 );
Width = Param("Width", 1, 0, 10, 0.05 );
Color = ParamColor("Color", colorLightGrey );
Style = ParamStyle("Style") | styleNoRescale;;

if(ppl==0) {

Plot( bbt = BBandTop( P, Periods, Width ), "BBTop" + _PARAM_VALUES(), Color, Style|styleDashed|styleThick ); 
Plot( bbb = BBandBot( P, Periods, Width ), "BBBot" + _PARAM_VALUES(), Color, Style|styleDashed|styleThick ); 
PlotOHLC( bbt, bbt, bbb, bbb, "", ColorBlend( Color, colorWhite, 0.9 ), styleCloud | styleNoRescale, Null, Null, Null, -1 );
}
_SECTION_END();

//ATR
_SECTION_BEGIN("ATR STOP LOSS ");
ppl = ParamToggle("","Off|On",1);
k = Optimize("K",Param("K",1.75,1,5,0.25),1,5,0.25);

Per= Optimize("atr",Param("atr",10,3,30,1),3,30,1);

j=(O+H+L+C)/4;

nm= (H-L);

rfsctor = WMA(nm, PER);

revers = K * rfsctor;

Trend = 1;

NW[0] = 0;

for(i = 1; i < BarCount; i++)

{

if(Trend[i-1] == 1)

{

if(j[i] < NW[i-1])

{

Trend[i] = -1;

NW[i] = j[i] + Revers[i];

}

else

{

Trend[i] = 1;

if((j[i] - Revers[i]) > NW[i-1])

{

NW[i] = j[i] - Revers[i];

}

else

{

NW[i] = NW[i-1];

}

}

}

if(Trend[i-1] == -1)

{

if(j[i] > NW[i-1])

{

Trend[i] = 1;

NW[i] = j[i] - Revers[i];

}

else

{

Trend[i] = -1;

if((j[i] + Revers[i]) < NW[i-1])

{

NW[i] = j[i] + Revers[i];

}

else

{

NW[i] = NW[i-1];

}

}

}

}
if(ppl==0) { 
Plot(NW, "", IIf(Trend == 1, 6, 4), ParamStyle("Style") );
}
_SECTION_END();

//_SECTION_BEGIN("Pivot")

	YH = TimeFrameGetPrice("H", inDaily, -1);		// yesterdays high
	YL = TimeFrameGetPrice("L", inDaily, -1);		//				low
	YC = TimeFrameGetPrice("C", inDaily, -1);		//				close
	YO = TimeFrameGetPrice("O", inDaily);			// current day open

	//Normal Pivot
	PP = (YH + YL + YC) / 3;
	R1 = (2 * PP) - YL;
	R2 = PP + (YH - YL);
	R3 = YH + 2*(PP-YL);
	S1 = (2 * PP) - YH;
	S2 = PP - (YH - YL);
	S3 = YL - 2*(YH - PP) ;


	WYH = TimeFrameGetPrice("H", inWeekly, -1);		
	WYL = TimeFrameGetPrice("L", inWeekly, -1);		
	WYC = TimeFrameGetPrice("C", inWeekly, -1);		
	WYO = TimeFrameGetPrice("O", inWeekly);			

	//Week Pivot
	WPP = (WYH + WYL + WYC) / 3;
	WR1 = (2 * WPP) - WYL;
	WR2 = WPP + (WYH - WYL);
	WR3 = WYH + 2*(WPP-WYL);
	WS1 = (2 * WPP) - WYH;
	WS2 = WPP - (WYH - WYL);
	WS3 = WYL - 2*(WYH - WPP) ;

TimeFrameSet( inDaily   );
EMADH = EMA(H,   5);
TimeFrameExpand( EMADH , inDaily ); 
EMADL = EMA(L,   5);
TimeFrameExpand( EMADL , inDaily );
EMADC = EMA(C,   5);
TimeFrameExpand( EMADC , inDaily );
TimeFrameRestore();


TimeFrameSet( inHourly   );
EMAHH = EMA(H,   5);
TimeFrameExpand( EMAHH , inHourly ); 
EMAHL = EMA(L,   5);
TimeFrameExpand( EMAHL , inHourly );
EMAHC = EMA(C,   5);
TimeFrameExpand( EMAHC , inHourly );
TimeFrameRestore();

// HOURLY,DAILY,WEEKLY DATA



_SECTION_BEGIN("Robert's Pivot Points");

 //---------------------------------------------------------------------------
 // Pivot Pointer
 //---------------------------------------------------------------------------
 // Now a days each and every trader wants pivot levels for thier day 
 // trading.But the main feature in this afl is you can get all types of 
 // pivot point in a single afl, Some of the traders use Woodie pivot, 
 // caramilla pivot, Fibonacci pivot and most of them used Classical 
 // pivot, i think this afl will solve all your needs.
 //---------------------------------------------------------------------------

 //---------------------------------------------------------------------------
 // Please write your comments to anuraghsr@yahoo.com
 //---------------------------------------------------------------------------

 //---------------------------------------------------------------------------
 // This section gets whether they want pivot level for intraday or thier eod 
 //---------------------------------------------------------------------------

 _N(ioreod =ParamList("Pivot Levels for ", "Intraday|EOD"));

 if (ioreod=="Intraday") 
 {
 yh = TimeFrameGetPrice( "H", inDaily, -1 );
 yl = TimeFrameGetPrice( "L", inDaily, -1 );
 yc = TimeFrameGetPrice( "C", inDaily, -1 );
 }
 else
 {
 yh = TimeFrameGetPrice( "H", inDaily, 0 );
 yl = TimeFrameGetPrice( "L", inDaily, 0 );
 yc = TimeFrameGetPrice( "C", inDaily, 0 );
 }

 //---------------------------------------------------------------------------
 // To calculate the Pivot Levels 
 //---------------------------------------------------------------------------

 to = TimeFrameGetPrice( "O", inDaily, 0 );
 pivot = (yh + yl + yc) / 3;
 range = yh - yl;
 _N(pist =ParamList("Select Pivot Type ", "Classical Pivot|Woodie
 Pivot|Caramilla Pivot|Fibonacci Pivot"));

 if (pist =="Classical Pivot" )
 {
 r1 = (2 * pivot) - yl ;
 s1 = (2 * pivot) - yh ;
 r2 = pivot - s1 + r1;
 s2 = pivot - (r1 - s1) ;
 r3 = 2 * (pivot - yl) + yh ;
 s3 = yl - (2 * (yh - pivot));
 }

 else if(pist =="Woodie Pivot" )
 {
 pivot = (yh + yl + yc + to) / 4;
 r1 = (2 * pivot) - yl;
 r2 = pivot + range;
 r3 = yh + 2 * (pivot - yl);
 r4 = r3 + range;
 s1 = (2 * pivot) - yh;
 s2 = pivot - range;
 s3 = yl - 2 * (yh - pivot);
 s4 = S3 - range;
 }

 else if(pist =="Caramilla Pivot" )
 {
 r4 = yc + range * 1.1/2;
 r3 = yc + range * 1.1/4;
 r2 = yc + range * 1.1/6;
 r1 = yc + range * 1.1/12;
 s1 = yc - range * 1.1/12;
 s2 = yc - range * 1.1/6;
 s3 = yc - range * 1.1/4;
 s4 = yc - range * 1.1/2;
 }

 else 
 {
 r3 = pivot + 1.000 * (yh - yl);
 r2 = pivot + 0.618 * (yh - yl);
 r1 = pivot + 0.382 * (yh - yl); 
 s1 = pivot - 0.382 * (yh - yl); 
 s2 = pivot - 0.618 * (yh - yl); 
 s3 = pivot - 1.000 * (yh - yl);
 }

 //---------------------------------------------------------------------------
 // To Plot Pivot Levels in the screen 
 //---------------------------------------------------------------------------

 _N(dsr =ParamList("Draw Intraday Pivot Levels ", 
 "None|Both|Support|Resistance"));

 if (dsr =="Support" OR dsr == "Both")
 {
 Plot(pivot, "\n Pivot - ",colorGreen,1);
 Plot(r1, "Resistance 1 - ",colorDarkRed,1);
 Plot(r2, "Resistance 2 - ",colorDarkRed,1);
 Plot(r3, "Resistance 3 - ",colorDarkRed,1);
 Plot((pivot+r1)/2, "Mid Value of R1 & Pivot ",colorLightBlue,1);
 Plot((r3+r2)/2, "Mid Value of R2 & R3 - ",colorLightBlue,1);
 Plot((r1+r2)/2, "Mid Value of R1 & R2 - ",colorLightBlue,1);
 }

 if( dsr == "Resistance" OR dsr == "Both")
 {
 Plot(pivot, "\n Pivot - ",colorGreen,1);
 Plot(s3, "Support 2 - ",colorDarkGreen,1);
 Plot(s2, "Support 2 - ",colorDarkGreen,1);
 Plot(s1, "Support 1 - ",colorDarkGreen,1);
 Plot((s3+s2)/2, "Mid Value of S2 & S3 ",colorWhite,1);
 Plot((s1+s2)/2, "Mid Value of S1 & S2 - ",colorWhite,1);
 Plot((pivot+s1)/2, "Mid Value of S1 & Pivot ",colorWhite,1);
 }

 //---------------------------------------------------------------------------
 // Printing the pivot level in interpretation window
 //---------------------------------------------------------------------------


 printf(Name()+ "\n\nResistance - 3 | %g\nResistance - 2 | %g\nResistance -
 1 | %g\n" + 
 "Pivot | %g\nSupport - 1 | %g\nSupport - 2 | 
 %g\nSupport - 3 | %g",
 r3,r2,r1,pivot,s1,s2,s3);


 //---------------------------------------------------------------------------
 // This section is for Exploration 
 //---------------------------------------------------------------------------

 Filter = 1;
 AddColumn(r3,"Resistance 3");
 AddColumn(r2,"Resistance 2");
 AddColumn(r1,"Resistance 1");
 AddColumn(Pivot,"Pivot");
 AddColumn(s1,"Support 1");
 AddColumn(s2,"Support 2");
 AddColumn(s3,"Support 3");

 //---------------------------------------------------------------------------
 // End of Pivot Point 
 //---------------------------------------------------------------------------

 _SECTION_END();

_SECTION_BEGIN("Fibo Retrace and Extensions");
fibs = ParamToggle("Plot Fibs","Off|On",1);
pctH = Param ("Pivot Hi %", 0.325,0.001,2.0,0.002);
HiLB = Param ("Hi LookBack",1,1,BarCount-1,1);
pctL = Param ("Pivot Lo %", 0.325,0.001,2.0,0.002);
LoLB = Param ("Lo LookBack",1,1,BarCount-1,1);
Back = Param ("Extend Left = 2",1,1,500,1);
Fwd = Param("Plot Forward", 0, 0, 500, 1);
text = ParamToggle("Plot Text","Off|On",1);
hts = Param ("Text Shift", -33.5,-50,50,0.10);
style =ParamStyle("Line Style",styleLine,styleNoLabel);
x = BarIndex();
pRp = PeakBars( H, pctH, 1) == 0;
yRp0 = SelectedValue(ValueWhen( pRp, H, HiLB));
xRp0 = SelectedValue(ValueWhen( pRp, x, HiLB));
pSp = TroughBars( L, pctL, 1) == 0;
ySp0 = SelectedValue(ValueWhen( pSp, L, LoLB));
xSp0 = SelectedValue(ValueWhen( pSp, x, LoLB));
Delta = yRp0 - ySp0;

function fib(ret)
{
retval = (Delta * ret);
Fibval = IIf(ret < 1.0 
AND xSp0 < xRp0, yRp0 - retval, IIf(ret < 1.0 
AND xSp0 > xRp0, ySp0 + retval,IIf(ret > 1.0 
AND xSp0 < xRp0, yRp0 - retval, IIf(ret > 1.0 
AND xSp0 > xRp0, ySp0 + retval, Null)))); 
return FibVal;
}

x0 = Min(xSp0,xRp0)-Back;
x1 = (BarCount -1);

r236 = fib(0.236);	r236I = LastValue (r236,1);
r382 = fib(0.382);	r382I = LastValue (r382,1);
r050 = fib(0.50);	 r050I = LastValue (r050,1);
r618 = fib(0.618);	r618I = LastValue (r618,1);
r786 = fib(0.786);	r786I = LastValue (r786,1);
e127 = fib(1.27);	 e127I = LastValue (e127,1);
e162 = fib(1.62);	 e162I = LastValue (e162,1);
e200 = fib(2.00);	 e200I = LastValue (e200,1);
e262 = fib(2.62);	 e262I = LastValue (e262,1);
e424 = fib(4.24);	 e424I = LastValue (e424,1);

p00 = IIf(xSp0 > xRp0,ySp0,yRp0); p00I = LastValue (p00,1);
p100 = IIf(xSp0 < xRp0,ySp0,yRp0); p100I = LastValue (p100,1);
color00 =IIf(xSp0 > xRp0,colorLime,colorRed);
color100 =IIf(xSp0 < xRp0,colorLime,colorRed);

numbars = LastValue(Cum(Status("barvisible")));
fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2);
if(fibs==0)
{
Plot(LineArray(xRp0-Fwd,yRp0,x1,yRp0,Back),"PR",32,8|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(xSp0-Fwd,ySp0,x1,ySp0,Back),"PS",27,8|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,r236,x1,r236,Back),"",45,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,r382,x1,r382,Back),"",44,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,r050,x1,r050,Back),"",41,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,r618,x1,r618,Back),"",43,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,r786,x1,r786,Back),"",42,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,e127,x1,e127,Back),"e127",47,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,e162,x1,e162,Back),"e162",47,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,e200,x1,e200,Back),"p200",47,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,e262,x1,e262,Back),"p262",47,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,e424,x1,e424,Back),"p424",25,style|styleNoRescale,Null, Null,Fwd);
}

if(text==0)
{ 
PlotText(" 0% = " + WriteVal(p00,fraction), LastValue(BarIndex())-(numbars/hts), p00I + 0.05, color00);
PlotText("23% = " + WriteVal(r236,fraction), LastValue(BarIndex())-(numbars/hts), r236I + 0.05, 45);
PlotText("38% = " + WriteVal(r382,fraction), LastValue(BarIndex())-(numbars/hts), r382I + 0.05, 44);
PlotText("50% = " + WriteVal(r050,fraction), LastValue(BarIndex())-(numbars/hts), r050I + 0.05, 41);
PlotText("62% = " + WriteVal(r618,fraction), LastValue(BarIndex())-(numbars/hts), r618I + 0.05, 43);
PlotText("78% = " + WriteVal(r786,fraction), LastValue(BarIndex())-(numbars/hts), r786I + 0.05, 42);
PlotText("100% = " + WriteVal(p100,fraction), LastValue(BarIndex())-(numbars/hts),p100I + 0.05, color100);
PlotText("127% = " + WriteVal(e127,fraction), LastValue(BarIndex())-(numbars/hts),e127I + 0.05, 47);
PlotText("162% = " + WriteVal(e162,fraction), LastValue(BarIndex())-(numbars/hts),e162I + 0.05, 47);
PlotText("200% = " + WriteVal(e200,fraction), LastValue(BarIndex())-(numbars/hts),e200I + 0.05, 47);
PlotText("262% = " + WriteVal(e262,fraction), LastValue(BarIndex())-(numbars/hts),e262I + 0.05, 47);
PlotText("424% = " + WriteVal(e424,fraction), LastValue(BarIndex())-(numbars/hts),e424I + 0.05, 25);
}


_SECTION_BEGIN("PIVOT POINTS");
/* This code calculates the previous days high, low and close */
Hi1 = IIf(Day()!=Ref(Day(),-1),Ref(HighestSince(Day()!=Ref(Day(),-1),H,1),-1),0);
Hi = ValueWhen(Day()!=Ref(Day(),-1),Hi1,1);
Lo1 = IIf(Day()!=Ref(Day(),-1),Ref(LowestSince(Day()!=Ref(Day(),-1),L,1),-1),0);
Lo = ValueWhen(Day()!=Ref(Day(),-1),Lo1,1);
Cl1 = IIf(Day()!=Ref(Day(),-1),Ref(C,-1),0);
C1 = ValueWhen(Day()!=Ref(Day(),-1),Cl1,1);
wHi=TimeFrameGetPrice("H",inWeekly,-1);
wLo=TimeFrameGetPrice("L",inWeekly,-1);
wCl=TimeFrameGetPrice("C",inWeekly,-1);
mHi=TimeFrameGetPrice("H",inMonthly,-1);
mLo=TimeFrameGetPrice("L",inMonthly,-1);
mCl=TimeFrameGetPrice("C",inMonthly,-1);

//----------------------------------------------------------------------------------

/* This code calculates Daily Piovts */

rg = (Hi - Lo);
bp = (Hi + Lo + C1)/3; bpI = LastValue (bp,1);
r1 = (bp*2)-Lo; r1I = LastValue (r1,1);
s1 = (bp*2)-Hi; s1I = LastValue (s1,1);
r2 = bp + r1 - s1; r2I = LastValue (r2,1);
s2 = bp - r1 + s1; s2I = LastValue (s2,1);
r3 = bp + r2 - s1; r3I = LastValue (r3,1);
s3 = bp - r2 + s1; s3I = LastValue (s3,1);
r4 = bp + r2 - s2; r4I = LastValue (r4,1);
s4 = bp - r2 + s2; s4I = LastValue (s4,1);
wrg = (wHi - wLo);
wbp = (wHi + wLo + wCl)/3; wbpI = LastValue (wbp,1);
wr1 = (wbp*2)-wLo; wr1I = LastValue (wr1,1);
ws1 = (wbp*2)-wHi; ws1I = LastValue (ws1,1);
wr2 = wbp + wr1 - ws1; wr2I = LastValue (wr2,1);
ws2 = wbp - wr1 + ws1; ws2I = LastValue (ws2,1);
wr3 = wbp + wr2 - ws1; wr3I = LastValue (wr3,1);
ws3 = wbp - wr2 + ws1; ws3I = LastValue (ws3,1);
wr4 = wbp + wr2 - ws2; wr4I = LastValue (wr4,1);
ws4 = wbp - wr2 + ws2; ws4I = LastValue (ws4,1);
mrg = (mHi - mLo);
mobp = (mHi + mLo + mCl)/3; mobpI = LastValue (mobp,1);
mr1 = (mobp*2)-mLo; mr1I = LastValue (mr1,1);
ms1 = (mobp*2)-mHi; ms1I = LastValue (ms1,1);
mr2 = mobp + mr1 - ms1; mr2I = LastValue (mr2,1);
ms2 = mobp - mr1 + ms1; ms2I = LastValue (ms2,1);
PIV = ParamToggle("Plot PIV","Off|On",1);
PivText = ParamToggle("Plot Text","Off|On",1);
if(PIV==0) {
Plot(bp,"",colorWhite,styleLine|styleLine|styleNoRescale);
Plot(s1,"",colorBrightGreen,styleDashed|styleNoRescale);
Plot(s2,"",colorBrightGreen,styleDashed|styleNoRescale);
Plot(s3,"",colorBrightGreen,styleDashed|styleNoRescale);
Plot(s4,"",colorBrightGreen,styleDashed|styleNoRescale);
Plot(r1,"",colorRed,styleDashed|styleNoRescale);
Plot(r2,"",colorRed,styleDashed|styleNoRescale);
Plot(r3,"",colorRed,styleDashed|styleNoRescale);
Plot(r4,"",colorRed,styleDashed|styleNoRescale);
Plot(wbp,"",colorTan,styleDashed|styleLine|styleNoRescale);
Plot(ws1,"",colorBlue,styleDashed|styleNoRescale);
Plot(ws2,"",colorBlue,styleDashed|styleNoRescale);
Plot(ws3,"",colorPaleGreen,styleDashed|styleNoRescale);
Plot(ws4,"",colorPaleGreen,styleDashed|styleNoRescale);
Plot(wr1,"",colorYellow,styleDashed|styleNoRescale);
Plot(wr2,"",colorYellow,styleDashed|styleNoRescale);
Plot(wr3,"",colorPaleBlue,styleDashed|styleNoRescale);
Plot(wr4,"",colorPaleBlue,styleDashed|styleNoRescale);
Plot(mobp,"",colorTan,styleDashed|styleLine|styleNoRescale);
Plot(ms1,"",colorPaleGreen,styleDashed|styleNoRescale);
Plot(mr1,"",colorDarkRed,styleDashed|styleNoRescale);
}
if(PivText==1) {
PlotText(" PIVOT = " + WriteVal(bp,fraction), LastValue(BarIndex())-(numbars/Hts), bpI +0.05, colorWhite);
PlotText(" Resi_ 1 = " + WriteVal(r1,fraction), LastValue(BarIndex())-(numbars/Hts), r1I +0.05, colorRed);
PlotText(" Sup_ 1 = " + WriteVal(s1,fraction), LastValue(BarIndex())-(numbars/Hts), s1I +0.05, colorGreen);
PlotText(" Resi_ 2 = " + WriteVal(r2,fraction), LastValue(BarIndex())-(numbars/Hts), r2I +0.05, colorRed);
PlotText(" Sup_ 2 = " + WriteVal(s2,fraction), LastValue(BarIndex())-(numbars/Hts), s2I +0.05, colorBrightGreen);
PlotText(" Resi_ 3 = " + WriteVal(r3,fraction), LastValue(BarIndex())-(numbars/Hts), r3I +0.05, colorRed);
PlotText(" Sup_ 3 = " + WriteVal(s3,fraction), LastValue(BarIndex())-(numbars/Hts), s3I +0.05, colorBrightGreen);
PlotText(" Resi_ 4 = " + WriteVal(r4,fraction), LastValue(BarIndex())-(numbars/Hts), r4I +0.05, colorRed);
PlotText(" Sup_ 4 = " + WriteVal(s4,fraction), LastValue(BarIndex())-(numbars/Hts), s4I +0.05, colorBrightGreen);
PlotText(" W PIVOT =" + WriteVal(wbp,fraction), LastValue(BarIndex())-(numbars/Hts), wbpI +0.05, colorTan);
PlotText(" W Resi_1 =" + WriteVal(wr1,fraction), LastValue(BarIndex())-(numbars/Hts), wr1I +0.05, colorYellow);
PlotText(" W Sup_ 1 = " + WriteVal(ws1,fraction), LastValue(BarIndex())-(numbars/Hts), ws1I +0.05, colorBlue);
PlotText(" W Resi_ 2 = " + WriteVal(wr2,fraction), LastValue(BarIndex())-(numbars/Hts), wr2I +0.05, colorYellow);
PlotText(" W Sup_ 2 = " + WriteVal(ws2,fraction), LastValue(BarIndex())-(numbars/Hts), ws2I +0.05, colorBlue);
PlotText(" W Resi_ 3 = " + WriteVal(wr3,fraction), LastValue(BarIndex())-(numbars/Hts), wr3I +0.05, colorPaleBlue);
PlotText(" W Sup_ 3 = " + WriteVal(ws3,fraction), LastValue(BarIndex())-(numbars/Hts), ws3I +0.05, colorPaleGreen);
PlotText(" W Resi_ 4 = " + WriteVal(wr4,fraction), LastValue(BarIndex())-(numbars/Hts), wr4I +0.05, colorPaleBlue);
PlotText(" W Sup_ 4 = " + WriteVal(ws4,fraction), LastValue(BarIndex())-(numbars/Hts), ws4I +0.05, colorPaleGreen);
PlotText(" M PIVOT = " + WriteVal(mobp,fraction), LastValue(BarIndex())-(numbars/Hts), mobpI+0.05, colorTan);
PlotText(" M Resistance 1 = " + WriteVal(mr1,fraction), LastValue(BarIndex())-(numbars/Hts), mr1I+0.05, colorPaleBlue);
PlotText(" M Support 1 = " + WriteVal(ms1,fraction), LastValue(BarIndex())-(numbars/Hts), ms1I+0.05, colorPaleGreen);
}

_SECTION_END();


_SECTION_BEGIN("PIVOTS Hourly");
TimeFrameSet(inHourly);
HourlyH= LastValue(Ref(H,-1));
HourlyL= LastValue(Ref(L,-1));
HourlyC= LastValue(Ref(C,-1));
TimeFrameRestore();

//Daily 
HPP = (HourlyL + HourlyH + HourlyC)/3;HPPI = LastValue (HPP,1);
HR1  =  (2 * HPP) - HourlyL;HR1I = LastValue (HR1,1);
HS1  =  (2 * HPP)  - HourlyH;HS1I = LastValue (HS1,1);
HR2  =  HPP + (HourlyH - HourlyL);HR2I = LastValue (HR2,1);
HS2  =  HPP - (HourlyH - HourlyL);HS2I = LastValue (HS2,1);
HR3 = HourlyH + 2*(HPP - HourlyL);HR3I = LastValue (HR3,1);
HS3 = HourlyL - 2*(HourlyH - HPP);HS3I = LastValue (HS3,1);
SHOWDPIVOTS = ParamToggle("Daily Pivots", "No|Yes",0);
SHOW3 = ParamToggle("3rd Line", "No|Yes",0); 

if (SHOWDPIVOTS & SHOW3)
{
 Plot(HS3, "S3",ColorR);
 Plot(HR3, "R3",ColorG);
 PlotText(" H Resis 3 = " + WriteVal(HR3,fraction), LastValue(BarIndex())-(numbars/Hts), HR3I +0.05, colorGreen);
 PlotText(" H Sup 3 = " + WriteVal(HS3,fraction), LastValue(BarIndex())-(numbars/Hts), HS3I +0.05, colorRed);

}


 
for (i=BarCount-2;i>(BarCount-13);i--)//set the last bars to the final PP value
{
 HPP[i] = HPP[BarCount-1];
 HR1[i] = HR1[BarCount-1];
 HR2[i] = HR2[BarCount-1];
 HS1[i] = HS1[BarCount-1];
 HS2[i] = HS2[BarCount-1];

 ColorG[i] = colorGreen;
 ColorB[i] = colorBlue;
 ColorR[i] = colorRed;
}

//
// Conceal all but the trailing portion of the line
//
for (i=0;i<BarCount-15;i++) //hide the line except most recent 15 bars
{
 ColorR[i] = ColorG[i] = ColorB[i] = colorBlack;
}


if (SHOWDPIVOTS) {
Plot(HR2, "R2",ColorG);
Plot(HR1, "R1",ColorG);
Plot(HPP, "PP",ColorB);
Plot(HS1, "S1",ColorR);
Plot(HS2, "S2",ColorR);
PlotText(" H Pivot = " + WriteVal(HPP,fraction), LastValue(BarIndex())-(numbars/Hts), HPPI +0.05, colorBlue);
PlotText(" H Resis 1 = " + WriteVal(HR1,fraction), LastValue(BarIndex())-(numbars/Hts), HR1I +0.05, colorGreen);
PlotText(" H Sup 1 = " + WriteVal(HS1,fraction), LastValue(BarIndex())-(numbars/Hts), HS1I +0.05, colorRed);
PlotText(" H Resis 2 = " + WriteVal(HR2,fraction), LastValue(BarIndex())-(numbars/Hts), HR2I +0.05, colorGreen);
PlotText(" H Sup 2 = " + WriteVal(HS2,fraction), LastValue(BarIndex())-(numbars/Hts), HS2I +0.05, colorRed);

}

if (SHOWDPIVOTS & SHOW3)
{
 Plot(S3, "S3",ColorR);
 Plot(R3, "R3",ColorG);
 PlotText(" H Resis 3 = " + WriteVal(HR3,fraction), LastValue(BarIndex())-(numbars/Hts), HR3I +0.05, colorGreen);
 PlotText(" H Sup 3 = " + WriteVal(HS3,fraction), LastValue(BarIndex())-(numbars/Hts), HS3I +0.05, colorRed);

}


_SECTION_END();
/* **********************************

Code to automatically identify pivots

********************************** */

// -- what will be our lookback range for the hh and ll?
farback=Param("How Far back to go",100,50,5000,10);
nBars = Param("Number of bars", 12, 5, 40);

// -- Title.

Title = Name() + " (" + StrLeft(FullName(), 15) + ") O: " + Open + ", 

H: " + High + ", L: " + Low + ", C: " + Close;

// -- Plot basic candle chart

PlotOHLC(Open, High, Low, Close, 

"BIdx = " + BarIndex() + 

"\n" + "O = " + O + "\n"+"H = "+ H + "\n"+"L = " + L

+ "\n"+"C ",

colorBlack, styleBar); 

GraphXSpace=7;

// -- Create 0-initialized arrays the size of barcount

aHPivs = H - H;

aLPivs = L - L;

// -- More for future use, not necessary for basic plotting

aHPivHighs = H - H;

aLPivLows = L - L;

aHPivIdxs = H - H;

aLPivIdxs = L - L;

nHPivs = 0;

nLPivs = 0;

lastHPIdx = 0;

lastLPIdx = 0;

lastHPH = 0;

lastLPL = 0;

curPivBarIdx = 0;

// -- looking back from the current bar, how many bars 

// back were the hhv and llv values of the previous 

// n bars, etc.?

aHHVBars = HHVBars(H, nBars);

aLLVBars = LLVBars(L, nBars);

aHHV = HHV(H, nBars);

aLLV = LLV(L, nBars);

// -- Would like to set this up so pivots are calculated back from

// last visible bar to make it easy to "go back" and see the pivots

// this code would find. However, the first instance of 

// _Trace output will show a value of 0

aVisBars = Status("barvisible");

nLastVisBar = LastValue(Highest(IIf(aVisBars, BarIndex(), 0)));

_TRACE("Last visible bar: " + nLastVisBar);

// -- Initialize value of curTrend

curBar = (BarCount-1);

curTrend = "";

if (aLLVBars[curBar] < 

aHHVBars[curBar]) {

curTrend = "D";

}

else {

curTrend = "U";

}

// -- Loop through bars. Search for 

// entirely array-based approach

// in future version

for (i=0; i<farback; i++) {

curBar = (BarCount - 1) - i;

// -- Have we identified a pivot? If trend is down...

if (aLLVBars[curBar] < aHHVBars[curBar]) {

// ... and had been up, this is a trend change

if (curTrend == "U") {

curTrend = "D";

// -- Capture pivot information

curPivBarIdx = curBar - aLLVBars[curBar];

aLPivs[curPivBarIdx] = 1;

aLPivLows[nLPivs] = L[curPivBarIdx];

aLPivIdxs[nLPivs] = curPivBarIdx;

nLPivs++;

}

// -- or current trend is up

} else {

if (curTrend == "D") {

curTrend = "U";

curPivBarIdx = curBar - aHHVBars[curBar];

aHPivs[curPivBarIdx] = 1;

aHPivHighs[nHPivs] = H[curPivBarIdx];

aHPivIdxs[nHPivs] = curPivBarIdx;

nHPivs++;

}

// -- If curTrend is up...else...

} 

// -- loop through bars

} 

// -- Basic attempt to add a pivot this logic may have missed

// -- OK, now I want to look at last two pivots. If the most 

// recent low pivot is after the last high, I could

// still have a high pivot that I didn't catch

// -- Start at last bar

curBar = (BarCount-1);

candIdx = 0;

candPrc = 0;

lastLPIdx = aLPivIdxs[0];

lastLPL = aLPivLows[0];

lastHPIdx = aHPivIdxs[0];

lastHPH = aHPivHighs[0];

if (lastLPIdx > lastHPIdx) {

// -- Bar and price info for candidate pivot

candIdx = curBar - aHHVBars[curBar];

candPrc = aHHV[curBar]; 

if (

lastHPH < candPrc AND

candIdx > lastLPIdx AND

candIdx < curBar) {


// -- OK, we'll add this as a pivot...

aHPivs[candIdx] = 1;

// ...and then rearrange elements in the 

// pivot information arrays

for (j=0; j<nHPivs; j++) {

aHPivHighs[nHPivs-j] = aHPivHighs[nHPivs-

(j+1)];

aHPivIdxs[nHPivs-j] = aHPivIdxs[nHPivs-(j+1)];

}

aHPivHighs[0] = candPrc ;

aHPivIdxs[0] = candIdx;

nHPivs++;

} 

} else {


// -- Bar and price info for candidate pivot

candIdx = curBar - aLLVBars[curBar];

candPrc = aLLV[curBar]; 

if (

lastLPL > candPrc AND

candIdx > lastHPIdx AND

candIdx < curBar) {


// -- OK, we'll add this as a pivot...

aLPivs[candIdx] = 1;

// ...and then rearrange elements in the 

// pivot information arrays

for (j=0; j<nLPivs; j++) {

aLPivLows[nLPivs-j] = aLPivLows[nLPivs-(j+1)];

aLPivIdxs[nLPivs-j] = aLPivIdxs[nLPivs-(j+1)];

}

aLPivLows[0] = candPrc;

aLPivIdxs[0] = candIdx;

nLPivs++;

}

}

// -- Dump inventory of high pivots for debugging

/*

for (k=0; k<nHPivs; k++) {

_TRACE("High pivot no. " + k

+ " at barindex: " + aHPivIdxs[k] + ", " 

+ WriteVal(ValueWhen(BarIndex()==aHPivIdxs[k], 

DateTime(), 1), formatDateTime)

+ ", " + aHPivHighs[k]);

}

*/

// -- OK, let's plot the pivots using arrows

PlotShapes(

IIf(aHPivs==1, shapeHollowDownArrow, shapeNone), colorRed, 0,

High, Offset=-15);

PlotShapes(

IIf(aLPivs==1, shapeHollowUpArrow , shapeNone), colorBrightGreen, 0, 

Low, Offset=-15);
_SECTION_END();



_SECTION_BEGIN("Gartley");

GBmin = Param("Swing B Min.",0.55,0.3,1,0.01);
GBmax = Param("Swing B Max.",0.72,0.4,1,0.01);
GCmin = Param("Swing C Min.",0.38,0.3,1.27,0.01);
GCmax = Param("Swing C Max.",1.0,0.4,1.27,0.01);
GDmin = Param("Swing D Min.(XA)",0.55,0.3,1,0.01);
GDmax = Param("Swing D Max.(XA)",1.0,0.4,1.0,0.01);

_SECTION_END();

_SECTION_BEGIN("Bat");

BatBmin = Param("Swing B Min.",0.38,0.3,1,0.01);
BatBmax = Param("Swing B Max.",0.55,0.4,1,0.01);
BatCmin = Param("Swing C Min.",0.38,0.3,1.62,0.01);
BatCmax = Param("Swing C Max.",1.27,0.4,1.62,0.01);
BatDmin = Param("Swing D Min.(XA)",0.5,0.3,1,0.01);
BatDmax = Param("Swing D Max.(XA)",1.0,0.4,1.0,0.01);

_SECTION_END();

_SECTION_BEGIN("Butterfly");

BtBmin = Param("Swing B Min.",0.55,0.3,1,0.01);
BtBmax = Param("Swing B Max.",0.9,0.4,1,0.01);
BtCmin = Param("Swing C Min.",0.38,0.3,1.62,0.01);
BtCmax = Param("Swing C Max.",1.27,0.4,1.62,0.01);
BtDmin = Param("Swing D Min.(XA)",1,1,1.8,0.01);
BtDmax = Param("Swing D Max.(XA)",1.8,1,1.8,0.01);  // Max XA of Butterfly = (1.0 - 1.618)

_SECTION_END();

_SECTION_BEGIN("Crab");

CBmin = Param("Swing B Min.",0.38,0.3,1,0.01);
CBmax = Param("Swing B Max.",0.65,0.4,1,0.01);
CCmin = Param("Swing C Min.",0.38,0.3,1.62,0.01);
CCmax = Param("Swing C Max.",1.270,0.4,1.62,0.01);
CDmin = Param("Swing D Min.(XA)",1.25,1,1.8,0.01);
CDmax = Param("Swing D Max.(XA)",1.8,1,2,0.01);

_SECTION_END();

_SECTION_BEGIN("AB=CD");

abcd_Cmin = Param("Swing C Min.",0.3,  0.3  ,  1,  0.01);
abcd_Cmax = Param("Swing C Max.",0.8,  0.8  ,  1,  0.01);
abcd_Dmin = Param("Swing D Min.",1.2,  1,  2.7,  0.01);
abcd_Dmax = Param("Swing D Max.",3.7,  1,  4,  0.01);

_SECTION_END();

_SECTION_BEGIN("Patterns");
 
//strength = Param("Strength",5,2,15,1);  // Best use: 3, 4, 5
strength = Param("BARS of each LINE",5,2,15,1);  // So luong bar cho moi duong XA, AB, BC, 
bu = ParamToggle("Bullish Pattern","Off|On",1);  // So bar/lines se quyet dinh. mo^ hinh` duoc ve the' nao`
be = ParamToggle("Bearish Pattern","Off|On",1);

bi = Cum(1)-1;

function GetTop(bars)  // Lay' gia' tri cao nhat' = di?nh
 {
 Top = H == HHV(H,2*bars) AND Ref(HHV(H,bars),bars) < H;
 Top = Top AND LastValue(bi)-ValueWhen(Top,bi) > bars;
 return Top;
 }

function GetValley(bars)  // La'y gia tri thap' nhat' = day'
 {
 Valley = L == LLV(L,2*bars) AND Ref(LLV(L,bars),bars) > L;
 Valley = Valley AND LastValue(bi)-ValueWhen(Valley,bi) > bars;
 return Valley;
 }


// Build fractals array

P1 = GetTop(strength);  // so' bar cho 1 duong` XA, AB, BC, CD
V1 = GetValley(Strength);

P1 = IIf(P1,IIf(ValueWhen(P1,bi,2) < ValueWhen(V1,bi),P1,IIf(ValueWhen(P1,H,2) > H,False,P1)),P1);
P1 = IIf(P1 AND ValueWhen(P1,bi,0) > bi,IIf(ValueWhen(P1,bi,0) < ValueWhen(V1,bi,0),IIf(ValueWhen(P1,H,0) >= H,False,P1),P1),P1);
V1 = IIf(V1,IIf(ValueWhen(V1,bi,2) < ValueWhen(P1,bi),V1,IIf(ValueWhen(V1,L,2)<L,False,V1)),V1);
V1 = IIf(V1 AND ValueWhen(V1,bi,0) > bi ,IIf(ValueWhen(V1,bi,0) < ValueWhen(P1,bi,0),IIf(ValueWhen(V1,L,0) <= L, False,V1),V1),V1); 


P1H1 = ValueWhen(P1,H);
P1Bar1 = ValueWhen(P1,bi);
P1H2 = ValueWhen(P1,H,2);
P1Bar2 = ValueWhen(P1,bi,2);
V1L1 = ValueWhen(V1,L);
V1Bar1 = ValueWhen(V1,bi);
V1L2 = ValueWhen(V1,L,2);
V1Bar2 = ValueWhen(V1,bi,2);


//============================================
//  BULLISH PATTERNS
//============================================
/*
 Mo hinh Bullish:
 A  =  P1H2
 B  =  V1L1
 C  =  P1H1
 X  =  V1L2

*/

PTvalid = (P1Bar1 > V1Bar1 AND V1Bar1 > P1Bar2 AND P1bar2 > V1Bar2) AND P1; // Peaks and troughs are in order

myAX  =  P1H2-V1L2;
myAB  =  P1H2-V1L1;
myBC  =  P1H1-V1L1;

myAB_AX  =  myAB/ myAX;
myBC_AB  =  myBC/ myAB;  

BullGartley4  = PTvalid  AND  (  myAB_AX > GBmin  )  AND (  myAB_AX < GBmax  )
 AND  (  myBC_AB > GCMin  )  AND (  myBC_AB < GCMax  ); 

BullBat4  = PTvalid  AND  (  myAB_AX > BatBmin )  AND (  myAB_AX < BatBmax  )
 AND  (  myBC_AB > BatCMin )  AND (  myBC_AB < BatCMax  ); 

BullButterfly4  = PTvalid  AND  (  myAB_AX > BtBmin )  AND (  myAB_AX < BtBMax  )
 AND  (  myBC_AB > BtCmin )  AND (  myBC_AB < BtCmin  );

BullCrab4  = PTvalid  AND  (  myAB_AX > CBmin )    AND (  myAB_AX < CBmax  )
 AND  (  myBC_AB > CCmin )  AND (  myBC_AB < CCmax  );

BullABCD4  = PTvalid AND  (  myBC_AB > abcd_Cmin)  AND (  myBC_AB < abcd_Cmax  );

strPattern = "";

//==================================================
//   BULLISH ABCD
//  Bullish pattern found. D retracement level is not evaluated
//==================================================
 dHigh  =  HighestSince(BullABCD4,H);  // Tinh' gia' tri min, max cua duong Ad. Duong Ad la duong con cua AD
 dLow  =  LowestSince(BullABCD4,L);
 
 myC  =  ValueWhen(BullABCD4,P1H1);
 myB  =  ValueWhen(BullABCD4,V1L1);
 myA  =  ValueWhen(BullABCD4,P1H2);
 myX  =  ValueWhen(BullABCD4,V1L2);
 myCB  =  myC - myB;

 my_d_min  =  myCB  *  abcd_DMin ;  // Tinh' gia' tri cua duong Ad con. Khi gia' giam? tu` tre^n xuong' thi` max -> min
 my_d_max  =  myCB  *  abcd_DMax ;
 my_Cd_min  =  myC - my_d_min; // Khoang dich chuyen cua duong Ad con.
 my_Cd_max  =  myC - my_d_max;

BullABCD    =  IIf(  ( dLow  <  my_Cd_min  )  AND  ( dLow  > my_Cd_max )  
 AND  ( dHigh  <=  myC  )  AND  ( dLow  ==  L), 
 True, False
 );

BullABCD  =  BullABCD  AND (dLow  <  myB);


//==================================================
//  BULLISH GARTLEY
//==================================================
 dHigh  =  HighestSince(BullGartley4,H);  // Tinh' gia' tri min, max cua duong Ad. Duong Ad la duong con cua AD
 dLow  =  LowestSince(BullGartley4,L);

 myC  =  ValueWhen(BullGartley4,P1H1);
 myB  =  ValueWhen(BullGartley4,V1L1);
 myA  =  ValueWhen(BullGartley4,P1H2);
 myX  =  ValueWhen(BullGartley4,V1L2);
 myAX  =  myA - myX;

 my_d_min  =  myAX  *  GDmin;  // Tinh' gia' tri cua duong Ad con. Khi gia' giam? tu` tre^n xuong' thi` max -> min
 my_d_max  =  myAX  *  GDMax;
 my_Ad_min  =  myA - my_d_min;  // Khoang dich chuyen cua duong Ad con.
 my_Ad_max  =  myA - my_d_max;

BullGartley  =  IIf(  ( dLow  <  my_Ad_min  )  AND  ( dLow  > my_Ad_max )  
 AND  ( dHigh  <=  myC  )  AND  ( dLow  ==  L), 
 True, False
 );
BullGartley  =  BullGartley  AND (dLow  <  myB);  // diem D thap' hon B
strPattern  =  WriteIf(BullGartley,"BULLISH GARTLEY",strPattern);



//==================================================
//  BULLISH BAT
//==================================================
 dHigh  =  HighestSince(BullBat4,H);  // Tinh' gia' tri min, max cua duong Ad. Duong Ad la duong con cua AD
 dLow  =  LowestSince(BullBat4,L);  

 myC  =  ValueWhen(BullBat4,P1H1);
 myB  =  ValueWhen(BullBat4,V1L1);
 myA  =  ValueWhen(BullBat4,P1H2);
 myX  =  ValueWhen(BullBat4,V1L2);
 myAX  =  myA - myX;

 my_d_min  =  myAX  *  BatDmin;  // Tinh' gia' tri cua duong Ad con. Khi gia' giam? tu` tre^n xuong' thi` max -> min
 my_d_max  =  myAX  *  BatDmax ;
 my_Ad_min  =  myA - my_d_min;  // Khoang dich chuyen cua duong Ad con.
 my_Ad_max  =  myA - my_d_max;

BullBat  =  IIf(  ( dLow  <  my_Ad_min  )  AND  ( dLow  > my_Ad_max )  
 AND  ( dHigh  <=  myC  )  AND  ( dLow  ==  L), 
 True, False
 );
BullBat  =  BullBat  AND (dLow  <  myB);  // diem d thap hon diem B
strPattern  =  WriteIf(BullBat,"BULLISH BAT",strPattern);


//==================================================
//  BULLISH CRAB - CUA
//==================================================
 dHigh  =  HighestSince(BullCrab4,H);  // Tinh' gia' tri min, max cua duong Ad. Duong Ad la duong con cua AD
 dLow  =  LowestSince(BullCrab4,L);

 myC  =  ValueWhen(BullCrab4,P1H1);
 myB  =  ValueWhen(BullCrab4,V1L1);
 myA  =  ValueWhen(BullCrab4,P1H2);
 myX  =  ValueWhen(BullCrab4,V1L2);
 myAX  =  myA - myX;

 my_d_min  =  myAX  *  CDmin ;  // Tinh' gia' tri cua duong Ad con. Khi gia' giam? tu` tre^n xuong' thi` max -> min
 my_d_max  =  myAX  *  CDmax ;
 my_Ad_min  =  myA - my_d_min;  // Khoang dich chuyen cua duong Ad con.
 my_Ad_max  =  myA - my_d_max;

BullCrab  =  IIf(  ( dLow  <  my_Ad_min  )  AND  ( dLow  > my_Ad_max )  
 AND  ( dHigh  <=  myC  )  AND  ( dLow  ==  L), 
 True, False
 );
BullCrab  =  BullCrab  AND (dLow  <  myX);  // diem D thap' hon X
strPattern  =  WriteIf(BullCrab ,"BULLISH CRAB",strPattern);


//==================================================
//  BULLISH  BUTTTERFLY
//==================================================
 dHigh  =  HighestSince(BullButterfly4,H);  // Tinh' gia' tri min, max cua duong Ad. Duong Ad la duong con cua AD
 dLow  =  LowestSince(BullButterfly4,L);

 myC  =  ValueWhen(BullButterfly4,P1H1);
 myB  =  ValueWhen(BullButterfly4,V1L1);
 myA  =  ValueWhen(BullButterfly4,P1H2);
 myX  =  ValueWhen(BullButterfly4,V1L2);
 myAX  =  myA - myX;

 my_d_min  =  myAX  *  BtDmin ;  // Tinh' gia' tri cua duong Ad con. Khi gia' giam? tu` tre^n xuong' thi` max -> min
 my_d_max  =  myAX  *  BtDmax ;
 my_Ad_min  =  myA - my_d_min;  // Khoang dich chuyen cua duong Ad con.
 my_Ad_max  =  myA - my_d_max;

BullButterfly  =  IIf(  ( dLow  <  my_Ad_min  )  AND  ( dLow  > my_Ad_max )  
 AND  ( dHigh  <=  myC  )  AND  ( dLow  ==  L), 
 True, False
 );
BullButterfly  =  BullButterfly  AND (dLow  <  myX);  // diem D thap' hon X
strPattern  =  WriteIf(BullButterfly ,"BULLISH BUTTERFLY",strPattern);



//==========================================================
// VE DUONG CHO MO HINH BULLISH ABCB 
//==========================================================
BullHar4  =  BullABCD4;
BullHar  =  BullABCD;

Point4 = IIf(BullHar,ValueWhen(BullHar4,bi),Null);
BullHar = IIf(BullHar, IIf(Point4 == ValueWhen(BullHar,point4,0) AND ValueWhen(BullHar,bi,0) > bi ,False,BullHar),BullHar);

A = ValueWhen(BullHar4,P1H2);
Abar = ValueWhen(BullHar4,P1bar2);
B = ValueWhen(BullHar4,V1L1);
Bbar = ValueWhen(BullHar4,V1bar1);
C1 = ValueWhen(BullHar4,P1H1);
C1bar = ValueWhen(BullHar4,P1bar1);
D = ValueWhen(BullHar,L);
Dbar = ValueWhen(BullHar,bi);

BCdAB = (C1-B)/(A-B);
BCdCD = (C1-D)/(C1-B);

PlotPattern = Dbar > C1bar;

if(LastValue(PlotPattern) AND bu)
{
 ColorX = colorGreen;
 // Ve cac duong AB, BC, CD
 Plot(LineArray(LastValue(Abar),LastValue(A),LastValue(Bbar),LastValue(B)),"",ColorX ,styleThick);
 Plot(LineArray(LastValue(Bbar),LastValue(B),LastValue(C1bar),LastValue(C1)),"",ColorX ,styleThick);
 Plot(LineArray(LastValue(C1bar),LastValue(C1),LastValue(Dbar),LastValue(D)),"",ColorX ,styleThick);
 Plot(LineArray(LastValue(Abar),LastValue(A),LastValue(C1bar),LastValue(C1)),"",ColorX ,styleDashed);
 Plot(LineArray(LastValue(Bbar),LastValue(B),LastValue(Dbar),LastValue(D)),"",ColorX ,styleDashed);

 // Ve cac gia tri Fibo
 PlotText(NumToStr(LastValue(BCdAB),1.2),(LastValue(C1bar)+LastValue(Abar))/2,(LastValue(C1)+LastValue(A))/2,ColorX );
 PlotText(NumToStr(LastValue(BCdCD),1.2),(LastValue(Bbar)+LastValue(Dbar))/2,(LastValue(B)+LastValue(D))/2,ColorX );

 //---------- Viet cac diem X, A, B, C, D: by binhnd---------------------
 xlech  =  0;
 ylech  =  2;
 PlotText("A",LastValue(Abar)  +  xlech,  LastValue(A)  +  ylech,  ColorX );
 PlotText("B",LastValue(Bbar)  +  xlech,  LastValue(B)  -  ylech,  ColorX );
 PlotText("C",LastValue(C1bar)  +  xlech,  LastValue(C1)  +  ylech,  ColorX );
 PlotText("D",LastValue(Dbar)  +  xlech,  LastValue(D)  -  ylech,  ColorX );

 //--------- Viet thuyet minh mo hinh: by binhnd--------------
 if (strPattern!="")  
 {
 myStr  =  "Pattern: BULLISH AB=CD";
 toadoX  =  LastValue(Abar);
 toadoY  =  LastValue(D);

 PlotText(myStr,toadoX,toadoY,ColorX );
 }

}  //  end of Ve duong` bullish abcd



//==========================================================
// VE DUONG CHO MO HINH BULLISH BAT, GARTLEY, BUTTERFLY, CRAB
//==========================================================


BullHar4 = BullGartley4 OR BullButterfly4 OR BullBat4 OR BullCrab4 ;
BullHar = BullGartley OR BullButterfly OR BullBat OR BullCrab;

Point4 = IIf(BullHar,ValueWhen(BullHar4,bi),Null);
BullHar = IIf(BullHar, IIf(Point4 == ValueWhen(BullHar,point4,0) AND ValueWhen(BullHar,bi,0) > bi ,False,BullHar),BullHar);

X = ValueWhen(BullHar4,V1L2);
Xbar = ValueWhen(BullHar4,V1Bar2);
A = ValueWhen(BullHar4,P1H2);
Abar = ValueWhen(BullHar4,P1bar2);
B = ValueWhen(BullHar4,V1L1);
Bbar = ValueWhen(BullHar4,V1bar1);
C1 = ValueWhen(BullHar4,P1H1);
C1bar = ValueWhen(BullHar4,P1bar1);
D = ValueWhen(BullHar,L);
Dbar = ValueWhen(BullHar,bi);

ABdXA = (A-B)/(A-X);
BCdAB = (C1-B)/(A-B);
ADdXA = (A-D)/(A-X);
BCdCD = (C1-D)/(C1-B);

PlotPattern = Dbar > C1bar;

if(LastValue(PlotPattern) AND bu)
{
 ColorX  = colorBlue;
 // Ve cac duong XA, AB, BC, CD
 Plot( LineArray(LastValue(Xbar),LastValue(X),LastValue(Abar),LastValue(A)),"",ColorX,styleThick);
 Plot(LineArray(LastValue(Abar),LastValue(A),LastValue(Bbar),LastValue(B)),"",ColorX,styleThick);
 Plot(LineArray(LastValue(Bbar),LastValue(B),LastValue(C1bar),LastValue(C1)),"",ColorX,styleThick);
 Plot(LineArray(LastValue(C1bar),LastValue(C1),LastValue(Dbar),LastValue(D)),"",ColorX,styleThick);
 Plot(LineArray(LastValue(Xbar),LastValue(X),LastValue(Bbar),LastValue(B)),"",ColorX,styleDashed);
 Plot(LineArray(LastValue(Xbar),LastValue(X),LastValue(Abar),LastValue(A)),"",ColorX,styleThick);
 Plot(LineArray(LastValue(Abar),LastValue(A),LastValue(C1bar),LastValue(C1)),"",ColorX,styleDashed);
 Plot(LineArray(LastValue(Bbar),LastValue(B),LastValue(Dbar),LastValue(D)),"",ColorX,styleDashed);
 Plot(LineArray(LastValue(Xbar),LastValue(X),LastValue(Dbar),LastValue(D)),"",ColorX,styleDashed);

 // Ve cac gia tri Fibo
 PlotText(NumToStr(LastValue(ABdXA),1.2),(LastValue(Bbar)+LastValue(Xbar))/2,(LastValue(B)+LastValue(X))/2,ColorX);
 PlotText(NumToStr(LastValue(BCdAB),1.2),(LastValue(C1bar)+LastValue(Abar))/2,(LastValue(C1)+LastValue(A))/2,ColorX);
 PlotText(NumToStr(LastValue(ADdXA),1.2) ,(LastValue(Dbar)+LastValue(Xbar))/2,(LastValue(D)+LastValue(X))/2,ColorX);
 PlotText(NumToStr(LastValue(BCdCD),1.2),(LastValue(Bbar)+LastValue(Dbar))/2,(LastValue(B)+LastValue(D))/2,ColorX);

 //---------- Viet cac diem X, A, B, C, D: by binhnd---------------------
 xlech  =  0;
 ylech  =  2;
 PlotText("X",LastValue(Xbar)  +  xlech,  LastValue(X)  -  ylech,  ColorX);
 PlotText("A",LastValue(Abar)  +  xlech,  LastValue(A)  +  ylech,  ColorX);
 PlotText("B",LastValue(Bbar)  +  xlech,  LastValue(B)  -  ylech,  ColorX);
 PlotText("C",LastValue(C1bar)  +  xlech,  LastValue(C1)  +  ylech,  ColorX);
 PlotText("D",LastValue(Dbar)  +  xlech,  LastValue(D)  -  ylech,  ColorX);

 //--------- Viet thuyet minh mo hinh: by binhnd--------------
 if (strPattern!="")  
 {
 strPattern  =  "Pattern: " + strPattern;
 toadoX  =  (LastValue(Dbar)+LastValue(Xbar))/2;
 toadoY  =  (LastValue(D)+LastValue(X))/2;

 PlotText(strPattern,toadoX,toadoY-2,ColorX);
 }

}  // end of Ve duong cho cac mo hinh Crab, Butterfly, Bat


//=============================================================
//  BEARISH PATTERNS
//=============================================================

PTvalid = (V1Bar1 > P1Bar1 AND P1Bar1 > V1Bar2 AND V1Bar2 > P1Bar2) AND V1;

/*=====================
 X  =  P1H2   Trong mo hinh` bear: Die^m X cao hon diem A. MyAX = X-> A
 A  =  V1L2
 B  =  P1H1
 C  =  V1L1

=======================*/
myAX  =  P1H2-V1L2;  
myAB  =  P1H1-V1L2;
myBC  =  P1H1-V1L1;

myAB_AX  =  myAB/ myAX;
myBC_AB  =  myBC/ myAB;  

BearGartley4  = PTvalid  AND  (  myAB_AX > GBmin  )  AND (  myAB_AX < GBmax  )
 AND  (  myBC_AB > GCMin  )  AND (  myBC_AB < GCMax  ); 

BearBat4  = PTvalid  AND  (  myAB_AX > BatBmin )  AND (  myAB_AX < BatBmax  )
 AND  (  myBC_AB > BatCMin )  AND (  myBC_AB < BatCMax  ); 

BearButterfly4  = PTvalid  AND  (  myAB_AX > BtBmin )  AND (  myAB_AX < BtBMax  )
 AND  (  myBC_AB > BtCmin )  AND (  myBC_AB < BtCmin  );

BearCrab4  = PTvalid  AND  (  myAB_AX > CBmin )    AND (  myAB_AX < CBmax  )
 AND  (  myBC_AB > CCmin )  AND (  myBC_AB < CCmax  );

BearABCD4  = PTvalid AND  (  myBC_AB > abcd_Cmin)  AND (  myBC_AB < abcd_Cmax  );

strPattern = "";



//==========================================================
//   BEARISH ABCD
//  Bearish pattern found. D retracement level is not evaluated
//==========================================================
 dHigh  =  HighestSince(BearABCD4,H);  // Tinh' gia' tri min, max cua duong Ad. Duong Ad la duong con cua AD
 dLow  =  LowestSince(BearABCD4,L);
 
 myA  =  ValueWhen(BearABCD4,V1L2);
 myB  =  ValueWhen(BearABCD4,P1H1);
 myC  =  ValueWhen(BearABCD4,V1L1);
 myCB  =  myB - myC;

 my_d_min  =  myCB  *  abcd_DMin ;  // Tinh' gia' tri cua duong Ad con. Khi gia' giam? tu` tre^n xuong' thi` max -> min
 my_d_max  =  myCB  *  abcd_DMax ;
 my_Cd_min  =  myC + my_d_min; // Khoang dich chuyen cua duong Ad con.
 my_Cd_max  =  myC + my_d_max;

BearABCD    =  IIf(  ( dHigh  >  my_Cd_min  )  AND  ( dHigh  < my_Cd_max )  
 AND  ( dLow  >=  myC  )  AND  ( dHigh  ==  H), 
 True, False
 );

BearABCD  =  BearABCD  AND (dHigh  >  myB);

//=============================================================
//  BEARISH GARTLEY
//=============================================================
 dHigh  =  HighestSince(BearGartley4,H);  // Tinh' gia' tri min, max cua duong Ad. Duong Ad la duong con cua AD
 dLow  =  LowestSince(BearGartley4,L);

 myX  =  ValueWhen(BearGartley4,P1H2);
 myA  =  ValueWhen(BearGartley4,V1L2);
 myAX  =  myX - myA;

 myB  =  ValueWhen(BearGartley4,P1H1);
 myC  =  ValueWhen(BearGartley4,V1L1);


 my_d_min  =  myAX  *  GDmin;  // Tinh' gia' tri cua duong Ad con. Khi gia' giam? tu` tre^n xuong' thi` max -> min
 my_d_max  =  myAX  *  GDMax;
 my_Ad_min  =  myA  +  my_d_min;  // Khoang dich chuyen cua duong Ad con.
 my_Ad_max  =  myA  +  my_d_max;

BearGartley  =  IIf(  ( dHigh  >  my_Ad_min  )  AND  ( dHigh  < my_Ad_max )  
 AND  ( dLow  >=  myC  )  AND  ( dHigh  ==  H), 
 True, False
 );
BearGartley  =  BearGartley  AND (dHigh  >  myB);  // diem D cao hon B
strPattern  =  WriteIf(BearGartley ,"BEARISH GARTLEY",strPattern);

//=============================================================
//  BEARISH BAT
//=============================================================
 dHigh  =  HighestSince(BearBat4,H);  // Tinh' gia' tri min, max cua duong Ad. Duong Ad la duong con cua AD
 dLow  =  LowestSince(BearBat4,L);

 myX  =  ValueWhen(BearBat4,P1H2);
 myA  =  ValueWhen(BearBat4,V1L2);
 myAX  =  myX - myA;

 myB  =  ValueWhen(BearBat4,P1H1);
 myC  =  ValueWhen(BearBat4,V1L1);


 my_d_min  =  myAX  *  BatDmin ;  // Tinh' gia' tri cua duong Ad con. Khi gia' giam? tu` tre^n xuong' thi` max -> min
 my_d_max  =  myAX  *  BatDMax ;
 my_Ad_min  =  myA  +  my_d_min;  // Khoang dich chuyen cua duong Ad con.
 my_Ad_max  =  myA  +  my_d_max;

BearBat  =  IIf(  ( dHigh  >  my_Ad_min  )  AND  ( dHigh  < my_Ad_max )  
 AND  ( dLow  >=  myC  )  AND  ( dHigh  ==  H), 
 True, False
 );
BearBat  =  BearBat  AND (dHigh  >  myB);  // diem D cao hon B
strPattern  =  WriteIf(BearBat ,"BEARISH BAT",strPattern);


//=============================================================
//  BEARISH BUTTERFLY
//=============================================================
 dHigh  =  HighestSince(BearButterfly4,H);  // Tinh' gia' tri min, max cua duong Ad. Duong Ad la duong con cua AD
 dLow  =  LowestSince(BearButterfly4,L);

 myX  =  ValueWhen(BearButterfly4,P1H2);
 myA  =  ValueWhen(BearButterfly4,V1L2);
 myAX  =  myX - myA;

 myB  =  ValueWhen(BearButterfly4,P1H1);
 myC  =  ValueWhen(BearButterfly4,V1L1);


 my_d_min  =  myAX  *  BtDmin ;  // Tinh' gia' tri cua duong Ad con. Khi gia' giam? tu` tre^n xuong' thi` max -> min
 my_d_max  =  myAX  *  BtDmax ;
 my_Ad_min  =  myA  +  my_d_min;  // Khoang dich chuyen cua duong Ad con.
 my_Ad_max  =  myA  +  my_d_max;

BearButterfly =  IIf(  ( dHigh  >  my_Ad_min  )  AND  ( dHigh  < my_Ad_max )  
 AND  ( dLow  >=  myC  )  AND  ( dHigh  ==  H), 
 True, False
 );
BearButterfly  =  BearButterfly  AND (dHigh  >  myX);  // diem D cao hon X
strPattern  =  WriteIf(BearButterfly ,"BEARISH BUTTERFLY",strPattern);



//=============================================================
//  BEARISH CRAB
//=============================================================
 dHigh  =  HighestSince(BearCrab4,H);  // Tinh' gia' tri min, max cua duong Ad. Duong Ad la duong con cua AD
 dLow  =  LowestSince(BearCrab4,L);

 myX  =  ValueWhen(BearCrab4,P1H2);
 myA  =  ValueWhen(BearCrab4,V1L2);
 myAX  =  myX - myA;

 myB  =  ValueWhen(BearCrab4,P1H1);
 myC  =  ValueWhen(BearCrab4,V1L1);


 my_d_min  =  myAX  *  CDmin ;  // Tinh' gia' tri cua duong Ad con. Khi gia' giam? tu` tre^n xuong' thi` max -> min
 my_d_max  =  myAX  *  CDmax ;
 my_Ad_min  =  myA  +  my_d_min;  // Khoang dich chuyen cua duong Ad con.
 my_Ad_max  =  myA  +  my_d_max;

BearCrab  =  IIf(  ( dHigh  >  my_Ad_min  )  AND  ( dHigh  < my_Ad_max )  
 AND  ( dLow  >=  myC  )  AND  ( dHigh  ==  H), 
 True, False
 );
BearCrab  =  BearCrab  AND (dHigh  >  myX);  // diem D cao hon X
strPattern  =  WriteIf(BearCrab ,"BEARISH CRAB",strPattern);



//==========================================================
// VE DUONG CHO MO HINH BEARISH ABCD
//==========================================================


BearHar4 = BearABCD4;
BearHar = BearABCD;

Point4 = IIf(BearHar,ValueWhen(BearHar4,bi),Null);
BearHar = IIf(BearHar, IIf(Point4 == ValueWhen(BearHar,point4,0) AND ValueWhen(BearHar,bi,0) > bi ,False,BearHar),BearHar);

A = ValueWhen(BearHar4,V1L2);
Abar = ValueWhen( BearHar4,V1bar2);
B = ValueWhen(BearHar4,P1H1);
Bbar = ValueWhen(BearHar4,P1bar1);
C1 = ValueWhen(BearHar4,V1L1);
C1bar = ValueWhen(BearHar4,V1bar1);
D = ValueWhen(BearHar,H);
Dbar = ValueWhen(BearHar,bi);

BCdAB = (B-C1)/(B-A);
BCdCD = (D-C1)/(B-C1);

PlotPattern = Dbar > C1bar;

//--------- Ve duong ------------------
if(LastValue(Plotpattern) AND be)
{
 ColorX = colorYellow;
 // Ve duong AB, BC
 Plot(LineArray(LastValue(Abar),LastValue(A),LastValue(Bbar),LastValue(B)),"",ColorX ,styleThick);
 Plot(LineArray(LastValue(Bbar),LastValue(B),LastValue(C1bar),LastValue(C1)),"",ColorX ,styleThick);
 Plot(LineArray(LastValue(C1bar),LastValue(C1),LastValue(Dbar),LastValue(D)),"",ColorX ,styleThick);
 Plot(LineArray(LastValue(Abar),LastValue(A),LastValue(C1bar),LastValue(C1)),"",ColorX ,styleDashed);
 Plot(LineArray(LastValue(Bbar),LastValue(B),LastValue(Dbar),LastValue(D)),"",ColorX ,styleDashed);

 // Viet cac gia tri Fibo tren duong AB, BC
 PlotText(NumToStr(LastValue(BCdAB),1.2),(LastValue(C1bar)+LastValue(Abar))/2,(LastValue(C1)+LastValue(A))/2,ColorX );
 PlotText(NumToStr(LastValue(BCdCD),1.2) ,(LastValue(Dbar)+LastValue(Bbar))/2,(LastValue(D)+LastValue(B))/2,ColorX );

 //---------- Viet cac diem A, B, C, D: by binhnd---------------------
 xlech  =  -1;
 ylech  =  1;
 PlotText("A",LastValue(Abar)  +  xlech,  LastValue(A)  -  ylech,  ColorX );
 PlotText("B",LastValue(Bbar)  +  xlech,  LastValue(B)  +  ylech,  ColorX );
 PlotText("C",LastValue(C1bar)  +  xlech,  LastValue(C1)  -  ylech,  ColorX );
 PlotText("D",LastValue(Dbar)  +  xlech,  LastValue(D)  +  ylech,  ColorX );

 //--------- Viet thuyet minh mo hinh: by binhnd--------------
 if (strPattern!="") 
 {
 myStr  =  "Pattern: BEARISH AB=CD";
 toadoaX  =  LastValue(Abar);
 toadoY  =  LastValue(D);

 PlotText(myStr,toadoaX,toadoY+1,ColorX );
 }
 
}  // end of VE DUONG CHO MO HINH BEARISH ABCD


//==========================================================
// VE DUONG CHO MO HINH BEARISH BAT, GARTLEY, BUTTERFLY, CRAB
//==========================================================

BearHar4 = BearGartley4 OR BearButterfly4 OR BearBat4 OR BearCrab4 ;
BearHar = BearGartley OR BearButterfly OR BearBat OR BearCrab ;

Point4 = IIf(BearHar,ValueWhen(BearHar4,bi),Null);
BearHar = IIf(BearHar, IIf(Point4 == ValueWhen(BearHar,point4,0) AND ValueWhen(BearHar,bi,0) > bi ,False,BearHar),BearHar);

X = ValueWhen(BearHar4,P1H2);
Xbar = ValueWhen(BearHar4,P1Bar2);
A = ValueWhen(BearHar4,V1L2);
Abar = ValueWhen( BearHar4,V1bar2);
B = ValueWhen(BearHar4,P1H1);
Bbar = ValueWhen(BearHar4,P1bar1);
C1 = ValueWhen(BearHar4,V1L1);
C1bar = ValueWhen(BearHar4,V1bar1);
D = ValueWhen(BearHar,H);
Dbar = ValueWhen(BearHar,bi);

ABdXA = (B-A)/(X-A);
BCdAB = (B-C1)/(B-A);
ADdXA = (D-A)/(X-A);
BCdCD = (D-C1)/(B-C1);

PlotPattern = Dbar > C1bar;

//--------- Ve duong ------------------
if(LastValue(Plotpattern) AND be)
{
 ColorX = colorRed;
 // Ve duong XA, AB, BC
 Plot( LineArray(LastValue(Xbar),LastValue(X),LastValue(Abar),LastValue(A)),"",ColorX ,styleThick);
 Plot(LineArray(LastValue(Abar),LastValue(A),LastValue(Bbar),LastValue(B)),"",ColorX ,styleThick);
 Plot(LineArray(LastValue(Bbar),LastValue(B),LastValue(C1bar),LastValue(C1)),"",ColorX ,styleThick);
 Plot(LineArray(LastValue(C1bar),LastValue(C1),LastValue(Dbar),LastValue(D)),"",ColorX ,styleThick);
 Plot(LineArray(LastValue(Xbar),LastValue(X),LastValue(Bbar),LastValue(B)),"",ColorX ,styleDashed);
 Plot(LineArray(LastValue(Xbar),LastValue(X),LastValue(Abar),LastValue(A)),"",ColorX ,styleThick);
 Plot(LineArray(LastValue(Abar),LastValue(A),LastValue(C1bar),LastValue(C1)),"",ColorX ,styleDashed);
 Plot(LineArray(LastValue(Bbar),LastValue(B),LastValue(Dbar),LastValue(D)),"",ColorX ,styleDashed);
 Plot(LineArray(LastValue(Xbar),LastValue(X),LastValue(Dbar),LastValue(D)),"",ColorX ,styleDashed);

 // Viet cac gia tri Fibo tren duong XA, AB, BC
 PlotText(NumToStr(LastValue(ABdXA),1.2),(LastValue(Bbar)+LastValue(Xbar))/2,(LastValue(B)+LastValue(X))/2,ColorX );
 PlotText(NumToStr(LastValue(BCdAB),1.2),(LastValue(C1bar)+LastValue(Abar))/2,(LastValue(C1)+LastValue(A))/2,ColorX );
 PlotText(NumToStr(LastValue(BCdCD),1.2) ,(LastValue(Dbar)+LastValue(Bbar))/2,(LastValue(D)+LastValue(B))/2,ColorX );
 PlotText(NumToStr(LastValue(ADdXA),1.2) ,(LastValue(Dbar)+LastValue(Xbar))/2,(LastValue(D)+LastValue(X))/2,ColorX );

 //---------- Viet cac diem X, A, B, C, D: by binhnd---------------------
 xlech  =  -1;
 ylech  =  1;
 PlotText("X",LastValue(Xbar)  +  xlech,  LastValue(X)  +  ylech,  ColorX );
 PlotText("A",LastValue(Abar)  +  xlech,  LastValue(A)  -  ylech,  ColorX );
 PlotText("B",LastValue(Bbar)  +  xlech,  LastValue(B)  +  ylech,  ColorX );
 PlotText("C",LastValue(C1bar)  +  xlech,  LastValue(C1)  -  ylech,  ColorX );
 PlotText("D",LastValue(Dbar)  +  xlech,  LastValue(D)  +  ylech,  ColorX );

 //--------- Viet thuyet minh mo hinh: by binhnd--------------
 if (strPattern!="") 
 {
 strPattern  =  "Pattern: " + strPattern;
 toadoaX  =  (LastValue(Dbar)+LastValue(Xbar))/2;
 toadoY  =  (LastValue(D)+LastValue(X))/2;

 PlotText(strPattern,toadoaX,toadoY+1,ColorX );
 }
 
}  // end of VE DUONG CHO MO HINH BEARISH BAT, GARTLEY, BUTTERFLY, CRAB




//=================================
// Show diem ho^~ tro. va` khang' cu. ko?
//=================================

plotFractals = ParamToggle("Plot Fractals","Off|On",1);  
if(PlotFractals)
{
 PlotShapes(shapeSmallCircle*P1,colorYellow,0,H,10);
 PlotShapes(shapeSmallCircle*V1,colorBlue,0,L,-10);
}



//==============================================
// DAT DIEU KIEN cho TIM KIEM BULL
//==============================================
dkBull = False;
ListBull  =  ParamList("Type of Bullish", "None|AB=CD|Gartley|Butterfly|Bat|Crab|All Patterns", 6);
 if  (  ListBull == "None"  )  dkBull =  True;
 if (  ListBull =="AB=CD"  )  dkBull  =  BullABCD ;
 if (  ListBull =="Gartley"  )  dkBull  =  BullGartley ;
 if (  ListBull =="Butterfly"  )  dkBull  =  BullButterfly ;
 if (  ListBull =="Bat"  )  dkBull  =  BullBat ;
 if (  ListBull =="Crab"  )  dkBull  =  BullCrab ;
 if (  ListBull =="All Patterns")  dkBull  =  (BullABCD) OR (BullGartley) OR (BullButterfly ) OR (BullBat ) OR (BullCrab);

//==============================================
// DAT DIEU KIEN cho TIM KIEM BEAR
//==============================================
dkBear = False;
ListBear  =  ParamList("Type of Bearish", "None|AB=CD|Gartley|Butterfly|Bat|Crab|All Patterns", 0);
 if  (  ListBear == "None"  )  dkBear =  True;
 if (  ListBear =="AB=CD"  )  dkBear  =  BearABCD ;
 if (  ListBear =="Gartley"  )  dkBear  =  BearGartley ;
 if (  ListBear =="Butterfly"  )  dkBear  =  BearButterfly ;
 if (  ListBear =="Bat"  )  dkBear  =  BearBat ;
 if (  ListBear =="Crab"  )  dkBear =  BearCrab ;
 if (  ListBear =="All Patterns")  dkBear =  (BearABCD ) OR (BearGartley ) OR (BearButterfly ) OR (BearBat ) OR (BearCrab );
//===============================

AddColumn(V,"Volume",1.0);
Filter = (dkBull) AND (dkBear);

_SECTION_END( );

_SECTION_BEGIN("MURREYMATH");

function splround(x)
{
	y=int(x)+round(x%int(x)*100)/100;
	return y;
}


up=Study("UP",GetChartID());
dm=Study("DN",GetChartID());

Color=IIf(C>O,colorGreen,colorRed);
//Graph0=Close; Graph0Color=1; Graph0Style=64;
Plot(C,"close",color,styleBar);


Period=Param("MM_Period", 32, 4, 256, 1) ;
TYpe=ParamList("Rolling/Intraday","Rolling|Intraday") ;
PER = Period;
dn=DateNum();
tn=TimeNum();
Lox=Hix=0;
Lox =  LLV(Min(H,L),PER )  ;
Hix =  HHV(Max(H,L),PER )  ;
avp=(O+C)/2;
Line0=Line1=Line2=Line3=Line4=Line5=Line6=Line7=Line8=Lineplus2=Lineminus2=0;
Lo=L[0];Hi=H[0];
for (i=0;i<BarCount;i++)
{
//if (i>0 AND i<BarCount)PlotText(WriteVal(dm[i],1.0),i,L[i]-15,colorWhite);

if (Type=="Intraday")
{
	if(I>1)
	{
		if(dn[i]!=dn[i-1])
		{
			Lo=L[i];
			Hi=H[i];
		}
	}
	if (L[i]<Lo)Lo=L[i];
	if (H[i]>Hi)Hi=H[i];
}
else if (type=="Rolling")
{
	Hi=Hix[i];
	Lo=Lox[i];
}

if (up[i]>hi)Hi=up[i];
if (dm[i]<lo)Lo=dm[i];
//PlotText(WriteVal(Lo,1.0),colorWhite,i,H[i]+15);

Fractal = IIf(Hi<=250,100, IIf(Hi<=2500,1000, IIf(Hi<=25000,10000, IIf(Hi<=250000,100000, 0 )))) ;
int_Log = int( log(Fractal/(Hi-Lo))/log(2) ) ;
Oct = Fractal * ( exp(ln(1/2)* int_Log ) ) ;


Min_1 = int( Lo / Oct ) * Oct ;

Max_1 = IIf( (Min_1 + Oct) > Hi, Min_1 + Oct, Min_1 + 2*Oct ) ;

Min_2 = IIf( (Min_1 + 1/8*(Max_1-Min_1)) <= Lo AND Hi <= (Max_1 - 1/8*(Max_1-Min_1)) ,
(Min_1 + 1/4*(Max_1-Min_1)) , Min_1 ) ;

Max_2 = IIf( (Min_1 + 1/8*(Max_1-Min_1)) <= Lo AND Hi <= (Max_1 - 1/8*(Max_1-Min_1)) ,
(Max_1 - 1/4*(Max_1-Min_1)) , Max_1 ) ;

/******************************/

Diff = Max_2 - Min_2 ;

H1 = IIf( (Min_2 + 3/16*Diff) <= Lo AND Hi <= (9/16*Diff + Min_2) ,
Min_2 + 1/2*Diff, 0) ;

H2 = IIf( (Min_2 - 1/8*Diff) <= Lo AND Hi <= (5/8*Diff + Min_2) AND H1==0,
Min_2 + 1/2*Diff, 0) ;

H3 = IIf( (Min_2 + 7/16*Diff) <= Lo AND Hi <= (Min_2 + 13/16*Diff), Min_2 + 3/4*Diff, 0 ) ;

H4 = IIf( (Min_2 + 3/8*Diff) <= Lo AND Hi <= (Min_2 + 9/8*Diff) AND H3==0,
Max_2, 0 ) ;

H5 = IIf( (Min_2 + 1/8*Diff)<=Lo AND Hi <= (Min_2 + 7/8*Diff) AND H1==0 AND H2==0 AND H3==0 AND H4==0,
Min_2 + 3/4*Diff , 0 ) ;

H6 = IIf( ( H1 + H2 + H3 + H4 + H5 ) == 0, Max_2, 0 ) ;

/**************************/

L1 = IIf(H1>0, Min_2 + 1/4*Diff, 0) ;

L2 = IIf(H2>0, Min_2, 0) ;

L3 = IIf(H3>0, Min_2 + 1/2*Diff, 0) ;

L4 = IIf(H4>0, Min_2 + 1/2*Diff, 0) ;

L5 = IIf(H5>0, Min_2 + 1/4*Diff, 0) ;

L6 = IIf(H6>0, Min_2, 0 ) ;


M_8 = ( H1 + H2 + H3 + H4 + H5 + H6 ) ;

M_0 = ( L1 + L2 + L3 + L4 + L5 + L6 ) ;

/**************************************/
Line0[i] =  M_0 ;

Line1[i] =  M_0 + (1*(0.125*(M_8-M_0)));

Line2[i] =  M_0 + (2*(0.125*(M_8-M_0)));

Line3[i] =  M_0 + (3*(0.125*(M_8-M_0)));

Line4[i] =  M_0 + (4*(0.125*(M_8-M_0)));

Line5[i] =  M_0 + (5*(0.125*(M_8-M_0)));

Line6[i] =  M_0 + (6*(0.125*(M_8-M_0)));

Line7[i] =  M_0 + (7*(0.125*(M_8-M_0)));



Line8[i] =  M_8  ;

Lineplus2[i] = M_8 + (2*(0.125*(M_8-M_0)));

Lineminus2[i] = M_0 - (2*(0.125*(M_8-M_0)));


}
//	Plot MM Levels in the charts
_N(dsr =ParamList("Draw MM Levels ", 
 "None|Both|Support|Resistance"));

 if (dsr =="Support" OR dsr == "Both")
 {
 Plot(Line4,"Line4",6,ParamStyle("Style"),styleLine);//4/8
 Plot(Lineminus2,"Lineminus2",4,ParamStyle("Style"),styleLine);//-2/8
 Plot(Line0,"Line0",6,ParamStyle("Style"),styleLine);//0/8
 Plot(Line1,"Line1",7,ParamStyle("Style"),styleLine);//1/8
 Plot(Line2,"Line2",4,ParamStyle("Style"),styleLine);//2/8
 Plot(Line3,"Line3",5,ParamStyle("Style"),styleLine|styleDashed);//3/8
 
 }

 if( dsr == "Resistance" OR dsr == "Both")
 {
 Plot(Line4,"Line4",6,ParamStyle("Style"),styleLine);//4/8
 Plot(Line8,"Line8",6,ParamStyle("Style"),styleLine);//8/8 
 Plot(Line7,"Line7",7,ParamStyle("Style"),styleLine);//7/8
 Plot(Line6,"Line6",4,ParamStyle("Style"),styleLine);//6/8
 Plot(Line5,"Line5",5,ParamStyle("Style"),styleLine|styleDashed);//5/8
 Plot(Lineplus2,"Lineplus2",4,ParamStyle("Style"),styleLine);//+2/8
 }
_SECTION_END();

_SECTION_BEGIN("Candle Pattern Recognition");
O1 = Ref(O,-1);O2 = Ref(O,-2);
H1 = Ref(H,-1);H2 = Ref(H,-2);
L1 = Ref(L,-1);L2 = Ref(L,-2);
C1 = Ref(C,-1);C2 = Ref(C,-2);
function CandlePattern(P)
   {
   global PatternName;
   if(P == 0) { PatternName = "NearDoji"; Pv = (abs(O-C)<= ((H-L)*0.1)); }
   else if(P == 1) { PatternName = "BlackCandle"; Pv = (O>C); }
   else if(P == 2) { PatternName = "LongBlackCandle"; Pv = (O>C AND
(O-C)/(.001+H-L)>.6); }
   else if(P == 3) { PatternName = "SmallBlackCandle"; Pv = ((O>C) AND
((H-L)>(3*(O-C)))); }
   else if(P == 4) { PatternName = "WhiteCandle"; Pv = (C>O); }
   else if(P == 5) { PatternName = "LongWhiteCandle"; Pv = ((C>O) AND
((C-O)/(.001+H-L)>.6)); }
   else if(P == 6) { PatternName = "SmallWhiteCandle"; Pv = ((C>O) AND
((H-L)>(3*(C-O)))); }
   else if(P == 7) { PatternName = "BlackMaubozu"; Pv = (O>C AND H==O AND
C==L); }
   else if(P == 8) { PatternName = "WhiteMaubozu"; Pv = (C>O AND H==C AND
O==L); }
   else if(P == 9) { PatternName = "BlackClosingMarubozu"; Pv = (O>C AND
C==L); }
   else if(P == 10) { PatternName = "WhiteClosingMarubozu"; Pv = (C>O AND
C==H); }
   else if(P == 11) { PatternName = "BlackOpeningMarubozu"; Pv = (O>C AND
O==H); }
   else if(P == 12) { PatternName = "WhiteOpeningMarubozu"; Pv = (C>O AND
O==L); }
   else if(P == 13) { PatternName = "HangingMan"; Pv = (((H-L)>4*(O-C)) AND
((C-L)/(.001+H-L)>= 0.75) AND ((O-L)/(.001+H-L)>= 0.75)); }
   else if(P == 14) { PatternName = "Hammer"; Pv = (((H-L)>3*(O-C)) AND
((C-L)/(.001+H-L)>0.6) AND ((O-L)/(.001+H-L)>0.6)); }
   else if(P == 15) { PatternName = "InvertedHammer"; Pv = (((H-L)>3*(O-C))
AND ((H-C)/(.001+H-L)>0.6) AND ((H-O)/(.001+H-L)>0.6)); }
   else if(P == 16) { PatternName = "ShootingStar"; Pv = (((H-L)>4*(O-C))
AND ((H-C)/(.001+H-L)>= 0.75) AND ((H-O)/(.001+H-L)>= 0.75)); }
   else if(P == 17) { PatternName = "BlackSpinningTop"; Pv = ((O>C) AND
((H-L)>(3*(O-C))) AND (((H-O)/(.001+H-L))<.4) AND
(((C-L)/(.001+H-L))<.4)); }
   else if(P == 18) { PatternName = "WhiteSpinningTop"; Pv = ((C>O) AND
((H-L)>(3*(C-O))) AND (((H-C)/(.001+H-L))<.4) AND
(((O-L)/(.001+H-L))<.4)); }
   else if(P == 19) { PatternName = "BearishAbandonedBaby"; Pv = ((C1 == O1)
AND (C2>O2) AND (O>C) AND (L1>H2) AND (L1>H)); }
   else if(P == 20) { PatternName = "BearishEveningDojiStar"; Pv = ((C2>O2)
AND ((C2-O2)/(.001+H2-L2)>.6) AND (C2<O1) AND (C1>O1) AND
((H1-L1)>(3*(C1-O1))) AND (O>C) AND (O<O1)); }
   else if(P == 21) { PatternName = "DarkCloudCover"; Pv = (C1>O1 AND
((C1+O1)/2)>C AND O>C AND O>C1 AND C>O1 AND (O-C)/(.001+(H-L)>0.6)); }
   else if(P == 22) { PatternName = "BearishEngulfing"; Pv = ((C1>O1) AND
(O>C) AND (O>= C1) AND (O1>= C) AND ((O-C)>(C1-O1))); }
   else if(P == 23) { PatternName = "ThreeOutsideDownPattern"; Pv = ((C2>O2)
AND (O1>C1) AND (O1>= C2) AND (O2>= C1) AND ((O1-C1)>(C2-O2)) AND (O>C) AND
(C<C1)); }
   else if(P == 24) { PatternName = "BullishAbandonedBaby"; Pv = ((C1 == O1)
AND (O2>C2) AND (C>O) AND (L2>H1) AND (L>H1)); }
   else if(P == 25) { PatternName = "BullishMorningDojiStar"; Pv = ((O2>C2)
AND ((O2-C2)/(.001+H2-L2)>.6) AND (C2>O1) AND (O1>C1) AND
((H1-L1)>(3*(C1-O1))) AND (C>O) AND (O>O1)); }
   else if(P == 26) { PatternName = "BullishEngulfing"; Pv = ((O1>C1) AND
(C>O) AND (C>= O1) AND (C1>= O) AND ((C-O)>(O1-C1))); }
   else if(P == 27) { PatternName = "ThreeOutsideUpPattern"; Pv = ((O2>C2)
AND (C1>O1) AND (C1>= O2) AND (C2>= O1) AND ((C1-O1)>(O2-C2)) AND (C>O) AND
(C>C1)); }
   else if(P == 28) { PatternName = "BullishHarami"; Pv = ((O1>C1) AND (C>O)
AND (C<= O1) AND (C1<= O) AND ((C-O)<(O1-C1))); }
   else if(P == 29) { PatternName = "ThreeInsideUpPattern"; Pv = ((O2>C2)
AND (C1>O1) AND (C1<= O2) AND (C2<= O1) AND ((C1-O1)<(O2-C2)) AND (C>O) AND
(C>C1) AND (O>O1)); }
   else if(P == 30) { PatternName = "PiercingLine"; Pv = ((C1<O1) AND
(((O1+C1)/2)<C) AND (O<C) AND (O<C1) AND (C<O1) AND
((C-O)/(.001+(H-L))>0.6)); }
   else if(P == 31) { PatternName = "BearishHarami"; Pv = ((C1>O1) AND (O>C)
AND (O<= C1) AND (O1<= C) AND ((O-C)<(C1-O1))); }
   else if(P == 32) { PatternName = "ThreeInsideDownPattern"; Pv = ((C2>O2)
AND (O1>C1) AND (O1<= C2) AND (O2<= C1) AND ((O1-C1)<(C2-O2)) AND (O>C) AND
(C<C1) AND (O<O1)); }
   else if(P == 33) { PatternName = "ThreeWhiteSoldiers"; Pv = (C>O*1.01)
AND (C1>O1*1.01) AND (C2>O2*1.01) AND (C>C1) AND (C1>C2) AND (O<C1) AND
(O>O1) AND (O1<C2) AND (O1>O2) AND (((H-C)/(H-L))<.2) AND
(((H1-C1)/(H1-L1))<.2) AND (((H2-C2)/(H2-L2))<.2); }
   else if(P == 34) { PatternName = "DarkCloudCover"; Pv = (C1>O1*1.01) AND
(O>C) AND (O>H1) AND (C>O1) AND (((C1+O1)/2)>C) AND (C>O1) AND
(MA(C,13)-Ref(MA(C,13),-4)>0); }
   else if(P == 35) { PatternName = "ThreeBlackCrows"; Pv = (O>C*1.01) AND
(O1>C1*1.01) AND (O2>C2*1.01) AND (C<C1) AND (C1<C2) AND (O>C1) AND (O<O1)
AND (O1>C2) AND (O1<O2) AND (((C-L)/(H-L))<.2) AND (((C1-L1)/(H1-L1))<.2)
AND (((C2-L2)/(H2-L2))<.2); }
   else if(P == 36) { PatternName = "doji"; Pv = (O == C); }
   else if(P == 37) { PatternName = "GapUp"; Pv = GapUp(); }
   else if(P == 38) { PatternName = "GapDown"; Pv = GapDown(); }
   else if(P == 39) { PatternName = "BigGapUp"; Pv = L>1.01*H1; }
   else if(P == 40) { PatternName = "BigGapDown"; Pv = H<0.99*L1; }
   else if(P == 41) { PatternName = "HugeGapUp"; Pv = L>1.02*H1; }
   else if(P == 42) { PatternName = "HugeGapDown"; Pv = H<0.98*L1; }
   else if(P == 43) { PatternName = "DoubleGapUp"; Pv = GapUp() AND
Ref(GapUp(),-1); }
   else if(P == 44) { PatternName = "DoubleGapDown"; Pv = GapDown() AND
Ref(GapDown(),-1); }
   return Pv;
   }

PatternNameList = "";
for(Cp=0; Cp<=44; Cp++)
	{
	VarSet("Pattern"+NumToStr(Cp,1.0),CandlePattern(cP));
	PatternNameList = PatternNameList +PatternName+","; 
	}

BI = BarIndex();
SelectedBar = SelectedValue(BI) -BI[0];
//Selectedbar = Status("lastvisiblebar")-1;
PStr="";
for(Cp=0; Cp<=44; Cp++)
	{
	Temp = VarGet("Pattern"+NumToStr(Cp,1.0));
	if(temp[SelectedBar]) Pstr=Pstr+"#"+NumToStr(Cp,1.0)+" -
"+StrExtract(PatternNameList,Cp)+"\n";
	}
Title = Date()+" Murray Maths "+ Interval(format=2)+"  "+Name()+" O "+WriteVal(O,1.2)+" H "+WriteVal(H,1.2)+"  L "+WriteVal(L,1.2)+" C "+
			WriteVal(C,1.2)+" "+EncodeColor(colorYellow)+"\n"+EncodeColor(colorGreen)+"Upper Breakout "+EncodeColor(colorRed)+WriteVal(Lineplus2,1.2)+EncodeColor(colorGreen)
			+" Resistance 8/8 "+EncodeColor(colorBlue)+WriteVal(Line8,1.2)+EncodeColor(colorGreen)+" Reversal 7/8 "+EncodeColor(colorYellow)
			+WriteVal(Line7,1.2)
+"\n"+EncodeColor(colorYellow)+"Middle S/R 4/8 "+EncodeColor(colorBlue)+WriteVal(Line4,1.2)
+"\n"+EncodeColor(colorRed)+"Lower Breakout "+EncodeColor(colorRed)+WriteVal(Lineminus2,1.2)+EncodeColor(colorRed)+" Support 0/8 "
			+EncodeColor(colorBlue)+WriteVal(Line0,1.2)+EncodeColor(colorRed)+" Reversal 1/8 "+EncodeColor(colorYellow)+WriteVal(Line1,1.2)+EncodeColor(colorYellow)+

("\nCandle Demostration \n"+ Pstr);
Back