Hi All,
This AFL is for the method/principles stated by TradeWithHunter in the following post as per the link
SH's MArket Correction Prediction Strategy
The code has an exploration also with it.Happy Trading Guys :clap::thumb:
Here is the code.I am using Ami 5.3 plus versions
This AFL is for the method/principles stated by TradeWithHunter in the following post as per the link
SH's MArket Correction Prediction Strategy
The code has an exploration also with it.Happy Trading Guys :clap::thumb:
Here is the code.I am using Ami 5.3 plus versions
Code:
SetChartOptions( 0, chartShowArrows | chartShowDates );
colorCrimson = ColorRGB( 220, 20, 60 );
SetChartBkColor( colorWhite );
/*
Reversion to Mean rules for NIFTY
- Nifty futures price has to revert to 3 EMA within a maximum of 3 days before it goes anywhere else.
- Nifty futures price has to revert to 15 EMA within a maximum of 6 weeks before it goes anywhere else..
- NIfty Futures price has to revert to 34 EMA within a maximum of 16-18 weeks (4 months) before it goes anywhere else.
- NIfty Futures price has to revert to 100 EMA within a maximum of 28 weeks before it goes anywhere else. (7 months)
*/
function getMA( period )
{
return EMA( C, period );
}
p1 = 3;
p2 = 15;
p3 = 34;
p4 = 100;
e1 = getMA( p1 );
e2 = getMA( p2 );
e3 = getMA( p3 );
e4 = getMA( p4 );
dCount1 = Null;
dCount2 = Null;
dCount3 = Null;
dCount4 = Null;
C1 = colorRed;
C2 = colorGreen;
C3 = colorBlue;
C4 = colorDarkBlue;
Plot( e1, "MA" + p1, C1, styleLine );
Plot( e2, "MA" + p2, C2, styleLine );
Plot( e3, "MA" + p3, C3, styleLine );
Plot( e4, "MA" + p4, C4, styleLine | styleDots );
GapUp1 = L > e1;
GapDown1 = H < e1;
Gap1 = GapUp1 OR GapDown1;
GapUp2 = L > e2;
GapDown2 = H < e2;
Gap2 = GapUp2 OR GapDown2;
GapUp3 = L > e3;
GapDown3 = H < e3;
Gap3 = GapUp3 OR GapDown3;
GapUp4 = L > e4;
GapDown4 = H < e4;
Gap4 = GapUp4 OR GapDown4;
myColor = IIf( C > Ref( C, -1 ), colorDarkBlue, ColorCrimson );
PlotOHLC( O, H, L, C, "OHLC", myColor, styleBar );
DayCount = Null;
Plot15_1 = Null;
Plot15_2 = Null;
for ( i = BarCount - 1;i >= 0;i-- )
{
if ( gap1[i] )
{
dcount1[i] = 0;
first = True;
m = H[i];
for ( j = i;j > 0 && gap1[j] == 1;j-- )
{
dcount1[i]++;
if ( first == False )
gap1[j] = 0;
first = False;
m = Max( m, H[j] );
}
PlotText( "" + dCount1[i], i, m, colorWhite, colorRed );
}
if ( gap2[i] )
{
dcount2[i] = 0;
m = H[i];
first = True;
for ( j = i;j > 0 && gap2[j] == 1;j-- )
{
dcount2[i]++;
if ( first == False )
gap2[j] = 0;
first = False;
m = Max( m, H[j] );
}
PlotText( "" + dCount2[i], ( i ) - 1, m, colorWhite, colorGreen );
}
if ( gap3[i] )
{
dcount3[i] = 0;
m = H[i];
first = True;
for ( j = i;j > 0 && gap3[j] == 1;j-- )
{
dcount3[i]++;
if ( first == False )
gap3[j] = 0;
first = False;
m = Max( m, H[j] );
}
PlotText( "" + dCount3[i], ( i ) - 2, m, colorWhite, colorBlue );
}
if ( gap4[i] )
{
dcount4[i] = 0;
m = H[i];
first = True;
for ( j = i;j > 0 && gap4[j] == 1;j-- )
{
dcount4[i]++;
if ( first == False )
gap4[j] = 0;
first = False;
m = Max( m, H[j] );
}
PlotText( "" + dCount4[i], ( i ) - 3, m, colorWhite, colorDarkBlue );
}
}
ToolTip = StrFormat( "Open: %g\nHigh: %g\nLow: %g\nClose: %g (%.1f%%)\nVolume: " + NumToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1 ) ) );
Cond = gap1 OR gap2 OR gap3 OR gap4;
Filter = COnd;
AddColumn( LastValue( C ), "Last Close", 0, colorBlue );
AddColumn( O, "Open", 0, colorDarkBlue, colorLightYellow, 60 );
AddColumn( H, "High", 0, colorDarkBlue, colorLightYellow, 60 );
AddColumn( L, "Low", 0, colorDarkBlue, colorLightYellow, 60 );
AddColumn( C, "Close", 0, colorDarkBlue, colorLightYellow, 60 );
AddColumn( dcount1, "EMA 3", 0, IIf( C - e1 > 0, colorRed, colorGreen ), colorLightYellow, 60 );
AddColumn( dcount2, "EMA 15", 0, IIf( C - e2 > 0, colorRed, colorGreen ), colorLightYellow, 60 );
AddColumn( dcount3, "EMA 34", 0, IIf( C - e3 > 0, colorRed, colorGreen ), colorLightYellow, 60 );
AddColumn( dcount4, "EMA 100", 0, IIf( C - e4 > 0, colorRed, colorGreen ), colorLightYellow, 60 );