Access to Professionalism in amibroker afl

#3
_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();
 

nac

Well-Known Member
#4
Plot(Buy,"",colorOrange,styleDashed|styleHistogram |styleOwnScale|styleNoLabel,0,1,0,0);
Plot(Sell,"",colorBlueGrey,styleDashed|styleHistogram|styleOwnScale|styleNoLabel,0,1,0,0);
Error in ln 533, col 86 : Error 16. Too many arguments
Error in ln 534, col 88 : Error 16. Too many arguments
 
#10
good indicator



_SECTION_BEGIN("cncp");
cd1=-(O-C)/(H-L)*100;
cd=Prec((cd1),2);
colore=IIf(cd>=68,colorYellow,IIf(cd<=-68,colorRed,colorCustom12));
_SECTION_END();
_SECTION_BEGIN("price");
barcolor = IIf((cd>=68)OR (cd<=-68),colorBrightGreen,colorBrightGreen);
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("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 );

_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("basicCandle");
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()+1)-(numbars/hts),SelectedValue(TDH),colorCustom12);
PlotText("" + WriteVal(TDL,fraction),
SelectedValue(BarIndex()+1)-(numbars/hts),SelectedValue(TDL),colorGold);
_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)+"% ",720,1);
GfxSetTextColor(colorWhite);

}
_SECTION_END();

_SECTION_BEGIN(" A/D");
SS=( ( ( ( C - L ) - ( H - C ) ) / (H - L) ) * V);
SS1=SS/10000000;
_SECTION_BEGIN(" A/D");
{ GfxSelectFont("Arial",12, 700 );
GfxSetBkMode(1);
GfxSetTextColor(colorCustom12);
GfxTextOut("A/D="+WriteVal(SS1,format=1.2)+" ",940,20);
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)+"% ",840,1);
}
_SECTION_END();






_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(PivotLow, shapeDigit1, shapeNone),colorYellow, 0,L, Offset=-15);

PlotShapes(IIf(PivotHigh, shapeDigit1, shapeNone),colorYellow, 0,H, Offset=15);







