Sujit,
Amibroker Library is now for the registered users
_SECTION_BEGIN("NR4 Historical Volatility System");
//------------------------------------------------------------------------------
//
// Formula Name: NR4 Historical Volatility System
// Author/Uploader: Daniel Ervi
// E-mail:
// Date/Time Added: 2001-09-08 17:28:09
// Origin: Street Smarts, Connors and Raschke. Also featured in TASC.
// Keywords: NR4 volatility
// Level: medium
// Flags: exploration
// Formula URL:
http://www.amibroker.com/library/formula.php?id=115
// Details URL:
http://www.amibroker.com/library/detail.php?id=115
//
//------------------------------------------------------------------------------
//
// Connors and Raschke NR4 Historical Volatility System. Compares the 6 day
// volatility to the 100 day volatility. When this ratio drops below 50%, a
// buy stop and sell stop bracket the current price, expecting historical
// volatility to revert to the mean. Four day Narrow-Range (NR4) and Inside
// Day patterns are used to filter the trades to increase probabilities. For
// further explanation, refer to "Street Smarts" from Connors and Raschke.
//
//------------------------------------------------------------------------------
/* Connors and Raschke Historical Volatility System
For further explanation, refer to "Street Smarts"
from Connors and Raschke.
Ported from Metastock code by Daniel Ervi */
//NumColumns = 5;
SetChartBkGradientFill( ParamColor("BgTop", colorLavender),ParamColor("BgBottom", colorBlack));
_SECTION_BEGIN("Price1");
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() );
_SECTION_END();
VolRatio = StDev(log(C/Ref(C,-1)),5) / StDev(log(C/Ref(C,-1)),99);
Column0 = VolRatio;
Column0Name = "VolRatio";
NR4Day = (H - L) < Ref(LLV(H-L,3),-1);
//Column1 = NR4Day;
//Column1Name = "Nr4Day";
NR7Day = (H - L) < Ref(LLV(H-L,6),-1);
InsideDay = H < Ref(High,-1) AND Low > Ref(Low,-1);
Buy = VolRatio < 0.5 AND (NR7Day == 1 AND InsideDay == 1);
Sell = VolRatio < 0.5 AND (NR7Day == 1 AND InsideDay == 1);
//shape = Buy * shapeSmallCircle + Sell * shapeSmallCircle;
//PlotShapes( shape, IIf( Buy, colorBrightGreen, colorRed ),0, IIf( Buy,High,Low ) );
dist = 2.0*ATR(10);
for( i = 0; i < BarCount; i++ )
{
if( Buy
) PlotText( "NR7Buy\n@" + H[ i ], i, H[ i ]+dist, colorGreen );
if( Sell ) PlotText( "NR7Sell\n@" + L[ i ], i, L[ i ]-dist, colorRed);
}
//Column2 = InsideDay;
//Column2Name = "Inside Day";
//Column3 = High + 0.125;
//Column3Name = "Buy Stop";
//Column4 = Low - 0.125;
//Column4Name = "Sell Stop";
Filter =VolRatio < 0.5 AND (NR4Day == 1 AND InsideDay == 1);
Buy = Filter;
//AddTextColumn(FullName(), "Company Name");
AddColumn(Buy, "Buy", 1);
AddColumn(C, "Close", 1.3);
AddColumn( VolRatio, " VolRatio");
AddColumn(Nr4day, "NR4day");
AddColumn(Nr4day, "NR7day");
AddColumn(InsideDay, "insideday");
AddColumn( High + 0.125, "BuyStop");
AddColumn(Low - 0.125, ",SellStop,");
Regards
Ken