kajal best afl trend reversal afl

#1
_SECTION_BEGIN("R2");
/* System Based on R2 Indiator - Karthikmarar
Indicator Adopted from Amibroker AFL Library */

/*To determine if the trend is statistically significant for a given x-period
linear regression line, Plot the r-squared indicator and refer to the following
table. This table shows the values of r-squared required for A 95% confidence
level at various time periods. If the r-squared value is less than the
critical values shown, you should assume that prices show no statistically
significant trend.

Number ofPeriods r-squaredCritical Value(95%confidence)
5 0.77
10 0.40
14 0.27
20 0.20
25 0.16
30 0.13
50 0.08
60 0.06
120 0.03
*/
Title = ("R2 SYSTEM - " + Name()+" " + Date() +" "+Interval(2) +" "+ EncodeColor(colorLime)+",Open "+Open +" ,High "+H+" ,Low "+L+" ,Close "+C+" "+"{{VALUES}}");
s1=Param("Filter Tune 1",0.5,0.1,1,0.1);
s2=Param("Filter Tune 2",2,1,3,0.5);
RPDS=ParamList("R2 Period", "20|25|14|5|10|30|50|60|120" ); /*for automatic adjustments to the r2 critical value line use one of
//the periods listed above*/
R2PDS=IIf(rpds=="5",5,IIf(rpds=="10",10,IIf(rpds=="14",14,IIf(rpds=="20",20,IIf(rpds=="25",25,IIf(rpds=="30",30,IIf(rpds=="50",50,IIf(rpds=="60",60,120))))))));

R2=Correlation(Cum( 1 ),C,r2pds)*Correlation(Cum( 1 ),C,r2pds);
slope=LinRegSlope(C,r2pds);

Crit=IIf(R2PDS==5,.77,IIf(R2PDS==10,.40,IIf(R2PDS==14,.27,IIf(R2PDS==20,.20,IIf(R2PDS==25,.16,IIf(R2PDS==30,.13,IIf(R2PDS==50,.08,IIf(R2PDS==60,.06,IIf(R2PDS==120,.03,0)))))))));
r2color=IIf(r2>(s2*Crit) AND slope>s1,colorLime,IIf(slope>0 AND r2<s2*Crit , colorPaleGreen,IIf(slope<0 AND r2<crit, colorPink,colorRed)));
// Buy sell condition
Buy=(Cross(slope,s1) AND r2>s2*Crit )OR (slope>s1 AND Cross(r2,(s2*Crit)));
Sell=Cross(0,slope) OR (Cross(Crit,r2) AND slope<0);
Short= Cross(r2,Crit) AND slope<-s1;
Cover= Cross(slope,0);
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);


PlotOHLC( Open, High, Low, Close, "", r2color, styleBar | styleThick );

shape = Buy * shapeUpArrow + Sell * shapeDownArrow + Short * shapeDownTriangle + Cover * shapeUpTriangle;


PlotShapes( shape, IIf( Buy, colorGreen, IIf(Sell,colorYellow,IIf(Cover,colorLightOrange,colorRed ))),0, IIf( Buy, Low, IIf(Sell,High,IIf(Cover,Low,High) ) ) );
GraphXSpace = 5;
dist = 1.5*ATR(10);

for( i = 0; i < BarCount; i++ )
{
if( Buy ) PlotText( "Buy\n@" + C[ i ], i, L[ i ]-dist, colorGreen );
if( Sell ) PlotText( "Sell\n@" + C[ i ], i, H[ i ]+dist, colorYellow);
if( Short ) PlotText( "Short\n@" + C[ i ], i, H[ i ]+dist, colorRed);
if( Cover ) PlotText( "cover\n@" + C[ i ], i, H[ i ]-dist, colorLightOrange);
}
_SECTION_END();

_SECTION_BEGIN("HH");
Q = Param( "% Change", 2, 0.1, 10, 0.1 );
Z = Zig( C , q ) ;
HH = ( ( Z < Ref( Z, -1 ) AND Ref( Z, -1 ) > Ref( Z, -2 ) ) AND (Peak( z, q, 1 ) > Peak( Z, q, 2 ) ) );
LH = ( ( Z < Ref( Z, -1 ) AND Ref( Z, -1 ) > Ref( Z, -2 ) ) AND (Peak( Z, q, 1 ) < Peak( Z, q, 2 ) ) );
HL = ( ( Z > Ref( Z, -1 ) AND Ref( Z, -1 ) < Ref( Z, -2 ) ) AND (Trough( Z, q, 1 ) > Trough( Z, q, 2 ) ) );
LL = ( ( Z > Ref( Z, -1 ) AND Ref( Z, -1 ) < Ref( Z, -2 ) ) AND (Trough( Z, q, 1 ) < Trough( Z, q, 2 ) ) );
GraphXSpace = 5;
dist = 0.5 * ATR( 20 );

