You are on page 1of 13

_SECTION_BEGIN("Price");

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close
%g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
rg=(H-L);
arg=Wilders(rg,30);
wrb=rg>(2.5*arg);
Cloc=C-L;
x=rg/Cloc;
x1=IIf(Cloc=0,arg,x);
dcls=x1>2;
j=MA(C,5);
tls=LinRegSlope(j,5);
utbar=wrb AND dcls AND tls>0 ;
//barcolor = IIf(utbar, colorRed, colorGreen);
//Plot( C, "Close", barcolor,styleBar );
//PlotShapes( shapeUpArrow *(utbar) , colorWhite, 0, H, 10 );
//Filter =utbar;
//AddColumn(utbar,"Trend Change",1,colorGreen,IIf(utbar,colorRed,colorGreen));

_SECTION_END();
_SECTION_BEGIN("Peak");
//Peak-Trough System + Auto ATR + Position sizing+Varible Sensitivity//
// Last Update 16 Oct 05 By Kook//

PctVlt=(ATR(14)/C)*100;//PercentVolatility

PK=IIf(PctVlt<0.5,Peak(Close,0.5,1),
IIf( PctVlt>=0.5 AND PctVlt< 1.0 ,Peak(Close,0.70,1),
IIf( PctVlt>=1.0 AND PctVlt< 1.5 ,Peak(Close,0.90,1),
IIf( PctVlt>=1.5 AND PctVlt< 2.0 ,Peak(Close,1.10,1),
IIf( PctVlt>=2.0 AND PctVlt< 2.5 ,Peak(Close,1.30,1),
IIf( PctVlt>=2.5 AND PctVlt< 3.0 ,Peak(Close,1.50,1),
IIf( PctVlt>=3.0 AND PctVlt< 3.5 ,Peak(Close,1.70,1),
IIf( PctVlt>=3.5 AND PctVlt< 4.0 ,Peak(Close,2.00,1),
Peak(Close,2.20,1) ))))))));

TGH=IIf(PctVlt<0.5,Trough(Close,0.5,1),
IIf( PctVlt>=0.5 AND PctVlt< 1.0 ,Trough(Close,0.75,1),
IIf( PctVlt>=1.0 AND PctVlt< 1.5 ,Trough(Close,1.00,1),
IIf( PctVlt>=1.5 AND PctVlt< 2.0 ,Trough(Close,1.25,1),
IIf( PctVlt>=2.0 AND PctVlt< 2.5 ,Trough(Close,1.50,1),
IIf( PctVlt>=2.5 AND PctVlt< 3.0 ,Trough(Close,1.75,1),
IIf( PctVlt>=3.0 AND PctVlt< 3.5 ,Trough(Close,2.00,1),
IIf( PctVlt>=3.5 AND PctVlt< 4.0 ,Trough(Close,2.25,1),
Trough(Close,2.50,1) ))))))));

Sens=IIf(PctVlt<0.5,0.5,
IIf( PctVlt>=0.5 AND PctVlt< 1.0 ,0.75,
IIf( PctVlt>=1.0 AND PctVlt< 1.5 ,1.00,
IIf( PctVlt>=1.5 AND PctVlt< 2.0 ,1.25,
IIf( PctVlt>=2.0 AND PctVlt< 2.5 ,1.50,
IIf( PctVlt>=2.5 AND PctVlt< 3.0 ,1.75,
IIf( PctVlt>=3.0 AND PctVlt< 3.5 ,2.00,
IIf( PctVlt>=3.5 AND PctVlt< 4.0 ,2.25,
2.50 ))))))));

Color=IIf(BarsSince(Cross(C,Ref(PK,-1)))<BarsSince(Cross(Ref(TGH,-
1),C)),colorBrightGreen,colorRed);
Plot(C,"Chaloke.com Peak-Trough",Color,styleCandle);
//PlotShapes( Cross(C,Ref(PK,-1))*shapeUpArrow,colorYellow,0,L);
//PlotShapes( Cross(Ref(TGH,-1),C)*shapeDownArrow,colorPink,0,H);
PlotShapes( Cross(84,RSI(36))*shapeDownArrow,colorYellow,0,H,Offset=-28 );
//PlotShapes( Cross(67.4,RSI(171))*shapeDownArrow,colorYellow,0,H,Offset=-28 );
PlotShapes( Cross(27,RSI(95))*shapeUpArrow,colorYellow,0,L,Offset=-28 );

