Need AFL Help: Previous days High Low Close

jsb2012

Active Member
#11
Thanks a lot kh!!! BUT I AM GETTING LOT OF ERRORS. MOREOVER U HAVE GIVEN IN TWO PARTS. SORRY I NEVER THOUGHT IT WOULD B SO DIFFICULT, PLS HELP
 
Last edited:

KelvinHand

Well-Known Member
#12
Thanks a lot kh!!! BUT I AM GETTING LOT OF ERRORS. MOREOVER U HAVE GIVEN IN TWO PARTS. SORRY I NEVER THOUGHT IT WOULD B SO DIFFICULT, PLS HELP
You need the Post #1 main script.
Insert Post #9 script into the main script where i [KH] told you to place to
Ignore Post #10
 

Nehal_s143

Well-Known Member
#14
Hi

I am trying to plot 3 day rolling pivot using

high of last 3 days + low of last 3 days + close of yesterday
----------------------------------------------------------
divided by 3

but i am getting different values in afl when i compare to manual calculation results

Please help

_SECTION_BEGIN("3DRP Levels");


TDH = TimeFrameGetPrice("H", inDaily, -3); // Last 3 days high
TDL = TimeFrameGetPrice("L", inDaily, -3); // Last 3 days low
TDC = TimeFrameGetPrice("C", inDaily, -1); // YESTERDAY close


if ( True )
{
TDPP = (TDH + TDL + TDC)/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,styleCloud | styleNoLabel);


_SECTION_END();




_SECTION_BEGIN("Price");
SetChartBkGradientFill( ParamColor("BgTop",colorBlack),ParamColor("BgBottom",colorBlack),ParamColor("Titleblock",colorLightGrey));
SetChartOptions(0,chartShowDates|chartShowArrows|chartLogarithmic|chartWrapTitle);
GraphXSpace = 5;
Plot(C,"",colorWhite,styleCandle);
_SECTION_END();

//Previous Days HI LO //

YDayH = TimeFrameGetPrice("H", inDaily, -1); DayHI = LastValue (YDayH,1);// yesterdays high
YDayL = TimeFrameGetPrice("L", inDaily, -1); DayLI = LastValue (YDayL,1); // yesterdays low
YDayC = TimeFrameGetPrice("C", inDaily, -1); // yesterdays close
YDayO = TimeFrameGetPrice("O", inDaily); // current day open
DayH2= TimeFrameGetPrice("H", inDaily, -2); DayH2I = LastValue (DayH2,1); // Two days before high
DayL2= TimeFrameGetPrice("L", inDaily, -2); DayL2I = LastValue (DayL2,1); // Two days before low
DayH3= TimeFrameGetPrice("H", inDaily, -3); DayH3I = LastValue (DayH3,1); // Three days before high
DayL3= TimeFrameGetPrice("L", inDaily, -3); DayL3I = LastValue (DayL3,1); // Three days before low

numbars = LastValue(Cum(Status("barvisible")));
hts = -33.5;