_SECTION_BEGIN("Fibonacci And Gann Projections");
Change = 5;
GannIncrement = 0.0625;
procedure PlotShapeAt( x, y, shape, shift )
{
PlotShapes( IIf( BarIndex() == x, shape, 0 ), colorRed, 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 =45;
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=-5);


PlotShapes(IIf(x ==t11,shapeHollowUpArrow , shapeNone),colorBrightGreen, 0, Low, Offset=-5);






_SECTION_BEGIN("zzt");
para = ParamToggle("plot zz0","off,on");
cbar = Param("cbar",10,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,2)==0;
ps =TroughBars(Low,2)==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,"",colorWhite,styleDots | styleNoLine|styleNoLabel);
Plot(sf1,"",colorWhite,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("zig zag signal");


min_thold=0.025;
thold=Max(min_thold,Median(ln(HHV(H,2)/LLV(L,2)),100));
thold=IIf(IsEmpty(thold),min_thold,thold);



t=Param("significance",2,2,6,1);

// initialization of variables

d=init=trig=HH=LL=z=0;



for(i=1;i<BarCount;i++){
if (log(H/L[init])>HH) HH=log(H/L[init]);
if (log(L/H[init])<LL) LL=log(L/H[init]);
if (HH>(t*thold[init]) && d<=0)
{ z[init]--; trig=-0.5; d=1;init=i;HH=0;LL=0; }

if (H>H[init] && d==1){init=i;LL=0;}

if (LL<(-t*thold[init]) && d>=0)
{ z[init]++; trig=0.5; d=-1;init=i;HH=0;LL=0; }

if (L<L[init] && d==-1){init=i;HH=0;}
}

z_up=z>0; z_dn=z<0;



Buy1=z<0;

Buy=Buy1 ;
Sell1=z>0;

Sell=Sell1 ;




_SECTION_END();












_SECTION_BEGIN("Pivot finder");
nBars = Param("Number of bars", 8, 5, 40);
bShowTCZ = Param("Show TCZ", 1, 0, 1);
nExploreBarIdx = 0;
nExploreDate = 0;
nCurDateNum = 0;
DN = DateNum();
DT = DateTime();
bTCZLong = False;
bTCZShort = False;
nAnchorPivIdx = 0;
ADX8 = ADX(8);
if(Status("action")==1) {
bDraw = True;
bUseLastVis = 1;
} else {
bDraw = False;
bUseLastVis = False;
bTrace = 1;
nExploreDate = Status("rangetodate");
for (i=LastValue(BarIndex());i>=0;i--) {
nCurDateNum = DN;
if (nCurDateNum == nExploreDate) {
nExploreBarIdx = i;
}
}
}
GraphXSpace=7;
if (bDraw) {
}
aHPivs = H - H;
aLPivs = L - L;
aHPivHighs = H - H;
aLPivLows = L - L;
aHPivIdxs = H - H;
aLPivIdxs = L - L;
aAddedHPivs = H - H;
aAddedLPivs = L - L;
aLegVol = H - H;
aRetrcVol = H - H;
nHPivs = 0;
nLPivs = 0;
lastHPIdx = 0;
lastLPIdx = 0;
lastHPH = 0;
lastLPL = 0;
curPivBarIdx = 0;
aHHVBars = HHVBars(H, nBars);
aLLVBars = LLVBars(L, nBars);
aHHV = HHV(H, nBars);
aLLV = LLV(L, nBars);
nLastVisBar = LastValue(
Highest(IIf(Status("barvisible"), BarIndex(), 0)));
curBar = IIf(nlastVisBar > 0 AND bUseLastVis, nlastVisBar,
IIf(Status("action")==4 AND nExploreBarIdx > 0, nExploreBarIdx,
LastValue(BarIndex())));
curTrend = "";
if (aLLVBars[curBar] < aHHVBars[curBar])
curTrend = "D";
else
curTrend = "U";
if (curBar >= 120) {
for (i=0; i<120; i++) {
curBar = IIf(nlastVisBar > 0 AND bUseLastVis,
nlastVisBar-i,
IIf(Status("action")==4 AND nExploreBarIdx > 0,
nExploreBarIdx-i,
LastValue(BarIndex())-i));
if (aLLVBars[curBar] < aHHVBars[curBar]) {
if (curTrend == "U") {
curTrend = "D";
curPivBarIdx = curBar - aLLVBars[curBar];
aLPivs[curPivBarIdx] = 1;
aLPivLows[nLPivs] = L[curPivBarIdx];
aLPivIdxs[nLPivs] = curPivBarIdx;
nLPivs++;
}
} else {
if (curTrend == "D") {
curTrend = "U";
curPivBarIdx = curBar - aHHVBars[curBar];
aHPivs[curPivBarIdx] = 1;
aHPivHighs[nHPivs] = H[curPivBarIdx];
aHPivIdxs[nHPivs] = curPivBarIdx;
nHPivs++;
}
}
}
}
curBar =
IIf(nlastVisBar > 0 AND bUseLastVis,
nlastVisBar,
IIf(Status("action")==4 AND nExploreBarIdx > 0,
nExploreBarIdx,
LastValue(BarIndex()))
);
if (nHPivs >= 2 AND nLPivs >= 2) {
lastLPIdx = aLPivIdxs[0];
lastLPL = aLPivLows[0];
lastHPIdx = aHPivIdxs[0];
lastHPH = aHPivHighs[0];
nLastHOrLPivIdx = Max(lastLPIdx, lastHPIdx);
nAddPivsRng = curBar - nLastHOrLPivIdx;
aLLVAfterLastPiv = LLV(L, nAddPivsRng);
nLLVAfterLastPiv = aLLVAfterLastPiv[curBar];
aLLVIdxAfterLastPiv = LLVBars(L, nAddPivsRng);
nLLVIdxAfterLastPiv = curBar - aLLVIdxAfterLastPiv[curBar];
aHHVAfterLastPiv = HHV(H, nAddPivsRng);
nHHVAfterLastPiv = aHHVAfterLastPiv[curBar];
aHHVIdxAfterLastPiv = HHVBars(H, nAddPivsRng);
nHHVIdxAfterLastPiv = curBar - aHHVIdxAfterLastPiv[curBar];
if (lastHPIdx > lastLPIdx) {
/* There are at least two possibilities here. One is that
the previous high was higher, indicating that this is a
possible short retracement or one in the making.
The other is that the previous high was lower, indicating
that this is a possible long retracement in the working.
However, both depend on opposing pivots. E.g., if I find
higher highs, what if I have lower lows?
If the highs are descending, then I can consider:
- a lower low, and leave it at that
- a higher high and higher low
- a lower low and another lower high
*/
if (aHPivHighs[0] < aHPivHighs[1]) {
if (nLLVAfterLastPiv < aLPivLows[0] AND
(nLLVIdxAfterLastPiv - lastHPIdx - 1) >= 1
AND nLLVIdxAfterLastPiv != curBar ) {
// -- OK, we'll add this as a pivot.
// Mark it for plotting...
aLPivs[nLLVIdxAfterLastPiv] = 1;
aAddedLPivs[nLLVIdxAfterLastPiv] = 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] = nLLVAfterLastPiv;
aLPivIdxs[0] = nLLVIdxAfterLastPiv;
nLPivs++;
// -- Test whether to add piv given last piv is high
// AND we have lower highs
}
// -- Here, the last piv is a high piv, and we have
// higher-highs. The most likely addition is a
// Low piv that is a retracement.
} else {
if (nLLVAfterLastPiv > aLPivLows[0] AND
(nLLVIdxAfterLastPiv - lastHPIdx - 1) >= 1
AND nLLVIdxAfterLastPiv != curBar ) {
// -- OK, we'll add this as a pivot.
// Mark it for plotting...
aLPivs[nLLVIdxAfterLastPiv] = 1;
aAddedLPivs[nLLVIdxAfterLastPiv] = 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] = nLLVAfterLastPiv;
aLPivIdxs[0] = nLLVIdxAfterLastPiv;
nLPivs++;
// -- Test whether to add piv given last piv is high
// AND we have lower highs
}
// -- The last piv is a high and we have higher highs
// OR lower highs
}
/* ****************************************************************
Still finding missed pivot(s). Here, the last piv is a low piv.
**************************************************************** */
} else {
// -- First case, lower highs
if (aHPivHighs[0] < aHPivHighs[1]) {
if (nHHVAfterLastPiv < aHPivHighs[0] AND
(nHHVIdxAfterLastPiv - lastLPIdx - 1) >= 1
AND nHHVIdxAfterLastPiv != curBar ) {
// -- OK, we'll add this as a pivot.
// Mark that for plotting
aHPivs[nHHVIdxAfterLastPiv] = 1;
aAddedHPivs[nHHVIdxAfterLastPiv] = 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] = nHHVAfterLastPiv;
aHPivIdxs[0] = nHHVIdxAfterLastPiv;
nHPivs++;
// -- Test whether to add piv given last piv is high
// AND we have lower highs
}
// -- Second case when last piv is a low piv, higher highs
// Most likely addition is high piv that is a retracement.
// Considering adding a high piv as long as it is higher
} else {
// -- Where I have higher highs,
if (nHHVAfterLastPiv > aHPivHighs[0] AND
(nHHVIdxAfterLastPiv - lastLPIdx - 1) >= 1
AND nHHVIdxAfterLastPiv != curBar ) {
// -- OK, we'll add this as a pivot.
// Mark it for plotting...
aHPivs[nHHVIdxAfterLastPiv] = 1;
aAddedHPivs[nHHVIdxAfterLastPiv] = 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] = nHHVAfterLastPiv;
aHPivIdxs[0] = nHHVIdxAfterLastPiv;
nHPivs++;
// -- Test whether to add piv given last piv is high
// AND we have lower highs
}
}
}
// -- If there are at least two of each
}
/* ****************************************

/* ****************************************
// -- Done with finding pivots
***************************************** */
if (bDraw) {
PivotEntry = ParamColor( "Entry Color", colorBrightGreen );
PivotEntry2 = ParamColor( "Entry Color2", colorYellow );
PivotExit = ParamColor( "Exit Color", colorRed );
PivotExit2 = ParamColor( "Exit Color2", colorYellow );
// -- OK, let's plot the pivots using arrows
PlotShapes(
IIf(aHPivs==1, shapeSmallDownTriangle, shapeNone),
PivotExit, 0, High, Offset=-15);
PlotShapes(
IIf(aAddedHPivs==1, shapeSmallDownTriangle, shapeNone),
PivotExit2, 0, High, Offset=-15);
PlotShapes(
IIf(aLPivs==1, shapeSmallUpTriangle , shapeNone),
PivotEntry, 0, Low, Offset=-15);
PlotShapes(
IIf(aAddedLPivs==1, shapeSmallUpTriangle , shapeNone),
PivotEntry2, 0, Low, Offset=-15);
PlotShapes(
IIf(aHPivs==1, shapeSmallDownTriangle, shapeNone),
colorOrange, 0, High, Offset=-25);
PlotShapes(
IIf(aAddedHPivs==1, shapeSmallDownTriangle, shapeNone),
colorCustom12, 0, High, Offset=-25);
PlotShapes(
IIf(aLPivs==1, shapeSmallUpTriangle , shapeNone),
colorWhite, 0, Low, Offset=-25);
PlotShapes(
IIf(aAddedLPivs==1, shapeSmallUpTriangle , shapeNone),
colorGreen, 0, Low, Offset=-25);
}

