Hw to Plot Pivots for the fresh day (start to end) instead of candle based

Dear forum members,

How can I plot the Standard pivots for the entire day instead of them being formed on candle to candle basis? When i meant entire day - I want the pivot lines of any fresh day to be plotted and shown till the day end on every fresh day start. As of now the plotting is happening based on candle to candle.

Code for floor pivots

// Standard  Pivots //

GraphXSpace = 5 ;
SetChartOptions(0,chartShowArrows|chartShowDates);

Plot(C,"Close",colorBlack, styleCandle);
ppl = ParamToggle("Plot Pivot Levels","Off|On",1);

numbars = LastValue(Cum(Status("barvisible")));
fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2);
hts = -33.5;

/* This code calculates the previous days high, low and close */
Hi1 = IIf(Day()!=Ref(Day(),-1),Ref(HighestSince(Day()!=Ref(Day(),-1),H,1),-1),0);
Hi = ValueWhen(Day()!=Ref(Day(),-1),Hi1,1);
Lo1 = IIf(Day()!=Ref(Day(),-1),Ref(LowestSince(Day()!=Ref(Day(),-1),L,1),-1),0);
Lo = ValueWhen(Day()!=Ref(Day(),-1),Lo1,1);
Cl1 = IIf(Day()!=Ref(Day(),-1),Ref(C,-1),0);
C1 = ValueWhen(Day()!=Ref(Day(),-1),Cl1,1);



/* aily pivots calculation*/

rg = (Hi - Lo);
bp = (Hi + Lo + C1)/3; bpI = LastValue (bp,1);
r1 = (bp*2)-Lo; r1I = LastValue (r1,1);
s1 = (bp*2)-Hi; s1I = LastValue (s1,1);
r2 = bp + r1 - s1; r2I = LastValue (r2,1);
s2 = bp - r1 + s1; s2I = LastValue (s2,1);
r3 = bp + r2 - s1; r3I = LastValue (r3,1);
s3 = bp - r2 + s1; s3I = LastValue (s3,1);
r4 = bp + r2 - s2; r4I = LastValue (r4,1);
s4 = bp - r2 + s2; s4I = LastValue (s4,1);

if(ppl==1) {
Plot(bp,"",colorBlue,styleLine|styleDots|styleNoRescale);
Plot(s1,"",colorRed,styleLine|styleNoRescale);
Plot(s2,"",colorRed,styleLine|styleNoRescale);
Plot(s3,"",colorRed,styleLine|styleNoRescale);
Plot(s4,"",colorRed,styleLine|styleNoRescale);
Plot(r1,"",colorGreen,styleLine|styleNoRescale);
Plot(r2,"",colorGreen,styleLine|styleNoRescale);
Plot(r3,"",colorGreen,styleLine|styleNoRescale);
Plot(r4,"",colorGreen,styleLine|styleNoRescale);
PlotText(" Pivot = " + WriteVal(bp,fraction), LastValue(BarIndex())-(numbars/Hts), bpI +0.05, colorBlue);
PlotText(" r1 = " + WriteVal(r1,fraction), LastValue(BarIndex())-(numbars/Hts), r1I +0.05, colorGreen);
PlotText(" s1 = " + WriteVal(s1,fraction), LastValue(BarIndex())-(numbars/Hts), s1I +0.05, colorRed);
PlotText(" r2 = " + WriteVal(r2,fraction), LastValue(BarIndex())-(numbars/Hts), r2I +0.05, colorGreen);
PlotText(" s2 = " + WriteVal(s2,fraction), LastValue(BarIndex())-(numbars/Hts), s2I +0.05, colorRed);
PlotText(" r3 = " + WriteVal(r3,fraction), LastValue(BarIndex())-(numbars/Hts), r3I +0.05, colorGreen);
PlotText(" s3 = " + WriteVal(s3,fraction), LastValue(BarIndex())-(numbars/Hts), s3I +0.05, colorRed);
PlotText(" r4 = " + WriteVal(r4,fraction), LastValue(BarIndex())-(numbars/Hts), r4I +0.05, colorGreen);
PlotText(" s4 = " + WriteVal(s4,fraction), LastValue(BarIndex())-(numbars/Hts), s4I +0.05, colorRed);
}

The above code represents chart as follows -
Current Pivots

Instead, I would like to have pivots plotted for the whole day right from start of the day as shown below...

Required format

Kindly help to get the needful..

1 Like

