Need AFL Help: Previous days High Low Close

mastermind007

Well-Known Member
#21
Neha

Please try following...

Code:
DH = TimeFrameGetPrice("H", inDaily);
DL = TimeFrameGetPrice("L", inDaily);
DC = TimeFrameGetPrice("C", inDaily);
TDPP = (HHV(DH,3) + LLV(DL,3) + Ref(DC,-1))/3;
If you do want previous day only, then use Ref(HHV(DH,3),-1)

I've removed if (true) because it is not needed.
If it was some part of your stub, retain it.

Idea is not to pollute the TF data and retain the timeframe array as pure as possible.
 
Last edited:

Nehal_s143

Well-Known Member
#22
Thanks sir

This plots perfectly on intraday chart,
Nifty spot 5min chart, yesterday Nifty crashed once closed below 3DPR and today rallied above 3DPR

here is full afl code together, if any body interested :)

_SECTION_BEGIN("3DRP Levels");

TDH = TimeFrameGetPrice("H", inDaily);
TDL = TimeFrameGetPrice("L", inDaily);
TDC = TimeFrameGetPrice("C", inDaily);
TDPP = (HHV(TDH,3) + LLV(TDL,3) + Ref(TDC,-1))/3;

// PARAMETERS
SHALD = ParamList("3DRP Levels", "all|selected only|hide" );

//day
PDP = ParamList("TDPP", "SHOW|HIDE" );

DayCOLOR = 34;

PP2 = (TDH + TDL)/2;

PPU = TDPP+(TDPP-PP2);
PPL = TDPP-(TDPP-PP2);

/*--------------------------------------*/
// PLOTS
style = IIf(ParamList("Chart style", "styleCandle|styleBar")=="styleCandle",64,128) ;
//Plot (C,Date ()+" close",11,style);
//day
if ((PDP=="SHOW" OR SHALD=="all") && SHALD!="hide")

Plot (TDPP,"TDPR",DayCOLOR,1);
Plot(PPU, "",colorLime,styleDashed);
Plot(PPL, "",colorLime,styleDashed);
//PlotOHLC(PPL,PPU,PPL,PPU,"",colorSkyblue,styleClou d | styleNoLabel);


_SECTION_END();

Neha

Please try following...

Code:
DH = TimeFrameGetPrice("H", inDaily);
DL = TimeFrameGetPrice("L", inDaily);
DC = TimeFrameGetPrice("C", inDaily);
TDPP = (HHV(DH,3) + LLV(DL,3) + Ref(DC,-1))/3;
If you do want previous day only, then use Ref(HHV(DH,3),-1)

I've removed if (true) because it is not needed.
If it was some part of your stub, retain it.

Idea is not to get/retain the timeframe array as pure as possible.
 
Last edited:

Nehal_s143

Well-Known Member
#23
only for positional trades.

Will hold positional Long only till price is above 3DPR Pivot and will hold Short till price is below 3DRP

Fresh Long if price close above 3DPR upper band and Fresh Short if price closes below 3DPR lower band
 

Nehal_s143

Well-Known Member
#24
SBIN Fired above 3DPR, I dont say each time stock will fore above 3DPR, but sure it is bullish once trades above 3DPR :) use your own method to take long
 
Last edited:

Nehal_s143

Well-Known Member
#25
Sir

Values are correct but not plotting on intraday chart properly, other method posted earlier by me has limitation of max 4 days we can't use for 5 or more days


_SECTION_BEGIN("3DRP Levels");

TimeFrameSet(inDaily);

TDH = HHV(Ref(H, -1), 3); // Last 3 days high
TDL = LLV(Ref(L, -1), 3); // Last 3 days low
TDC = Ref(C, -1); // YESTERDAY close

TimeFrameRestore();

TDPP = (TDH + TDL + TDC)/3;

PP2 = (TDH + TDL)/2;

Dif = abs(TDPP-PP2);

PPU = TDPP+Dif;
PPL = TDPP-Dif;

Plot (TDPP,"TDPR",34,1);
Plot(PPU, "",colorLime,styleDashed);
Plot(PPL, "",colorLime,styleDashed);

_SECTION_END();

Your algorithm could be wrong.
When you use TimeFrameGetPrice("H OR L", inDaily, -3), you are reference to the 3rd Last Bar from Current Bar.