YHL = ParamToggle("Yesterday HI LO","Show|Hide",0);
if(YHL==1) {
Plot(YDayL,"YL",colorTurquoise,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(YDayH,"YH",colorTurquoise,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
PlotText(" YH " , LastValue(BarIndex())-(numbars/Hts), DayHI, colorTurquoise);
PlotText(" YL " , LastValue(BarIndex())-(numbars/Hts), DayLI, colorTurquoise);
}

TDBHL = ParamToggle("2/3Days before HI LO","Show|Hide",0);
if(TDBHL==1) {
Plot(DayL2,"2DBL",colorTurquoise,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(DayH2,"2DBH",colorTurquoise,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(DayL3,"3DBL",colorTurquoise,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(DayH3,"3DBH",colorTurquoise,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
PlotText(" 2DBH " , LastValue(BarIndex())-(numbars/Hts), DayH2I, colorTurquoise);
PlotText(" 2DBL " , LastValue(BarIndex())-(numbars/Hts), DayL2I, colorTurquoise);
PlotText(" 3DBH " , LastValue(BarIndex())-(numbars/Hts), DayH3I, colorTurquoise);
PlotText(" 3DBL " , LastValue(BarIndex())-(numbars/Hts), DayL3I, colorTurquoise);
}

// Pivot Levels //
PP = (YDayL + YDayH + YDayC)/3; PPI = LastValue (PP,1); // Pivot
R1 = (PP * 2) - YDayL; R1I = LastValue (R1,1); // Resistance 1
S1 = (PP * 2) - YDayH; S1I = LastValue (S1,1); // Support 1
R2 = PP + R1 - S1; R2I = LastValue (R2,1); // Resistance 2
S2 = PP - R1 + S1; S2I = LastValue (S2,1); // Support 2
R3 = PP + R2 - S1; R3I = LastValue (R3,1); // Resistance 3
S3 = PP - R2 + S1; S3I = LastValue (S3,1); // Support 3

ppl = ParamToggle("Pivot Levels","Show|Hide",0);
if(ppl==1) {
Plot(PP, "PP",colorYellow,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(R1, "R1",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(S1, "S1",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(R2, "R2",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(S2, "S2",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(R3, "R3",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(S3, "S3",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);

PlotText(" Pivot ", LastValue(BarIndex())-(numbars/Hts), PPI, colorYellow);
PlotText(" R1 " , LastValue(BarIndex())-(numbars/Hts), R1I, colorViolet);
PlotText(" S1 " , LastValue(BarIndex())-(numbars/Hts), S1I, colorViolet);
PlotText(" R2 " , LastValue(BarIndex())-(numbars/Hts), R2I, colorViolet);
PlotText(" S2 " , LastValue(BarIndex())-(numbars/Hts), S2I, colorViolet);
PlotText(" R3 " , LastValue(BarIndex())-(numbars/Hts), R3I, colorViolet);
PlotText(" S3 " , LastValue(BarIndex())-(numbars/Hts), S3I, colorViolet);
}

// Current Days Hi Lo //
THL = ParamToggle("Todays Hi Lo","Show|Hide",1);
if(THL==1) {
isRth = TimeNum() >= 084500 & TimeNum() <= 085959;
isdRth = TimeNum() >= 084500 & TimeNum() <= 160000;
aRthL = IIf(isRth, L, 1000000);
aRthH = IIf(isdRth, H, Null);
aRthLd = IIf(isdRth, L, 1000000);
DayH = TimeFrameCompress( aRthH, inDaily, compressHigh );
DayH = TimeFrameExpand( DayH, inDaily, expandFirst );
DayL = TimeFrameCompress( aRthLd, inDaily, compressLow );
DayL = TimeFrameExpand( DayL, inDaily, expandFirst );
Bars = BarsSince(TimeNum() >= 94500 AND TimeNum() < 095959);//,BarIndex(),1); // AND DateNum()==LastValue(DateNum());
x0 = BarCount-LastValue(Bars);
x1 = BarCount-1;
DayHline=LineArray(x0,LastValue(DayH),x1,LastValue (DayH),0);
DayLline=LineArray(x0,LastValue(DayL),x1,LastValue (DayL),0);
DayHlineI = LastValue (DayHline,1);
DayLlineI = LastValue (DayLline,1);
Plot(DayHline,"DayH",colorYellow,styleBar|styleNoRescale|styleNoTitle);
Plot(DayLline,"DayL",colorYellow,styleBar|styleNoRescale|styleNoTitle);
PlotText(" Day Hi " , LastValue(BarIndex())-(numbars/Hts), DayHlineI +0.05, colorYellow);
PlotText(" Day Lo " , LastValue(BarIndex())-(numbars/Hts), DayLlineI +0.05, colorYellow);
}

//Intraday Hrl HI LO //

HiHrly = TimeFrameGetPrice("H", inHourly);
LoHrly = TimeFrameGetPrice("L", inHourly);

Plot(HiHrly ,"",colorBlue, styleLine );
Plot(LoHrly ,"",colorDarkRed,styleLine);

RangeTitle = EncodeColor(colorBlack) + "TODay Range= " + EncodeColor(colorBlack) + StrToNum(NumToStr(round((DayH - DayL)), 4.4));
YSDAYRangeTitle = EncodeColor(colorBlack) + "YSDay Range= " + EncodeColor(colorBlack) + StrToNum(NumToStr(round((YDayH - YDayL)), 5.4));
Hodcolorsheme=colorDarkBlue;
LodColorscheme=colorOrange;
Title = EncodeColor(colorDarkBlue)+ "HULK HOD-LOD" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorRed) +
" - " + Date() +" - "+"\n" +EncodeColor(colorBlack) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n" +
EncodeColor(Hodcolorsheme) + "HiHrly= " + EncodeColor(colorBlack) + HiHrly + "\n" +
EncodeColor(LodColorscheme) + "LowHrly= " + EncodeColor(colorBlack) + LoHrly + "\n" +
EncodeColor(Hodcolorsheme) + "HOD= " + EncodeColor(colorBlack) + DayH + "\n" +
EncodeColor(LodColorscheme) + "LOD= " + EncodeColor(colorBlack) + DayL + "\n" + RangeTitle +"\n" +
EncodeColor(Hodcolorsheme) + "YsdayHi= " + EncodeColor(colorBlack) + YDayH+ "\n" +
EncodeColor(LodColorscheme) + "YsdayLow= " + EncodeColor(colorBlack) + YDayL + "\n" + YSDAYRangeTitle;
_SECTION_END();


In above code I added Todya Hi / low + Hourly Hi /low , Yesterday Hi/Low , 2Days/3Days Hi / Lo also with range & PP

When u plot a chart by default u cans see 4 lines on chart i.e Hrly hi / low lines , Daily hi / low Doted lines

Now if u go to parameter windows you can see option call, Ysday hi low / 2 Days / 3 Days Hi low & Pivot = Show(by default), if u change to Hide then you can see all lines also on chart.


Enjoy :thumb:

HULK
 

pratapvb

Well-Known Member
#15
Hi

I am trying to plot 3 day rolling pivot using

high of last 3 days + low of last 3 days + close of yesterday
----------------------------------------------------------
divided by 3

but i am getting different values in afl when i compare to manual calculation results

Please help

_SECTION_BEGIN("3DRP Levels");


TDH = TimeFrameGetPrice("H", inDaily, -3); // Last 3 days high
TDL = TimeFrameGetPrice("L", inDaily, -3); // Last 3 days low
TDC = TimeFrameGetPrice("C", inDaily, -1); // YESTERDAY close


if ( True )
{
TDPP = (TDH + TDL + TDC)/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,styleCloud | styleNoLabel);


_SECTION_END();
Use ref(tdh, -1) and ref(tdl,-1) for prev 3 day high and low


so use
TDPP = (Ref(TDH,-1) + Ref(TDL,-1) + TDC)/3;
 
Last edited:

KelvinHand

Well-Known Member
#16
Hi

I am trying to plot 3 day rolling pivot using

high of last 3 days + low of last 3 days + close of yesterday
----------------------------------------------------------
divided by 3

but i am getting different values in afl when i compare to manual calculation results

Please help
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();
 
Last edited:

pratapvb

Well-Known Member
#17
When you use TimeFrameGetPrice("H OR L", inDaily, -3), you are reference to the 3rd Last Bar from Current Bar.

IF he intended to find "High of last 3 days + Low of last 3 days + Close of yesterday", THEN
He 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);

Definitely don't forget to put above statements in between TimeFrameSet(inDaily); AND TimeFrameRestore();
Kevin either should work in my view.

I just used the path that has the least changes to his code and the values he already got from Timeframegetprice

ref(tdh, -1)

when tdh is the highest high of last 3 bars including current bar. So ref(xx,-1) of that will give the highest high of 3 bars as of yday including yday bar
 

Nehal_s143

Well-Known Member
#18
Thanks Pratap Sir & Kelvin Sir

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();

This worked :)

I have also tried in other way which also worked, found afl for 4 day high low on net which I adjusted to 3 day now both afl giving same result

_SECTION_BEGIN("3 day rolling pivot method");
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
DC=TimeFrameGetPrice( "C", inDaily, 0);
TDC=TimeFrameGetPrice( "C", inDaily, -1);
dh=TimeFrameGetPrice( "H", inDaily, 0);
dh1=TimeFrameGetPrice( "H", inDaily, -1);
dh2=TimeFrameGetPrice( "H", inDaily, -2);
dh3=TimeFrameGetPrice( "H", inDaily, -3);
dh4=TimeFrameGetPrice( "H", inDaily, -3);
DL=TimeFrameGetPrice( "L", inDaily, 0);
dl1=TimeFrameGetPrice( "l", inDaily, -1);
dl2=TimeFrameGetPrice( "l", inDaily, -2);
dl3=TimeFrameGetPrice( "l", inDaily, -3);
dl4=TimeFrameGetPrice( "l", inDaily, -3);
do1=TimeFrameGetPrice( "O", inDaily, -1);
doo=TimeFrameGetPrice( "O", inDaily, 0);

Maxh1=Max(dh1,dh2);
Maxh2=Max(dh3,dh4);
Maxh=Max(Maxh1,Maxh2);
//Plot(Maxh,"maxh",colorBrown,styleLine);

Minl1=Min(dl1,dl2);
Minl2=Min(dl3,dl4);
Minl=Min(Minl1,Minl2);
//Plot(Minl,"minl",colorYellow,styleLine);


TDPP = (Maxh + Minl + TDC)/3;

DayCOLOR = 34;

PP2 = (Maxh + Minl)/2;

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


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


Title = EncodeColor(colorBlack)+ "" + "" + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +" - "+"\n" +EncodeColor(colorBlue) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+" 3dh= "+WriteVal(Maxh)+" 3dL= "+WriteVal(Minl);

_SECTION_END();


Thank you Sir once gain for prompt help
 
#19
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
 

Nehal_s143

Well-Known Member
#20
If price is trading above 3 day pivot range then its bullish trend and if trend below lower range then its bearish trend, if trend is bullish look for only buy trades as per system you follow for trading and vise verse
 

Similar threads