adding a moving average on the script, and plot

How to I add a moving average to the below script? I added it manually on the chart , but I want It on the script. This is what it looks like on the daily chart. could not get the plot function to get it to work( see pic below ).

thanks,

q1=MACD(Week(PERIODAMOUNT=1), BAR1=12, BAR2=26, OSC=9).Histogram; this worked

q2=MA(Week(PERIODAMOUNT=1), q1, BARS=20, STYLE=Center, CALC=Close); this did not work

q1 and q2 - does not look like below :

 

Capture

Hi,

You need to specify the plots after the script functions are set. For example:

V1 = MACD(Week(PERIODAMOUNT=1), BAR1=12, BAR2=26, OSC=9).Histogram;

V2 = MA(V1, BARS=25, CALC=Close) ;

Plot1 = V1 ;

Plot1.Plotstyle = Histogram;

Plot2 = V2 ;

Plot2.Colour = Red;

The above script will produce a result as per the following image when used with a Show View tool…

Ex5

For more information on setting up multi plot scripts please refer to Section 10 of the Intermediate Scripting course here:

https://learn.optuma.com/course/intermediate-scripting/

 

the 2nd one is where I add the ma manually . the top one is the script. please help me to have them look the same. I want it to look like the bottom one, what is wrong with the script? thanksCapture12

Hi,

From what i can see the Moving Averages vary because a Time Frame over ride is being used in the histogram script. On the Show View where the MA is included as part of the script, the timeframe override for the histogram to weekly is picked up by the MA, and weekly values are used (so the data is padded, that is why the line is straight for each 5 bar segment). That means the Moving Average is calculating the average of the last 20 weekly histogram values.

With the other show view where the MA has been manually applied, the MA has no reference to the time frame override being used, as a result it calculates using the last 20 (daily) values of the histogram.

When you change the charts time frame to weekly, you will see that both MA lines match.

Got it , thank you !