PlotShapes( Cross(95.9,StochD(4200))*shapeDownArrow,colorCustom12,0,H,Offset=-
28 );
PlotShapes( Cross(0.50,StochD(4200))*shapeUpArrow,colorCustom12,0,H,Offset=-28 );

//TIME FRAME CALCULATION


H1 = TimeFrameGetPrice("H", inDaily, -1); // yesterdays high
L1 = TimeFrameGetPrice("L", inDaily, -1); // low
C1= TimeFrameGetPrice("C", inDaily, -1); // close
DayO = TimeFrameGetPrice("O", inDaily); // current day open

// PIVOT Calculation
P = ( H1+ L1 + C1 )/3;
S1 = (2*P)-H1;
R1 = (2*P)-L1;
S2 = P -(H1 - L1);
S3 = S1 - (H1-L1);
R2 = P +(H1 - L1);
R3 = R1 +(H1-L1);

// PIVOT mid points


MIDR1 = (P+R1)/2;
MIDR2 = (R1+R2)/2;
MIDR3 = (R2+R3)/2;
MIDS1 = (P+S1)/2;
MIDS2 = (S1+S2)/2;
MIDS3 = (S2+S3)/2;

//PLOTS
//Plot(R1, "",colorRed,styleLine+styleNoRescale);
//Plot(R2, "",colorRed,styleLine+styleNoRescale);
//Plot(R3, "",colorRed,styleLine+styleNoRescale);

//Plot(P, "",colorWhite,styleDots+styleNoRescale);

//Plot(S1, "",colorAqua,styleLine+styleNoRescale);
//Plot(S2, "",colorAqua,styleLine+styleNoRescale);
//Plot(S3, "",colorAqua,styleLine+styleNoRescale);

//Plot(MIDR1, "",colorPink,styleDashed+styleNoRescale);
//Plot(MIDR2, "",colorPink,styleDashed+styleNoRescale);
//Plot(MIDR3, "",colorPink,styleDashed+styleNoRescale);

//Plot(MIDS1, "",colorYellow,styleDashed+styleNoRescale);
//Plot(MIDS2, "",colorYellow,styleDashed+styleNoRescale);
//Plot(MIDS3, "",colorYellow,styleDashed+styleNoRescale);

//Plot(H1, "",colorRed,styleDots+styleNoRescale);
//Plot(L1, "",colorYellow,styleDots+styleNoRescale);
//Plot(C1, "",colorOrange,styleDots+styleNoRescale);

// text section

"HIGH /LOW /CLOSE = " +H +" / "+ L+" / "+ C +"\n";


"H1 /L1 /C1 = " +H1 +" / "+ L1+" / "+ C1 +"\n";

"R3 = " +R3;


"midr3 = " +MIDR3;
"R2 = " +R2;
"midr2 = " +MIDR2;
"R1 = " +R1;
"midr1 = " +MIDR1;
"*************";
"p = " +p;
"*************";
"mids1 = " +MIDS1;
"S1 = " +S1;
"mids2 = " +MIDS2;
"S2 = " +S2;
"mids3 = " +MIDS3;
"S3 = " +S3;

_SECTION_END();
//Plot(EMA(O,10), "ema5", colorBlue , styleLine|styleThick|styleNoRescale);

//Plot(EMA(C,50), "ema10",colorCustom12 , styleLine|styleThick|styleNoRescale);

Plot(EMA(C,6), "EMA2.5",colorYellow ,styleLine|styleThick|styleNoRescale);

//Plot(Wilders(H,30), "Wilders25", colorYellow , styleStaircase| styleDashed|


styleNoRescale);
//Plot(Wilders(H,79), "WILDERS81",colorCustom12 , styleStaircase| styleDashed|
styleNoRescale);
//Topping Bar
//Range = H - L ;
//TPB = Volume > MA(Volume,9) AND Close < Low + Range/2 AND Range <= Ref(Range,-1);
//PlotShapes(shapeSmallCircle * TPB,colorYellow,0,H,20);