Both codes show DAILY pivots.
What you mean is that you want to remove connection line between days.

BTW this one is not good at all

Instead you just need three short lines!

Hi = TimeFrameGetPrice("H", inDaily, -1);
Lo = TimeFrameGetPrice("L", inDaily, -1);
C1 = TimeFrameGetPrice("C", inDaily, -1);


/// Standard  Pivots //
/// @link https://forum.amibroker.com/t/hw-to-plot-pivots-for-the-fresh-day-start-to-end-instead-of-candle-based/21289
GraphXSpace = 5 ;
SetChartOptions(0,chartShowArrows|chartShowDates);

Plot(C,"Close",colorBlack, styleCandle);
ppl = ParamToggle("Plot Pivot Levels","Off|On",1);
fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2);

dn = DateNum();
newday = dn != Ref( dn, -1);

/* This code calculates the previous days high, low and close */
Hi = TimeFrameGetPrice("H", inDaily, -1);
Lo = TimeFrameGetPrice("L", inDaily, -1);
C1 = TimeFrameGetPrice("C", inDaily, -1);

/* aily pivots calculation*/
rg = (Hi - Lo);
bp = (Hi + Lo + C1)/3; bpI = LastValue (bp,1);
r1 = (bp*2)-Lo; r1I = LastValue (r1,1);
s1 = (bp*2)-Hi; s1I = LastValue (s1,1);
r2 = bp + r1 - s1; r2I = LastValue (r2,1);
s2 = bp - r1 + s1; s2I = LastValue (s2,1);
r3 = bp + r2 - s1; r3I = LastValue (r3,1);
s3 = bp - r2 + s1; s3I = LastValue (s3,1);
r4 = bp + r2 - s2; r4I = LastValue (r4,1);
s4 = bp - r2 + s2; s4I = LastValue (s4,1);

/// @link https://forum.amibroker.com/t/hw-to-plot-pivots-for-the-fresh-day-start-to-end-instead-of-candle-based/21289/2
function SetNull(array, mode) {
	global newday;
	if ( mode )
		result = IIf(! newday, array, Null);
	else
		result = IIf(newday OR Ref(newday,-1), array, Null);
	return result;
}

if(ppl==1) {
	y_offset = 2;
	Plot(SetNull(bp, 1),"",colorBlue,styleStaircase|styleDots|styleNoRescale);
	Plot(SetNull(bp, 0),"",colorBlue,styleStaircase|styleNoRescale);
	PlotText(" Pivot = " + WriteVal(bp,fraction), BarCount+2, bpI, colorBlue, -1, y_offset);
	for (i = 1; i <= 4; i++) {
		s = VarGet("s"+i);
		Plot(SetNull(s,1),"",colorRed,styleLine|styleNoRescale);
		Plot(SetNull(s,0),"",colorRed,styleStaircase|styleNoRescale);
		PlotText(" s"+i+" = " + WriteVal(s,fraction), BarCount+2, LastValue(s), colorRed, -1, y_offset);
		r = VarGet("r"+i);
		Plot(SetNull(r,1),"",colorGreen,styleLine|styleNoRescale);
		Plot(SetNull(r,0),"",colorGreen,styleStaircase|styleNoRescale);
		PlotText(" r"+i+" = " + WriteVal(r,fraction), BarCount+2, LastValue(r), colorGreen, -1, y_offset);
	}
}

14

3 Likes

Dear @fxshrat,

First and foremost thanks a ton for your instant response and the very nature of helping.. After looking at the suggestion from you, I assume that i might have not properly communicated well enough on my requirement.

My requirement is to have the pivots plotted for the entire day at the start of the day itself rather forming them candle by candle... If we bar replay, we can see the pivot lines being created with each fresh candle. I do not want this but instead al pivots for a fresh trading session to be plotted at the day start itself ( plotting to be extended till day end from the day start ) as shown in the below picture.

The below picture is taken from a different software during the middle of a trading session. If you notice, all the pivots are plotted and extended till the day end and it gives an idea on what price levels the pivots are extended for the entire day. Kindly help me achieve this format of plotting.

Required format

On this suggestion, I absolutely agree with you. But i intend to create a switch between multiple lower time frames to plot pivots of different time frames.. As of now it is just on Daily time frame. Hence I have used the above. Thanks for making that point.

Here you go...

