Tuesday, July 23, 2013

NR7 Amibroker AFL and NR4 Amibroker AFL with Exploration

NR7 implies Narrow Range computed for last 7 bars. The NR7 applied on a daily timeframe
tends to be more effective . However intraday traders even use it for 4 hourly or hourly  time frame to gauge the probability of some violent movement due to volatility squeezing for a considerable period of time. Due to high volatility leading to low volatility and vice versa Narrow ranges lead to
range expansion . Some traders also use NR4 for entering into low volatility periods. Below AFL as provided by the author of the AFL makes the task very easy to identify the NR4 & NR7 stocks through exploration. 

Copy The Code Give Below:

_SECTION_BEGIN("NR7");

/*********** NR7 System for Chart and Exploration ***********************/

R = H - L;
NR7 = False;
NR4 = False;
m7 = m4 = idm7 = idm4 = idm = 0;

for(i = 7; i < BarCount; i++)
{
if( R[i] < R[i - 1] AND R[i] < R[i -2] AND R[i] < R[i - 3] AND R[i] < R[i - 4] AND R[i] < R[i - 5] AND R[i] < R[i - 6])
{
NR7[i] = True;
m7[i] = 1;
}
}

for(i = 4; i < BarCount; i++)
{
if((R[i] < R[i - 1] AND R[i] < R[i -2] AND R[i] < R[i - 3] ) AND NOT NR7[i])
{
NR4[i] = True;
m4[i] = 1;
}
}
IDNR7 = Inside() * NR7;
IDNR4 = Inside() * NR4;
ID = Inside();
idm7 = IIf(IDNR7, 1, 0);
idm4 = IIf(IDNR4, 1, 0);
idm = IIf(id, 1, 0);

for(i = 1; i < BarCount; i++)
{
if(IDNR7[i] == IDNR7[i - 1]) idm7[i] = idm7[i] + idm7[i - 1];
if(IDNR4[i] == IDNR4[i - 1]) idm4[i] = idm4[i] + idm4[i - 1];
if(NR7[i] == NR7[i - 1]) m7[i] = m7[i] + m7[i - 1];
if(NR4[i] == NR4[i - 1]) m4[i] = m4[i] + m4[i - 1];
if(ID[i] == ID[i - 1]) idm[i] = idm[i] + idm[i - 1];
}

MarkerIDNR7 = MarkerIDNR4 = shapeStar ;

Marker7 = shapeDigit7;
NR7Color = colorBrightGreen;

Marker4 = shapeDigit4;
NR4Color = colorLightOrange;

MarkerID = shapeHollowCircle;
IDColor = colorYellow;

IDNR7Color = colorBrightGreen;
IDNR4Color = colorLightOrange;

MarkerDist = L * 0.995;
IDNRDist = H * 1.03;

if(Status("action") == actionIndicator)
{
_N(Title = StrFormat("{{NAME}}, {{DATE}} ({{INTERVAL}}): {{VALUES}}") + ", Range=" + Prec(R + 0.00001, 2) + ","
+ WriteIf(IDNR7, EncodeColor(colorBrightGreen) + WriteIf(idm7 > 1, StrLeft(NumToStr(idm7), 4), "") + " IDNR7 ", "")
+ WriteIf(IDNR4, EncodeColor(colorLightOrange) + WriteIf(idm4 > 1, StrLeft(NumToStr(idm4), 4), "") + " IDNR4 ", "")
+ WriteIf(NR7 AND NOT ID, EncodeColor(colorBrightGreen) + WriteIf(m7 > 1, StrLeft(NumToStr(m7), 4), "") + " NR7 ", "")
+ WriteIf(NR4 AND NOT ID, EncodeColor(colorLightOrange) + WriteIf(m4 > 1, StrLeft(NumToStr(m4), 4), "") + " NR4 ", "")
+ WriteIf(ID AND NOT NR7 AND NOT NR4, EncodeColor(colorTurquoise) + WriteIf(idm > 1, StrLeft(NumToStr(idm), 4), "") + " Inside Day ", ""));

PlotOHLC(O, H, L, C, "Close", colorLightGrey, styleBar);
PlotShapes(IIf(IDNR7, MarkerIDNR7, shapeNone), IDNR7Color, 0, IDNRDist);
PlotShapes(IIf(IDNR4 AND NOT IDNR7, MarkerIDNR4, shapeNone), IDNR4Color, 0, IDNRDist);
PlotShapes(IIf(NR7 AND NOT ID, Marker7, shapeNone), NR7Color, 0, MarkerDist);
PlotShapes(IIf(NR4 AND NOT NR7 AND NOT ID, Marker4, shapeNone), NR4Color, 0, MarkerDist);
PlotShapes(IIf(ID AND NOT NR7 AND NOT NR4, MarkerID, shapeNone), IDColor, 0, IDNRDist);
}

