Modified NR4/NR7/ID indicator

KelvinHand

Well-Known Member
#1
This NR quite interesting, but Code very messy, so modified for readability.

I just give you the guide line:

Code:
* Condition 1 (EOD-previous day) Done.
 - TimeFrameSet( inDaily );
Code:
*Condition 2 (Real Time-today):
  Using the AFL today in Real time charts we shortlist stocks which meet Condition 1 AND which broke previous day Hi or Low in real time today   {maybe we can apply a filter below the Hi & above the Low so that we are alerted that the Hi or Low might get broken soon}.

  Basically to track NR stocks from previous day EOD in todays Real Time charts.

 Idea is to Buy/Sell (such stocks which are NR7/NR4/Indisde Bar on EOD) as soon as it breaks the High/Low of previous day. 

 Eg: Today Nifty on EOD chart is NR7. Tommorrow/Next trading day in Real Time chart we can use the AFL to shortlist (using a fliter) Nifty as it gets   
 ready to break Hi/Low.
- TimeFrameRestore() to your current timeframe,
- i don't have the realtime platform setup for AMi, so do your exploration yourself or with other people help. Should be easy for you and the rest of expert around.


//------------------------------------------------------------------------
Code:
_SECTION_BEGIN("NR Chart");
bgTop = ParamColor("BgTop",    colorBlack);
bgBot = ParamColor("BgBottom", colorBlack);
bgTitle = ParamColor("Title", colorGrey50);

SetChartBkGradientFill( bgTop ,bgBot, bgTitle);