/*_SECTION_BEGIN("Advanced Trend Lines");


function GetXSupport(Lo, Percentage, Back)
{
return ((BarCount - 1) - LastValue(TroughBars(Lo, Percentage,Back)));
}
function GetYSupport(Lo, Percentage, Back)
{
return (LastValue(Trough(Lo, Percentage, back)));
}

function GetXResistance(Hi, Percentage, Back)


{
return ((BarCount - 1) -LastValue(PeakBars(Hi, Percentage, Back)));
}
function GetYResistance(Hi, Percentage, Back)
{
return (LastValue(Peak(Hi, Percentage, Back)));
}
function TD_Supply(P)
{
return ( P > Ref(P, 1) AND P > Ref(P, -1) AND P > Ref(C, -2));
}
function TD_Demand(P)
{
return ( P < Ref(P, 1) AND P < Ref(P, -1) AND P < Ref(C, -2));
}
////////////////////////////////////////////////////////////////////////
//Parameters
Percentage = Param("Percentage", 1.000, 0.01, 100. ,0.01);
DrawAllLines = ParamToggle("Draw All Lines?", "No|Yes", 1);
Lines = Param("Lines?", 1, 1, BarCount-2);
DrawR = ParamList("Resistance Points", "Off|High to High|High to
Low", 1);
DrawS = ParamList("Support Points", "Off|Low to Low|Low to High",
1);
ShowTDP = ParamToggle("Show TD Pionts", "No|Yes", 0);
AllOrDownR = ParamToggle("Resistance Direction", "All|Down");
AllOrUpS = ParamToggle("Support Direction", "All|Up");
ShowSR = ParamToggle("Show Vert S/R","No|Yes", 1);
SRPer = Param("S/R Percentage", 1, 1);
SRBack = Param("S/R Back", 1, 1);
str = "";
Res = Sup = 0;
Con = 1;
////////////////////////////////////////////////////////////////////////
Main = C;
Con = ConS = ConR = 1;
if(DrawS=="Low to Low")
{
Support1 = L;
Support2 = L;
}
else
{
Support1 = L;
Support2 = H;
}
if(DrawR=="High to High")
{
Resistance1 = H;
Resistance2 = H;
}
else
{
Resistance1 = H;
Resistance2 = L;
}
////////////////////////////////////////////////////////////////////////
//Plotting Area
Plot(Main, "", IIf(C>O,colorGreen, colorRed), styleBar);
if(DrawAllLines)
for(i = 2; i<=Lines+1; i++)
{
if(DrawS!="Off")
{
x0 = GetXSupport(Support1, Percentage, i);
x1 = GetXSupport(Support2, Percentage, i-1);
y0 = GetYSupport(Support1, Percentage, i);
y1 = GetYSupport(Support2, Percentage, i-1);
x = LineArray(x0, y0, x1, y1, 1);
if(AllOrUpS) ConS = StrToNum(NumToStr(y0 < y1));
if(Con AND ConS)
Plot(x, "", IIf(LastValue(C) < LastValue(x),
colorBlue,colorYellow),4+8+2048);

}
if(DrawR!="Off")
{
x0 = GetXResistance(Resistance1, Percentage, i);
x1 = GetXResistance(Resistance2, Percentage, i-1);
y0 = GetYResistance(Resistance1, Percentage, i);
y1 = GetYResistance(Resistance2, Percentage, i-1);
x = LineArray(x0, y0, x1, y1, 1);
if(AllOrDownR) ConR = y0 > y1;
if(Con AND ConR)
Plot(x, "", IIf(LastValue(C) < LastValue(x),
colorBlue,colorYellow),4+8+2048);

}
}
else
{
if(DrawS!="Off")
{
x0 = GetXSupport(Support1, Percentage, Lines+1);
x1 = GetXSupport(Support2, Percentage, Lines);
y0 = GetYSupport(Support1, Percentage, Lines+1);
y1 = GetYSupport(Support2, Percentage, Lines);
x = LineArray(x0, y0, x1, y1, 1 );
Sup = LastValue(LinRegSlope(x, Lines+1));
if(AllOrUpS) ConS = y0 < y1;
if(Con AND ConS)
Plot(x, "", IIf(LastValue(C) < LastValue(x),
colorBlue,colorYellow),4+8+2048);

}
if(DrawR!="Off")
{
x0 = GetXResistance(Resistance1, Percentage, Lines+1);
x1 = GetXResistance(Resistance2, Percentage, Lines);
y0 = GetYResistance(Resistance1, Percentage, Lines+1);
y1 = GetYResistance(Resistance2, Percentage, Lines);
x = LineArray(x0, y0, x1, y1, 1 );
Res = LastValue(LinRegSlope(x, Lines+1));
if(AllOrDownR) ConR = y0 > y1;
if(Con AND ConR)
Plot(x, "", IIf(LastValue(C) < LastValue(x),
colorBlue,colorYellow),4+8+2048);

}
str = "\nR Slope=("+Res+"), S Slope=("+Sup+")";
}

if(ShowTDP)
{
PlotShapes(TD_Supply(H)*shapeSmallCircle, colorRed, 0, H, H*.001);
PlotShapes(TD_Demand(L)*shapeSmallCircle, colorGreen, 0, L, -L*.001);
}
if(ShowSR)
{
for(i=1; i<=SRBack; i++)
{
x0 = GetXSupport(L, SRPer, i);
x1 = BarCount-1;
y0 = GetYSupport(L, SRPer, i);
x = LineArray(x0, y0, x1, y0, 0);
//Plot(x, "", IIf(LastValue(C) > x, colorCustom13, colorCustom12),
4+8+2048);

x0 = GetXResistance(H, SRPer, i);


y0 = GetYResistance(H, SRPer, i);
x = LineArray(x0, y0, x1, y0, 0);
Plot(x, "", IIf(LastValue(C) > x, colorCustom13, colorCustom12),
4+8+2048);

}
}
Title =FullName()+" ({{NAME}})\n{{DATE}}\n"+"Open: "+O+", Hi: "+H+", Lo: "+L+",
Close: "+C+StrFormat(" (%.2f %.2f\%)", C-Ref(C, -1), SelectedValue(ROC(C, 1)))
+str;
*/
Bars_so_far_today = 1 + BarsSince( Day() != Ref(Day(), -1));
TT= RSIa(C,60);
StartBar = ValueWhen(TimeNum() == 093000, BarIndex());
TodayVolume = Sum(TT,Bars_so_far_today);
IIf (BarIndex() >= StartBar, VWAP = Sum (C * TT, Bars_so_far_today ) /
TodayVolume,0);
Plot (VWAP,"VWAP",colorOrange,4 +8+2048 );

