_SECTION_BEGIN("Name");
GfxSetOverlayMode(1);
pxh= Status("pxHeight"); pxw=Status("pxWidth");
GfxSelectFont("Tahoma",pxh/30);
GfxSetTextColor(colorWhite);
GfxSetTextAlign(6); GfxSetBkMode(0);
GfxTextOut(FullName(),pxw/2.4,pxh/12);
GfxSelectFont("Tahoma",pxh/15);
GfxTextOut("",pxw/2,pxh/3);
_SECTION_END();
_SECTION_BEGIN("companyclos");
{ GfxSelectFont("french script mt",13, 800 );
GfxSetBkMode(1);
GfxSetTextColor(colorWhite);
GfxTextOut("C="+C+" ",580,1);
}
_SECTION_END();
_SECTION_BEGIN("companyhigh");
{ GfxSelectFont("french script mt",13, 800 );
GfxSetBkMode(1);
GfxSetTextColor(colorCustom13);
GfxTextOut("H="+H+" ",480,1);
}
_SECTION_END();
_SECTION_BEGIN("companyopen");
{ GfxSelectFont("french script mt",13, 800 );
GfxSetBkMode(1);
GfxSetTextColor(colorWhite);
GfxTextOut("O="+O+" ",380,1);
}
_SECTION_END();
_SECTION_BEGIN("companylow");
{ GfxSelectFont("french script mt",13, 800 );
GfxSetBkMode(1);
GfxSetTextColor(colorYellow);
GfxTextOut("L="+L+" ",280,1);
}
_SECTION_END();
_SECTION_BEGIN("cncp");
cd1=-(O-C)/(H-L)*100;
cd=Prec((cd1),2);
barcolor = IIf((cd>=68)OR (cd<=-68),colorYellow,colorCustom12);
Plot(C, "", barcolor, styleNoTitle| styleThick | styleCandle|styleNoLabel);
Plot(C, "",styleCandle, colorBlack, styleThick);
_SECTION_END();
_SECTION_BEGIN("");
_SECTION_BEGIN("MACD");
ml = MACD(6, 13);
dd= Signal(6,13,5);
Hist=ml-dd;
col_hist= IIf(Hist > BBandTop( Hist, 5, 0.5 ),colorLightBlue,IIf(Hist < BBandBot( Hist, 5, 0.5 ),colorBlue,colorRed));
pr=PeakBars(C,5)==0;
ps =TroughBars(C,5)==0;
PlotShapes(IIf(ps,shapeDigit2 ,Null),colorBlue,0,L,-30);
PlotShapes(IIf(pr,shapeDigit2 ,Null),colorBlue,0,H,30);
_SECTION_BEGIN(" ZigZagTrend ");
array = Close;
amount = Param("Amount", 5, 1, 50, 0.5 );
zz0 = Zig( array, amount );
zz1 = Ref( zz0, -1 );
zz2 = Ref( zz0, -2 );
tr = ValueWhen(zz0 > zz1 AND zz1 < zz2, zz1);
pk = ValueWhen(zz0 < zz1 AND zz1 > zz2, zz1);
PU = tr + 0.01 * abs(tr)*amount;
PD = pk - 0.01 * abs(pk)*amount;
ZZT = IIf( array >= PU AND zz0 > zz1, 1,
IIf( array <= PD AND zz0 < zz1, -1, 0 ) );
ZZT = ValueWhen( ZZT != 0, ZZT );
// plot Zigzag and zigzag trend
Plot( ZZT, "ZigZagTrend", colorGrey40, styleOwnScale|styleNoTitle );
Buy = Cover = Cross( ZZT, 0 );
Sell = Short = Cross( 0, ZZT );
PlotShapes(IIf(Cross( ZZT, 0 ),shapeDigit6,Null),colorYellow,0,Max(0,0),250);
PlotShapes(IIf(Cross( ZZT, 0 ),shapeUpArrow,Null),colorYellow,0,Max(0,0),240);
PlotShapes(IIf(Cross( 0, ZZT ),shapeDigit7,Null),colorCustom12,0,Min(0,0),-240);
PlotShapes(IIf(Cross( 0, ZZT ),shapeDownArrow,Null),colorCustom12,0,Min(0,0),230);
_SECTION_BEGIN("Magnified Price");
FS=Param("Font Size",15,11,100,1);
GfxSelectFont("Arial", FS, 700, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ParamColor("Color",colorWhite) );
Hor=Param("Horizontal Position",250,2,1,2);
Ver=Param("Vertical Position",1,1,1,1);
GfxTextOut("C="+C,Hor , Ver+55 );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSelectFont("Arial", 12, 700, True );
GfxSetBkMode( colorYellow );
GfxSetTextColor(ParamColor("Color",colorBlue) );
GfxTextOut(""+DD+" ("+xx+"%)", Hor , Ver+40 );
_SECTION_END();
_SECTION_BEGIN("Nd");
Nd=((C)-(O))/(L)*10000;
Filter=Close;
AddColumn(Nd , "Nd",1.2,colorBrown);
_SECTION_BEGIN(" Nd");
{ GfxSelectFont("Arial",12, 700 );
GfxSetBkMode(1);
GfxSetTextColor(colorCustom12);
GfxTextOut("Nd="+WriteVal(Nd,format=1.2)+"% ",750,1);
GfxSetTextColor(colorWhite);
}
_SECTION_END();
_SECTION_BEGIN("CNcP");
Cd1=-(O-C)/(H-L)*100;
Cd=Prec((Cd1),2);
Filter=Close;
AddColumn(Cd , "Cd",1.2,colorOrange);
_SECTION_END();
_SECTION_BEGIN(" Cd");
{ GfxSelectFont("Arial",13, 700 );
GfxSetBkMode(1);
GfxSetTextColor(colorGold);
GfxTextOut("Cd="+WriteVal(Cd,format=1.2)+"% ",870,1);
}
_SECTION_END();
_SECTION_BEGIN("SAR");
acc = Param("Acceleration", 0.02, 0, 1, 0.001 );
accm = Param("Max. acceleration", 0.2, 0, 1, 0.001 );
Col = IIf(SAR( acc, accm )>C,colorCustom12,colorCustom11);
Plot(SAR(acc,accm), _DEFAULT_NAME(), col, styleDashed );
Plot(1.5, "",IIf(C>SAR(acc,accm), colorCustom11, colorCustom12), styleArea|styleOwnScale,0,100);
_SECTION_END();
Buy=Cross(C,SAR(acc,accm));
Sell=Cross(SAR(acc,accm),C);
PlotShapes(IIf(Buy,shapeSmallUpTriangle,shapeNone),colorCustom11,0,L,-15);
PlotShapes(IIf(Sell,shapeSmallDownTriangle, shapeNone),colorCustom12,0,H,-15);
_SECTION_BEGIN("Zig_Zag_");
PercentChange = 4;
mystartbar = SelectedValue(BarIndex()); // FOR GRAPHING
mystartbardate = LastValue(ValueWhen(mystartbar == BarIndex(), DateNum(),1));
InitialValue = LastValue(ValueWhen(mystartbardate == DateNum(), C , 1 ) ) ;
ZZ = Zig(C,LastValue(PercentChange)) ;
PivotLow = Ref(IIf(Ref(ROC(ZZ,1),-1) < 0 AND ROC(ZZ,1) > 0, 1,Null),1);
PivotHigh = Ref(IIf(Ref(ROC(ZZ,1),-1) > 0 AND ROC(ZZ,1) < 0, 1,Null),1);
PlotShapes(IIf(ps,shapeDigit1 ,Null),colorYellow,0,L,-15);
PlotShapes(IIf(pr,shapeDigit1 ,Null),colorYellow,0,H,15);
_SECTION_BEGIN("ZigZag");
{ GfxSelectFont("Arial",13, 700 );
GfxSetBkMode(1);
GfxSetTextColor(colorGold);
GfxTextOut(" ZigZag="+WriteVal(ZZ,format=1.2)+"",100,20);
}
_SECTION_END();
_SECTION_BEGIN("Fibonacci And Gann Projections");
Change = 5;
GannIncrement = 0.0625;
procedure PlotShapeAt( x, y, shape, shift )
{
PlotShapes( IIf( BarIndex() == x, shape, 0 ), colorWhite, 0, y, shift );
}
procedure PlotBlueDot( x, y )
{
for( i = -2; i <= 2; i++ )
{
if( i != 0 )
{
yGann = ( sqrt( y ) + i * GannIncrement ) ^ 2;
}
}
}
bi = BarIndex();
sbi = SelectedValue( bi );
GraphXSpace = 2;
upshift =50;
if( SelectedValue( PeakBars( C, Change ) < TroughBars( C, Change ) ) )
{
pt1 = PeakBars( C, Change, 1 ) == 0 ;
pt2 = TroughBars( C, Change, 1 ) == 0 ;
}
else
{
pt1 = TroughBars( C, Change, 1 ) == 0 ;
pt2 = PeakBars( C, Change, 1 ) == 0 ;
upshift = -upshift;
}
bpt1 = SelectedValue( ValueWhen( pt1, bi ) );
bpt2 = SelectedValue( ValueWhen( pt2, bi ) );
bpt3 = SelectedValue( ValueWhen( pt1, bi, 2 ) );
bpt4 = SelectedValue( ValueWhen( pt2, bi, 2 ) );
bpt5 = SelectedValue( ValueWhen( pt1, bi, 3 ) );
bpt6 = SelectedValue( ValueWhen( pt2, bi, 3 ) );
PlotShapeAt( bpt1, C, shapeDigit1, upshift );
PlotShapeAt( bpt2, C, shapeDigit2, -upshift );
PlotShapeAt( bpt3, C, shapeDigit3, upshift );
PlotShapeAt( bpt4, C, shapeDigit4, -upshift );
PlotShapeAt( bpt5, C, shapeDigit5, upshift );
PlotShapeAt( bpt6, C, shapeDigit6, -upshift );
Level = SelectedValue( ValueWhen( pt1, C ) );
PlotBlueDot( round( bpt1 + 1.618 * ( bpt1 - bpt2 ) ), Level );
PlotBlueDot( round( bpt1 + 0.382 * ( bpt1 - bpt2 ) ), Level );
PlotBlueDot( round( bpt1 + 0.5 * ( bpt2 - bpt3 ) ), Level );
PlotBlueDot( round( bpt1 + 1.732 * ( bpt2 - bpt3 ) ), Level );
PlotBlueDot( round( bpt1 + 0.618 * ( bpt4 - bpt5 ) ), Level );
PlotBlueDot( round( bpt1 + 2 * ( bpt4 - bpt5 ) ), Level );
PlotBlueDot( round( bpt2 + 0.6707 * ( bpt4 - bpt2 ) ), Level );
PlotBlueDot( round( bpt2 + 2.618 * ( bpt4 - bpt2 ) ), Level );
PlotBlueDot( round( bpt2 + 1 * ( bpt6 - bpt2 ) ), Level );
PlotBlueDot( round( bpt2 + 3 * ( bpt6 - bpt2 ) ), Level );
_SECTION_END();
_SECTION_BEGIN("CE??CE?? ??C??E ?I??");
per1=Param ("per1", 0.1,0.1,50,0.10);
per=per1;
x = Cum(1);
s1=L;
s11=H;
pS = TroughBars( s1, per, 1 ) == 0;
endt= SelectedValue(ValueWhen( pS, x, 1 ));
startt=SelectedValue(ValueWhen( pS, x, 2 ));
dtS =endt-startt;
endS = SelectedValue(ValueWhen( pS, s1, 1 ) );
startS = SelectedValue( ValueWhen( pS, s1, 1 ));
aS = (endS-startS)/dtS;
bS = endS;
trendlineS = aS * ( x -endt ) + bS;
g3= IIf(x>startt-10,trendlineS,-1e10);
pR = PeakBars( s11, per, 1 ) == 0;
endt1= SelectedValue(ValueWhen( pR, x, 1 ));
startt1=SelectedValue(ValueWhen( pR, x, 2 ));
dtR =endt1-startt1;
endR = SelectedValue(ValueWhen( pR, s11, 1 ) );
startR = SelectedValue( ValueWhen( pR, s11, 1 ));
aR = (endR-startR)/dtR;
bR = endR;
trendlineR = aR * ( x -endt1 ) + bR;
g4= IIf(x>startT1-10,trendlineR,-1e10);
//////////////////////////////////////////////////////////////////////////////////////////////////
perc=per1;
x=BarIndex();xx=SelectedValue(x);
t1=SelectedValue(ValueWhen(PeakBars(C,perc)==0,x)) ;
H1=SelectedValue(ValueWhen(PeakBars(C,perc)==0,C)) ;
t11=SelectedValue(ValueWhen(TroughBars(C,perc)==0, x));
H11=SelectedValue(ValueWhen(TroughBars(C,perc)==0, C));
g=t1>t11;
PlotShapes(IIf(x==t1, shapeHollowDownArrow , shapeNone),colorRed, 0,High, Offset=-15);
PlotShapes(IIf(x ==t11,shapeHollowUpArrow , shapeNone),colorBrightGreen, 0, Low, Offset=-15);
_SECTION_BEGIN("Stochastic Slow");
SP = Param( "Periods", 5, 1, 200, 1 );
Ksmooth = Param( "%K avg", 3, 1, 200, 1 );
Dsmooth = Param( "%D avg", 3, 1, 200, 1 );
StochDval = StochD( SP , Ksmooth, DSmooth );
StochKval = StochK( SP , Ksmooth);
Dsmooth = Param( "%D avg", 3, 1, 200, 1 );
StochBuy = Cross(StochK(SP,Ksmooth), StochD(SP,Ksmooth, DSmooth)) AND
(StochD(SP,Ksmooth, DSmooth) > 20) AND (StochK(SP,Ksmooth) > 20) AND
(StochD(SP,Ksmooth, DSmooth) < 80) AND (StochK(SP,Ksmooth) < 80);
StochSell = Cross (StochD(SP,Ksmooth, DSmooth), StochK(SP,Ksmooth)) AND
(StochD(SP,Ksmooth, DSmooth) > 20) AND (StochK(SP,Ksmooth) > 20) AND
(StochD(SP,Ksmooth, DSmooth) < 80) AND (StochK(SP,Ksmooth) < 80);
StochStrongBuy = Cross(StochK(SP,Ksmooth),StochD(SP,Ksmooth, DSmooth)) AND
(StochD(SP,Ksmooth, DSmooth) < 20) AND (StochK(SP,Ksmooth) < 20) ;
StochStrongSell = Cross (StochD(SP,Ksmooth,DSmooth), StochK(SP , Ksmooth));
(StochD(SP,Ksmooth, DSmooth) > 80) AND (StochK(SP,Ksmooth) > 80);
//****************** BULLISH / BEARISH *******************/
StochBull = StochK(SP , Ksmooth)>StochD(SP , Ksmooth, DSmooth) AND
(StochD(SP,Ksmooth, DSmooth) > 20) AND (StochK(SP,Ksmooth) > 20) AND
(StochD(SP,Ksmooth, DSmooth) < 80) AND (StochK(SP,Ksmooth) < 80);
StochBear = StochK(SP , Ksmooth)<StochD(SP , Ksmooth, DSmooth)AND
(StochD(SP,Ksmooth, DSmooth) > 20) AND (StochK(SP,Ksmooth) > 20) AND
(StochD(SP,Ksmooth, DSmooth) < 80) AND (StochK(SP,Ksmooth) < 80);
StochOB = (StochD(SP,Ksmooth, DSmooth) > 80) AND (StochK(SP,Ksmooth) > 80);
StochOS = (StochD(SP,Ksmooth, DSmooth) < 20) AND (StochK(SP,Ksmooth) < 20) ;
GraphXSpace=Param("GraphXSpace",10,0,100,1);
dec = (Param("Decimals",2,0,7,1)/10)+1;
R = HHV(H,14);
S = LLV (L,14);
Title = EncodeColor(55)+ Title = Name() + " " + EncodeColor(32) + Date() +
" " + EncodeColor(5) + "{{INTERVAL}} " +
EncodeColor(55)+ " Open = "+ EncodeColor(52)+ WriteVal(O,dec) +
EncodeColor(55)+ " High = "+ EncodeColor(5) + WriteVal(H,dec) +
EncodeColor(55)+ " Low = "+ EncodeColor(32)+ WriteVal(L,dec) +
EncodeColor(55)+ " Close = "+ EncodeColor(7)+ WriteVal(C,dec)+
"\n"+
EncodeColor(55)+ " HHV(H,14) = "+ EncodeColor(11)+ WriteVal(R)+
EncodeColor(55)+ " LLV (L,14) = "+ EncodeColor(11)+ WriteVal(S)
+" @ " + EncodeColor(colorWhite)+ WriteIf(StochBuy,EncodeColor(colorBrightGreen)+"Buy stoch",WriteIf(StochSell,EncodeColor(colorRed)+"Sell stoch",
WriteIf(StochStrongBuy,EncodeColor(colorBrightGreen)+"Strong Buy stoch",WriteIf(StochStrongSell,EncodeColor(colorRed)+"Strong Sell stoch","Neutral"))))
+" @ " + "Stochastics Trend = "+WriteIf(StochBull,EncodeColor(colorBrightGreen)+"Bullish",WriteIf(StochBear,EncodeColor(colorRed)+"Bearish"
,WriteIf(StochOS,EncodeColor(colorBrightGreen)+"OverSold",WriteIf(StochOB,EncodeColor(colorRed)+"OverBrought","Neutral"))));
_SECTION_BEGIN("zzt");
para = ParamToggle("plot zz0","off,on");
cbar = Param("cbar",15,2,50,1);
per = Param("per",5,1,30,1);
zz0 = Zig(C,per);
zz1 = Ref( zz0, -1 );
zz2 = Ref( zz0, -2 );
tr = ValueWhen(zz0 > zz1 AND zz1 < zz2, zz1);
pk = ValueWhen(zz0 < zz1 AND zz1 > zz2, zz1);
pu = tr + 0.01 * abs(tr)*per;
pd = pk - 0.01 * abs(pk)*per;
zzt = IIf(C>= pu AND zz0 > zz1, 1,
IIf(C<= pd AND zz0 < zz1, -1, 0 ) );
zzt= ValueWhen( zzt != 0, zzt );
colorp2= IIf((C>O)OR(C<O),colorWhite,colorYellow);
Plot(IIf(para,zz0,Null)," ",colorWhite,styleLine|styleNoTitle);
pr=PeakBars(High,5)==0;
ps =TroughBars(Low,5)==0;
rf=ValueWhen(pr,High);
sf=ValueWhen(ps,Low);
rf1 = IIf(rf AND BarsSince(pr) <=cbar,rf,Null);
sf1 = IIf(sf AND BarsSince(ps ) <=cbar,sf,Null);
Plot(rf1,"",colorLightOrange,styleDots | styleNoLine|styleNoLabel);
Plot(sf1,"",colorLightOrange,styleDots | styleNoLine|styleNoLabel);
_SECTION_END();
numbars = SelectedValue(Cum(Status("barvisible")));
fraction= IIf(StrRight(Name(),3) == "",3.2,3.2);
hts = Param ("text shift", -50,-100,100,10);
PlotText("" + WriteVal(rf,fraction),
SelectedValue(BarIndex()+6)-(numbars/hts),SelectedValue(rf),colorWhite,colorOrange);
PlotText("" + WriteVal(sf,fraction),
SelectedValue(BarIndex()+6)-(numbars/hts),SelectedValue(sf),colorWhite,colorOrange);
_SECTION_END();
Plot( Open, "open", 0, stylehidden| styleNoTitle );
Plot(Close, "close", 0, stylehidden| styleNoTitle );
Plot(High, "high", 0, stylehidden| styleNoTitle );
Plot(Low, "low", 0, stylehidden| styleNoTitle );
numbars = SelectedValue(Cum(Status("barvisible")));
fraction= IIf(StrRight(Name(),3) == "",3.2,3.2);
hts = Param ("text shift", -50,-100,100,10);
_SECTION_END();
_SECTION_BEGIN("MotheCandle");
Mothc=Ref(H,-1)>H AND Ref(L,-1)<L;
y0 = StrToNum(NumToStr(ValueWhen(Mothc, Ref(L,-1))));
TDL = LineArray(0, y0, (BarCount-1), y0);
Plot(TDL, "", colorGold,styleDashed|styleNoLabel);
y0 = StrToNum(NumToStr(ValueWhen(Mothc, Ref(H,-1))));
TDH= LineArray(0, y0, (BarCount-1), y0);
PlotShapes(shapeSmallCircle*(Ref(Mothc,1)), colorGold,0,H,5);
PlotShapes(shapeSmallCircle*(Ref(Mothc,1)),colorGold,0,L,-5);
Plot(TDH, "", colorCustom12,styleDashed|styleNoLabel);
numbars = SelectedValue(Cum(Status("barvisible")));
fraction= IIf(StrRight(Name(),3) == "",3.2,3.2);
hts = Param ("Text Shift", -50,-100,100,10);
PlotText("" + WriteVal(TDH,fraction),
SelectedValue(BarIndex()+5)-(numbars/hts),SelectedValue(TDH),colorBlack,colorCustom12);
PlotText("" + WriteVal(TDL,fraction),
SelectedValue(BarIndex()+5)-(numbars/hts),SelectedValue(TDL),colorBlack,colorGold);
_SECTION_END();
_SECTION_BEGIN("AuthorName");
k = (GetPerformanceCounter()/100)%100;
printf("GetPerformance Counter %g",k);
GfxSelectFont("ARIAL", 12,800);
GfxSetBkMode(1);
GfxSetTextColor(colorGold);
GfxTextOut("MotherCandle",450,20);
RequestTimedRefresh(10);
_SECTION_END();
_SECTION_BEGIN("WMA 50");
slope = Param("slope",2,2,100,1);
Color20= IIf(LinRegSlope(WMA(C,50),slope)<0,colorCustom13,colorCustom13);
event1= LinRegSlope(WMA(C,50),slope)<1;
Plot( WMA( C,50), "",Color20,styleNoLine|styleNoLabel);
_SECTION_END();
_SECTION_BEGIN("WMA 50");
{ GfxSelectFont("ARIAL",12, 800 );
GfxSetBkMode(1);
GfxSetTextColor(colorCustom13);
GfxTextOut("MA50="+WMA( C,50),250,20);
}
_SECTION_END();
_SECTION_BEGIN("Auto trend line Trendline");
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
THIS SECTION DRAWS TD TREND LINES */
percent = 0.01 * 1;
firstpointL = 2;
firstpointH = 2;
y0=LastValue(Trough(L,percent,firstpointL));
y1=LastValue(Trough(Ref(L,-1),percent,1));
for( i = 1; i < BarCount AND y0 >= y1; i++ )
{
firstpointL++;
y0=LastValue(Trough(L,percent,firstpointL));
}
x0=BarCount - 1 - LastValue(TroughBars(L,percent,firstpointL));
x1=BarCount - 1 - LastValue(TroughBars(Ref(L,-1),percent,1));
LineL = LineArray( x0, y0, x1, y1, 1 );
/*
Plot(C, "C", colorBlack, styleCandle);
*/
Plot( LineL, " Support Trend line", colorBlueGrey,4 +8 );
yt0=LastValue(Peak(H,percent,firstpointH));
yt1=LastValue(Peak(Ref(H,-1),percent,1));
for(i = 1; i < BarCount AND yt0 <= yt1; i++ )
{
firstpointH++;
yt0=LastValue(Peak(H,percent,firstpointH));
}
xt0=BarCount - 1 - LastValue(PeakBars(H,percent,firstpointH));
xt1=BarCount - 1 - LastValue(PeakBars(Ref(H,-1),percent,1));
LineH = LineArray( xt0, yt0, xt1, yt1, 1 );
Plot( lineH, "resistance trend line", colorOrange,4 + 8 );
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
_SECTION_END();
Buy=Cross(C,lineh);
Sell=Cross( linel,C);
PlotShapes(IIf(Buy,shapeSmallUpTriangle,shapeNone),colorOrange,0,C,-25);
PlotShapes(IIf(Sell,shapeSmallDownTriangle, shapeNone),colorBlueGrey,0,C,-25);
PlotShapes(IIf(Buy,shapeHollowCircle, shapeNone),colorOrange, 0,C,0);
PlotShapes(IIf(Sell,shapeHollowCircle, shapeNone),colorWhite, 0,C,0);
Plot(Buy,"",colorOrange,styleDashed|styleHistogram|styleOwnScale|styleNoLabel,0,1,0,0);
Plot(Sell,"",colorBlueGrey,styleDashed|styleHistogram|styleOwnScale|styleNoLabel,0,1,0,0);
Filter=Close;
AddColumn(IIf(Sell,C,Null),"sell",1.4,colorBlack);
AddColumn(IIf(Buy,C,Null),"buy",1.4,colorBlue);
_SECTION_END();
_SECTION_BEGIN("Pivot_Finder");
/* **********************************
Code to automatically identify pivots
********************************** */
// -- what will be our lookback range for the hh and ll?
farback=Param("How Far back to go",100,0,5000,10);
nBars = Param("Number of bars", 8, 5, 40);
// -- 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, shapeSmallDownTriangle, shapeNone), colorRed, 0, High, Offset=-25);
PlotShapes(IIf(aLPivs==1, shapeSmallUpTriangle , shapeNone), colorBrightGreen, 0, Low, Offset=-25);
//////////////////////////////////////////////////////////////////////////////
/* **********************************
Code to automatically identify pivots
********************************** */
// -- what will be our lookback range for the hh and ll?
farback=Param("How Far back to go",100,12,30,1);
nBars = Param("Number of bars", 8, 1, 30, 1);
// -- 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, shapeHollowSmallDownTriangle, shapeNone), colorOrange, 0, High, Offset=-15);
PlotShapes(IIf(aLPivs==1, shapeHollowSmallUpTriangle , shapeNone), colorWhite, 0, Low, Offset=-15);
Sell = aHPivs == 1 ;
Buy = aLPivs == 1 ;
Filter=Buy OR Sell;
Sell=ExRem(Sell,Buy);
Buy=ExRem(Buy,Sell);
_SECTION_END();
// Linear Regression Line with 2 Standard Deviation Channels Plotted Above and Below
// Written by Patrick Hargus, with critical hints from Marcin Gorzynski, Amibroker.com Technical Support
// Designed for use with AB 4.63 beta and above, using drag and drop feature.
// Permits plotting a linear regression line of any price field available on the chart for a period determined by the user.
// 2 Channels, based on a standard deviation each determined by the user, are plotted above and below the linear regression line.
// A look back feature is also provided for examining how the indicator would have appeared on a chart X periods in the past.
P = ParamField("Price field",-1);
Daysback = Param("Period for Liner Regression Line",21,1,240,1);
shift = Param("Look back period",0,0,240,1);
// =============================== Math Formula =============================================================
x = Cum(1);
lastx = LastValue( x ) - shift;
aa = LastValue( Ref(LinRegIntercept( p, Daysback), -shift) );
bb = LastValue( Ref(LinRegSlope( p, Daysback ), -shift) );
y = Aa + bb * ( x - (Lastx - DaysBack +1 ) );
// ==================Plot the Linear Regression Line ==========================================================
LRColor = ParamColor("LR Color", colorCycle );
LRStyle = ParamStyle("LR Style");
LRLine = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y, Null );
Plot( LRLine , "LinReg", LRCOLOR, styleLine+styleThick|styleNoTitle ); // styleDots );
// ========================== Plot 1st SD Channel ===============================================================
SDP = Param("Standard Deviation", 1.5, 0, 6, 0.1);
SD = SDP/2;
width = LastValue( Ref(SD*StDev(p, Daysback),-shift) ); // THIS IS WHERE THE WIDTH OF THE CHANELS IS SET
SDU = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y+width , Null ) ;
SDL = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y-width , Null ) ;
SDColor = ParamColor("SD Color", colorCycle );
SDStyle = ParamStyle("SD Style");
Plot( SDU , "Upper Lin Reg", SDColor,SDStyle|styleNoTitle );
Plot( SDL , "Lower Lin Reg", SDColor,SDStyle |styleNoTitle);
// ========================== Plot 2d SD Channel ===============================================================
SDP2 = Param("2d Standard Deviation", 2.0, 0, 6, 0.1);
SD2 = SDP2/2;
width2 = LastValue( Ref(SD2*StDev(p, Daysback),-shift) ); // THIS IS WHERE THE WIDTH OF THE CHANELS IS SET
SDU2 = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y+width2 , Null ) ;
SDL2 = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y-width2 , Null ) ;
SDColor2 = ParamColor("2 SD Color", colorCycle );
SDStyle2 = ParamStyle("2 SD Style");
Plot( SDU2 , "Upper Lin Reg", SDColor2,SDStyle2|styleNoTitle );
Plot( SDL2 , "Lower Lin Reg", SDColor2,SDStyle2|styleNoTitle );
// ============================ End Indicator Code ==============================================================
PlotOHLC( O, SDU, SDL,C , _DEFAULT_NAME(), ColorRGB(56,63,118), styleCloud|styleNoLabel );
_SECTION_END();
_SECTION_BEGIN("td fractl line");
strength = Param("strength",1,1,15,1);
pr=PeakBars(RSI(14),strength)==0;
_SECTION_END();
_SECTION_BEGIN("td fractl line");
ps =TroughBars(RSI(14),strength)==0;
_SECTION_END();
_SECTION_BEGIN("price risistance");
rt=SelectedValue(ValueWhen(pr,H));
st=SelectedValue(ValueWhen(ps,L));
_SECTION_BEGIN("td fractl line");
pr=PeakBars(RSI(14),strength)==0;
pivothigh = Ref(pr,-1)<pr AND pr>Ref(pr,1);
y0=SelectedValue(ValueWhen(pivothigh,H,2));
y1=SelectedValue(ValueWhen(pivothigh,H,1));
x0=SelectedValue(ValueWhen(pivothigh,Cum( 1)-1,2));
x1=SelectedValue(ValueWhen(pivothigh,Cum( 1)-1,1));
linea=LineArray(x0,y0,x1,y1,1);
_SECTION_END();
_SECTION_BEGIN("td fractl line");
ps =TroughBars(RSI(14),strength)==0;
pivotlow = Ref(ps,-1)<ps AND ps>Ref(ps,1);
yt0=SelectedValue(ValueWhen(pivotlow,L,2));
yt1=SelectedValue(ValueWhen(pivotlow,L,1));
xt0=SelectedValue(ValueWhen(pivotlow,Cum( 1)-1,2));
xt1=SelectedValue(ValueWhen(pivotlow,Cum( 1)-1,1));
lineb=LineArray(xt0,yt0,xt1,yt1,1);
_SECTION_END();
_SECTION_BEGIN("ema1");
p = ParamField("price field",-1);
_SECTION_END();
pi = atan(1.00) * 4;
periods = 30;
highhigh = HHV(H, periods);
lowlow = LLV(L, periods);
range = 25 / (highhigh - lowlow) * lowlow;
ma1= MA(C,100);
x1_ma = 0;
x2_ma= 1;
y1_ma= 0;
y2_ma= (Ref(ma1, -1) - ma1) / Avg * range;
c_ma= sqrt((x2_ma- x1_ma)*(x2_ma- x1_ma) + (y2_ma- y1_ma)*(y2_ma- y1_ma));
angle_ma= round(180 * acos((x2_ma - x1_ma)/c_ma) / pi);
angle_ma= IIf(y2_ma> 0, -angle_ma, angle_ma);
col=IIf(angle_ma>3,colorYellow,IIf(angle_ma<(-3),colorRed,colorCustom12));
buy1=Cross(C,linea) AND RSI(14)>60 AND angle_ma>=1;
buy2=Cross(C,rt)AND RSI(14)>60 AND angle_ma>=1;Buy=buy1 OR buy2;
sell1=Cross(lineb,C)AND RSI(14)<40 AND angle_ma<=(-1);
sell2=Cross(rt,C)AND RSI(14)<40 AND angle_ma<=(-1);Sell=sell1 OR sell2;
_SECTION_BEGIN("t trend");
{ GfxSelectFont("Arial",12, 800 );
GfxSetBkMode(1);
GfxSetTextColor(colorRed);
GfxTextOut("RSI="+WriteVal(RSI(14),format=1.2)+" ",750,20);
}
_SECTION_END();
_SECTION_BEGIN("t trend");
{ GfxSelectFont("Arial",13, 800 );
GfxSetBkMode(1);
GfxSetTextColor(colorCustom11);
GfxTextOut("angle="+angle_ma+"% ",600,20);
}
_SECTION_END();
r=MFI(14);
_SECTION_BEGIN("WRSI");
k = (GetPerformanceCounter()/100)%100;
{ GfxSelectFont("ARIAL",12, 800 );
GfxSetBkMode(1);
GfxSetTextColor(colorYellow);
GfxTextOut("MFI="+WriteVal(r,format=1.2)+" ",970,1);
}
_SECTION_END();
_SECTION_BEGIN("MACD");
r1 = Param("Fast avg", 14, 2, 200, 1);
r2 = Param("Slow avg", 26, 2, 200, 1);
r3 = Param("Signal avg", 9, 2, 200, 1);
m1 = MACD(r1,r2);
s1 = Signal(r1,r2,r3);
_SECTION_END();
//Hook Bullish
Z= Cross(C, EMA(C,5))AND RSI(9)>30;
//Bearish Bullish
t= Cross(EMA(C,5), C)AND RSI(9)<70;
// Histogram
pt = m1-s1;
Tp = Ref(pT,-1) == HHV(pT,3);
Vl = Ref(pT,-1) == LLV(pT,3);
//ADX related calculations
plus = EMA(PDI(14),3)>Ref(EMA(PDI(14),3),-5);
ap = EMA(ADX(14),3)>Ref(EMA(ADX(14),3),-5);
Minus = EMA(MDI(14),3)>Ref(EMA(MDI(14),3),-5);
//Power Dips - Bullish
PDIp = ADX(14)>MDI(14) AND PDI(14)>MDI(14) AND ap AND Vl AND m1>s1 AND plus;
//Power Dips - Bearish
PDIm = ADX(14)>PDI(14) AND MDI(14)>PDI(14) AND ap AND Tp AND m1<s1 AND Minus;
Title = "waleed"+ " @ " + Interval(2) + EncodeColor() + " - " + Date() +" - "
+"\n\n\n\n"+EncodeColor(colorBrightGreen)+
WriteIf (PDIP, " Bullish Power Dip","")+
WriteIf (PDIm, " Bearish Power Dip","")+
WriteIf (z, " Bullish hook","")+
WriteIf (t, " Bearish hook","");
_SECTION_END();