Plot( C, "Close", ParamColor("Color", colorWhite ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_N(Title = StrFormat("{{NAME}}- {{INTERVAL}} {{DATE}} O= %g, H= %g, L= %g, C= %g (%.1f%%) V= " +WriteVal( V, 1.0 ) +"\n{{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));




//-- Function Declaration --------------------
function NR(n)
{
  R=H-L;
  NRx=False;
  
  for(i=n; i<BarCount; i++)
  {
      iSum=0;
      for(j=1; j<n; j++)
        if (R[i]<R[i-j]) iSum++;
      if (iSum== (n-1))
       NRx[i] = True;

   }
   return (NRx); 
}


/*********************************************************/
  TimeFrameSet( inDaily ); 
/**********************************************************/

R=H-L;

NR4=NR(4);
NR7=NR(7);
ID=Inside(); 

//Mixed of ID & NR7
ID_NR7 = Inside() * NR7;
ID_NR4 = Inside() * NR4;


Pure_NR7 = (NR7 AND NOT ID);
Pure_NR7_Count=0;

Pure_NR4 = (NR4 AND NOT NR7 AND NOT ID);
Pure_NR4_Count=0;

Pure_ID  = (ID AND NOT NR7 AND NOT NR4);
Pure_ID_Count=0;

Mix_ID_NR7  = ID_NR7;
Mix_ID_NR7_Count=0;

Mix_ID_NR4  = ID_NR4 AND NOT ID_NR7;
Mix_ID_NR4_Count=0;


for(i=1; i<BarCount; i++)
{
  Count=0;
  for(j=0; Pure_NR7[i-j]; j++) Count++;
  if (Count>0) Pure_NR7_Count[i]=Count; 

  Count=0;
  for(j=0; Pure_NR4[i-j]; j++) Count++;
  if (Count>0) Pure_NR4_Count[i]=Count; 

  Count=0;
  for(j=0; Pure_ID[i-j]; j++) Count++;
  if (Count>0) Pure_ID_Count[i]=Count; 

  Count=0;
  for(j=0; Mix_ID_NR7[i-j]; j++) Count++;
  if (Count>0) Mix_ID_NR7_Count[i]=Count; 

  Count=0;
  for(j=0; ID_NR4[i-j]; j++) Count++;
  if (Count>0) Mix_ID_NR4_Count[i]=Count; 

 
}

/*********************************************************/
  TimeFrameRestore(); // restore time frame to original 
/**********************************************************/

Pure_NR7_Color = colorBrightGreen;
Pure_NR4_Color = colorLightOrange;
Pure_ID_Color  = colorYellow;
Mix_ID_NR7_Color = colorGreen;
Mix_ID_NR4_Color = colorGold;

switch(Status("action"))
{
  case actionIndicator:

	_N(Title = Title + 
  		WriteIf(Mix_ID_NR7, EncodeColor(Mix_ID_NR7_Color) + WriteIf(Mix_ID_NR7_Count>1, StrLeft(NumToStr(Mix_ID_NR7_Count), 4), "") + " IDNR7 ",
  		WriteIf(Mix_ID_NR4, EncodeColor(Mix_ID_NR4_Color) + WriteIf(Mix_ID_NR4_Count>1, StrLeft(NumToStr(Mix_ID_NR4_Count), 4), "") + " IDNR4 ",
  		WriteIf(Pure_NR7,   EncodeColor(Pure_NR7_Color)   + WriteIf(Pure_NR7_Count > 1,  StrLeft(NumToStr(Pure_NR7_Count), 4), "") + " NR7 ",
  		WriteIf(Pure_NR4,   EncodeColor(Pure_NR4_Color)   + WriteIf(Pure_NR4_Count > 1,  StrLeft(NumToStr(Pure_NR4_Count), 4), "") + " NR4 ",
  		WriteIf(Pure_ID,    EncodeColor(Pure_ID_Color)    + WriteIf(Pure_ID_Count > 1,   StrLeft(NumToStr(Pure_ID_Count), 4), "") + " InsideDay ", "")))))
	);


	/**** 
   	Plot Shapes 
 	****/


	//-- Plot NR4 & NR7 --
	Dist = L * 0.995;

	//-- Plot Pure NR7
	PlotShapes(Pure_NR7*shapeDigit7, 
           Pure_NR7_Color, 
           0, 
           Dist);

	//-- Plot Pure NR4
	PlotShapes(Pure_NR4*shapeDigit4, 
           Pure_NR4_Color, 
           0, 
           Dist);


	//-- Plot ID & Mix ID --
	Dist = H * 1.03;

	//-- Plot Pure ID
	PlotShapes(Pure_ID*shapeHollowCircle, 
				 Pure_ID_Color,  
           0, 
           Dist);


	// -- Plot Mix NR7 & ID 
	PlotShapes(Mix_ID_NR7*shapeStar, 
           Mix_ID_NR7_Color, 
           0, 
           Dist);

	// -- Plot Mix NR4 & ID 
	PlotShapes(Mix_ID_NR4*shapeStar, 
           Mix_ID_NR4_Color, 
           0, 
           Dist);

	break;


	case actionExplore:
	Buy    = Mix_ID_NR7 OR Pure_NR7 AND Volume > 50000 AND Close > 50; 
	Sell   = Mix_ID_NR4 OR Pure_NR4 AND Volume > 50000 AND Close > 50; 
	Filter = (Pure_NR7_Count > 0) OR (Pure_NR4_Count > 0) OR (Pure_ID_Count > 0);

	SetOption("NoDefaultColumns", True);
	AddColumn(DateTime(), "DATE", formatDateTime,colorDefault, colorDefault, 80);
	AddTextColumn(Name(), "SYMBOL", 77);
	
	AddColumn(IIf(Pure_ID_Count,  48 + Pure_ID_Count,  32), "INSIDE", formatChar, colorYellow, IIf(Pure_ID_Count, colorLightBlue, colorDefault));
	AddColumn(IIf(Pure_NR4_Count, 48 + Pure_NR4_Count, 32), "NR4",    formatChar, colorYellow, IIf(Pure_NR4_Count, colorBlue, colorDefault));
	AddColumn(IIf(Pure_NR7_Count, 48 + Pure_NR7_Count, 32), "NR7",    formatChar, colorYellow, IIf(Pure_NR7_Count, colorGreen, colorDefault));

  
  AddColumn(R, "Range", 6.2, colorDefault, colorDefault, 84);
  AddColumn(High, "High", 6.2, colorDefault, colorDefault, 120);
  AddColumn(Low,  "Low",  6.2, colorDefault, colorDefault, 120);
	break;      

}   

_SECTION_END();
 
Last edited:

ashokram1

Active Member
#2
hii kelvinhand..

i have added the afl in amibroker it shows nr7 and nr4 but how to trade using it and what is the holding period for the stocks
 

ethan hunt

Well-Known Member
#4
This NR quite interesting, but Code very messy, so modified for readability.

I just give you the guide line:

Code:
* Condition 1 (EOD-previous day) Done.
 - TimeFrameSet( inDaily );
Code:
*Condition 2 (Real Time-today):
  Using the AFL today in Real time charts we shortlist stocks which meet Condition 1 AND which broke previous day Hi or Low in real time today   {maybe we can apply a filter below the Hi & above the Low so that we are alerted that the Hi or Low might get broken soon}.

  Basically to track NR stocks from previous day EOD in todays Real Time charts.

 Idea is to Buy/Sell (such stocks which are NR7/NR4/Indisde Bar on EOD) as soon as it breaks the High/Low of previous day. 

 Eg: Today Nifty on EOD chart is NR7. Tommorrow/Next trading day in Real Time chart we can use the AFL to shortlist (using a fliter) Nifty as it gets   
 ready to break Hi/Low.
- TimeFrameRestore() to your current timeframe,
- i don't have the realtime platform setup for AMi, so do your exploration yourself or with other people help. Should be easy for you and the rest of expert around.


//------------------------------------------------------------------------
Code:
_SECTION_BEGIN("NR Chart");
bgTop = ParamColor("BgTop",    colorBlack);
bgBot = ParamColor("BgBottom", colorBlack);
bgTitle = ParamColor("Title", colorGrey50);

SetChartBkGradientFill( bgTop ,bgBot, bgTitle);

Plot( C, "Close", ParamColor("Color", colorWhite ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_N(Title = StrFormat("{{NAME}}- {{INTERVAL}} {{DATE}} O= %g, H= %g, L= %g, C= %g (%.1f%%) V= " +WriteVal( V, 1.0 ) +"\n{{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));




//-- Function Declaration --------------------
function NR(n)
{
  R=H-L;
  NRx=False;
  
  for(i=n; i<BarCount; i++)
  {
      iSum=0;
      for(j=1; j<n; j++)
        if (R[i]<R[i-j]) iSum++;
      if (iSum== (n-1))
       NRx[i] = True;

   }
   return (NRx); 
}


/*********************************************************/
  TimeFrameSet( inDaily ); 
/**********************************************************/

R=H-L;

NR4=NR(4);
NR7=NR(7);
ID=Inside(); 

//Mixed of ID & NR7
ID_NR7 = Inside() * NR7;
ID_NR4 = Inside() * NR4;


Pure_NR7 = (NR7 AND NOT ID);
Pure_NR7_Count=0;

Pure_NR4 = (NR4 AND NOT NR7 AND NOT ID);
Pure_NR4_Count=0;

Pure_ID  = (ID AND NOT NR7 AND NOT NR4);
Pure_ID_Count=0;

Mix_ID_NR7  = ID_NR7;
Mix_ID_NR7_Count=0;

Mix_ID_NR4  = ID_NR4 AND NOT ID_NR7;
Mix_ID_NR4_Count=0;


for(i=1; i<BarCount; i++)
{
  Count=0;
  for(j=0; Pure_NR7[i-j]; j++) Count++;
  if (Count>0) Pure_NR7_Count[i]=Count; 

  Count=0;
  for(j=0; Pure_NR4[i-j]; j++) Count++;
  if (Count>0) Pure_NR4_Count[i]=Count; 

  Count=0;
  for(j=0; Pure_ID[i-j]; j++) Count++;
  if (Count>0) Pure_ID_Count[i]=Count; 

  Count=0;
  for(j=0; Mix_ID_NR7[i-j]; j++) Count++;
  if (Count>0) Mix_ID_NR7_Count[i]=Count; 

  Count=0;
  for(j=0; ID_NR4[i-j]; j++) Count++;
  if (Count>0) Mix_ID_NR4_Count[i]=Count; 

 
}

/*********************************************************/
  TimeFrameRestore(); // restore time frame to original 
/**********************************************************/

Pure_NR7_Color = colorBrightGreen;
Pure_NR4_Color = colorLightOrange;
Pure_ID_Color  = colorYellow;
Mix_ID_NR7_Color = colorGreen;
Mix_ID_NR4_Color = colorGold;

switch(Status("action"))
{
  case actionIndicator:

	_N(Title = Title + 
  		WriteIf(Mix_ID_NR7, EncodeColor(Mix_ID_NR7_Color) + WriteIf(Mix_ID_NR7_Count>1, StrLeft(NumToStr(Mix_ID_NR7_Count), 4), "") + " IDNR7 ",
  		WriteIf(Mix_ID_NR4, EncodeColor(Mix_ID_NR4_Color) + WriteIf(Mix_ID_NR4_Count>1, StrLeft(NumToStr(Mix_ID_NR4_Count), 4), "") + " IDNR4 ",
  		WriteIf(Pure_NR7,   EncodeColor(Pure_NR7_Color)   + WriteIf(Pure_NR7_Count > 1,  StrLeft(NumToStr(Pure_NR7_Count), 4), "") + " NR7 ",
  		WriteIf(Pure_NR4,   EncodeColor(Pure_NR4_Color)   + WriteIf(Pure_NR4_Count > 1,  StrLeft(NumToStr(Pure_NR4_Count), 4), "") + " NR4 ",
  		WriteIf(Pure_ID,    EncodeColor(Pure_ID_Color)    + WriteIf(Pure_ID_Count > 1,   StrLeft(NumToStr(Pure_ID_Count), 4), "") + " InsideDay ", "")))))
	);


	/**** 
   	Plot Shapes 
 	****/


	//-- Plot NR4 & NR7 --
	Dist = L * 0.995;

	//-- Plot Pure NR7
	PlotShapes(Pure_NR7*shapeDigit7, 
           Pure_NR7_Color, 
           0, 
           Dist);

	//-- Plot Pure NR4
	PlotShapes(Pure_NR4*shapeDigit4, 
           Pure_NR4_Color, 
           0, 
           Dist);


	//-- Plot ID & Mix ID --
	Dist = H * 1.03;

	//-- Plot Pure ID
	PlotShapes(Pure_ID*shapeHollowCircle, 
				 Pure_ID_Color,  
           0, 
           Dist);


	// -- Plot Mix NR7 & ID 
	PlotShapes(Mix_ID_NR7*shapeStar, 
           Mix_ID_NR7_Color, 
           0, 
           Dist);

	// -- Plot Mix NR4 & ID 
	PlotShapes(Mix_ID_NR4*shapeStar, 
           Mix_ID_NR4_Color, 
           0, 
           Dist);

	break;


	case actionExplore:
	Buy    = Mix_ID_NR7 OR Pure_NR7 AND Volume > 50000 AND Close > 50; 
	Sell   = Mix_ID_NR4 OR Pure_NR4 AND Volume > 50000 AND Close > 50; 
	Filter = (Pure_NR7_Count > 0) OR (Pure_NR4_Count > 0) OR (Pure_ID_Count > 0);

	SetOption("NoDefaultColumns", True);
	AddColumn(DateTime(), "DATE", formatDateTime,colorDefault, colorDefault, 80);
	AddTextColumn(Name(), "SYMBOL", 77);
	
	AddColumn(IIf(Pure_ID_Count,  48 + Pure_ID_Count,  32), "INSIDE", formatChar, colorYellow, IIf(Pure_ID_Count, colorLightBlue, colorDefault));
	AddColumn(IIf(Pure_NR4_Count, 48 + Pure_NR4_Count, 32), "NR4",    formatChar, colorYellow, IIf(Pure_NR4_Count, colorBlue, colorDefault));
	AddColumn(IIf(Pure_NR7_Count, 48 + Pure_NR7_Count, 32), "NR7",    formatChar, colorYellow, IIf(Pure_NR7_Count, colorGreen, colorDefault));

  
  AddColumn(R, "Range", 6.2, colorDefault, colorDefault, 84);
  AddColumn(High, "High", 6.2, colorDefault, colorDefault, 120);
  AddColumn(Low,  "Low",  6.2, colorDefault, colorDefault, 120);
	break;      

}   

_SECTION_END();
Thanks for the afl.

But it's not finding the stocks in RT (breking hi / lo) which were shortlisted as per condition 1 (eod).
 

KelvinHand

Well-Known Member
#6
Hello kevinhand,

Thanx you for modification in Nr4/NR7 afl.

I guess only High/Low added in exploration.


I have one Query for u..

Inside bar or Nr4 or Nr7

Which one is more effective for Intraday or short term trading (1-2 days)???

please reply.
Why NR ? Because there are indecision. You are trying to find consolidation, ranging setup.
You may see 1 Inside Bar in the higher time frame, but NRx in the lower time frame. so
NR4 or NR7 may be NR x multiples.

So they are all important whatever trading if you know how to use them.

The NR4 or NR7 was modified from someone here, was trying to reduce the repetitive between NR4 and NR7 at certain point. Therefore when you see NR7, it may inclusive of NR4.
 
Last edited:

KelvinHand

Well-Known Member
#7
hello kevinhand,

------------------------------------------------------------------------
My knowldge -

I know is u have to buy above previous day High
n keep stoploss at previous day Low n same for selling vice-versa in Inside bar or in any Nrx--4 or 7.

If u could put some more knowldge on it.

Thanx you
If you know how to trade in Daily, then you know how to apply the same technique in intraday.
Your this technique is good to avoid a series of ranging situation, but in certain time, it is a late entry.

There are other techniques like early entry at fib-r 50/62%, SnR, fine tune in lower time frame ...etc. NRx will give you certain likely situation, You need to combine with candlestick pattern in order to better success because this technique can be risky but the loss can be smaller.

Here is the example:


Take Note:
- At the NR4 or NR7, it is the your Previous Day (or Bar), so Bar @NRx High/Low is your Entry, and Bar @NRx Low/High is your StopLoss
- These are based on Historical Data to show you the typical entry
 
Last edited:

Similar threads