Plot(Ref(VWAP,-TroughBars(VWAP,0.39 ,1)),"",colorAqua,4 + 8+2048 );

Plot(Ref(VWAP,-PeakBars(VWAP,0.39 ,1)),"",colorCustom1, 4 + 8+2048 );

_SECTION_END();

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

//Plot(C, "", IIf(O>=C, colorOrange, colorGreen), ParamStyle("Price


Style",styleBar,maskPrice));
//////////////////////////////////////////////////////////////////
_SECTION_BEGIN("Fib Retracements");
fibs = ParamToggle("Plot Fibs","Off|On",1);
pctH = Param ("Pivot Hi %", 0.78,0.001,2.0,0.002);
HiLB = Param ("Hi LookBack",1,1,BarCount-1,1);
pctL = Param ("Pivot Lo %", 0.78,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==1)
{
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==1)
{
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_END();
//////////////////////////////////////////////////////////////////
if (tchoice==1 )
{
_N(Title = EncodeColor(colorWhite)+StrFormat(" {{NAME}} - {{INTERVAL}}
{{DATE}} Open: %g, High: %g, Low: %g, Close: %g
{{VALUES}}",O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
}
//////////////////////////////////////////////////////////////////
if (tchoice==2 )
{
Title = EncodeColor(colorWhite)+ Date() + " Tick = " + EncodeColor(5) +
Interval()+
EncodeColor(colorWhite) + " Open = " + EncodeColor(colorWhite) + O +
EncodeColor(colorWhite) + " High = " + EncodeColor(5) + H +
EncodeColor(colorWhite) + " Low = " + EncodeColor(colorRed) + L +
EncodeColor(colorWhite) + " Close = " + EncodeColor(colorWhite) + C + "\n" +
EncodeColor( colorWhite) +"_______________"+"\n"+
EncodeColor( colorWhite) + "424% = " + EncodeColor(25)+ e424 + " " +"\n"+
EncodeColor( colorWhite) + "262% = " + EncodeColor(47)+ e262 + " " +"\n"+
EncodeColor( colorWhite) + "200% = " + EncodeColor(47)+ e200 + " " +"\n"+
EncodeColor( colorWhite) + "162% = " + EncodeColor(47)+ e162 + " " +"\n"+
EncodeColor( colorWhite) + "127% = " + EncodeColor(47)+ e127 + " " +"\n"+
EncodeColor( colorYellow) + " Res = " + EncodeColor(32)+ p100 + " "
+"\n"+
EncodeColor( colorWhite) + " 78% = "+ EncodeColor(42)+ r786 + " " +"\n"+
EncodeColor( colorWhite) + " 62% = "+ EncodeColor(43)+ r618 + " " +"\n"+
EncodeColor( colorWhite) + " 50% = "+ EncodeColor(41)+ r050 + " " +"\n"+
EncodeColor( colorWhite) + " 38% = "+ EncodeColor(44)+ r382 + " " +"\n"+
EncodeColor( colorWhite) + " 23% = "+ EncodeColor(45)+ r236+ " " +"\n"+
EncodeColor( colorYellow) + " Sup = " + EncodeColor(34)+ p00 + " " ;
}
GraphXSpace=5;

_SECTION_BEGIN("RSI BUY SELL");

n=42;
per =13;
x = Cum(1);
s1=IIf(RSIa(L,n)>Min(RSIa(C,n),RSIa(O,n)),Min(RSIa(C,n),RSIa(O,n)),RSIa(L,n));
s11=IIf(RSIa(H,n)<Max(RSIa(C,n),RSIa(O,n)),Max(RSIa(C,n),RSIa(O,n)),RSIa(H,n));
pS = TroughBars( s1, per, 1 ) == 0;
endt= LastValue(ValueWhen( pS, x, 1 ));
startt=LastValue(ValueWhen( pS, x, 2 ));
dtS =endt-startt;
endS = LastValue(ValueWhen( pS, s1, 1 ) );
startS = LastValue( ValueWhen( pS, s1, 2 ));
aS = (endS-startS)/dtS;bS = endS;
trendlineS = aS * ( x -endt ) + bS;
pR = PeakBars( s11, per, 1 ) == 0;
endt1= LastValue(ValueWhen( pR, x, 1 ));
startt1=LastValue(ValueWhen( pR, x, 2 ));
dtR =endt1-startt1;
endR = LastValue(ValueWhen( pR, s11, 1 ) );
startR = LastValue( ValueWhen( pR, s11, 2 ));
aR = (endR-startR)/dtR;
bR = endR;
trendlineR = aR * ( x -endt1 ) + bR;
//Plot(ValueWhen( (Cross(RSIa(C,n), trendlineS ) OR (S1==trendlineS )), L),"",
colorGreen, styleDashed|styleNoRescale|styleThick);
//Plot(ValueWhen((Cross(RSIa(C,n),trendlineR )OR (S11==trendlineR )), H),"",
colorRed, styleDashed|styleNoRescale|styleThick);
Buy = (S1==trendlineS );
Sell = (S11==trendlineR );
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );
PlotShapes( Buy * shapeUpArrow + Sell * shapeDownArrow, IIf( Buy, colorGold ,
colorGold) );
dist = 0.71*ATR(10);
for( i = 0; i < BarCount; i++ )
{
if( Buy[i] ) PlotText( "RSI Buy " + L[ i ], i, L[ i ]-dist[i], colorWhite );
if( Sell[i] ) PlotText( "RSI Sell " + H[ i ], i, H[ i ]+dist[i], colorAqua);
}
n=260;
per =12;
x = Cum(1);
s1=IIf(RSIa(L,n)>Min(RSIa(C,n),RSIa(O,n)),Min(RSIa(C,n),RSIa(O,n)),RSIa(L,n));
s11=IIf(RSIa(H,n)<Max(RSIa(C,n),RSIa(O,n)),Max(RSIa(C,n),RSIa(O,n)),RSIa(H,n));
pS = TroughBars( s1, per, 1 ) == 0;
endt= LastValue(ValueWhen( pS, x, 1 ));
startt=LastValue(ValueWhen( pS, x, 2 ));
dtS =endt-startt;
endS = LastValue(ValueWhen( pS, s1, 1 ) );
startS = LastValue( ValueWhen( pS, s1, 2 ));
aS = (endS-startS)/dtS;bS = endS;
trendlineS = aS * ( x -endt ) + bS;
pR = PeakBars( s11, per, 1 ) == 0;
endt1= LastValue(ValueWhen( pR, x, 1 ));
startt1=LastValue(ValueWhen( pR, x, 2 ));
dtR =endt1-startt1;
endR = LastValue(ValueWhen( pR, s11, 1 ) );
startR = LastValue( ValueWhen( pR, s11, 2 ));
aR = (endR-startR)/dtR;
bR = endR;
trendlineR = aR * ( x -endt1 ) + bR;
//Plot(ValueWhen( (Cross(RSIa(C,n), trendlineS ) OR (S1==trendlineS )), L),"",
colorGreen, styleDashed|styleNoRescale|styleThick);
//Plot(ValueWhen((Cross(RSIa(C,n),trendlineR )OR (S11==trendlineR )), H),"",
colorRed, styleDashed|styleNoRescale|styleThick);
Buy = (S1==trendlineS );
Sell = (S11==trendlineR );
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );
PlotShapes( Buy * shapeUpArrow + Sell * shapeDownArrow, IIf( Buy, colorGold ,
colorRed) );
dist = 2*ATR(10);
for( i = 0; i < BarCount; i++ )
{
if( Buy[i] ) PlotText( "RSI 260strong Buy " + L[ i ], i, L[ i ], colorGreen );
if( Sell[i] ) PlotText( "RSI 260strong Sell " + H[ i ], i, H[ i ], colorRed);

n=150;
per =12;
x = Cum(1);
s1=IIf(RSIa(L,n)>Min(RSIa(C,n),RSIa(O,n)),Min(RSIa(C,n),RSIa(O,n)),RSIa(L,n));
s11=IIf(RSIa(H,n)<Max(RSIa(C,n),RSIa(O,n)),Max(RSIa(C,n),RSIa(O,n)),RSIa(H,n));
pS = TroughBars( s1, per, 1 ) == 0;
endt= LastValue(ValueWhen( pS, x, 1 ));
startt=LastValue(ValueWhen( pS, x, 2 ));
dtS =endt-startt;
endS = LastValue(ValueWhen( pS, s1, 1 ) );
startS = LastValue( ValueWhen( pS, s1, 2 ));
aS = (endS-startS)/dtS;bS = endS;
trendlineS = aS * ( x -endt ) + bS;
pR = PeakBars( s11, per, 1 ) == 0;
endt1= LastValue(ValueWhen( pR, x, 1 ));
startt1=LastValue(ValueWhen( pR, x, 2 ));
dtR =endt1-startt1;
endR = LastValue(ValueWhen( pR, s11, 1 ) );
startR = LastValue( ValueWhen( pR, s11, 2 ));
aR = (endR-startR)/dtR;
bR = endR;
trendlineR = aR * ( x -endt1 ) + bR;
//Plot(ValueWhen( (Cross(RSIa(C,n), trendlineS ) OR (S1==trendlineS )), L),"",
colorGreen, styleDashed|styleNoRescale|styleThick);
//Plot(ValueWhen((Cross(RSIa(C,n),trendlineR )OR (S11==trendlineR )), H),"",
colorRed, styleDashed|styleNoRescale|styleThick);
Buy = (S1==trendlineS );
Sell = (S11==trendlineR );
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );
PlotShapes( Buy * shapeUpArrow + Sell * shapeDownArrow, IIf( Buy, colorYellow ,
colorCustom12) );
dist = 1.8*ATR(10);
for( i = 0; i < BarCount; i++ )
{
if( Buy[i] ) PlotText( "Rsi150 strong Buy " + L[ i ], i, L[ i ]-dist[i],
colorYellow );
if( Sell[i] ) PlotText( "Rsi150 strong Sell " + H[ i ], i, H[ i ]+dist[i],
colorCustom12);
}
kk=ParamToggle("select type","YES|NO",1);
if(kk == 0)
{
DayH = SelectedValue(TimeFrameGetPrice("H", inDaily, -1));// yesterdays high
DayL = SelectedValue(TimeFrameGetPrice("L", inDaily, -1));//low
DayH1 = SelectedValue(TimeFrameGetPrice("H", inDaily, -2));// yesterdays high
DayL1 = SelectedValue(TimeFrameGetPrice("L", inDaily, -2));//low
DayH2 = SelectedValue(TimeFrameGetPrice("H", inDaily, -3));// yesterdays high
DayL2 = SelectedValue(TimeFrameGetPrice("L", inDaily, -3));//low
}
else if( kk ==1)
{
DayH = SelectedValue(TimeFrameGetPrice("H", inDaily));// yesterdays high
DayL = SelectedValue(TimeFrameGetPrice("L", inDaily));//low
DayH1 = SelectedValue(TimeFrameGetPrice("H", inDaily, -1));// yesterdays high
DayL1 = SelectedValue(TimeFrameGetPrice("L", inDaily, -1));//low
DayH2 = SelectedValue(TimeFrameGetPrice("H", inDaily, -2));// yesterdays high
DayL2 = SelectedValue(TimeFrameGetPrice("L", inDaily, -2));//low
}