for ( i = 0; i < BarCount; i++ )
{
if ( HH )
PlotText( "HH", i, H[ i ] + dist, colorRed );

if ( LH )
PlotText( "LH", i, H[ i ] + dist, colorRed );

if ( HL )
PlotText( "HL", i, L[ i ] - dist, colorBrightGreen );

if ( LL )
PlotText( "LL", i, L[ i ] - dist, colorBrightGreen );

}

Filter=HH OR HL OR LH OR LL;
AddColumn(RSI(2),"RSI",1.2);
AddColumn(Close,"PRICE",1.2);
AddColumn(HH,"SHORT");
AddColumn(LH,"LH");
AddColumn(HL,"HL");
AddColumn(LL,"COVER");
AddColumn(V,"volume",1.0);
_SECTION_END();



i have tested it best time frame to do trade is hourly and for long term daily hope u enjoy trading .....as reversal given suddenly pink candle change....:clapping::clapping::thumb:.....all the best friends
 

suri112000

Well-Known Member
#4
Its showing lot of errors. Any help. My ami version 5.0
 

rkkarnani

Well-Known Member
#6
_SECTION_BEGIN("R2");
/* System Based on R2 Indiator - Karthikmarar
Indicator Adopted from Amibroker AFL Library */

/*To determine if the trend is statistically significant for a given x-period
linear regression line, Plot the r-squared indicator and refer to the following
table. This table shows the values of r-squared required for A 95% confidence
level at various time periods. If the r-squared value is less than the
critical values shown, you should assume that prices show no statistically
significant trend.

Number ofPeriods r-squaredCritical Value(95%confidence)
5 0.77
10 0.40
14 0.27
20 0.20
25 0.16
30 0.13
50 0.08
60 0.06
120 0.03
*/
Title = ("R2 SYSTEM - " + Name()+" " + Date() +" "+Interval(2) +" "+ EncodeColor(colorLime)+",Open "+Open +" ,High "+H+" ,Low "+L+" ,Close "+C+" "+"{{VALUES}}");
s1=Param("Filter Tune 1",0.5,0.1,1,0.1);
s2=Param("Filter Tune 2",2,1,3,0.5);
RPDS=ParamList("R2 Period", "20|25|14|5|10|30|50|60|120" ); /*for automatic adjustments to the r2 critical value line use one of
//the periods listed above*/
R2PDS=IIf(rpds=="5",5,IIf(rpds=="10",10,IIf(rpds=="14",14,IIf(rpds=="20",20,IIf(rpds=="25",25,IIf(rpds=="30",30,IIf(rpds=="50",50,IIf(rpds=="60",60,120))))))));

R2=Correlation(Cum( 1 ),C,r2pds)*Correlation(Cum( 1 ),C,r2pds);
slope=LinRegSlope(C,r2pds);

Crit=IIf(R2PDS==5,.77,IIf(R2PDS==10,.40,IIf(R2PDS==14,.27,IIf(R2PDS==20,.20,IIf(R2PDS==25,.16,IIf(R2PDS==30,.13,IIf(R2PDS==50,.08,IIf(R2PDS==60,.06,IIf(R2PDS==120,.03,0)))))))));
r2color=IIf(r2>(s2*Crit) AND slope>s1,colorLime,IIf(slope>0 AND r2<s2*Crit , colorPaleGreen,IIf(slope<0 AND r2<crit, colorPink,colorRed)));
// Buy sell condition
Buy=(Cross(slope,s1) AND r2>s2*Crit )OR (slope>s1 AND Cross(r2,(s2*Crit)));
Sell=Cross(0,slope) OR (Cross(Crit,r2) AND slope<0);
Short= Cross(r2,Crit) AND slope<-s1;
Cover= Cross(slope,0);
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);


PlotOHLC( Open, High, Low, Close, "", r2color, styleBar | styleThick );

shape = Buy * shapeUpArrow + Sell * shapeDownArrow + Short * shapeDownTriangle + Cover * shapeUpTriangle;


PlotShapes( shape, IIf( Buy, colorGreen, IIf(Sell,colorYellow,IIf(Cover,colorLightOrange,colorRed ))),0, IIf( Buy, Low, IIf(Sell,High,IIf(Cover,Low,High) ) ) );
GraphXSpace = 5;
dist = 1.5*ATR(10);

