AFL Programming for Floor Pivots and Central Pivot Range

Respected Members,

I'm an intraday trader and work on 5 min charts. I use Daily, Weekly and Monthly Floor Pivot Points and Central Pivot Range based on the previous day's high, low and close prices. I'm totally new to amibroker and want to plot these levels on my intraday charts. But I'm struggling to have them on charts. I see daily charts with weekly and monthly floor pivots put on them and then I work on 5 min chart with daily pivot and CPR plotted on my 5 min chart. This daily floor pivot and CPR gets calculated based on the previous day's high, low and close. Can any fellow member please help me with the AFL programming so that I can put these levels on my daily and intraday charts. The relevant formulas are:

Daily Floor Pivots:
Central Pivot Point (PP) = (High+Low+Close)/3
R1 = (2Pivot)-Low
R2 = Pivot + (High-Low)
R3 = R1 + (High-Low)
S1 = (2
Pivot)-High
S2 = Pivot - (High-Low)
S3 = S1 -(High-Low)
These levels calculated based on the high, low, close of previous day

Weekly and Monthly Floor Pivots:
Calculated based on the previous week and previous month's high, low, close using the same above mentioned formulae.

Central Pivot Range/CPR:
I want to use CPR calculated on the basis of previous day's high, low, close data using following formulae and then put it on my intraday chart:
Central Pivot Line (CPL) = (High+Low+Close)/3
Lower Boundary (LB) = (High+Low)/2
Upper Boundary (UB) = (Central Pivot Line-LB)+Central Pivot Line

The daily floor pivots and the CPR needs to appear on intraday chart of may previous days together i.e. if 5 min chart of 5 days is opened the daily pivot of each day must appear for the relevant day and the CPR for each of these 5 days must appear on the chart. Can somebody provide me the AFL programming for all these levels? I know nothing about AFL programming.

Thanks

1 Like

I have arranged following AFL and it's working ok.

But the problem is that I can see the lines for the next day only when the next day comes and first candle for that day becomes. I want to see the lines for the next day the previous day itself. Say levels of 10th march on 9th march itself.

Can somebody here do the necessary editing so that I can see lines for next day on previous day itself when market closes on the previous day?

_SECTION_BEGIN("CPR");


PDH =  TimeFrameGetPrice("H", inDaily, -1);    
PDL =  TimeFrameGetPrice("L", inDaily, -1);
PDC =  TimeFrameGetPrice("C", inDaily, -1);

PV=(PDH+PDL+PDC)/3;
LB=(PDH+PDL)/2;
UB=2*PV-LB;

Plot(UB, "U B",colorAqua,styleLine);
Plot(PV, "Pivot",colorAqua,styleLine);
Plot(LB, "L B",colorAqua,styleLine);

_SECTION_BEGIN("Price1");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();

_SECTION_BEGIN("Pivot Levels");


PDH =  TimeFrameGetPrice("H", inDaily, -1);    
PDL =  TimeFrameGetPrice("L", inDaily, -1);
PDC =  TimeFrameGetPrice("C", inDaily, -1);

PV=(PDH+PDL+PDC)/3;
R1=2*PV-PDL;
R2=PV+PDH-PDL;
S1=2*PV-PDH;
S2=PV-PDH+PDL;

Plot(R1, "R 1",colorRed,styleLine);
Plot(R2, "R 2",colorOrange,styleLine);
Plot(PV, "Pivot",colorAqua,styleLine);
Plot(S1, "S 1",colorGreen,styleLine);
Plot(S2, "S 2",colorLime,styleLine);

_SECTION_BEGIN("Price1");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();

There are many ways to code for what you are looking for. Drawing clues from what has already been discussed in this KB Article and from what other Seniors have shared in their previous posts below is one way to code.

_SECTION_BEGIN( "CPR" );
	 dtDayStartComp = TimeFrameCompress( DateTime(), inDaily, compressOpen );
	 dtDayStartExp = TimeFrameExpand( dtDayStartComp, inDaily, expandFirst );
	 dtDayEndComp = TimeFrameCompress( DateTime(), inDaily, compressLast );
	 dtDayEndExp = TimeFrameExpand( dtDayEndComp, inDaily, expandFirst );
	 DayCond = DateTime() >= dtDayStartExp AND DateTime() < dtDayEndExp;	 
	 
	 // Previous Days High Low Close
	 PDH =  TimeFrameGetPrice( "H", inDaily, -1 );
	 PDL =  TimeFrameGetPrice( "L", inDaily, -1 );
	 PDC =  TimeFrameGetPrice( "C", inDaily, -1 );
	 
	 PV = ( PDH + PDL + PDC ) / 3;
	 LB = ( PDH + PDL ) / 2;
	 UB = 2 * PV - LB;
	 
	 Plot( IIf( DayCond, UB, Null ), "UB", colorAqua, styleLine, Null, Null, 0 );
	 Plot( IIf( DayCond, UB, Null ), "UB", colorAqua, styleLine, Null, Null, 2 );
	 
	 Plot( IIf( DayCond, PV, Null), "Pivot", colorAqua, styleLine, Null, Null, 0 );
	 Plot( IIf( DayCond, PV, Null), "Pivot", colorAqua, styleLine, Null, Null, 2 );
	 
	 Plot( IIf( DayCond, LB, Null), "LB", colorAqua, styleLine, Null, Null, 0 );
	 Plot( IIf( DayCond, LB, Null), "LB", colorAqua, styleLine, Null, Null, 2 );