/// Standard  Pivots //
/// @link https://forum.amibroker.com/t/hw-to-plot-pivots-for-the-fresh-day-start-to-end-instead-of-candle-based/21289
GraphXSpace = 5 ;
SetChartOptions(0,chartShowArrows|chartShowDates);

Plot(C,"Close",colorBlack, styleCandle);
ppl = ParamToggle("Plot Pivot Levels","Off|On",1);
fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2);

/* This code calculates the previous days high, low and close */
tmfrm = inDaily;
Hi = TimeFrameGetPrice("H", tmfrm, -1);
Lo = TimeFrameGetPrice("L", tmfrm, -1);
C1 = TimeFrameGetPrice("C", tmfrm, -1);

/* aily pivots calculation*/
rg = (Hi - Lo);
bp = (Hi + Lo + C1)/3; bpI = LastValue (bp,1);
r1 = (bp*2)-Lo; r1I = LastValue (r1,1);
s1 = (bp*2)-Hi; s1I = LastValue (s1,1);
r2 = bp + r1 - s1; r2I = LastValue (r2,1);
s2 = bp - r1 + s1; s2I = LastValue (s2,1);
r3 = bp + r2 - s1; r3I = LastValue (r3,1);
s3 = bp - r2 + s1; s3I = LastValue (s3,1);
r4 = bp + r2 - s2; r4I = LastValue (r4,1);
s4 = bp - r2 + s2; s4I = LastValue (s4,1);

/// @link https://forum.amibroker.com/t/hw-to-plot-pivots-for-the-fresh-day-start-to-end-instead-of-candle-based/21289/2
function SetNull(array, mode) {
	global newday;
	if ( mode )
		result = IIf(! newday, array, Null);
	else
		result = IIf(newday OR Ref(newday,-1), array, Null);
	return result;
}

dn = DateNum();
newday = dn != Ref( dn, -1);
is_last_day = dn == LastValue(dn);

y_offset = 2;	
bars = LastValue(ValueWhen(newday, Ref(BarsSince(newday),-1)));
shift = bars - LastValue(BarsSince(newday));
x_txt = BarCount+shift+1;

if (ppl==1) {
	Plot(SetNull(bp, 1),"",colorBlue,styleStaircase|styleDots|styleNoRescale);
	Plot(SetNull(bp, 0),"",colorBlue,styleStaircase|styleNoRescale);
	Plot(IIf(is_last_day, bp, Null),"",colorBlue,styleLine|styleDots|styleNoRescale, Null, Null, shift );	
	PlotText(" Pivot = " + WriteVal(bp,fraction), x_txt, bpI, colorBlue, -1, y_offset);
	for (i = 1; i <= 4; i++) {
		s = VarGet("s"+i);
		Plot(SetNull(s,1),"",colorRed,styleLine|styleNoRescale);
		Plot(SetNull(s,0),"",colorRed,styleStaircase|styleNoRescale);
		PlotText(" s"+i+" = " + WriteVal(s,fraction), x_txt, LastValue(s), colorRed, -1, y_offset);
		r = VarGet("r"+i);
		Plot(SetNull(r,1),"",colorGreen,styleLine|styleNoRescale);
		Plot(SetNull(r,0),"",colorGreen,styleStaircase|styleNoRescale);
		PlotText(" r"+i+" = " + WriteVal(r,fraction), x_txt, LastValue(r), colorGreen, -1, y_offset);
		//
		Plot(IIf(is_last_day, s, Null),"",colorRed,styleLine|styleNoRescale, Null, Null, shift );
		Plot(IIf(is_last_day, r, Null),"",colorGreen,styleLine|styleNoRescale, Null, Null, shift);
	}
}

14


Then just set different Interval single time.

tmfrm = inDaily;
Hi = TimeFrameGetPrice("H", tmfrm, -1);
Lo = TimeFrameGetPrice("L", tmfrm, -1);
C1 = TimeFrameGetPrice("C", tmfrm, -1);
2 Likes

Dear @fxshrat,

That was real quick and does the needful with a different approach. When i bar replayed, two lines of each pivot are joined from two different ends to form a horizontal line . I have just a taken a screenshot of the same when the lines are yet to join as shown below.

new image

Out of curiosity, Can't the lines be plotted for the entire day without having dependency on the candle formation? Even now, a piece of line is plotted from both ends as in when a fresh candle is formed and then get connected to form a single line ( somewhere in the middle of trading session) . My whole idea of getting this done is to have a clear view of the pivots right from the start of the day.

Thanks in advance..