for( i = 0; i < BarCount; i++ )
{
if( Buy ) PlotText( "Buy\n@" + C[ i ], i, L[ i ]-dist, colorGreen );
if( Sell ) PlotText( "Sell\n@" + C[ i ], i, H[ i ]+dist, colorYellow);
if( Short ) PlotText( "Short\n@" + C[ i ], i, H[ i ]+dist, colorRed);
if( Cover ) PlotText( "cover\n@" + C[ i ], i, H[ i ]-dist, colorLightOrange);
}
_SECTION_END();

_SECTION_BEGIN("HH");
Q = Param( "% Change", 2, 0.1, 10, 0.1 );
Z = Zig( C , q ) ;
HH = ( ( Z < Ref( Z, -1 ) AND Ref( Z, -1 ) > Ref( Z, -2 ) ) AND (Peak( z, q, 1 ) > Peak( Z, q, 2 ) ) );
LH = ( ( Z < Ref( Z, -1 ) AND Ref( Z, -1 ) > Ref( Z, -2 ) ) AND (Peak( Z, q, 1 ) < Peak( Z, q, 2 ) ) );
HL = ( ( Z > Ref( Z, -1 ) AND Ref( Z, -1 ) < Ref( Z, -2 ) ) AND (Trough( Z, q, 1 ) > Trough( Z, q, 2 ) ) );
LL = ( ( Z > Ref( Z, -1 ) AND Ref( Z, -1 ) < Ref( Z, -2 ) ) AND (Trough( Z, q, 1 ) < Trough( Z, q, 2 ) ) );
GraphXSpace = 5;
dist = 0.5 * ATR( 20 );

for ( i = 0; i < BarCount; i++ )
{
if ( HH )
PlotText( "HH", i, H[ i ] + dist, colorRed );

if ( LH )
PlotText( "LH", i, H[ i ] + dist, colorRed );

if ( HL )
PlotText( "HL", i, L[ i ] - dist, colorBrightGreen );

if ( LL )
PlotText( "LL", i, L[ i ] - dist, colorBrightGreen );

}

Filter=HH OR HL OR LH OR LL;
AddColumn(RSI(2),"RSI",1.2);
AddColumn(Close,"PRICE",1.2);
AddColumn(HH,"SHORT");
AddColumn(LH,"LH");
AddColumn(HL,"HL");
AddColumn(LL,"COVER");
AddColumn(V,"volume",1.0);
_SECTION_END();



i have tested it best time frame to do trade is hourly and for long term daily hope u enjoy trading .....as reversal given suddenly pink candle change....:clapping::clapping::thumb:.....all the best friends


I dont use Amibroker but would love to see a Chart with this AFL! Others also might be interested.
Please oblige !
 
#7
Backtesting Results -


It seems that the formula references FUTURE quotes.
If you backtest this system you may receive outstanding results
that CAN NOT be reproduced in real trading.

7527 data bars used during this check. Total execution time: 0.0333172 sec.
Approximately 4744 past and 4500 future quotes are needed to calculate the formula properly
 

guptak03

Well-Known Member
#10
plz delete gap and make new afl so that one can easly do it.

PHP:
_SECTION_BEGIN("R2");
/* System Based on R2 Indiator - Karthikmarar
Indicator Adopted from Amibroker AFL Library */

/*To determine if the trend is statistically significant for a given x-period
linear regression line, Plot the r-squared indicator and refer to the following
table. This table shows the values of r-squared required for A 95% confidence
level at various time periods. If the r-squared value is less than the
critical values shown, you should assume that prices show no statistically
significant trend.

Number ofPeriods r-squaredCritical Value(95%confidence)
5 0.77
10 0.40
14 0.27
20 0.20
25 0.16
30 0.13
50 0.08
60 0.06
120 0.03
*/
Title = ("R2 SYSTEM - " + Name()+" " + Date() +" "+Interval(2) +" "+ EncodeColor(colorLime)+",Open "+Open +" ,High "+H+" ,Low "+L+" ,Close "+C+" "+"{{VALUES}}");
s1=Param("Filter Tune 1",0.5,0.1,1,0.1);
s2=Param("Filter Tune 2",2,1,3,0.5);
RPDS=ParamList("R2 Period", "20|25|14|5|10|30|50|60|120" ); /*for automatic adjustments to the r2 critical value line use one of
//the periods listed above*/
R2PDS=IIf(rpds=="5",5,IIf(rpds=="10",10,IIf(rpds== "14",14,IIf(rpds=="20",20,IIf(rpds=="25",25,IIf(rpds=="30",30,IIf(rpds=="50",50,IIf(rpds=="60",60,120))))))));

