Plot weekly MACD on a daily chart

I have tried to code this several times over the last couple of years, all to no avail.
I have searched this database and other webpages and I have used the examples in the Help section of AmiBroker. I have built and deleted my code three times and this is the third, so I am turning to this forum for some help.
I have the two time frame charts on one window (daily candles, and other indicators, and the MACD (with special parameters) on the second panel, as shown in the scree clip.
Mt coding plots some lines, but they make no sense, and they change value as I scroll the chart.

I have tried to code this several times over the last couple of years, all to no avail.
I have searched this database and other webpages and I have used the examples in the Help section of AmiBroker. I have built and deleted my code three times and this is the third, so I am turning to this forum for some help.
I have the two time frame charts on one window (daily candles, and other indicators, and the Weekly MACD (with special parameters) on the second panel, as shown in the screen clip below.
My coding plots some lines, but they make no sense, and they change value as I scroll the chart back and forward.
At present, I use this setup and look at both the daily and weekly charts, to check the conditions on each indicator.

image

Looking at the above charts, the cursor line in the middle of the Daily chart, shows the start of a good uptrend, AND, looking at the Weekly chart, the linked cursor line shows both the special Weekly MACD and the Signal line, both are trending up. I realise that the historical Weekly MACD chart is showing the END value, in real time, this value changes as the week progresses, and is still useful.
While this method is OK for detailed evaluation, I would like to add the Weekly MACD values into the Exploration Analysis, to reduce the number of shares in the Output.
There appears to be no correlation between the Daily chart and the Weekly chart, AND the plots on the Daily chart change as the charts are scrolled.

// 21-5-2022   Trying to get MACD weekly to plot on the Daily time frame chart
(GfxSetBkMode(2)+
GfxSetBkColor(colorWhite) +
GfxSetTextColor(colorBlack) +
GfxSetOverlayMode(0 ) +
GfxSelectFont("Times New Roman", 8, 700, False ) +
GfxTextOut("MACD 2019 Wkly to Daily. ", 8, 15 ) +
GfxSelectFont("Times New Roman", 8, 400, False ) +
GfxTextOut(" 3, 10, 15 ", 10, 30 )); // +

SetChartBkColor( ColorRGB( 200,184,0 ));
GraphXSpace = 10;
//SetChartOptions(0,chartShowArrows|chartShowDates);


//===   MACD   ===================
E20 = EMA(C, 20);		//  For unitising the MACD

_SECTION_BEGIN("MACD"); // General calculations
r1 = 3;		//  B Burns values for a weekly chart  17-6-2019 & 4-12-2020
r2 = 10;
r3 = 15;

E3 = EMA(Close, r1);
E10 = EMA(Close, r2);
MACDnew = (E3 - E10)/E20 * 1000;		//  Cannot use MACD as it is a reserved word by AmiB
										// *1000 for scaling - do not like decimal values
//MACDnew = (E3 - E10);
		//	MACDnew is the MOM line from B Burns

MACDnewSig = EMA(MACDnew, r3);
_SECTION_END();
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

_SECTION_BEGIN("Time frame set");	// Calculations for a Weekly time frame
TimeFrameSet( inWeekly ); // switch to Weekly time frame
MACDnewWky = (E3 - E10)/E20 * 1000;		//  Cannot use MACD as it is a reserved word by AmiB

MACDnewSigWky = EMA(MACDnewWky, r3);

TimeFrameRestore(); // restore time frame to original

// plot expanded MACD & Signal
Plot(0 ,"Zero", colorWhite , styleLine|styleThick | stylenotitle); 
//  MACD
Plot( TimeFrameExpand( MACDnewWky, inWeekly), "MACDnewWky", colorRed , styleLine,0,0,0,0,2);
Plot( TimeFrameExpand( MACDnewWky, inWeekly), "MACDnewWky", colorRed , styleHistogram,0,0,0,0,4);
// MACDsig
Plot( TimeFrameExpand( MACDnewSigWky, inWeekly), "MACDnewSigWky", colorGreen , styleLine |styleOwnScale,0,0,0,0,2);
_SECTION_END();

//===   End of coding   ===============================================================================================================================


I would welcome anyone to suggest where I have made mistakes in my coding.
Thank you, from oldhiker.

1 Like

This one is not proper one

It should be like this:

TimeFrameSet( inWeekly ); // switch to Weekly time frame
E3 = EMA(Close, r1);
E10 = EMA(Close, r2);
E20 = EMA(C, 20);		//  For unitising the MACD

MACDnewWky = (E3 - E10)/E20 * 1000;		//  Cannot use MACD as it is a reserved word by AmiB

MACDnewSigWky = EMA(MACDnewWky, r3);

TimeFrameRestore(); // restore time frame to original
2 Likes

Simple when you know how and why. It now works the way that I expect.
Thank you very much fxshrat.

1 Like

My first post did not print all of my post - so I had to re-post the whole post again. That should explain why there are two introductions in the post.

1 Like

Please take a look here with examples there:
http://www.amibroker.com/guide/h_timeframe.html

You just have to put arrays of the interval that you want to switch to inside Timeframeset / Timeframerestore procedure.

1 Like

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