IF You intended to find "High of last 3 days + Low of last 3 days + Close of yesterday", THEN
You need to treat 3days as 1 single bar, just like weekly bar as 5bars per day.

In such the High of last 3 days should be HHV(ref(H, -1), 3) AND
Low of last 3 days should be LLV(ref(L, -1), 3) AND
Close of yesterday should be ref(C, -1);

PHP:
TimeFrameSet(inDaily);

TDH = HHV(Ref(H, -1), 3); // Last 3 days high
TDL = LLV(Ref(L, -1), 3); // Last 3 days low
TDC = Ref(C,  -1); // YESTERDAY close

TimeFrameRestore();
 
#26
Please help me to plot previous days high and low value on intraday price chart

below code will plot only line
_SECTION_BEGIN("PreDay HLC");
//TIME FRAME CALCULATION
H1 = TimeFrameGetPrice("H", inDaily, -1); // yesterdays high
L1 = TimeFrameGetPrice("L", inDaily, -1); // low
C1= TimeFrameGetPrice("C", inDaily, -1); // close
DayO = TimeFrameGetPrice("-1", inDaily); // current day open

//PLOTS

Plot(H1, "",colorRed,styleLine+styleThick+styleNoRescale+st yleNoLabel);
Plot(L1, "",colorBrightGreen,styleLine+styleThick+styleNoLa bel);
Plot(C1, "",colorLightGrey,styleLine+styleNoRescale+styleNo Label);
_SECTION_END();

Thanks
 

mastermind007

Well-Known Member
#28
Please help me to plot previous days high and low value on intraday price chart

below code will plot only line
_SECTION_BEGIN("PreDay HLC");
//TIME FRAME CALCULATION
H1 = TimeFrameGetPrice("H", inDaily, -1); // yesterdays high
L1 = TimeFrameGetPrice("L", inDaily, -1); // low
C1= TimeFrameGetPrice("C", inDaily, -1); // close
DayO = TimeFrameGetPrice("-1", inDaily); // current day open

//PLOTS

Plot(H1, "",colorRed,styleLine+styleThick+styleNoRescale+st yleNoLabel);
Plot(L1, "",colorBrightGreen,styleLine+styleThick+styleNoLa bel);
Plot(C1, "",colorLightGrey,styleLine+styleNoRescale+styleNo Label);
_SECTION_END();

Thanks
Nothing seems to be wrong in the code. Play with colors (in plot calls) or play with different scrip, post your screenshot if that fails.

Now, some improvements:

1) Delete the line (or comment) that reads "DayO = ...."

2) In all 3 plot calls, add names. So, instead of Plot(H1, "", ... it should be Plot(H1, "H1", ...

3), In all 3 plot calls, use pipe character (|) instead of plus (+).
something like this. styleLine|styleNoRescale|styleNoLabel
 

mastermind007

Well-Known Member
#29
Hi,

1.What will be the afl to locate a series of n consecutive bars where all of them has got equal lows (or highs)?

This afl will locate all such groups of bars in a single security throughout its history.

2. How to scan for those stocks that has ONLY n most recent bars whose highs(or lows) are equal?

This afl will be run everyday after the day's data is imported, and will scan throughout the whole database.

Please help a newbie
I am intrigued by your idea. What is it that you are planning to do? Series of consecutive lows is very very rare.

Anyways, here is the Explorer code that'd do what you want. It will not work with Scanner. You can control period to scan from Ami's analysis window itself.

Code:
dC = Param("Min. Number of Consecutive Lows", 2, 2, 10);
SLB[0] = 0;
for (i = dC; i < BarCount; i++)
{
	k = 1;
	for (j = i; j > i - dC + 1; j--)
	{
		if (Low[j] != (Low[j - 1])
			k++;
	}
	
	SLB[i] = (k == dC);
}
                             
Filter = 1;                             
AddColumn(SLB, "Low Series");
 

XRAY27

Well-Known Member
#30
only for positional trades.

Will hold positional Long only till price is above 3DPR Pivot and will hold Short till price is below 3DRP

Fresh Long if price close above 3DPR upper band and Fresh Short if price closes below 3DPR lower band
3DPR what is the meaning of this... thanks for the afl
 

Similar threads