if(Status("action") == actionExplore)
{
Filter = (m7 > 0) OR (m4 > 0) OR (idm > 0);

SetOption("NoDefaultColumns", True);

AddColumn(DateTime(), "DATE", formatDateTime, colorDefault, colorDefault, 96);
AddTextColumn(Name(), "SYMBOL", 77, colorDefault, colorDefault, 120);
AddColumn(R, "Range", 6.2, colorDefault, colorDefault, 84);
AddColumn(IIf(idm, 48 + idm, 32), "INSIDE", formatChar, colorYellow, IIf(idm, colorLightBlue, colorDefault));
AddColumn(IIf(m4, 48 + m4, 32), "NR4", formatChar, colorYellow, IIf(m4, colorBlue, colorDefault));
AddColumn(IIf(m7, 48 + m7, 32), "NR7", formatChar, colorYellow, IIf(m7, colorGreen, colorDefault));
}

/************************** END OF AFL CODE *****************************/

_SECTION_END();

15 comments:

  1. Hi
    How do I see the plots on the graph as indicated in your picture. When I run explore in the analysis the ticks doesnt appear.

    Your help is appreciated.

    Thanks

    Jacobus

    ReplyDelete
    Replies
    1. Hi
      I assume you cant see the marks reflected without placing the code in a chart, which I did and then I sam the same picture. Sorry for bothering you.

      Regards

      Delete
    2. You are absolutely right Jacobus.

      Happy Trading.

      Thanks.

      Delete
    3. The Hollow Marking is an Inside Bar or called an Inside Day Marking.

      The Star Marking is an Inside Day which is also a NR4 & NR7 Bar.

      The colour does not refer anything.

      Delete
  2. My copy/paste doesnt run in backtest of amibroker

    ReplyDelete
    Replies
    1. You will have to use the Explore feature in New Analysis and not the Backtest feature.

      Delete
  3. how to add buy above sell below column

    ReplyDelete
  4. Plz add Buy Above , Sell Below Column in Exploration With Stop Loss Link the Below
    https://www.facebook.com/groups/AmibrokerAFLcollection/permalink/1664158410337609/?comment_id=1698781946875255&reply_comment_id=1701073699979413&notif_id=1524017378042019&notif_t=group_comment&ref=notif

    ReplyDelete
    Replies
    1. Unfortunately I am not a member of facebook & the link is asking to login into Facebook.

      Delete
  5. OK...How to Add Buy Above , Sell Below Column in Exploration With Stop Loss

    ReplyDelete
    Replies
    1. You do one thing. Register at the below mentioned link of a forum and you can get ample help regarding your Amibroker queries. There is a full section on Amibroker in this forum.

      http://www.inditraders.com/amibroker/

      Delete
  6. Sir,
    I need the afl "tradecatcher.blogspot.com/2013/03/amibroker-afl-to-identify-trend..." posted which is with Heiking Ashi "Flower" and best support resistance etc.Please give me link to download.
    Thanks in advace.

    ReplyDelete
    Replies
    1. Hi Harish,

      That AFL was not a good one. I have removed that AFL due to its faulty nature. The new one is still better.

      Happy Trading

      Delete
  7. Sir,
    Thanks for your reply.Please provide the link for the new on which you think is better.
    Actually I was using the RSI figure showing on the chart on the last candle but do to formatting of the PC,I lost it.
    Which was very much useful.It was good to track Support Resistance and end of trending move.

    ReplyDelete
    Replies
    1. Hi ,

      The new one which I updated is at the same link which earlier comprised of the Heiken Ashi AFL. Here is the link

      http://tradecatcher.blogspot.in/2013/03/amibroker-afl-to-identify-trend-reversal.html

      There is a download link given in the Post at last which will take you to Google Drive Page for download.

      Happy Trading !!

      Delete

Required US Government Disclaimer & CTFC Rule 4.41

Futures trading contains substantial risk and is not suitable for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only consider risk capital that should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. CTFC RULE 4.41 – HYPOTHETICAL OR SIMULATED PERFORMANCE RESULTS HAVE CERTAIN LIMITATIONS. UNLIKE AN ACTUAL PERFORMANCE RECORD, SIMULATED RESULTS DO NOT REPRESENT ACTUAL TRADING. ALSO, SINCE THE TRADES HAVE NOT BEEN EXECUTED, THE RESULTS MAY HAVE UNDER-OR-OVER COMPENSATED FOR THE IMPACT, IF ANY, OF CERTAIN MARKET FACTORS SUCH AS LIQUIDITY. SIMULATED TRADING PROGRAMS IN GENERAL ARE ALSO SUBJECT TO THE FACT THAT THEY ARE DESIGNED WITH THE BENEFIT OF HINDSIGHT. NO REPRESENTATION IS BEING MADE THAT ANY ACCOUNT WILL OR IS LIKELY TO ACHIEVE PROFIT OR LOSSES SIMILAR TO THOSE SHOWN. All trades, patterns, charts, systems, etc., discussed in this website or advertisement are for illustrative purposes only and not construed as specific advisory recommendations. All ideas and materials presented herein are for information and educational purposes only. No system or trading methodology has ever been developed that can guarantee profits or prevent losses. The testimonials and examples used herein are exceptional results which do not apply to average people and are not intended to represent or guarantee that anyone will achieve the same or similar results. Trades placed on the reliance of Trend Methods systems are taken at your own risk for your own account. This is not an offer to buy or sell futures interests.