1 Like

You go beyond Barcount. So full day does not exits yet! And Plot() is function to plot array data.

You would have to draw last day's pivot values via Gfx*.
Then it will work.

If you do not need the labels on price axis then you may draw the entire last day via Gfx only and restrict Plot() to output till day before last day only.

/// Standard  Pivots //
/// @link https://forum.amibroker.com/t/hw-to-plot-pivots-for-the-fresh-day-start-to-end-instead-of-candle-based/21289
GraphXSpace = 5 ;
SetChartOptions(0,chartShowArrows|chartShowDates);

Plot(C,"Close",colorBlack, styleCandle);
ppl = ParamToggle("Plot Pivot Levels","Off|On",1);
fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2);

/* This code calculates the previous days high, low and close */
tmfrm = inDaily;
Hi = TimeFrameGetPrice("H", tmfrm, -1);
Lo = TimeFrameGetPrice("L", tmfrm, -1);
C1 = TimeFrameGetPrice("C", tmfrm, -1);

/* aily pivots calculation*/
rg = (Hi - Lo);
bp = (Hi + Lo + C1)/3; bpI = LastValue (bp,1);
r1 = (bp*2)-Lo; r1I = LastValue (r1,1);
s1 = (bp*2)-Hi; s1I = LastValue (s1,1);
r2 = bp + r1 - s1; r2I = LastValue (r2,1);
s2 = bp - r1 + s1; s2I = LastValue (s2,1);
r3 = bp + r2 - s1; r3I = LastValue (r3,1);
s3 = bp - r2 + s1; s3I = LastValue (s3,1);
r4 = bp + r2 - s2; r4I = LastValue (r4,1);
s4 = bp - r2 + s2; s4I = LastValue (s4,1);

/// @link https://forum.amibroker.com/t/hw-to-plot-pivots-for-the-fresh-day-start-to-end-instead-of-candle-based/21289/9
function SetNull(array, mode) {
	global is_last_day, newday;
	if ( mode )
		result = IIf(! newday, array, Null);
	else
		result = IIf((newday OR Ref(newday,-1)), array, Null);
	return result;
}

bi = BarIndex();
dn = DateNum();
newday = dn != Ref( dn, -1);
first_bar = LastValue(ValueWhen(newday, bi));

y_offset = 2;	
bars = LastValue(ValueWhen(newday, Ref(BarsSince(newday),-1)));
x_txt = first_bar+bars+2;

if (ppl==1) {
	GfxSetCoordsMode(1);
	GfxSetBkMode(1);
	Plot(SetNull(bp, 1),"",colorBlue,styleStaircase|styleDots|styleNoRescale);
	Plot(SetNull(bp, 0),"",colorBlue,styleStaircase|styleNoRescale);
	GfxSelectPen( colorBlue, 1, 2 );
	GfxMoveTo( BarCount-1, LastValue(bp));
	GfxLineTo( x_txt-2, LastValue(bp));
	PlotText(" Pivot = " + WriteVal(bp,fraction), x_txt, bpI, colorBlue, -1, y_offset);
	for (i = 1; i <= 4; i++) {
		s = VarGet("s"+i);
		Plot(SetNull(s,1),"",colorRed,styleLine|styleNoRescale);
		Plot(SetNull(s,0),"",colorRed,styleStaircase|styleNoRescale);
		PlotText(" s"+i+" = " + WriteVal(s,fraction), x_txt, LastValue(s), colorRed, -1, y_offset);
		r = VarGet("r"+i);
		Plot(SetNull(r,1),"",colorGreen,styleLine|styleNoRescale);
		Plot(SetNull(r,0),"",colorGreen,styleStaircase|styleNoRescale);
		PlotText(" r"+i+" = " + WriteVal(r,fraction), x_txt, LastValue(r), colorGreen, -1, y_offset);
		//		
		GfxSelectPen( colorGreen, 1, 2 );
		GfxMoveTo(BarCount-1, LastValue(r));
		GfxLineTo(x_txt-2, LastValue(r));
		//
		GfxSelectPen( colorRed, 1, 2 );
		GfxMoveTo(BarCount-1, LastValue(s));
		GfxLineTo(x_txt-2, LastValue(s));
	}
}

15

7 Likes

Dear @fxshrat,

Thai serves my requirement. Thanks a lot. I sometimes wonder that you can do anything with your coding skills... Awww man, You are a true champ !! Thanks again :slight_smile:

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.