Timeframegetprice * #s

Good day, friends.

Here is the code I'm having difficulty with.

PREVIOUS_YEAR_CLOSE = TimeFrameGetPrice("C", inYearly, -1);

PIVOT_MULTIPLE_IN_MONTHS = Optimize("MONTHS", 12, 1, 12, 1);
PIVOT = PREVIOUS_YEAR_CLOSE;

Plot(PIVOT, "PIVOT", colorCustom8, styleLine | styleNoRescale);
PlotOHLC(PIVOT, PIVOT, C, C, "", 
	IIF(C >= PIVOT, ColorRGB(0, 50, 50), ColorRGB(50, 0, 50)),
	styleCloud | styleNoLabel | styleNoTitle| styleNoRescale);

Buy = Cross(Close, PIVOT); Sell = Cross(PIVOT, Close);

SHAPE = Buy * shapeSmallUpTriangle + Sell * shapeSmallDownTriangle;
PlotShapes(SHAPE, IIF(Buy, colorCustom11, colorCustom12), 0, IIF(Buy, Low, High), -30);

What I expect it to do is plot the closing price for each period of months. It gets "x 1" right. It has the same results as simply using TimeFrameGetPrice("C", inMonthly , -1), without the multiple. But I saw this in the guide, so I tried to experiment.

I am not trying to get TimeFrameGetPrice("C", inMonthly , -2), which gives me the closing price from two months ago.

I was expecting for "x 12" to work like TimeFrameGetPrice("C", InYearly, -1), where it gives me the last year's closing price. I was hoping to do the same with "x 3" for quarterly close, and "x 6" for semi-annual close.

I attached some pictures. Notice that in "x 12", the plot doesn't even begin/end at the date the period changed unlike with inYearly. And it's not even 12 months.


I hope everything is clear. I already searched the forum, but failed to find anything relevant to this.

Thank you in advance.

No, inYearly is NOT 12 * inMonthly.

The value of inYearly constant is different than the value of 12 * inMonthly, so they behave differently. That is done on purpose, on exact purpose of differentiating the two.

inYearly is calendar year from January 1st to December 31.
12 * inMonthly may be any running 12 months.

Thanks, Tomasz, for the insight.

I tried this and I think this is a step in the right direction. Code still looks redundant. Will clean and improve on it later.