_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= EMA(C,200);
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> 3, -angle_ma, angle_ma);
col=IIf(angle_ma>3,colorDarkGreen,IIf(angle_ma<(-3),colorRed,colorPink));
Plot(EMA( p,200), _DEFAULT_NAME(), col, styleDots );
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;
PlotShapes(IIf(Buy,shapeSmallUpTriangle,shapeNone),colorBlue,0,L,-20);
PlotShapes(IIf(Sell,shapeSmallDownTriangle, shapeNone),colorYellow,0,H,-20);

if (SelectedValue(Buy)==1) Say("super move");
if (SelectedValue(Sell)==1) Say("weake move");
_SECTION_BEGIN("exploration");
Filter=Close;
var = WriteIf(Buy,"buy",WriteIf(Sell,"sell",""));
AddTextColumn( var , "buy/sell", 1.2 , colorWhite, IIf( Buy, colorBlue,IIf(Sell,colorRed,colorWhite) ));
AddColumn(angle_ma,"angle",1.4,colorBlue);
_SECTION_END();

_SECTION_BEGIN("t trend");
{ GfxSelectFont("Arial",12, 800 );
GfxSetBkMode(1);
GfxSetTextColor(colorWhite);
GfxTextOut("RSI="+WriteVal(RSI(14),format=1.2)+" ",720,20);
}
_SECTION_END();