_SECTION_END();

_SECTION_BEGIN( "Pivot Levels" );
	 //PDH =  TimeFrameGetPrice( "H", inDaily, -1 );
	 //PDL =  TimeFrameGetPrice( "L", inDaily, -1 );
	 //PDC =  TimeFrameGetPrice( "C", inDaily, -1 );

	 //PV = ( PDH + PDL + PDC ) / 3;
	 R1 = 2 * PV - PDL;
	 R2 = PV + PDH - PDL;
	 S1 = 2 * PV - PDH;
	 S2 = PV - PDH + PDL;

	 Plot( IIf( DayCond, R1, Null ), "R1", colorRed, styleLine, Null, Null, 0 );
	 Plot( IIf( DayCond, R1, Null ), "R1", colorRed, styleLine, Null, Null, 2 );
	 
	 Plot( IIf( DayCond, R2, Null ), "R2", colorOrange, styleLine, Null, Null, 0 );
	 Plot( IIf( DayCond, R2, Null ), "R2", colorOrange, styleLine, Null, Null, 2 );
	 
	 Plot( IIf( DayCond, S1, Null ), "S1", colorGreen, styleLine, Null, Null, 0 );
	 Plot( IIf( DayCond, S1, Null ), "S1", colorGreen, styleLine, Null, Null, 2 );
	 
	 Plot( IIf( DayCond, S2, Null ), "S2", colorLime, styleLine, Null, Null, 0 );
	 Plot( IIf( DayCond, S2, Null ), "S2", colorLime, styleLine, Null, Null, 2 );
_SECTION_END();

_SECTION_BEGIN( "Price1" );
	 SetChartOptions( 0, chartShowArrows | chartShowDates );
	 _N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );
	 Plot( C, "Close", ParamColor( "Color", colorDefault ), styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );
_SECTION_END();



_SECTION_BEGIN( "To view Pivots of Next Day as Today closes" );
	 shift = 10; //Number of Bars to be shifted, could use a Param if needed
	 bi = BarIndex();
	 lvbi = LastValue( bi );
	 LAx0 = lvbi - shift + 1;
	 LAx1 = lvbi;
	 
	 // Present Days High Low Close
	 // These levels will be dynamic as day progresses and would ahow up in the no bar region after the last visible Bar for shifted number of bars (i.e. 10 in this case)
	 // Do use "Bar Replay" to figure out what I mean
	 dH = TimeFrameGetPrice( "H", inDaily, 0 );
	 dL = TimeFrameGetPrice( "L", inDaily, 0 );
	 dC = TimeFrameGetPrice( "C", inDaily, 0 );
	 
	 //Central Pivots shifted for Next Day
	 dPV = ( dH + dL + dC ) / 3;
	 LB = ( dH + dL ) / 2;
	 UB = 2 * dPV - LB;	 
	 
	 y = LastValue( dPV );
	 la = LineArray( LAx0, y, LAx1, y );
	 Plot( la, "PV", colorAqua, styleLine, Null, Null, shift );
	 
	 y = LastValue( LB );
	 la = LineArray( LAx0, y, LAx1, y );
	 Plot( la, "LB", colorAqua, styleLine, Null, Null, shift );
	 
	 y = LastValue( UB );
	 la = LineArray( LAx0, y, LAx1, y );
	 Plot( la, "UB", colorAqua, styleLine, Null, Null, shift );
	 
	 //Pivot Levels shifted for Next Day
	 R1 = 2 * dPV - dL;
	 R2 = dPV + dH - dL;
	 S1 = 2 * dPV - dH;
	 S2 = dPV - dH + dL;
	 
	 y = LastValue( R1 );
	 la = LineArray( LAx0, y, LAx1, y );
	 Plot( la, "R1", colorRed, styleLine, Null, Null, shift );
	 
	 y = LastValue( R2 );
	 la = LineArray( LAx0, y, LAx1, y );
	 Plot( la, "R2", colorOrange, styleLine, Null, Null, shift );
	 
	 y = LastValue( S1 );
	 la = LineArray( LAx0, y, LAx1, y );
	 Plot( la, "S1", colorGreen, styleLine, Null, Null, shift );
	 
	 y = LastValue( S2 );
	 la = LineArray( LAx0, y, LAx1, y );
	 Plot( la, "S2", colorLime, styleLine, Null, Null, shift );
_SECTION_END();
9 Likes

Sir, I think you solved my problem. Many thanks

Hello deepaksharma
I am also struggling with the same issues as you experienced in CPR. can you provide me with the programming required. I know next to nothing about amibroker programming.

Please help.

Hi can you please add Yesterday high low and close along with weekly high low and close.

Hi,
Thanks for the above code, but when I am using pivot and cpr using above code my chart looks little compressed type which was not before using CPR afl.
And when I remove CPR afl chart looks normal.

Please anyone can help me how to fix this issue.

It opens too much. Can it fit and look perfect?

Dear Sir,

I want put those codes in order to get new formula for suport and resistant number to the curve. Can you help me how to put this new formula? Thank you Sir

Hi Thanks for reply, but not sure how to fix this.
thanks!

1 Like