R2=Correlation(Cum( 1 ),C,r2pds)*Correlation(Cum( 1 ),C,r2pds);
slope=LinRegSlope(C,r2pds);

Crit=IIf(R2PDS==5,.77,IIf(R2PDS==10,.40,IIf(R2PDS==14,.27,IIf(R2PDS==20,.20,IIf(R2PDS==25,.16,IIf(R2PDS==30,.13,IIf(R2PDS==50,.08,IIf(R2PDS==60,.06,IIf(R2PDS==120,.03,0)))))))));
r2color=IIf(r2>(s2*Crit) AND slope>s1,colorLime,IIf(slope>0 AND r2<s2*Crit , colorPaleGreen,IIf(slope<0 AND r2<crit, colorPink,colorRed)));
// Buy sell condition
Buy=(Cross(slope,s1) AND r2>s2*Crit )OR (slope>s1 AND Cross(r2,(s2*Crit)));
Sell=Cross(0,slope) OR (Cross(Crit,r2) AND slope<0);
Short= Cross(r2,Crit) AND slope<-s1;
Cover= Cross(slope,0);
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);
PlotOHLC( Open, High, Low, Close, "", r2color, styleBar | styleThick );

shape = Buy * shapeUpArrow + Sell * shapeDownArrow + Short * shapeDownTriangle + Cover * shapeUpTriangle;


PlotShapes( shape, IIf( Buy, colorGreen, IIf(Sell,colorYellow,IIf(Cover,colorLightOrange,colorRed ))),0, IIf( Buy, Low, IIf(Sell,High,IIf(Cover,Low,High) ) ) );
GraphXSpace = 5;
dist = 1.5*ATR(10);

for( i = 0; i < BarCount; i++ )
{
if( Buy[i] ) PlotText( "Buy\n@" + C[ i ], i, L[ i ]-dist[i], colorGreen );
if( Sell[i] ) PlotText( "Sell\n@" + C[ i ], i, H[ i ]+dist[i], colorYellow);
if( Short[i] ) PlotText( "Short\n@" + C[ i ], i, H[ i ]+dist[i], colorRed);
if( Cover[i] ) PlotText( "cover\n@" + C[ i ], i, H[ i ]-dist[i], colorLightOrange);
}
_SECTION_END();

_SECTION_BEGIN("HH");
Q = Param( "% Change", 2, 0.1, 10, 0.1 );
Z = Zig( C , q ) ;
HH = ( ( Z < Ref( Z, -1 ) AND Ref( Z, -1 ) > Ref( Z, -2 ) ) AND (Peak( z, q, 1 ) > Peak( Z, q, 2 ) ) );
LH = ( ( Z < Ref( Z, -1 ) AND Ref( Z, -1 ) > Ref( Z, -2 ) ) AND (Peak( Z, q, 1 ) < Peak( Z, q, 2 ) ) );
HL = ( ( Z > Ref( Z, -1 ) AND Ref( Z, -1 ) < Ref( Z, -2 ) ) AND (Trough( Z, q, 1 ) > Trough( Z, q, 2 ) ) );
LL = ( ( Z > Ref( Z, -1 ) AND Ref( Z, -1 ) < Ref( Z, -2 ) ) AND (Trough( Z, q, 1 ) < Trough( Z, q, 2 ) ) );
GraphXSpace = 5;
dist = 0.5 * ATR( 20 );

for ( i = 0; i < BarCount; i++ )
{
if ( HH[i] )
PlotText( "HH", i, H[ i ] + dist[i], colorRed );

if ( LH[i] )
PlotText( "LH", i, H[ i ] + dist[i], colorRed );

if ( HL[i] )
PlotText( "HL", i, L[ i ] - dist[i], colorBrightGreen );

if ( LL[i] )
PlotText( "LL", i, L[ i ] - dist[i], colorBrightGreen );

}

Filter=HH OR HL OR LH OR LL;
AddColumn(RSI(2),"RSI",1.2);
AddColumn(Close,"PRICE",1.2);
AddColumn(HH,"SHORT");
AddColumn(LH,"LH");
AddColumn(HL,"HL");
AddColumn(LL,"COVER");
AddColumn(V,"volume",1.0);
_SECTION_END();

now try :thumb:
 

Similar threads