Range = ((DayH +DayH1 +DayH2)/3 - (DayL+DayL1+DayL2)/3);


sellline= (Range *0.292)+DayL;
Buyline= Dayh-(Range *0.33);
GapUpbuyline= (Range *0.702)+DayL;
Gapdownbuyline= DayH-(Range *0.655);

style = styleLine | styleNoRescale|styleLine;


Plot(sellline, "selllinetoday",colorWhite ,styleDashed|styleNoRescale|styleThick);
Plot(buyline, "buyinetoday",colorGold ,styleDashed|styleNoRescale|styleThick);
Plot(GapUpbuyline, "gapup buyinetoday",colorPink , styleDashed|styleNoRescale|
styleThick);
Plot(Gapdownbuyline, "gapup buyinetoday",colorOrange ,styleDashed|styleNoRescale|
styleThick);

percent = Param("Percentage", 1.5, 0.01, 100. ,0.01);


L1=L;//IIf(RSIa(L,n)>Min(RSIa(C,n),RSIa(O,n)),Min(RSIa(C,n),RSIa(O,n)),RSIa(L,n));
H1=H;//IIf(RSIa(H,n)<Max(RSIa(C,n),RSIa(O,n)),Max(RSIa(C,n),RSIa(O,n)),RSIa(H,n));
y0=LastValue(Trough(L1,percent ,2));
y1=LastValue(Trough(L1,percent ,1));
x0=BarCount - 1 - LastValue(TroughBars(L1,percent ,2));
x1=BarCount - 1 - LastValue(TroughBars(L1,percent ,1));
x = LineArray( x0, y0, x1, y1, 1 );
Plot( x, "Trend line", colorYellow,4+8+2048 );

y0=LastValue(Peak(H1,percent ,2));
y1=LastValue(Peak(H1,percent ,1));
x0=BarCount - 1 - LastValue(PeakBars(H1,percent ,2));
x1=BarCount - 1 - LastValue(PeakBars(H1,percent ,1));
xx = LineArray( x0, y0, x1, y1, 1 );

Plot( xx, "Trend line", colorBlue,4+8+2048 );

Plot(ValueWhen( (l1==x ), L),"", colorAqua, styleDashed|styleNoRescale|styleThick);


Plot(ValueWhen( (h1==xx ), H),"", colorBrown, styleDashed|styleNoRescale|
styleThick);
//Sell = Cross(H1, xx) OR (xx==H1) ;
//Buy =Cross(x,L1) OR (x==L1);
Sell = (round(xx)==round(H1)) ;
Buy =(round(x)==round(L1));
_SECTION_END();

_SECTION_END();

You might also like