# Weekly pivot line changes value within current week

I have a formula, which calculates Floor Pivot Points based on High, Low and Close of previous week (Week -1). Lines are supposed to be the same for next week (Week 0), but they change within this week while I scroll chart horizontally. What mistake did I make?

I created my formula based on some daily Camarilla Pivot Points AFL code.
I also don't understand what "if ( True )" statement means - what is true actually?

Also would be perfect if I could somehow manipulate zoom of chart, because seeing the most extreme pivot lines makes chart so short, that it is almost invisible, so I would happily see for example only chart + let's say 40% of chart height on top and 40% on the bottom.

Any help is much appreciated!

``````_SECTION_BEGIN("Price");
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", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

if ( True )
{
WeekH = TimeFrameGetPrice("H", inWeekly, -1);		// high last week
WeekL = TimeFrameGetPrice("L", inWeekly, -1);		// low last week
WeekC = TimeFrameGetPrice("C", inWeekly, -1);		// close last week

PP = (WeekH + WeekL + WeekC) / 3;
R1 = 2*PP - WeekL;
S1 = 2*PP - WeekH;
R2 = PP + (R1 - S1);
S2 = PP - (R1 - S1);
R3 = WeekH + 2 * (PP - WeekL);
S3 = WeekL - 2 * (WeekH - PP);

PP = Round(PP);
R1 = Round(R1);
S1 = Round(S1);
R2 = Round(R2);
S2 = Round(S2);
R3 = Round(R3);
S3 = Round(S3);

Plot(PP, "PP",colorYellow,styleLine);
Plot(R1, "R1",colorGreen,styleLine);
Plot(S1, "S1",colorRed,styleLine);
Plot(R2, "R2",colorGreen,styleLine);
Plot(S2, "S2",colorRed,styleLine);
Plot(R3, "R3",colorGreen,styleLine);
Plot(S3, "S3",colorRed,styleLine);
}
``````

@Taisho try this version:

``````_SECTION_BEGIN( "Price" );
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", colorBlack ), styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );
_SECTION_END();

GraphXSpace = Param( "GraphXSpace", 2, 0, 400, 1 );

WeekH = TimeFrameGetPrice( "H", inWeekly, -1 );		// high last week
WeekL = TimeFrameGetPrice( "L", inWeekly, -1 );		// low last week
WeekC = TimeFrameGetPrice( "C", inWeekly, -1 );		// close last week

PP = round( ( WeekH + WeekL + WeekC ) / 3 );
R1 = round( 2 * PP - WeekL );
S1 = round( 2 * PP - WeekH );
R2 = round( PP + ( R1 - S1 ) );
S2 = round( PP - ( R1 - S1 ) );
R3 = round( WeekH + 2 * ( PP - WeekL ) );
S3 = round( WeekL - 2 * ( WeekH - PP ) );

Plot( PP, "PP", colorYellow, styleStaircase | styleNoRescale );
Plot( R1, "R1", colorGreen, styleStaircase | styleNoRescale );
Plot( S1, "S1", colorRed, styleStaircase | styleNoRescale );
Plot( R2, "R2", colorGreen, styleStaircase | styleNoRescale );
Plot( S2, "S2", colorRed, styleStaircase | styleNoRescale );
Plot( R3, "R3", colorGreen, styleStaircase | styleNoRescale );
Plot( S3, "S3", colorRed, styleStaircase | styleNoRescale );
``````

Use Chart's Parameters to change `GraphXSpace` variable which I have added. A quote from: https://www.amibroker.com/guide/h_indbuilder2.html

`GraphXSpace` defines how much extra space should be added above and below graph line (in percent). For example: `GraphXSpace = 5` adds 5% extra space above and below the graph line. When GraphXSpace is not defined in the formula then default 2% is used.

I also added `StyleNoRescale` to your Plots.

I haven't noticed any problem with the lines when scrolling...

In your case, this statement was always true (the condition was always met), so it didn't have any sense.

3 Likes

Thank You a lot for explanation and GraphXSpace parameter slider which works just perfectly!

About rounding, it's true that I didn't need to round in 2 steps for most of pivots, but some are used in calculation later (PP, R1 and S1) and I want raw, not rounded values to be used, actually only because I want my code to match system of one analyst who uses Pivot levels that are equal to what I receive when rounding is done in the end, else my pivots are sometimes 1 point off.

The problem with lines when scrolling horizontally (mouse wheel) persists and it is presented on 2 screenshots. Whole screen is the same trading week. Main Pivot Point, Resistance and Support lines change values. I discovered that when I use the same pivot calculation rules for trading system, explore shows values of PP, all R and S correctly, meaning each of them has the same value for whole trading week. It looks like the problem is with display only then.  I can only guess, but it looks like you don't have enough data available on the chart to draw consistent lines (to make previous weekly Close, Low, High from 1 - second data) inspite of the fact that `TimeFrameGetPrice()` forces using necessary amount of bars by default.

1. Click--> New Blank Chart, insert your code and see if the problem persists.

2. Try changing the interval to 1 minute or Hourly and see if the problem persists.

3 Likes

Changing interval to 1 minute solved the problem. Many thanks!

1 Like