Dear @Happy_Singh Kindly help me in the following
I have this AFL which plots Central Pivot Range (CPR) and Pivot support/resistances, for both the current day and for the upcoming/next day.
What I really need is, it should also plot ‘DEVELOPING CPR OF THE DAY’ starting from the first candle of the intraday chart and ending at the last candle.
It simply means, how the CPR is shaping up during the intraday, which at the end of the trading day, becomes ‘next’ day CPR.
Here is the 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 = (PV - LB) + PV;
Plot( IIf( DayCond, UB, Null ), "UB", colorBlack, styleLine, styleNoRescale, Null, Null, 0 );
Plot( IIf( DayCond, UB, Null ), "UB", colorBlack, styleLine, styleNoRescale, Null, Null, 2 );
Plot( IIf( DayCond, PV, Null), "Pivot", colorBlack, styleLine, styleNoRescale, Null, Null, 0 );
Plot( IIf( DayCond, PV, Null), "Pivot", colorBlack, styleLine, styleNoRescale, Null, Null, 2 );
Plot( IIf( DayCond, LB, Null), "LB", colorBlack, styleLine, styleNoRescale, Null, Null, 0 );
Plot( IIf( DayCond, LB, Null), "LB", colorBlack, styleLine, styleNoRescale, 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", colorBlue, styleLine + styleThick, Null, Null, 0 );
Plot( IIf( DayCond, R1, Null ), "R1", colorBlue, styleLine, styleNoRescale, Null, Null, 2 );
Plot( IIf( DayCond, R2, Null ), "R2", colorRed, styleLine + styleThick, Null, Null, 0 );
Plot( IIf( DayCond, R2, Null ), "R2", colorRed, styleLine, styleNoRescale, Null, Null, 2 );
Plot( IIf( DayCond, S1, Null ), "S1", colorGreen, styleLine + styleThick, Null, Null, 0 );
Plot( IIf( DayCond, S1, Null ), "S1", colorGreen, styleLine, styleNoRescale, Null, Null, 2 );
Plot( IIf( DayCond, S2, Null ), "S2", colorDarkGreen, styleLine + styleThick, Null, Null, 0 );
Plot( IIf( DayCond, S2, Null ), "S2", colorDarkGreen, styleLine, styleNoRescale, 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 = (dPV - LB) + dPV;
y = LastValue( dPV );
la = LineArray( LAx0, y, LAx1, y );
Plot( la, "PV", colorBlack, styleLine, Null, Null, shift );
y = LastValue( LB );
la = LineArray( LAx0, y, LAx1, y );
Plot( la, "LB", colorBlack, styleLine, Null, Null, shift );
y = LastValue( UB );
la = LineArray( LAx0, y, LAx1, y );
Plot( la, "UB", colorBlack, 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", colorBlue, styleLine + styleThick, Null, Null, shift );
y = LastValue( R2 );
la = LineArray( LAx0, y, LAx1, y );
Plot( la, "R2", colorRed, styleLine + styleThick, Null, Null, shift );
y = LastValue( S1 );
la = LineArray( LAx0, y, LAx1, y );
Plot( la, "S1", colorGreen, styleLine + styleThick, Null, Null, shift );
y = LastValue( S2 );
la = LineArray( LAx0, y, LAx1, y );
Plot( la, "S2", colorDarkGreen, styleLine + styleThick, Null, Null, shift );
_SECTION_END();
Thanks and regards,
I have this AFL which plots Central Pivot Range (CPR) and Pivot support/resistances, for both the current day and for the upcoming/next day.
What I really need is, it should also plot ‘DEVELOPING CPR OF THE DAY’ starting from the first candle of the intraday chart and ending at the last candle.
It simply means, how the CPR is shaping up during the intraday, which at the end of the trading day, becomes ‘next’ day CPR.
Here is the 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 = (PV - LB) + PV;
Plot( IIf( DayCond, UB, Null ), "UB", colorBlack, styleLine, styleNoRescale, Null, Null, 0 );
Plot( IIf( DayCond, UB, Null ), "UB", colorBlack, styleLine, styleNoRescale, Null, Null, 2 );
Plot( IIf( DayCond, PV, Null), "Pivot", colorBlack, styleLine, styleNoRescale, Null, Null, 0 );
Plot( IIf( DayCond, PV, Null), "Pivot", colorBlack, styleLine, styleNoRescale, Null, Null, 2 );
Plot( IIf( DayCond, LB, Null), "LB", colorBlack, styleLine, styleNoRescale, Null, Null, 0 );
Plot( IIf( DayCond, LB, Null), "LB", colorBlack, styleLine, styleNoRescale, 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", colorBlue, styleLine + styleThick, Null, Null, 0 );
Plot( IIf( DayCond, R1, Null ), "R1", colorBlue, styleLine, styleNoRescale, Null, Null, 2 );
Plot( IIf( DayCond, R2, Null ), "R2", colorRed, styleLine + styleThick, Null, Null, 0 );
Plot( IIf( DayCond, R2, Null ), "R2", colorRed, styleLine, styleNoRescale, Null, Null, 2 );
Plot( IIf( DayCond, S1, Null ), "S1", colorGreen, styleLine + styleThick, Null, Null, 0 );
Plot( IIf( DayCond, S1, Null ), "S1", colorGreen, styleLine, styleNoRescale, Null, Null, 2 );
Plot( IIf( DayCond, S2, Null ), "S2", colorDarkGreen, styleLine + styleThick, Null, Null, 0 );
Plot( IIf( DayCond, S2, Null ), "S2", colorDarkGreen, styleLine, styleNoRescale, 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 = (dPV - LB) + dPV;
y = LastValue( dPV );
la = LineArray( LAx0, y, LAx1, y );
Plot( la, "PV", colorBlack, styleLine, Null, Null, shift );
y = LastValue( LB );
la = LineArray( LAx0, y, LAx1, y );
Plot( la, "LB", colorBlack, styleLine, Null, Null, shift );
y = LastValue( UB );
la = LineArray( LAx0, y, LAx1, y );
Plot( la, "UB", colorBlack, 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", colorBlue, styleLine + styleThick, Null, Null, shift );
y = LastValue( R2 );
la = LineArray( LAx0, y, LAx1, y );
Plot( la, "R2", colorRed, styleLine + styleThick, Null, Null, shift );
y = LastValue( S1 );
la = LineArray( LAx0, y, LAx1, y );
Plot( la, "S1", colorGreen, styleLine + styleThick, Null, Null, shift );
y = LastValue( S2 );
la = LineArray( LAx0, y, LAx1, y );
Plot( la, "S2", colorDarkGreen, styleLine + styleThick, Null, Null, shift );
_SECTION_END();
Thanks and regards,