_SECTION_BEGIN("t trend");
{ GfxSelectFont("Arial",13, 800 );
GfxSetBkMode(1);
GfxSetTextColor(colorCustom11);
GfxTextOut("angle="+angle_ma+"% ",840,20);
}


_SECTION_END();







_SECTION_END();

SS1=MFI(14);
SS=Prec(SS1,2);

_SECTION_BEGIN("Exploration");
Filter=Close;
AddColumn(SS,"Monentume",1.4,colorBlue);
_SECTION_END();

_SECTION_BEGIN("WRSI");
k = (GetPerformanceCounter()/100)%100;
{ GfxSelectFont("ARIAL",12, 800 );
GfxSetBkMode(1);
GfxSetTextColor(colorYellow);

GfxTextOut("MFI="+WriteVal(SS-Ref(MFI(14),-1),format=1.2)+" ",940,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;

//Bullish Crossed up above zero
j1 = Cross(m1,s1)AND m1>0;


// Bullish crossover up below zero
j2 = Cross(m1,s1)AND m1<0 ;


//Bearish Crossed down below Zero
j3 = Cross(s1,m1) AND m1>0;


// Bearish crossover down above zero
j4 = Cross(s1,m1)AND m1<0;

GraphXSpace=Param("GraphXSpace",10,0,100,1);
dec = (Param("Decimals",2,0,7,1)/10)+1;

Title = EncodeColor(55)+ Title = Name() + " " + EncodeColor(32) + Date() +
" "+ EncodeColor(5) + "{{INTERVAL}} " +

"\n\n\n"+EncodeColor(colorBrightGreen)+
WriteIf (PDIP, " @Bullish Power Dip","")+EncodeColor(colorRed)+
WriteIf (PDIm, " @Bearish Power Dip","")+EncodeColor(colorBrightGreen)+
WriteIf (z, " @Bullish hook","")+EncodeColor(colorRed)+
WriteIf (t, " @Bearish hook","")+EncodeColor(colorBrightGreen)+
WriteIf (Vl AND m1>s1, "@Histogram peak","")+EncodeColor(colorRed)+
WriteIf (Tp AND m1<s1, " @Histogram troughs","")+EncodeColor(colorBrightGreen)+
WriteIf (j1, " @Bullish Crossed up above zero","")+EncodeColor(colorBrightGreen)+
WriteIf (j2, " @Bullish crossover up below zero","")+EncodeColor(colorRed)+
WriteIf (j4, "@Bearish Crossed down below Zero","")+EncodeColor(colorRed)+
WriteIf (j3, " @Bearish crossover down above zero","")+"\n"+EncodeColor(colorCustom11)+
WriteIf (Cross(C,SAR(acc,accm)), "@ BUY SAR","")+EncodeColor(colorCustom12)+
WriteIf (Cross(SAR(acc,accm),C), "@ SELL SAR","")+EncodeColor(colorYellow)+
WriteIf (ps, "@ BUY MACD","")+EncodeColor(colorYellow)+
WriteIf (pr, "@ SELL MACD","")+EncodeColor(colorGold)+
WriteIf (aLPivs==1, "@ BUY Pivot_Finder","")+"\n"+EncodeColor(colorGold)+
WriteIf (aHPivs==1, "@ SELL Pivot_Finder","")+EncodeColor(colorOrange)+
WriteIf (z_up, "@ start down trend","")+"\n"+EncodeColor(colorYellow)+
WriteIf (-z_dn, "@ start up trend ","");
_SECTION_END();


_SECTION_BEGIN("EMA Time Frame");
r= RSI(14);
pR=PeakBars(RSI(14),1)==0;
pivothigh = Ref(pR,-1)<pR AND pR>Ref(pR,1);
y0=SelectedValue(ValueWhen(pivothigh,RSI(14),2));
y1=SelectedValue(ValueWhen(pivothigh,RSI(14),1));
x0=SelectedValue(ValueWhen(pivothigh,Cum( 1)-1,2));
x1=SelectedValue(ValueWhen(pivothigh,Cum( 1)-1,1));
LineA=LineArray(x0,y0,x1,y1,1);
pS =TroughBars(RSI(14),1)==0;
pivotlow = Ref(pS,-1)<pS AND pS>Ref(pS,1);
yt0=SelectedValue(ValueWhen(pivotlow,RSI(14),2));
yt1=SelectedValue(ValueWhen(pivotlow,RSI(14),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_BEGIN("DIV");
u00=LastValue(Peak(H,1,2));
u11=LastValue(Peak(H,1,1));
a00=BarCount - 1 - LastValue(PeakBars(H,1,2));
price_start1=Close[a00];
a11=BarCount - 1 - LastValue(PeakBars(H,1,1));
price_end1=Close[a11];
Line = LineArray(a00,u00,a11,u11, 0 );
LastPointSell = LineArray(a11-1,u11-1,a11,u11,0);

GG=u11<u00 AND price_end1>price_start1;
PlotShapes(shapeSmallCircle*GG ,colorDarkRed,0,Line,-2);




_SECTION_END();

_SECTION_BEGIN("DIV");
u0=LastValue(Trough(L,1,2));
u1=LastValue(Trough(L,1,1));
a0=BarCount - 1 - LastValue(TroughBars(L,1,2));
price_start=Close[a0];
a1=BarCount - 1 - LastValue(TroughBars(L,1,1));
price_end=Close[a1];
Line = LineArray(a0,u0,a1,u1, 0 );

TT=u1>u0 AND price_end<price_start;
LastPointBuy = LineArray(a1-1,u1-1,a1,u1,0);
PlotShapes(shapeSmallCircle*TT,colorDarkRed,0,Line,-2);
Filter=Close;
AddColumn(GG , "NEG.DIV",1.2,colorRed);
AddColumn(TT , "POS.DIV",1.2,colorBlue);

_SECTION_END();


_SECTION_BEGIN("Target&Trail SL");

SetChartOptions(0, chartShowDates | chartWrapTitle);

Type = ParamList("Average Type", "Wilders");
P = Param("Averaging Period", 20, 3, 100,1);
Q = Param("%Change", 1, 0.1, 10, 0.1);
BP = Param("BB Period", 20, 3, 100);
BW = Param("BB Width", 2, 0.5, 10, 0.5);
BBOption = ParamToggle("Plot BB", "No I Yes");

A=Param( "Swing", 20, 1, 100);
SL = Max(LLV(L, 5), Trough(L, Q, 1));

Tgt = 2 * H - SL;
MeanPrice = Prec((O + C) / 2, 2);

Part = 100 * (H - A) / (H - L);

BBTop = BBandTop(C, BP, BW);
BBBot = BBandBot(C, BP, BW);

res=HHV(H,A);
sup=LLV(L,A);
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);

// line code
Plot(tsl, _DEFAULT_NAME(), ParamColor( "ColorD", colorRed ), styleStaircase|styleNoLabel|styleNoLine);

// arrows code
Buy=Cross(C,Ref(res,-1));
Sell=Cross(Ref(sup,-1),C);
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);

Bought = Flip(Buy, Sell);
Sold = Flip(Sell, Buy);
NextTgt = ValueWhen(Buy, Tgt, 1);

for(i = 1; i < BarCount; i++)
{
if(Bought AND NOT Buy)
{
SL = Max(SL, SL[i - 1]);
if(C[i - 1] >= 0.9999 * NextTgt[i - 1]) NextTgt = Tgt[i - 1];
NextTgt = Max(NextTgt, NextTgt[i - 1]);
}
}
BuyDate = ValueWhen(Buy, Ref(DateTime(), 1), 1);
BuyPrice = ValueWhen(Buy, Ref(MeanPrice, 1), 1);
SellPrice = ValueWhen(Sell, Ref(MeanPrice, 1), 1);

TgtReached = IIf(Bought AND NOT Buy AND C >= 0.9999 * NextTgt, True, False);
SLHit = IIf(Bought AND NOT Buy AND C < SL, True, False);
SLHit = ExRem(SLHit, Buy);
Plot(IIf(Bought, NextTgt, Null), "Target", colorRed,styleNoLine|styleNoTitle|styleNoLabel);
Plot(SL, "Trail SL", colorGrey40, styleNoLine|styleNoTitle|styleNoLabel);
_SECTION_BEGIN(" ");
{ GfxSelectFont("Arial",13, 700 );
GfxSetBkMode(1);
GfxSetTextColor(colorDarkYellow);
GfxTextOut("TR="+WriteVal(NextTgt,format=1.2)+"",300,20);
GfxSetTextColor(colorBlue);
GfxTextOut("Trail="+WriteVal(SL,format=1.2)+"",450,20);
GfxSetTextColor(colorRed);
GfxTextOut(" SL="+WriteVal(tsl,format=1.2)+"",600,20);

}
_SECTION_END();


_SECTION_BEGIN("super trend");


procedure calcTrend_proc(ATR_Period,tr,ATR_Multiplier,TrendMode,CalcPrice)
{
global buffer_line_down;
global buffer_line_up;
buffer_line_down = Null;
buffer_line_up = Null;

PHASE_NONE = 0;
PHASE_BUY = 1;
PHASE_SELL = -1;

phase=PHASE_NONE;
band_upper = 0;band_lower = 0;

for(i = ATR_Period + 1; i < BarCount; i++)
{
band_upper = CalcPrice + ATR_Multiplier * tr;
band_lower = CalcPrice - ATR_Multiplier * tr;

if(phase==PHASE_NONE)
{
buffer_line_up = CalcPrice;
buffer_line_down = CalcPrice;
}
if(phase!=PHASE_BUY && Close>buffer_line_down[i-1] && !IsEmpty(buffer_line_down[i-1]))
{
phase = PHASE_BUY;
buffer_line_up = band_lower;
buffer_line_up[i-1] = buffer_line_down[i-1];
}
if(phase!=PHASE_SELL && Close<buffer_line_up[i-1] && !IsEmpty(buffer_line_up[i-1]))
{
phase = PHASE_SELL;
buffer_line_down = band_upper;
buffer_line_down[i-1] = buffer_line_up[i-1];
}
if(phase==PHASE_BUY && ((TrendMode==0 && !IsEmpty(buffer_line_up[i-2])) || TrendMode==1) )
{
if(band_lower>buffer_line_up[i-1])
{
buffer_line_up = band_lower;
}
else
{
buffer_line_up = buffer_line_up[i-1];
}
}
if(phase==PHASE_SELL && ((TrendMode==0 && !IsEmpty(buffer_line_down[i-2])) || TrendMode==1) )
{
if(band_upper<buffer_line_down[i-1])
{
buffer_line_down = band_upper;
}
else
{
buffer_line_down = buffer_line_down[i-1];
}
}
}
}

SetBarsRequired(sbrAll,sbrAll);

TrendMode = ParamToggle("TrendMode","Off|On",1);
ATR_Multiplier = Param("ATR_Multiplier",2,0.1,10,0.1);
ATR_Period = Param( "ATR_Period",5,1,20,1);
tr = ATR(ATR_Period);

CalcPrice = (H+L)/2;
calcTrend_proc(ATR_Period,tr,ATR_Multiplier,TrendMode,CalcPrice);

SetChartOptions(0,chartShowDates);
Plot( 2,"",IIf(buffer_line_up,colorGreen,colorBlack),styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );
Plot( 4,"",IIf(buffer_line_down,colorRed,colorBlack),styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );

_SECTION_END();

_SECTION_BEGIN(" super trend");
{ GfxSelectFont("Arial",12, 700 );
GfxSetBkMode(1);
GfxSetTextColor(colorGreen);
GfxTextOut("TU="+WriteVal(buffer_line_up,format=1.2)+" ",50,20);
GfxSetTextColor(colorRed);
GfxTextOut("TD="+WriteVal(buffer_line_down,format=1.2)+" ",180,20);

}
_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("BB");
bb2top = BBandTop(Close,20,2.25);
bb1top = BBandTop(Close,20,1);
bb2bot = BBandBot(Close,20,2.25);
bb1bot = BBandBot(Close,20,1);

Plot (bb1top,"",IIf(bb1top > Ref(bb1top,-1) AND bb1bot < Ref(bb1bot,-1),colorRed,colorRed),32);
Plot (bb1bot,"",IIf(bb1top > Ref(bb1top,-1) AND bb1bot < Ref(bb1bot,-1),colorYellow,colorYellow),32);
Plot (bb2top,"",IIf(bb2top > Ref(bb2top,-1) AND bb2bot < Ref(bb2bot,-1),colorLightGrey,colorLightGrey),32);
Plot (bb2bot,"",IIf(bb2top > Ref(bb2top,-1) AND bb2bot < Ref(bb2bot,-1),colorLightGrey,colorLightGrey),32);
PlotOHLC(bb2top,bb2top,bb1top,bb1top,"",ColorRGB(56,63,118),styleCloud);
PlotOHLC(bb1bot,bb1bot,bb2bot,bb1bot,"",ColorRGB(56,63,118),styleCloud);


_SECTION_END();


SetChartBkColor( ParamColor("background",colorDarkTeal));