Daily pivots doesn't work in higher timeframes

Dear @fxshrat

I got the following code from another post

/// 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);
	}
}

It draws the daily pivots perfectly when the time frame is 15 minutes.
image

When I change my time frame to hourly (and higher), it seems that something is wrong, you can find some continuous lines there
image
and also pivot lines are congested on Mondays:
image

I would appreciate it if you could help me in this regard.

Best regards

1 Like

Quick fix without code...

Go to File - Database settings - Intraday settings and...

Do not set start time of session to something like 08:30, 09:40,....
But set to full hour e.g. 08:00 or 09:00 ,...
As in example picture below

28

2 Likes

Thanks for your reply, the hourly timeframe works well now, but the 4h is not working well:
image

I also have another question for you but it is not related to this post: What is the best intraday setting for Forex for someone in North America? It might be a ridiculous question but sometimes changing the intraday setting can show different candles from MT5.
image

1 Like

Answer is in same upper post:

Use different start time.

Set to even start hour so e.g 08:00 or since you are at FX set to 00:00 so that 4 hours go from 00:00, 04:00, 08:00, 12:00, 16:00, 20:00

Right now your 4 hours go from 01:00, 05:00, 09:00, 13:00, 17:00, 21:00

2 Likes

Thank you so much. Thanks for your help and time.

Dear @fxshrat

Today, I found that it doesn't work well on 12h and daily.
image

image

I tried different intraday setting as below but it doesn't work:
image
image

I would be grateful if you could help me in this matter.

Best regards,

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