Conditional Plotting

I have been trying to get my way around this but somehow, seems am missing something, cause i've tried in different ways but am unable to get the desired result.

I want to plot yesterdays H&L if there is either an Inside bar or NR 7. And if so, i want the plotting to begin from yesterdays open.

The code mentioned below uses DayOfYear function, but i would prefer to using trendline plotting via LineArray function but am unable to get the X0 co-ordinate for the open of the previous day when i am in lower time frame than Daily, say 5m. And that is the first issue. Please suggest which function is better for making such plotting!

The second is that the condition of IB or NR7 is not validating somehow. I believe i am doing something wrong here, ... or maybe somewhere else in the code.

Request someone to have a look and suggest the right function for plotting the HL starting from the previous day open and the right way to validate the IB or NR7 condition.


//NR 7 & InsideBar RANGES
Plot( C, "Close", colorDefault,GetPriceStyle() ); 

TimeFrameSet( inDaily ); 
range = H-L;
Condition0 = range<Ref(range,-1) AND range<Ref(range,-2) AND range<Ref(range,-3)AND range<Ref(range,-4)AND range<Ref(range,-5)AND range<Ref(range,-6);
NR7 = IIf(Condition0,True, False);
in = Inside();

// Exploration
WriteIf(NR7,"07"," "));
Filter = NR7 OR in;
AddTextColumn(NRstatus, "NR", 1,colorBlack, colorLime,120);

NRS = TimeFrameExpand(NR,inDaily,expandFirst);
iif(NRS AND Interval(0)==86400,	PlotShapes(shapeHollowSmallSquare*NRS,colorGreen,0,H,5),0);

function CDL( array )
    doy = DayOfYear();
    Lastdoy = doy == LastValue( doy );
    Dayline = array * Lastdoy;
    return IIf( Dayline, Dayline, Null );
function cdlS( array )
    doy = DayOfYear();
    Lastdoy = doy == LastValue( doy-1);
    Dayline = array * Lastdoy;
    return IIf( Dayline, Dayline, Null );
H1=TimeFrameGetPrice( "H", inDaily, -1 );
L1=TimeFrameGetPrice( "L", inDaily, -1 );
L0=TimeFrameGetPrice( "L", inDaily,0);
H0=TimeFrameGetPrice( "H", inDaily,0);

Plot (cdl(H1),"H1",colorCustom11,styleDots|styleNoRescale|styleNoLabel);
Plot (cdl(L1),"L1",colorCustom12,styleDots|styleNoRescale|styleNoLabel);


////================  any of the 2 if's  =======================================================
	IIf(id,Plot(cdlS(H0),"H1",colorCustom11,styleDots|styleNoRescale|styleNoLabel) AND
					Plot (cdlS(L0),"L1",colorCustom12,styleDots|styleNoRescale|styleNoLabel),0);
	//if(id)	{Plot(cdlS(H0),"H1",colorCustom11,styleDots|styleNoRescale|styleNoLabel);
	//				Plot (cdlS(L0),"L1",colorCustom12,styleDots|styleNoRescale|styleNoLabel);}

Looks like a little Crabel work from his book. Anyway, just a very brief generic comment with these type of things.

Explorations using every quote, versus last bar or day, verse a chart plot might be different, not sure. Just remember AB works in arrays, and so do the plot functions, so go over your code and try to see what you have written in terms of Moving bar by bar in time, versus populating array variables all at once. That might help you see what is wrong. Then I would look at the time frame set afterwards and see if that causes an issue.


Thanks for the response.

Yes, there are couple of things that the code attempts to do.

  1. Looking up for NR7 & IB ranges.
  2. Exploration
  3. Validating and Plotting.

The first two elements are that of a borrowed code from the net.
The functions used in the 3rd element are also copied from else where in order to get the plots from the start of the previous day.

It is only when i am validating the NR or IB conditions for the previous day that am facing the error of invalidation of NR or IB. That is the only hickup i am facing.

Like i mentioned, i have attempted to do it in various different ways but am unable to get the desired result for validation. If i was any better in coding, i would have solved it myself.

Cheers, :slight_smile:

Am trying as i write. Nested important referance points as LastValue. Will make sure and get back.

In the meanwhile, let me know.
Cheers, :slight_smile:

I think It's much more simple than you think , there's no need to use linearray , just use plot and it will do what you seek

The below code will detect NR7 formation and IB , if it find one or more of them it would plot the high and low of the last bar in the formation , i assume you will apply this in 1 minute frame ( or any time frame less than Daily ) , because you used Timeframeset Function , also when you perform Exploration make sure to check the periodicity to the desired time frame

Plot( C, "Close", colorDefault,styleBar ); 


// Signal Detection ...
R   = Range      = H-L;
NRS = NR7_Signal = LLV(R,7) == R;
IB  = Inside_Bar = Inside();

// Plotting High and Low Relating to NR7 and IB ...
HNRS = ValueWhen(NRS,High);
LNRS = ValueWhen(NRS,Low);
HIB  = ValueWhen(IB,High);
LIB  = ValueWhen(IB,Low);


Plot(TimeFrameExpand(HNRS,inDaily,expandFirst),"NR7's High",colorLime,styleLine);
Plot(TimeFrameExpand(LNRS,inDaily,expandFirst),"NR7's Low ",colorRed,styleLine);
Plot(TimeFrameExpand(HIB,inDaily,expandFirst),"IB's High"  ,colorWhite,styleLine);
Plot(TimeFrameExpand(LIB,inDaily,expandFirst),"IB's Low "  ,colorOrange,styleLine);

// Adjust your Backtest setting to Daily ...
Filter = NRS OR IB ;
AddColumn(NRS ,"NR7"        ,1.0,colorDefault,colorLime);
AddColumn(HNRS,"NR7's High" ,1.0,colorDefault,colorDefault);
AddColumn(LNRS,"NR7's Low"  ,1.0,colorDefault,colorDefault);
AddColumn(IB  ,"Inside Bar" ,1.0,colorDefault,colorLightOrange);
AddColumn(HIB ,"Inside Bar's High",1.0,colorDefault,colorDefault);
AddColumn(LIB ,"Inside Bar's Low",1.0,colorDefault,colorDefault);

if you have some notes on the above code , i would like to hear it form you , hope it would be helpful ...


Hello Sebastian. Appreciate the guidance, really! Thanks a lot man. I picked up a few things from your style of code and plotting. Cheers, :slight_smile:

I was able to crack the issue and in the end noticed my limitation of knowledge regarding the AFL language. After cracking and smoothing it out, all i just did was to add an extra line of code and refer to that line as validation for NR7 or IB.

NRO = IIf(LastValue(Ref(NR,-1)), True,False);  //  Just this addition

Validation : if(NRO)

Thanks to the community for the support.