Sei sulla pagina 1di 28

/*

HARMONIC PATTERN DETECTION

Automatic Detection of Harmonic Patterns - Gartley, Bat, Butterfly and Crab.


Zig Zag is not used in this AFL. It is based on fractals
Contact - joy.edakad@gmail.com
*/
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Cl
ose %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorWhite ), styleNoTitle | ParamStyle("S
tyle") | GetPriceStyle() );
_SECTION_END();
_SECTION_BEGIN("Gartley");
GBmin
GBmax
GCmin
GCmax
GDmin
GDmax

=
=
=
=
=
=

Param("Swing
Param("Swing
Param("Swing
Param("Swing
Param("Swing
Param("Swing

B
B
C
C
D
D

Min.",0.55,0.3,1,0.01);
Max.",0.72,0.4,1,0.01);
Min.",0.38,0.3,1.27,0.01);
Max.",1.0,0.4,1.27,0.01);
Min.(XA)",0.55,0.3,1,0.01);
Max.(XA)",1.0,0.4,1.0,0.01);

_SECTION_END();
_SECTION_BEGIN("Bat");
BatBmin
BatBmax
BatCmin
BatCmax
BatDmin
BatDmax

=
=
=
=
=
=

Param("Swing
Param("Swing
Param("Swing
Param("Swing
Param("Swing
Param("Swing

B
B
C
C
D
D

Min.",0.38,0.3,1,0.01);
Max.",0.55,0.4,1,0.01);
Min.",0.38,0.3,1.62,0.01);
Max.",1.27,0.4,1.62,0.01);
Min.(XA)",0.5,0.3,1,0.01);
Max.(XA)",1.0,0.4,1.0,0.01);

_SECTION_END();
_SECTION_BEGIN("Butterfly");
BtBmin
BtBmax
BtCmin
BtCmax
BtDmin
BtDmax

=
=
=
=
=
=

Param("Swing B Min.",0.55,0.3,1,0.01);
Param("Swing B Max.",0.9,0.4,1,0.01);
Param("Swing C Min.",0.38,0.3,1.62,0.01);
Param("Swing C Max.",1.27,0.4,1.62,0.01);
Param("Swing D Min.(XA)",1,1,1.8,0.01);
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
CBmax
CCmin
CCmax

=
=
=
=

Param("Swing
Param("Swing
Param("Swing
Param("Swing

B
B
C
C

Min.",0.38,0.3,1,0.01);
Max.",0.65,0.4,1,0.01);
Min.",0.38,0.3,1.62,0.01);
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
0.01);
abcd_Cmax
0.01);
abcd_Dmin
abcd_Dmax
0.01);

= Param("Swing C Min.",0.3,

0.3

1,

= Param("Swing C Max.",0.8,

0.8

1,

= Param("Swing D Min.",1.2,
= Param("Swing D Max.",3.7,

1,
1,

2.7,
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' = da
y'
{
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,b


i,0),IIf(ValueWhen(V1,L,0) <= L, False,V1),V1),V1);
P1H1 =
P1Bar1
P1H2 =
P1Bar2
V1L1 =
V1Bar1
V1L2 =
V1Bar2

ValueWhen(P1,H);
= ValueWhen(P1,bi);
ValueWhen(P1,H,2);
= ValueWhen(P1,bi,2);
ValueWhen(V1,L);
= ValueWhen(V1,bi);
ValueWhen(V1,L,2);
= 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; // P
eaks and troughs are in order
myAX
myAB
myBC

=
=
=

P1H2-V1L2;
P1H2-V1L1;
P1H1-V1L1;

myAB_AX
myBC_AB

=
=

BullGartley4
AND (

= PTvalid
myAB_AX < GBmax )

myBC_AB > GCMin

myAB/ myAX;
myBC/ myAB;

BullBat4
n )

)
AND (

AND

AND (

AND
myBC_AB < GCMax );

= PTvalid
myAB_AX < BatBmax

AND
)

myAB_AX > GBmin )

myBC_AB > BatCMin )

AND (

myBC_AB < BatCMax

BullButterfly4 = PTvalid
AND ( myAB_AX < BtBMax

AND
)

myBC_AB > BtCmin )

AND (

myBC_AB < BtCmin

BullCrab4
)

AND (

myAB_AX > BatBmi


AND
);

AND
);
(
)

BullABCD4
AND ( myBC_AB < abcd_Cmax

= PTvalid AND
);

strPattern = "";

myAB_AX > CBmin


AND

AND (

myAB_AX > BtBmin )

= PTvalid
AND
myAB_AX < CBmax

myBC_AB > CCmin )

myBC_AB < CCmax );


(

myBC_AB > abcd_Cmin)

//==================================================
//
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 c
ua AD
dLow
=
LowestSince(BullABCD4,L);
myC
myB
myA
myX
myCB

=
=
=
=
=

ValueWhen(BullABCD4,P1H1);
ValueWhen(BullABCD4,V1L1);
ValueWhen(BullABCD4,P1H2);
ValueWhen(BullABCD4,V1L2);
myC - myB;

my_d_min

=
myCB
// Tinh' gia' tri cua
re^n xuong' thi` max -> min
my_d_max
=
myCB
my_Cd_min
=
myC // Khoang dich chuyen cua duong Ad
my_Cd_max
=
myC BullABCD
n
)
<=

*
abcd_DMax ;
my_d_min;
con.
my_d_max;

IIf(
( dLow > my_Cd_max )

AND

AND

myC

*
abcd_DMin ;
duong Ad con. Khi gia' giam? tu` t

( dLow <

( dLow ==

my_Cd_mi

AND
( dHigh
L),
True, False

);
BullABCD
<
myB);

BullABCD

AND (dLow

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

=
=
=
=
=

my_d_min

ValueWhen(BullGartley4,P1H1);
ValueWhen(BullGartley4,V1L1);
ValueWhen(BullGartley4,P1H2);
ValueWhen(BullGartley4,V1L2);
myA - myX;

myAX
// Tinh' gia'
m? tu` tre^n xuong' thi` max -> min
my_d_max
=
myAX
my_Ad_min
=
myA // Khoang dich chuyen
my_Ad_max
=
myA BullGartley
)
AND

IIf(
( dLow > my_Ad_max )

*
GDmin;
tri cua duong Ad con. Khi gia' gia
*
GDMax;
my_d_min;
cua duong Ad con.
my_d_max;
( dLow <

my_Ad_min
AND

( dHigh

<=

myC

BullGartley
myB);
strPattern
);

AND

( dLow ==

L),
True, False

);
AND (dLow
<
// diem D thap' hon B
WriteIf(BullGartley,"BULLISH GARTLEY",strPattern

BullGartley

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

=
=
=
=
=

my_d_min

ValueWhen(BullBat4,P1H1);
ValueWhen(BullBat4,V1L1);
ValueWhen(BullBat4,P1H2);
ValueWhen(BullBat4,V1L2);
myA - myX;

myAX
// Tinh' gia'
m? tu` tre^n xuong' thi` max -> min
my_d_max
=
myAX
my_Ad_min
=
myA // Khoang dich chuyen
my_Ad_max
=
myA BullBat
n
)
<=

BullBat
<
myB);
strPattern

*
BatDmax ;
my_d_min;
cua duong Ad con.
my_d_max;

IIf(
( dLow > my_Ad_max )

AND

);
BullBat
AND (dLow
// diem d thap hon diem B
WriteIf(BullBat,"BULLISH BAT",strPattern);

AND

myC

*
BatDmin;
tri cua duong Ad con. Khi gia' gia

( dLow <

( dLow ==

my_Ad_mi

AND
( dHigh
L),
True, False

//==================================================
//
BULLISH CRAB - CUA
//==================================================
dHigh
=
HighestSince(BullCrab4,H);
// Tinh' gia' tri min, max cua duong Ad. Duong Ad la duong con c
ua AD
dLow
=
LowestSince(BullCrab4,L);
myC
myB
myA
myX
myAX
my_d_min

=
=
=
=
=

ValueWhen(BullCrab4,P1H1);
ValueWhen(BullCrab4,V1L1);
ValueWhen(BullCrab4,P1H2);
ValueWhen(BullCrab4,V1L2);
myA - myX;

=
myAX
*
CDmin ;
// Tinh' gia' tri cua duong Ad con. Khi gia' giam? tu` tre^n xuo
ng' 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
n
)
<=

IIf(
( dLow > my_Ad_max )

AND

);
AND (dLow
// diem D thap' hon X
WriteIf(BullCrab ,"BULLISH CRAB",strPattern);

AND

myC

BullCrab
<
myX);
strPattern

( dLow <

( dLow ==

my_Ad_mi

AND
( dHigh
L),
True, False

BullCrab

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

=
=
=
=
=

ValueWhen(BullButterfly4,P1H1);
ValueWhen(BullButterfly4,V1L1);
ValueWhen(BullButterfly4,P1H2);
ValueWhen(BullButterfly4,V1L2);
myA - myX;

my_d_min

myAX

*
BtDmin ;
// Tinh' gia' tri cua duong Ad c
on. 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
)
AND

( dHigh <=

myC

BullButterfly =
myX);
strPattern
Y",strPattern);

IIf(
( dLow > my_Ad_max )

my_Ad_min

AND
( dLow ==
L),
True, False
);
BullButterfly AND (dLow
<
// diem D thap' hon X
WriteIf(BullButterfly ,"BULLISH BUTTERFL
)

( dLow <

AND

//==========================================================
// 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(B
ullHar,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),Last
Value(B)),"",ColorX ,styleThick);
Plot(LineArray(LastValue(Bbar),LastValue(B),LastValue(C1bar),Las
tValue(C1)),"",ColorX ,styleThick);
Plot(LineArray(LastValue(C1bar),LastValue(C1),LastValue(Dbar),La
stValue(D)),"",ColorX ,styleThick);
Plot(LineArray(LastValue(Abar),LastValue(A),LastValue(C1bar),Las
tValue(C1)),"",ColorX ,styleDashed);
Plot(LineArray(LastValue(Bbar),LastValue(B),LastValue(Dbar),Last
Value(D)),"",ColorX ,styleDashed);
// Ve cac gia tri Fibo
PlotText(NumToStr(LastValue(BCdAB),1.2),(LastValue(C1bar)+LastVa
lue(Abar))/2,(LastValue(C1)+LastValue(A))/2,ColorX );
PlotText(NumToStr(LastValue(BCdCD),1.2),(LastValue(Bbar)+LastVal
ue(Dbar))/2,(LastValue(B)+LastValue(D))/2,ColorX );

+
+
-

//---------- Viet cac diem X, A, B, C,


xlech
=
0;
ylech
=
2;
PlotText("A",LastValue(Abar)
ylech, ColorX );
PlotText("B",LastValue(Bbar)
ylech, ColorX );
PlotText("C",LastValue(C1bar)
ylech, ColorX );
PlotText("D",LastValue(Dbar)
ylech, ColorX );

D: by binhnd--------------------+

xlech, LastValue(A)

xlech, LastValue(B)

xlech, LastValue(C1)

xlech, LastValue(D)

//--------- Viet thuyet minh mo hinh: by binhnd-------------if (strPattern!="")


{
myStr
=
"Pattern: BULLISH AB=CD"
;
toadoX
toadoY

=
=

LastValue(Abar);
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(B
ullHar,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
BCdAB
ADdXA
BCdCD

=
=
=
=

(A-B)/(A-X);
(C1-B)/(A-B);
(A-D)/(A-X);
(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(A
bar),LastValue(A)),"",ColorX,styleThick);
Plot(LineArray(LastValue(Abar),LastValue(A),LastValue(Bb
ar),LastValue(B)),"",ColorX,styleThick);
Plot(LineArray(LastValue(Bbar),LastValue(B),LastValue(C1
bar),LastValue(C1)),"",ColorX,styleThick);
Plot(LineArray(LastValue(C1bar),LastValue(C1),LastValue(
Dbar),LastValue(D)),"",ColorX,styleThick);
Plot(LineArray(LastValue(Xbar),LastValue(X),LastValue(Bb
ar),LastValue(B)),"",ColorX,styleDashed);
Plot(LineArray(LastValue(Xbar),LastValue(X),LastValue(Ab
ar),LastValue(A)),"",ColorX,styleThick);
Plot(LineArray(LastValue(Abar),LastValue(A),LastValue(C1
bar),LastValue(C1)),"",ColorX,styleDashed);
Plot(LineArray(LastValue(Bbar),LastValue(B),LastValue(Db
ar),LastValue(D)),"",ColorX,styleDashed);
Plot(LineArray(LastValue(Xbar),LastValue(X),LastValue(Db
ar),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--------------------

e(X)

ylech,

e(A)

ylech,

e(B)

ylech,

e(C1)

ylech,

e(D)

ylech,

xlech
=
0;
ylech
=
2;
PlotText("X",LastValue(Xbar)
ColorX);
PlotText("A",LastValue(Abar)
ColorX);
PlotText("B",LastValue(Bbar)
ColorX);
PlotText("C",LastValue(C1bar)
ColorX);
PlotText("D",LastValue(Dbar)
ColorX);

xlech, LastValu

xlech, LastValu

xlech, LastValu

xlech, LastValu

xlech, LastValu

//--------- Viet thuyet minh mo hinh: by binhnd-------------if (strPattern!="")


{
strPattern
=
"Pattern: " + strPattern
;
toadoX

(LastValue(Dbar)

toadoY

(LastValue(D)+La

+LastValue(Xbar))/2;
stValue(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
o hinh` bear: Die^m X cao hon diem A. MyAX = X-> A
A
=
V1L2
B
=
P1H1
C
=
V1L1
=======================*/
myAX
=
myAB
=
myBC
=

Trong m

P1H2-V1L2;
P1H1-V1L2;
P1H1-V1L1;

myAB_AX
myBC_AB

=
=

myAB/ myAX;
myBC/ myAB;

BearGartley4
AND (

= PTvalid
myAB_AX < GBmax )

AND

myAB_AX > GBmin )

myBC_AB > GCMin


BearBat4
n )

)
AND (

AND
myBC_AB < GCMax );

AND (

= PTvalid
myAB_AX < BatBmax

AND
)

myBC_AB > BatCMin )

AND (

myBC_AB < BatCMax

BearButterfly4 = PTvalid
AND ( myAB_AX < BtBMax

AND
)

myBC_AB > BtCmin )

AND (

myBC_AB < BtCmin

BearCrab4
)

AND (

myAB_AX > BatBmi


AND
);

AND
);
(
)

BearABCD4
AND ( myBC_AB < abcd_Cmax

= PTvalid AND
);

myAB_AX > CBmin


AND

AND (

myAB_AX > BtBmin )

= PTvalid
AND
myAB_AX < CBmax

myBC_AB > CCmin )

myBC_AB < CCmax );


(

myBC_AB > abcd_Cmin)

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 c
ua AD
dLow
=
LowestSince(BearABCD4,L);
myA
myB
myC
myCB

=
=
=
=

ValueWhen(BearABCD4,V1L2);
ValueWhen(BearABCD4,P1H1);
ValueWhen(BearABCD4,V1L1);
myB - myC;

my_d_min

=
myCB
// Tinh' gia' tri cua
re^n xuong' thi` max -> min
my_d_max
=
myCB
my_Cd_min
=
myC +
// Khoang dich chuyen cua duong Ad
my_Cd_max
=
myC +
BearABCD
my_Cd_min
>=

=
AND

myC

*
abcd_DMin ;
duong Ad con. Khi gia' giam? tu` t
*
abcd_DMax ;
my_d_min;
con.
my_d_max;

IIf(
( dHigh
( dHigh < my_Cd_max )
)

>
AND
( dLow
( dHigh ==

AND

H),
True, False
);
BearABCD
>
myB);

BearABCD

AND (dHigh

//=============================================================
//
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
myA
myAX

=
=

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

=
=

ValueWhen(BearGartley4,P1H1);
ValueWhen(BearGartley4,V1L1);

myB
myC
my_d_min

=
myAX
*
GDmin;
// Tinh' gia' tri cua duong Ad con. Khi gia' giam? tu` t
re^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
)
AND
>=

IIf(
( dHigh < my_Ad_max )

myC

( dHigh >

my_Ad_min

AND

AND
( dLow
( dHigh ==

H),
BearGartley
myB);
strPattern
n);

True, False
);
BearGartley
AND (dHigh
>
// diem D cao hon B
WriteIf(BearGartley ,"BEARISH GARTLEY",strPatter

=
=

//=============================================================
//
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
myA
myAX

=
=

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

=
=

ValueWhen(BearBat4,P1H1);
ValueWhen(BearBat4,V1L1);

myB
myC
my_d_min

myAX
*
BatDmin ;
// Tinh' gia' tri cua duong Ad con. Khi gia' gia
m? 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
n
)
>=

=
AND
myC

IIf(
( dHigh < my_Ad_max )
)

AND

( dHigh >

my_Ad_mi

AND
( dLow
( dHigh ==

H),
BearBat
>
myB);
strPattern

=
=

True, False
);
BearBat
AND (dHigh
// diem D cao hon B
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
myA
myAX

=
=

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

=
=

ValueWhen(BearButterfly4,P1H1);
ValueWhen(BearButterfly4,V1L1);

myB
myC
my_d_min

myAX
*
BtDmin ;
// Tinh' gia' tri cua duong Ad con. Khi gia' gia
m? 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 =
)
AND
>=

IIf(
( dHigh < my_Ad_max )
myC

( dHigh >

my_Ad_min

AND

AND
( dLow
( dHigh ==

H),
BearButterfly =
myX);
strPattern
Y",strPattern);

True, False
);
BearButterfly AND (dHigh
>
// diem D cao hon X
WriteIf(BearButterfly ,"BEARISH BUTTERFL

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

=
=

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

=
=

ValueWhen(BearCrab4,P1H1);
ValueWhen(BearCrab4,V1L1);

my_d_min

=
myAX
*
CDmin ;
// Tinh' gia' tri cua duong Ad con. Khi gia' giam? tu` t
re^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
n
)
>=

=
AND

IIf(
( dHigh < my_Ad_max )

myC

( dHigh >

AND

my_Ad_mi

AND
( dLow
( dHigh ==

H),
BearCrab
>
myX);
strPattern

=
=

True, False
);
BearCrab
AND (dHigh
// diem D cao hon X
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(B
earHar,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),Last
Value(B)),"",ColorX ,styleThick);
Plot(LineArray(LastValue(Bbar),LastValue(B),LastValue(C1bar),Las
tValue(C1)),"",ColorX ,styleThick);
Plot(LineArray(LastValue(C1bar),LastValue(C1),LastValue(Dbar),La
stValue(D)),"",ColorX ,styleThick);
Plot(LineArray(LastValue(Abar),LastValue(A),LastValue(C1bar),Las

tValue(C1)),"",ColorX ,styleDashed);
Plot(LineArray(LastValue(Bbar),LastValue(B),LastValue(Dbar),Last
Value(D)),"",ColorX ,styleDashed);
// Viet cac gia tri Fibo tren duong AB, BC
PlotText(NumToStr(LastValue(BCdAB),1.2),(LastValue(C1bar)+LastVa
lue(Abar))/2,(LastValue(C1)+LastValue(A))/2,ColorX );
PlotText(NumToStr(LastValue(BCdCD),1.2) ,(LastValue(Dbar)+LastVa
lue(Bbar))/2,(LastValue(D)+LastValue(B))/2,ColorX );

+
+

//---------- Viet cac diem A, B, C, D:


xlech
=
-1;
ylech
=
1;
PlotText("A",LastValue(Abar)
ylech, ColorX );
PlotText("B",LastValue(Bbar)
ylech, ColorX );
PlotText("C",LastValue(C1bar)
ylech, ColorX );
PlotText("D",LastValue(Dbar)
ylech, ColorX );

by binhnd--------------------+

xlech, LastValue(A)

xlech, LastValue(B)

xlech, LastValue(C1)

xlech, LastValue(D)

//--------- Viet thuyet minh mo hinh: by binhnd-------------if (strPattern!="")


{
myStr
=
"Pattern: BEARIS
H 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(B
earHar,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),Las
tValue(A)),"",ColorX ,styleThick);
Plot(LineArray(LastValue(Abar),LastValue(A),LastValue(Bbar),Last
Value(B)),"",ColorX ,styleThick);
Plot(LineArray(LastValue(Bbar),LastValue(B),LastValue(C1bar),Las
tValue(C1)),"",ColorX ,styleThick);
Plot(LineArray(LastValue(C1bar),LastValue(C1),LastValue(Dbar),La
stValue(D)),"",ColorX ,styleThick);
Plot(LineArray(LastValue(Xbar),LastValue(X),LastValue(Bbar),Last
Value(B)),"",ColorX ,styleDashed);
Plot(LineArray(LastValue(Xbar),LastValue(X),LastValue(Abar),Last
Value(A)),"",ColorX ,styleThick);
Plot(LineArray(LastValue(Abar),LastValue(A),LastValue(C1bar),Las
tValue(C1)),"",ColorX ,styleDashed);
Plot(LineArray(LastValue(Bbar),LastValue(B),LastValue(Dbar),Last
Value(D)),"",ColorX ,styleDashed);
Plot(LineArray(LastValue(Xbar),LastValue(X),LastValue(Dbar),Last
Value(D)),"",ColorX ,styleDashed);
// Viet cac gia tri Fibo tren duong XA, AB, BC
PlotText(NumToStr(LastValue(ABdXA),1.2),(LastValue(Bbar)+LastVal
ue(Xbar))/2,(LastValue(B)+LastValue(X))/2,ColorX );
PlotText(NumToStr(LastValue(BCdAB),1.2),(LastValue(C1bar)+LastVa
lue(Abar))/2,(LastValue(C1)+LastValue(A))/2,ColorX );
PlotText(NumToStr(LastValue(BCdCD),1.2) ,(LastValue(Dbar)+LastVa
lue(Bbar))/2,(LastValue(D)+LastValue(B))/2,ColorX );
PlotText(NumToStr(LastValue(ADdXA),1.2) ,(LastValue(Dbar)+LastVa
lue(Xbar))/2,(LastValue(D)+LastValue(X))/2,ColorX );

+
+
+

//---------- Viet cac diem X, A, B, C,


xlech
=
-1;
ylech
=
1;
PlotText("X",LastValue(Xbar)
ylech, ColorX );
PlotText("A",LastValue(Abar)
ylech, ColorX );
PlotText("B",LastValue(Bbar)
ylech, ColorX );
PlotText("C",LastValue(C1bar)
ylech, ColorX );
PlotText("D",LastValue(Dbar)
ylech, ColorX );

D: by binhnd--------------------+

xlech, LastValue(X)

xlech, LastValue(A)

xlech, LastValue(B)

xlech, LastValue(C1)

xlech, LastValue(D)

//--------- Viet thuyet minh mo hinh: by binhnd-------------if (strPattern!="")


{
strPattern
=
"Pattern: " + strPattern
;
toadoaX
ue(Xbar))/2;

(LastValue(Dbar)+LastVal

toadoY

(LastValue(D)+La

stValue(X))/2;
PlotText(strPattern,toadoaX,toadoY+1,ColorX );
}
}
TERFLY, CRAB

// end of VE DUONG CHO MO HINH BEARISH BAT, GARTLEY, BUT

//=================================
// 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 =
BullButt
erfly ;
if (
ListBull =="Bat"
)
dkBull
=
BullBat ;
if (
ListBull =="Crab"
)
dkBull
=
BullCrab ;
if (
ListBull =="All Patterns")
dkBull =
(BullABC
D) 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 =
BearButt
erfly ;

if (
ListBear =="Bat"
BearBat ;
if (
ListBear =="Crab"
BearCrab ;
if (
ListBear =="All Patterns")
D ) OR (BearGartley ) OR (BearButterfly ) OR (BearBat )
//===============================

dkBear

dkBear =

dkBear =
(BearABC
OR (BearCrab );

AddColumn(V,"Volume",1.0);
Filter = (dkBull) AND (dkBear);
_SECTION_BEGIN("Kpl System");
/* my entry is very simple(daily data for trading)
kpl system for entry only & exit as follow:
1 st exit at x % from entry price only 1/3 quantity.(ie 1st profit target)
2 nd exit when exit Signal comes from kpl sys remaining 1/3 quantity.
3. scale-in to initial quantity if new kpl Buy Signal comes.
re-do above scaling-out & scaling-in till filal exit.
4. final exit all quantity when Close below 21 Day EMA.
kpl system code bellow :
*/
//AFL by Kamalesh Langote. Email:kpl@...
no=Param( "Swing", 8, 1, 55 );
tsl_col=ParamColor( "Color", colorLightGrey );
res=HHV(H,no);
sup=LLV(L,no);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
tsl=IIf(avn==1,sup,res);
Buy=Cover=Cross(C,tsl) ;
Sell=Short=Cross(tsl,C) ;
Plot(tsl, _DEFAULT_NAME(), tsl_col, styleStaircase);
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,Low,-15);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorYellow, 0,High,-15);
PlotShapes(IIf(Cover, shapeHollowCircle, shapeNone),colorWhite, 0,Close,0);
PlotShapes(IIf(Short, shapeHollowCircle, shapeNone),colorYellow, 0,Close,0);

SetPositionSize(300,spsShares);
ApplyStop(0,1,10,1);
//-----------end-------------Long=Flip(Buy,Sell);
Shrt=Flip(Sell,Buy);
BuyPrice=ValueWhen(Buy,C);
SellPrice=ValueWhen(Sell,C);

Edc=(
WriteIf (Buy AND Ref(shrt,-1), " BUY@ "+C+" ","")+
WriteIf (Sell AND Ref(Long,-1), " SEll@ "+C+" ","")+
WriteIf(Sell , "Last Trade Profit Rs."+(C-BuyPrice)+"","")+
WriteIf(Buy , "Last Trade Profit Rs."+(SellPrice-C)+"",""));
_SECTION_END();
//============== TITLE ==============
_SECTION_BEGIN("Title");
if( Status("action") == actionIndicator )
(
Title = EncodeColor(colorGold)+ "KRISHNA Trading System" + EncodeColor(colorRose
)+" (" + Name() + ") " + EncodeColor(colorGold)+ Interval(2) +
" " + Date() +" " +"
Open "+WriteVal(O,1.2)+"
"+"Hi "+WriteVal(H,1.2)+"
+"Lo "+WriteVal(L,1.2)+"
"+
"Close "+WriteVal(C,1.2)+" ("+WriteVal(C-Ref(C,-1),1,0)+" "+WriteVal((C-Ref(C,-1
))*100/Ref(C,-1),1.1)+ "%)
Vol= "+ WriteVal(V,1.0)

+"\n"+EncodeColor(colorGrey50)+"-----------------------------------------------------------------------------------------------------------"
+"\n"+EncodeColor(colorGold)+
WriteIf (Buy , "Signal: Go Long - Entry Price: "+WriteVal(C)+" - Traget: "+Write
Val((BuyPrice-tsl)+BuyPrice)
+" - StopLoss:"+WriteVal(tsl)+" "
,"")+
WriteIf (Sell , "Signal: Go Short - Entry Price: "+WriteVal(C)+" - Target: "+Wri
teVal((tsl-SellPrice)-SellPrice)+" - StopLoss:"+WriteVal(tsl)+" ","")+
EncodeColor(ColorRGB(111,208,255))+
WriteIf(Long AND NOT Buy, "Trade: Long - Entry Price: "+WriteVal((BuyPrice))+" Profit: "+WriteVal((C-BuyPrice))+" "+EncodeColor(colorLime)+"Let your profit ru
ns!","")+
WriteIf(shrt AND NOT Sell, "Trade: Short - Entry Price: "+WriteVal((SellPrice))+
" - Profit: "+WriteVal((SellPrice-C))+" - "+EncodeColor(colorLime)+"Let your pr
ofit runs!","")
+"\n"+EncodeColor(colorGrey50)+"-----------------------------------------------------------------------------------------------------------"
);
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("S
tyle") | GetPriceStyle() );
dist = 3*ATR(15);
dist1 = 3*ATR(15);
for( i = 0; i < BarCount; i++ )
{
if( Buy[i] )
{
PlotText( "\nBuy:" + C[ i ] + "\nT= " + ((C[i]-tsl[i])+C[i]) + "\nSL= " + tsl[
i], i, C[ i ]-dist[i], colorGreen, colorBlack );
}
if( Sell[i] )
{
PlotText( "Sell:" + C[ i ] + "\nT= " + (C[i]-(tsl[i]-C[i])) + "\nSL= " + tsl[i
], i, C[ i ]+dist1[i], colorRed, colorBlack );
}
}

"

/*Plot Ribbon */
Ribbon1=IIf( (C) >(tsl) ,colorWhite, IIf(( tsl )>( C ), colorOrange,colorYello
w));
_SECTION_END();
MAPeriod = Param("MA Period", 4, 1, 100);
MAOpen = EMA(Open, MAPeriod);
MAHigh = EMA(High, MAPeriod);
MALow = EMA(Low, MAPeriod);
MAClose = EMA(Close, MAPeriod);
HaClose = (MAOpen + MAHigh + MALow + MAClose) / 4;
HaOpen = AMA(Ref(HaClose, -1), 0.5);
// for graph collapse
//for(i = 0; i <= MAPeriod; i++) HaClose[i] = Null;
/*
// same
// HaOpen = (Ref(HaOpen, -1) + Ref(HaClose, -1)) / 2;
HaOpen[ 0 ] = HaClose[ 0 ];
for(i = 1; i < BarCount; i++) {
HaOpen[i] = (HaOpen[i - 1] + HaClose[i - 1]) / 2;
}
*/
HaHigh = Max(MAHigh, Max(HaClose, HaOpen));
HaLow = Min(MALow, Min(HaClose, HaOpen));
//////////////////////////////////////////////////////////////////////////
_SECTION_BEGIN("Peak");
PK = HaHigh > Ref(HaHigh,-1) AND Ref(HaHigh,1) < HaHigh;//Peak
PKV0 = ValueWhen(PK,HaHigh,0);//PeakValue0
PKV1 = ValueWhen(PK,HaHigh,1);//PeakValue1
PKV2 = ValueWhen(PK,HaHigh,2);//PeakValue2
MPK = PKV2 < PKV1 AND PKV1 > PKV0 ;//MajorPeak
MPKV = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,1); //MajorPeakValue
MPKD = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),1); //MajorPeakDate
SD = IIf(DateNum() < LastValue(MPKD,lastmode = True ), Null, LastValue(MPKV,Last
mode = True));//SelectedDate
Plot(SD, "LastMinorResistance",colorRed,styleLine,styleThick);
//PLOT THE SECOND LAST MAJOR PEAK RESISTANCE LINE
MPKV2 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,2); //MajorPeakValue
MPKD2 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),2); //MajorPeakDate
SD2 = IIf(DateNum() < LastValue(MPKD2,lastmode = True ), Null, LastValue(MPKV2,L
astmode = True));//SelectedDate
Plot(SD2, "LastMajorResistance",colorRed,styleLine);
_SECTION_END();
_SECTION_BEGIN("Support");
SP = Ref(HaLow,1) > HaLow AND HaLow < Ref(HaLow,-1);//Peak
SPV0 = ValueWhen(SP,HaLow,0);//PeakValue0
SPV1 = ValueWhen(SP,HaLow,1);//PeakValue1
SPV2 = ValueWhen(SP,HaLow,2);//PeakValue2
MSP = SPV2 > SPV1 AND SPV1 < SPV0 ;//MajorPeak

MSPV = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,1);


MSPD = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),1);
SD = IIf(DateNum() < LastValue(MSPD,lastmode = True ), Null, LastValue(MSPV,Last
mode = True));
Plot(SD,"LastMinorSupport",colorGreen,styleLine,styleThick);
MSPV2 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,2);
MSPD2 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),2);
SD2 = IIf(DateNum() < LastValue(MSPD2,lastmode = True ), Null, LastValue(MSPV2,L
astmode = True));
Plot(SD2,"LastMajorSupport",colorGreen,styleLine);
_SECTION_END();
//ESSENTIAL TRADER TOOLS//
// Compiled by K.Vidyasagar, vkunisetty@yahoo.com //
//Previous Days HI LO //
DayH = TimeFrameGetPrice("H", inDaily, -1);
DayHI = LastValue (DayH,1);// y
esterdays high
DayL = TimeFrameGetPrice("L", inDaily, -1);
DayLI = LastValue (DayL,1);
// yesterdays low
DayC = TimeFrameGetPrice("C", inDaily, -1);
// yesterdays close
DayO = TimeFrameGetPrice("O", inDaily);
// current day open
WeekH= TimeFrameGetPrice("H", inWeekly, 1); WeekHI = LastValue (WeekH,1); // On
e Week before high
WeekL= TimeFrameGetPrice("L", inWeekly, 1); WeekLI = LastValue (WeekL,1); // O
ne Week before low
MonthH= TimeFrameGetPrice("H", inMonthly, 1); MonthHI = LastValue (MonthH,1);
// One Month before high
MonthL= TimeFrameGetPrice("L", inMonthly, 1); MonthLI = LastValue (MonthL,1);
// One Month before low
numbars = LastValue(Cum(Status("barvisible")));
hts = -33.5;
YHL = ParamToggle("Yesterday HI LO","Hide|Show",1);
if(YHL==1) {
Plot(DayL,"YL",colorTurquoise,styleDashed|styleNoRescale|styleNoTitle);
Plot(DayH,"YH",colorOrange,styleDashed|styleNoRescale|styleNoTitle);
PlotText(" YstrdayH " ,
LastValue(BarIndex())-(numbars/Hts), DayHI, colo
rOrange);
PlotText(" YstrdayL " ,
LastValue(BarIndex())-(numbars/Hts), DayLI, colo
rTurquoise);
}
TDBHL = ParamToggle("Week And Month HI LO","Hide|Show",1);
if(TDBHL==1) {
Plot(WeekL,"WeekL",colorTurquoise,styleDots|styleNoLine|styleNoRescale|styleNo
Title);
Plot(WeekH,"WeekH",colorOrange,styleDots|styleNoLine|styleNoRescale|styleNoTit
le);
Plot(MonthL,"MonthL",colorTurquoise,styleDots|styleNoLine|styleNoRescale|style
NoTitle);
Plot(MonthH,"MonthH",colorOrange,styleDots|styleNoLine|styleNoRescale|styleNoT
itle);
PlotText(" WeekH " , LastValue(BarIndex())-(numbars/Hts), WeekHI, colorOrange
);

PlotText(" WeekL " , LastValue(BarIndex())-(numbars/Hts), WeekLI, colorTurquo


ise);
PlotText(" MonthH " ,
LastValue(BarIndex())-(numbars/Hts), MonthHI, co
lorOrange);
PlotText(" MonthL " ,
LastValue(BarIndex())-(numbars/Hts), MonthLI, co
lorTurquoise);
}
//
PP
R1
S1
R2
S2
R3
S3

Pivot Levels //
= (DayL + DayH + DayC)/3;
= (PP * 2) - DayL;
= (PP * 2) - DayH;
= PP + R1 - S1;
= PP - R1 + S1;
= PP + R2 - S1;
= PP - R2 + S1;

PPI
R1I
S1I
R2I
S2I
R3I
S3I

=
=
=
=
=
=
=

LastValue
LastValue
LastValue
LastValue
LastValue
LastValue
LastValue

(PP,1);
(R1,1);
(S1,1);
(R2,1);
(S2,1);
(R3,1);
(S3,1);

//
//
//
//
//
//
//

Pivot
Resistance 1
Support 1
Resistance 2
Support 2
Resistance 3
Support 3

ppl = ParamToggle("Pivot Levels","Hide|Show",0);


if(ppl==1) {
Plot(PP, "PP",colorYellow,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(R1, "R1",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(S1, "S1",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(R2, "R2",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(S2, "S2",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(R3, "R3",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(S3, "S3",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
PlotText("
PlotText("
PlotText("
PlotText("
PlotText("
PlotText("
PlotText("

Pivot ",
R1 " ,
S1 " ,
R2 " ,
S2 " ,
R3 " ,
S3 " ,

LastValue(BarIndex())-(numbars/Hts),
LastValue(BarIndex())-(numbars/Hts),
LastValue(BarIndex())-(numbars/Hts),
LastValue(BarIndex())-(numbars/Hts),
LastValue(BarIndex())-(numbars/Hts),
LastValue(BarIndex())-(numbars/Hts),
LastValue(BarIndex())-(numbars/Hts),

PPI,
R1I,
S1I,
R2I,
S2I,
R3I,
S3I,

colorYellow);
colorViolet);
colorViolet);
colorViolet);
colorViolet);
colorViolet);
colorViolet);

}
// Camerilla Levels //
rg = (DayH - DayL);
H5=DayC+1.1*rg;
H4=DayC+1.1*rg/2;
H3=DayC+1.1*rg/4;
H2=DayC+1.1*rg/6;
H1=DayC+1.1*rg/12;
L1=DayC-1.1*rg/12;
L2=DayC-1.1*rg/6;
L3=DayC-1.1*rg/4;
L4=DayC-1.1*rg/2;
L5=DayC-1.1*rg;

H5I
H4I
H3I
H2I
H1I
L1I
L2I
L3I
L4I
L5I

=
=
=
=
=
=
=
=
=
=

LastValue
LastValue
LastValue
LastValue
LastValue
LastValue
LastValue
LastValue
LastValue
LastValue

(H5,1);
(H4,1);
(H3,1);
(H2,1);
(H1,1);
(L1,1);
(L2,1);
(L3,1);
(L4,1);
(L5,1);

pcl = ParamToggle("Camerilla Levels","Hide|Show",0);


if(pcl==1) {
Plot(H5,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(H4,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(H3,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(H2,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(H1,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(L1,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(L2,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(L3,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);

Plot(L4,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(L5,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
PlotText(" H5 = " , LastValue(BarIndex())-(numbars/Hts), H5I +0.05, colorRo
se);
PlotText(" H4 = " , LastValue(BarIndex())-(numbars/Hts), H4I +0.05, colorRo
se);
PlotText(" H3 = " , LastValue(BarIndex())-(numbars/Hts), H3I +0.05, colorRo
se);
PlotText(" H2 = " , LastValue(BarIndex())-(numbars/Hts), H2I +0.05, colorRo
se);
PlotText(" H1 = " , LastValue(BarIndex())-(numbars/Hts), H1I +0.05, colorRo
se);
PlotText(" L1 = " , LastValue(BarIndex())-(numbars/Hts), L1I +0.05, colorRo
se);
PlotText(" L2 = " , LastValue(BarIndex())-(numbars/Hts), L2I +0.05, colorRo
se);
PlotText(" L3 = " , LastValue(BarIndex())-(numbars/Hts), L3I +0.05, colorRo
se);
PlotText(" L4 = " , LastValue(BarIndex())-(numbars/Hts), L4I +0.05, colorRo
se);
PlotText(" L5 = " , LastValue(BarIndex())-(numbars/Hts), L5I +0.05, colorRo
se);
}
// Current Days Hi Lo //
THL = ParamToggle("Todays Hi Lo","Hide|Show",1);
if(THL==1) {
isRth = TimeNum() >= 084500 & TimeNum() <= 085959;
isdRth = TimeNum() >= 084500 & TimeNum() <= 160000;
aRthL = IIf(isRth, L, 1000000);
aRthH = IIf(isdRth, H, Null);
aRthLd = IIf(isdRth, L, 1000000);
DayH = TimeFrameCompress( aRthH, inDaily, compressHigh );
DayH = TimeFrameExpand( DayH, inDaily, expandFirst );
DayL = TimeFrameCompress( aRthLd, inDaily, compressLow );
DayL = TimeFrameExpand( DayL, inDaily, expandFirst );
Bars = BarsSince(TimeNum() >= 94500 AND TimeNum() < 095959);//,BarIndex(),1);
// AND DateNum()==LastValue(DateNum());
x0 = BarCount-LastValue(Bars);
x1 = BarCount-1;
DayHline=LineArray(x0,LastValue(DayH),x1,LastValue (DayH),0);
DayLline=LineArray(x0,LastValue(DayL),x1,LastValue (DayL),0);
DayHlineI = LastValue (DayHline,1);
DayLlineI = LastValue (DayLline,1);
Plot(DayHline,"DayH",colorGold,styleDashed|styleNoRescale|styleNoTitle);
Plot(DayLline,"DayL",colorBlue,styleDashed|styleNoRescale|styleNoTitle);
PlotText(" Day Hi " ,
LastValue(BarIndex())-(numbars/Hts), DayHlineI
+0.05, colorYellow);
PlotText(" Day Lo " ,
LastValue(BarIndex())-(numbars/Hts), DayLlineI
+0.05, colorYellow);
}
_SECTION_BEGIN("Title");
DDayO = TimeFrameGetPrice("O", inDaily);
DHiDay = TimeFrameGetPrice("H", inDaily);
DLoDay = TimeFrameGetPrice("L", inDaily);
prvC = TimeFrameGetPrice("C", inDaily, -1);//close
Title =EncodeColor(colorYellow)+ Date()+EncodeColor(colorPink)+" "+Interval(fo
rmat=2)+EncodeColor(colorOrange)+"
"+Name()+EncodeColor(colorBrightGreen)+"
Open:"+WriteVal(O,1.2)+EncodeColor(colorBrightGreen)+"
High: "+WriteVal(

H,1.2)+EncodeColor(colorWhite)+"
Low: "+WriteVal(L,1.2)+EncodeColor(colorY
ellow)+"
Close "+
WriteVal(C,1.2) +
"
~ Prev Close : " + EncodeColor(colorYello
w) + prvC +EncodeColor(colorGold)+
"\n Day-Open : " +DDayO + " Day-High : " +DHiDay + " Day-Low : "+ DLoDay ;
_SECTION_END();
_SECTION_BEGIN("Background");
tchoice=Param("Title Selection ",2,1,2,1);
Plot(C, "", IIf(O>=C, colorWhite, colorBrightGreen), ParamStyle("Price Style",st
yleCandle,maskPrice));
//////////////////////////////////////////////////////////////////
_SECTION_BEGIN("Background text");
SetChartBkColor(colorBlack);
strWeekday = StrMid("---sunday---Monday--TuesdayWednesday-Thursday--Friday--Satu
rday", SelectedValue(DayOfWeek())*9,9);
GraphXSpace=Param("GraphXSpace",0,-55,200,1);
C13=Param("fonts",30,10,30,1 );
C14=Param("left-right",2.1,1.0,5.0,0.1 );
C15=Param("up-down",12,1,20,1 );
Miny = Status("axisminy");
Maxy = Status("axismaxy");
lvb = Status("lastvisiblebar");
fvb = Status("firstvisiblebar");
pxwidth = Status("pxwidth");
pxheight = Status("pxheight");
GfxSetBkMode(transparent=1);
GfxSetOverlayMode(1);
GfxSelectFont("Candara", Status("pxheight")/C13 );
GfxSetTextAlign( 6 );
GfxSetTextColor( ColorRGB (217,217,213));
GfxTextOut( Name(), Status("pxwidth")/C14, Status("pxheight")/C15 );
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxSetTextColor( ColorRGB (103,103,103));
GfxTextOut( "By", Status("pxwidth")/C14, Status("pxheight")/C15*2.5 );
GfxSelectFont("Candara", Status("pxheight")/C13*0.5 );
GfxSetTextColor( ColorRGB (103,103,103));
GfxTextOut( " krishna_vaastu@yahoo.com", Status("pxwidth")/C14, Status("pxheight
")/C15*4 );
GfxSelectFont("MS Sans Serif", 10, 500, False, False, 0);
_SECTION_END();
_SECTION_BEGIN("Parameters");
LB1= Param("Long LookBack Periods",42,1,60,1);
LB3= Param("Mid LookBack Periods",18,1,30,1);
LB2= Param("Short LookBack Periods",6,1,30,1);
_SECTION_END();
ppl = ParamToggle("","Off|On",0);
numbars = LastValue(Cum(Status("barvisible")));
fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2);
hts = -33.5;

_SECTION_BEGIN("Indicators");
RSI_Periods
=
Param("RSI Periods", 2, 1, 100, 1);
MA_Periods
=
Param("Periods for MAV", 50, 1, 200, 1);
Daily_Trend_MA_Pds
=
Param("Periods for Trend EMA", 6, 1, 100, 1);
MAV_Value
=
V/EMA(V, MA_Periods);
_SECTION_END();
// Check if previous day's close is above its 6-day EMA
DailyClose
=
TimeFrameCompress(Close, inDaily);
DailyEMA
=
EMA( DailyClose, Daily_Trend_MA_Pds);
DailyClose
=
TimeFrameExpand(DailyClose, inDaily, expandFirst
);
DailyEma
=
TimeFrameExpand(DailyEMA, inDaily, expandFirst);
//Plot(DailyEma,"DailEma",colorCustom12,styleLine);
// Trend detection based on 6EMA for Daily
Daily_Trend_UP
=
DailyClose > DailyEMA;
Daily_Trend_DOWN
=
DailyClose < DailyEMA;
Trend_UP_Text
=
WriteIf(Daily_Trend_UP, "Daily Trend UP", "");
Trend_DOWN_Text =
WriteIf(Daily_Trend_DOWN, "Daily Trend DOWN", "");
Trend_Neutral_Text
=
WriteIf(NOT Daily_Trend_DOWN AND NOT Daily_Trend
_UP, "Neutral", "");
TrendCol
=
IIf(Daily_Trend_UP, colorGreen, IIf(Daily_Trend_
DOWN, colorRed, colorLightGrey));
_SECTION_END();

_SECTION_BEGIN("Price");
pds = 20;
MAFAST = EMA( Close, 20 );
MASLOW = EMA( Close, 40 );
DonchianUpper = HHV( Ref( H, -1 ), pds ); // Highest high value of highs in last
20 periods
DonchianLower = LLV( Ref( L, -1 ), pds ); // Lowest low value of low in last 20
periods
DonchianMiddle = ( DonchianUpper + DonchianLower ) / 2;
UpTrend = C > ( LLV( L, 20 ) + 2 * ATR( 10 ) ) AND EMA( Close, 20 ) > EMA( Close
, 40 );
DnTrend = C < ( HHV( H, 20 ) - 2 * ATR( 10 ) ) AND EMA( Close, 20 ) < EMA( Close
, 40 );
Color = IIf( UpTrend, colorBlue, IIf( DnTrend, colorRed, colorYellow) );
// Plots a 20 period Donchian channel
Plot( C, "Price", Color, styleCandle | styleThick );
NewDay = IIf(Day() != Ref(Day(), -1) OR BarIndex() == LastValue(BarIndex()), 1,
0);
//Plot(NewDay, "", 47, 2 + 32768 + 4096, Minvalue = 0, Maxvalue = 1);
_SECTION_END();
_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);
if(ppl==1) {
Plot(bp,"",colorWhite,styleLine|styleLine|styleNoRescale);
Plot(s1,"",colorGreen,styleDashed|styleNoRescale);
Plot(s2,"",colorBrightGreen,styleDashed|styleNoRescale);
Plot(s3,"",colorBrightGreen,styleDashed|styleNoRescale);
Plot(s4,"",colorBrightGreen,styleDashed|styleNoRescale);
Plot(r1,"",colorRed,styleDashed|styleNoRescale);
Plot(r2,"",colorDarkRed,styleDashed|styleNoRescale);
Plot(r3,"",colorDarkRed,styleDashed|styleNoRescale);
Plot(r4,"",colorDarkRed,styleDashed|styleNoRescale);
Plot(wbp,"",colorTan,styleDashed|styleLine|styleNoRescale);
Plot(ws1,"",colorPaleGreen,styleDashed|styleNoRescale);
Plot(ws2,"",colorPaleGreen,styleDashed|styleNoRescale);
//Plot(ws3,"",colorPaleGreen,styleDashed|styleNoRescale);
//Plot(ws4,"",colorPaleGreen,styleDashed|styleNoRescale);
Plot(wr1,"",colorPaleBlue,styleDashed|styleNoRescale);
Plot(wr2,"",colorPaleBlue,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,"",colorPaleBlue,styleDashed|styleNoRescale);
PlotText(" Pivot = " + WriteVal(bp,fraction), LastValue(BarIndex())-(numbars/Hts
), bpI +0.05, colorWhite);
PlotText(" Resistance 1 = " + WriteVal(r1,fraction), LastValue(BarIndex())-(numb
ars/Hts), r1I +0.05, colorRed);
PlotText(" Support 1 = " + WriteVal(s1,fraction), LastValue(BarIndex())-(numbars
/Hts), s1I +0.05, colorGreen);
PlotText(" Resistance 2 = " + WriteVal(r2,fraction), LastValue(BarIndex())-(numb
ars/Hts), r2I +0.05, colorDarkRed);
PlotText(" Support 2 = " + WriteVal(s2,fraction), LastValue(BarIndex())-(numbars
/Hts), s2I +0.05, colorBrightGreen);
PlotText(" Resistance 3 = " + WriteVal(r3,fraction), LastValue(BarIndex())-(numb
ars/Hts), r3I +0.05, colorDarkRed);
PlotText(" Support 3 = " + WriteVal(s3,fraction), LastValue(BarIndex())-(numbars
/Hts), s3I +0.05, colorBrightGreen);
PlotText(" Resistance 4 = " + WriteVal(r4,fraction), LastValue(BarIndex())-(numb
ars/Hts), r4I +0.05, colorDarkRed);
PlotText(" Support 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 Resistance 1 = " + WriteVal(wr1,fraction), LastValue(BarIndex())-(n
umbars/Hts), wr1I +0.05, colorPaleBlue);
PlotText(" W Support 1 = " + WriteVal(ws1,fraction), LastValue(BarIndex())-(numb
ars/Hts), ws1I +0.05, colorPaleGreen);
PlotText(" W Resistance 2 = " + WriteVal(wr2,fraction), LastValue(BarIndex())-(n
umbars/Hts), wr2I +0.05, colorPaleBlue);
PlotText(" W Support 2 = " + WriteVal(ws2,fraction), LastValue(BarIndex())-(numb
ars/Hts), ws2I +0.05, colorPaleGreen);
//PlotText(" W Resistance 3 = " + WriteVal(wr3,fraction), LastValue(BarIndex())(numbars/Hts), wr3I +0.05, colorPaleBlue);
//PlotText(" W Support 3 = " + WriteVal(ws3,fraction), LastValue(BarIndex())-(nu
mbars/Hts), ws3I +0.05, colorPaleGreen);
//PlotText(" W Resistance 4 = " + WriteVal(wr4,fraction), LastValue(BarIndex())(numbars/Hts), wr4I +0.05, colorPaleBlue);
//PlotText(" W Support 4 = " + WriteVal(ws4,fraction), LastValue(BarIndex())-(nu
mbars/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())-(n
umbars/Hts), mr1I+0.05, colorPaleBlue);
PlotText(" M Support 1 = " + WriteVal(ms1,fraction), LastValue(BarIndex())-(numb
ars/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(Bar
Index())-(numbars/Hts), HR3I +0.05, colorGreen);
PlotText(" H Sup 3 = " + WriteVal(HS3,fraction), LastValue(BarIn
dex())-(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())-(numbar
s/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())-(numbar
s/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(Bar
Index())-(numbars/Hts), HR3I +0.05, colorGreen);
PlotText(" H Sup 3 = " + WriteVal(HS3,fraction), LastValue(BarIn
dex())-(numbars/Hts), HS3I +0.05, colorRed);
}
_SECTION_END();
_SECTION_BEGIN("Time Left");
function GetSecondNum()
{
Time = Now( 4 );
Seconds = int( Time % 100 );
Minutes = int( Time / 100 % 100 );
Hours = int( Time / 10000 % 100 );
SecondNum = int( Hours * 60 * 60 + Minutes * 60 + Seconds );
return SecondNum;
}
RequestTimedRefresh( 1 );
TimeFrame = Interval();
SecNumber = GetSecondNum();
Newperiod = SecNumber % TimeFrame == 0;
SecsLeft = SecNumber - int( SecNumber / TimeFrame ) * TimeFrame;
SecsToGo = TimeFrame - SecsLeft;
x=Param("xposn",0,0,1000,1);
y=Param("yposn",900,0,1000,1);
GfxSelectSolidBrush( ColorRGB( 230, 230, 230 ) );
GfxSelectPen( ColorRGB( 230, 230, 230 ), 2 );
if ( NewPeriod )
{
GfxSelectSolidBrush( colorYellow );
GfxSelectPen( colorYellow, 2 );
Say( "New time CANDLE start" );
}
cx = Param( "cxposn", 682, 0, 1250, 1 );
cy = Param( "cyposn", 15, 0, 500, 1 );
GfxSelectFont( "bold", 10, 98, False );
//gfxcup
= SelectedValue(C > Ref(C,-1));
//gfxpcolor = IIf(gfxcup,colorBrightGreen,colorRed);
GfxSetTextColor(colorBrightGreen);
//GfxSetTextColor( colorWhite );
GfxTextOut( "Time left for candle close " + SecsToGo + " ", cx, cy );
_SECTION_END();

Potrebbero piacerti anche