NEW AFL FOR INTRA TRADING:
:thumb:
_SECTION_BEGIN("ZigZag Retracement");
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
Pivot = ParamToggle("Pivot_NEXTday", "YES|NO", 1);
if(Pivot)
{
Hia = TimeFrameGetPrice("H", inDaily, -1); // yesterdays high
Loa = TimeFrameGetPrice("L", inDaily, -1); // low
C1a= TimeFrameGetPrice("C", inDaily, -1); // low
}
else
{
Hia = TimeFrameGetPrice("H", inDaily ); // yesterdays high
Loa = TimeFrameGetPrice("L", inDaily); // low
C1a = TimeFrameGetPrice("C", inDaily); // low
}
Plot( (C1a),"close",colorBlack,4+8+2048);
//Plot( (Hia),"Dh",colorCustom12,4+8+2048);
//Plot( (Loa),"Dl",colorAqua,4+8+2048);
diff = Hia-Loa;
L102 =diff*0.382;
L103 =Loa+L102;
///Plot(L103 ,"E1",colorPink,4+8+2048);
L104 =diff*0.191;
L105 =Loa+L104;
//Plot(L105 ,"E2",colorGreen,4+8+2048);
L106 =L103-Loa;
L107 =L106*1.272;
L108 =L105+L107;
//Plot(L108 ,"E3",colorRed,4+8+2048);
L109 =L108-L105;
L110 =L109*0.5;
L111 =L108-L110;
//Plot(L111 ,"E4",colorOrange,4+8+2048);
L112 =L102+L111;
//Plot(L112,"E5",colorBrown,4+8+2048);
di =(Hia-L103);
//Plot(di,"di",colorTan,4+8+2048);
Lo=(Hia+L103)/2;
Plot(Lo,"TREND",colorGold,4+8+2048);
t1 =di*1.618;
//Plot(t1,"t1",colorCustom1,4+8+2048);
DT=(Lo-t1);
Plot(DT,"",colorCustom1,styleLine+styleNoRescale );
Hi=(Lo+t1);
Plot(Hi,"",colorCustom1,styleLine+styleNoRescale );
bearish = Hia-diff*0.618;
Plot(bearish,"BEARISH",colorOrange,4+8+2048);
bullish = Hia+diff*0.618;
Plot(bullish,"BULLISH",colorCustom13,4+8+2048);
diff = Hi-Lo;
H1 = Hi+diff*0.23836;
H2 =Hi+diff*0.38582;
H3 = Hi+diff*0.5050;
H4 = Hi+diff*0.62418;
H5 =Hi+diff*0.7716;
H6 = Hi+diff*0.89082;
H7 = Hi+diff*1;
Plot(H1, "",colorAqua,styleLine+styleNoRescale );
Plot(H2, "",colorBlue,styleLine+styleNoRescale );
Plot(H3, "",colorPink,styleLine+styleNoRescale);
Plot(H4, "",colorBrown,styleLine+styleNoRescale );
Plot( H5, "", colorViolet, styleLine+styleNoRescale );
Plot( H6, "", colorCustom4, styleLine+styleNoRescale );
Plot(H7 ,"",colorCustom12,styleLine+styleNoRescale );
H1 = Lo+diff*0.23836;
H2 =Lo+diff*0.38582;
H3 = Lo+diff*0.505;
H4 =Lo+diff*0.62418;
H5 =Lo+diff*0.7716;
H6 = Lo+diff*0.89082;
H7 = Lo+diff*1;
Plot(H1, "",colorAqua,styleLine+styleNoRescale );
Plot(H2, "",colorBlue,styleLine+styleNoRescale );
Plot(H3, "",colorPink,styleLine+styleNoRescale);
Plot(H4, "",colorBrown,styleLine+styleNoRescale );
Plot( H5, "", colorViolet, styleLine+styleNoRescale );
Plot( H6, "", colorCustom4, styleLine+styleNoRescale );
Plot(H7 ,"",colorCustom12,styleLine+styleNoRescale );
diff = Lo-DT;
H1 = DT+diff*0.23836;
H2 =DT+diff*0.38582;
H3 = DT+diff*0.505;
H4 =DT+diff*0.62418;
H5 =DT+diff*0.7716;
H6 = DT+diff*0.89082;
H7 = DT+diff*1;
Plot(H1, "",colorAqua,styleLine+styleNoRescale );
Plot(H2, "",colorBlue,styleLine+styleNoRescale );
Plot(H3, "",colorPink,styleLine+styleNoRescale);
Plot(H4, "",colorBrown,styleLine+styleNoRescale );
Plot( H5, "", colorViolet, styleLine+styleNoRescale );
Plot( H6, "", colorCustom4, styleLine+styleNoRescale );
Plot(H7 ,"",colorCustom12,styleLine+styleNoRescale );
H1 = DT-diff*0.23836;
H2 =DT-diff*0.38582;
H3 = DT-diff*0.505;
H4 =DT-diff*0.62418;
H5 =DT-diff*0.7716;
H6 = DT-diff*0.89082;
H7 = DT-diff*1;
Plot(H1, "",colorAqua,styleLine+styleNoRescale );
Plot(H2, "",colorBlue,styleLine+styleNoRescale );
Plot(H3, "",colorPink,styleLine+styleNoRescale);
Plot(H4, "",colorBrown,styleLine+styleNoRescale );
Plot( H5, "", colorViolet, styleLine+styleNoRescale );
Plot( H6, "", colorCustom4, styleLine+styleNoRescale );
Plot(H7 ,"",colorCustom12,styleLine+styleNoRescale );
Plot(EMA(O,20), "",colorTan , styleLine|styleThick );
Plot(EMA(Avg,10), "",colorCustom16 , styleLine|styleThick );
Plot(Wilders(H,260.6), "",colorCustom12 , styleDashed|styleThick );
//Plot(EMA(C,55), "WILDERS",colorCustom12 ,styleDashed|styleNoRescale);
n=139.03;
per =12.36;
x = Cum(1);
s1=IIf(RSIa(L,n)>Min(RSIa(C,n),RSIa(O,n)),Min(RSIa(C,n),RSIa(O,n)),RSIa(L,n));
s11=IIf(RSIa(H,n)<Max(RSIa(C,n),RSIa(O,n)),Max(RSIa(C,n),RSIa(O,n)),RSIa(H,n));
pS = TroughBars( s1, per, 1 ) == 0;
endt= LastValue(ValueWhen( pS, x, 1 ));
startt=LastValue(ValueWhen( pS, x, 2 ));
dtS =endt-startt;
endS = LastValue(ValueWhen( pS, s1, 1 ) );
startS = LastValue( ValueWhen( pS, s1, 2 ));
aS = (endS-startS)/dtS;bS = endS;
trendlineS = aS * ( x -endt ) + bS;
pR = PeakBars( s11, per, 1 ) == 0;
endt1= LastValue(ValueWhen( pR, x, 1 ));
startt1=LastValue(ValueWhen( pR, x, 2 ));
dtR =endt1-startt1;
endR = LastValue(ValueWhen( pR, s11, 1 ) );
startR = LastValue( ValueWhen( pR, s11, 2 ));
aR = (endR-startR)/dtR;
bR = endR;
trendlineR = aR * ( x -endt1 ) + bR;
//Plot(ValueWhen( (S1==trendlineS ), L),"", colorGreen, styleDashed|styleNoRescale|styleThick);
//Plot(ValueWhen((S11==trendlineR ), H),"", colorRed, styleDashed|styleNoRescale|styleThick);
Buy = (S1==trendlineS );
Sell = (S11==trendlineR );
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );
PlotShapes( Buy * shapeUpArrow + Sell * shapeDownArrow, IIf( Buy, colorRed, colorCustom12) );
dist = 1.9*ATR(10);
for( i = 0; i < BarCount; i++ )
{
if( Buy ) PlotText( "Rsi139.03 Buy " + L[ i ], i, L[ i ]-dist, colorBlack);
if( Sell ) PlotText( "Rsi139.03Sell " + H[ i ], i, H[ i ]+dist, colorCustom12);
}
_SECTION_END();
:thumb:
_SECTION_BEGIN("ZigZag Retracement");
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
Pivot = ParamToggle("Pivot_NEXTday", "YES|NO", 1);
if(Pivot)
{
Hia = TimeFrameGetPrice("H", inDaily, -1); // yesterdays high
Loa = TimeFrameGetPrice("L", inDaily, -1); // low
C1a= TimeFrameGetPrice("C", inDaily, -1); // low
}
else
{
Hia = TimeFrameGetPrice("H", inDaily ); // yesterdays high
Loa = TimeFrameGetPrice("L", inDaily); // low
C1a = TimeFrameGetPrice("C", inDaily); // low
}
Plot( (C1a),"close",colorBlack,4+8+2048);
//Plot( (Hia),"Dh",colorCustom12,4+8+2048);
//Plot( (Loa),"Dl",colorAqua,4+8+2048);
diff = Hia-Loa;
L102 =diff*0.382;
L103 =Loa+L102;
///Plot(L103 ,"E1",colorPink,4+8+2048);
L104 =diff*0.191;
L105 =Loa+L104;
//Plot(L105 ,"E2",colorGreen,4+8+2048);
L106 =L103-Loa;
L107 =L106*1.272;
L108 =L105+L107;
//Plot(L108 ,"E3",colorRed,4+8+2048);
L109 =L108-L105;
L110 =L109*0.5;
L111 =L108-L110;
//Plot(L111 ,"E4",colorOrange,4+8+2048);
L112 =L102+L111;
//Plot(L112,"E5",colorBrown,4+8+2048);
di =(Hia-L103);
//Plot(di,"di",colorTan,4+8+2048);
Lo=(Hia+L103)/2;
Plot(Lo,"TREND",colorGold,4+8+2048);
t1 =di*1.618;
//Plot(t1,"t1",colorCustom1,4+8+2048);
DT=(Lo-t1);
Plot(DT,"",colorCustom1,styleLine+styleNoRescale );
Hi=(Lo+t1);
Plot(Hi,"",colorCustom1,styleLine+styleNoRescale );
bearish = Hia-diff*0.618;
Plot(bearish,"BEARISH",colorOrange,4+8+2048);
bullish = Hia+diff*0.618;
Plot(bullish,"BULLISH",colorCustom13,4+8+2048);
diff = Hi-Lo;
H1 = Hi+diff*0.23836;
H2 =Hi+diff*0.38582;
H3 = Hi+diff*0.5050;
H4 = Hi+diff*0.62418;
H5 =Hi+diff*0.7716;
H6 = Hi+diff*0.89082;
H7 = Hi+diff*1;
Plot(H1, "",colorAqua,styleLine+styleNoRescale );
Plot(H2, "",colorBlue,styleLine+styleNoRescale );
Plot(H3, "",colorPink,styleLine+styleNoRescale);
Plot(H4, "",colorBrown,styleLine+styleNoRescale );
Plot( H5, "", colorViolet, styleLine+styleNoRescale );
Plot( H6, "", colorCustom4, styleLine+styleNoRescale );
Plot(H7 ,"",colorCustom12,styleLine+styleNoRescale );
H1 = Lo+diff*0.23836;
H2 =Lo+diff*0.38582;
H3 = Lo+diff*0.505;
H4 =Lo+diff*0.62418;
H5 =Lo+diff*0.7716;
H6 = Lo+diff*0.89082;
H7 = Lo+diff*1;
Plot(H1, "",colorAqua,styleLine+styleNoRescale );
Plot(H2, "",colorBlue,styleLine+styleNoRescale );
Plot(H3, "",colorPink,styleLine+styleNoRescale);
Plot(H4, "",colorBrown,styleLine+styleNoRescale );
Plot( H5, "", colorViolet, styleLine+styleNoRescale );
Plot( H6, "", colorCustom4, styleLine+styleNoRescale );
Plot(H7 ,"",colorCustom12,styleLine+styleNoRescale );
diff = Lo-DT;
H1 = DT+diff*0.23836;
H2 =DT+diff*0.38582;
H3 = DT+diff*0.505;
H4 =DT+diff*0.62418;
H5 =DT+diff*0.7716;
H6 = DT+diff*0.89082;
H7 = DT+diff*1;
Plot(H1, "",colorAqua,styleLine+styleNoRescale );
Plot(H2, "",colorBlue,styleLine+styleNoRescale );
Plot(H3, "",colorPink,styleLine+styleNoRescale);
Plot(H4, "",colorBrown,styleLine+styleNoRescale );
Plot( H5, "", colorViolet, styleLine+styleNoRescale );
Plot( H6, "", colorCustom4, styleLine+styleNoRescale );
Plot(H7 ,"",colorCustom12,styleLine+styleNoRescale );
H1 = DT-diff*0.23836;
H2 =DT-diff*0.38582;
H3 = DT-diff*0.505;
H4 =DT-diff*0.62418;
H5 =DT-diff*0.7716;
H6 = DT-diff*0.89082;
H7 = DT-diff*1;
Plot(H1, "",colorAqua,styleLine+styleNoRescale );
Plot(H2, "",colorBlue,styleLine+styleNoRescale );
Plot(H3, "",colorPink,styleLine+styleNoRescale);
Plot(H4, "",colorBrown,styleLine+styleNoRescale );
Plot( H5, "", colorViolet, styleLine+styleNoRescale );
Plot( H6, "", colorCustom4, styleLine+styleNoRescale );
Plot(H7 ,"",colorCustom12,styleLine+styleNoRescale );
Plot(EMA(O,20), "",colorTan , styleLine|styleThick );
Plot(EMA(Avg,10), "",colorCustom16 , styleLine|styleThick );
Plot(Wilders(H,260.6), "",colorCustom12 , styleDashed|styleThick );
//Plot(EMA(C,55), "WILDERS",colorCustom12 ,styleDashed|styleNoRescale);
n=139.03;
per =12.36;
x = Cum(1);
s1=IIf(RSIa(L,n)>Min(RSIa(C,n),RSIa(O,n)),Min(RSIa(C,n),RSIa(O,n)),RSIa(L,n));
s11=IIf(RSIa(H,n)<Max(RSIa(C,n),RSIa(O,n)),Max(RSIa(C,n),RSIa(O,n)),RSIa(H,n));
pS = TroughBars( s1, per, 1 ) == 0;
endt= LastValue(ValueWhen( pS, x, 1 ));
startt=LastValue(ValueWhen( pS, x, 2 ));
dtS =endt-startt;
endS = LastValue(ValueWhen( pS, s1, 1 ) );
startS = LastValue( ValueWhen( pS, s1, 2 ));
aS = (endS-startS)/dtS;bS = endS;
trendlineS = aS * ( x -endt ) + bS;
pR = PeakBars( s11, per, 1 ) == 0;
endt1= LastValue(ValueWhen( pR, x, 1 ));
startt1=LastValue(ValueWhen( pR, x, 2 ));
dtR =endt1-startt1;
endR = LastValue(ValueWhen( pR, s11, 1 ) );
startR = LastValue( ValueWhen( pR, s11, 2 ));
aR = (endR-startR)/dtR;
bR = endR;
trendlineR = aR * ( x -endt1 ) + bR;
//Plot(ValueWhen( (S1==trendlineS ), L),"", colorGreen, styleDashed|styleNoRescale|styleThick);
//Plot(ValueWhen((S11==trendlineR ), H),"", colorRed, styleDashed|styleNoRescale|styleThick);
Buy = (S1==trendlineS );
Sell = (S11==trendlineR );
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );
PlotShapes( Buy * shapeUpArrow + Sell * shapeDownArrow, IIf( Buy, colorRed, colorCustom12) );
dist = 1.9*ATR(10);
for( i = 0; i < BarCount; i++ )
{
if( Buy ) PlotText( "Rsi139.03 Buy " + L[ i ], i, L[ i ]-dist, colorBlack);
if( Sell ) PlotText( "Rsi139.03Sell " + H[ i ], i, H[ i ]+dist, colorCustom12);
}
_SECTION_END();