Using a Moving Average as a Data Point

Questions about MultiCharts and user contributed studies.
molandes
Posts: 1
Joined: 10 Aug 2013

Using a Moving Average as a Data Point

Postby molandes » 10 Aug 2013

Hello, I am in the process of transposing my custom indicators created in Ensign to MultiCharts. This will require the ability to use a moving average as a data point in the calculation of another moving average. For example:

[MA_1 - (MA_2(MA_3)] + MA_4

This formula takes MA_1 and subtracts another moving average which uses a third moving average as the data point (MA_2(MA_3) and then finally adds the value of a fourth moving average (MA_4).

Can anyone point me into the right direction on how the code would look in SC to achieve this? Any documented examples of this would be greatly appreciated as well.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Using a Moving Average as a Data Point

Postby TJ » 10 Aug 2013

in SC ???

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Using a Moving Average as a Data Point

Postby TJ » 10 Aug 2013

try post #1
[FAQ] EasyLanguage / PowerLanguage
viewtopic.php?f=16&t=6929

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Using a Moving Average as a Data Point

Postby TJ » 10 Aug 2013

a simple application example

is it possible to apply a moving average to a moving average
viewtopic.php?f=1&t=32471&p=83725

User avatar
piranhaxp
Posts: 241
Joined: 18 Oct 2005
Has thanked: 4 times
Been thanked: 30 times

Re: Using a Moving Average as a Data Point

Postby piranhaxp » 10 Aug 2013

Something like this should work ...

Code: Select all

// *** INPUTS ***

input: p1(5); // period for moving average 1
input: p2(10); // period for moving average 2
input: p3(15); // period for moving average 3
input: p4(20); // period for moving average 4

// *** VARIABLES ***

var: vp1(0); // converts input1 into var1
var: vp2(0); // converts input2 into var2
var: vp3(0); // converts input3 into var3
var: vp4(0); // converts input4 into var4
var: ma1(0); // variable for calc. of moving average 1 with input 1 as period/length
var: ma2(0); // variable for calc. of moving average 2 with input 2 as period/length
var: ma3(0); // variable for calc. of moving average 3 with input 3 as period/length
var: ma4(0); // variable for calc. of moving average 4 with input 4 as period/length
var: equ(0); // what you want

// *** CALCULATIONS ***

// conversion of inputs into variables

vp1 = p1;
vp2 = p2;
vp3 = p3;
vp4 = p4;

// calculations for moving averages

ma1 = averagefc( close, vp1 );
ma2 = averagefc( close, vp2 ); // SMA of SMA
ma3 = averagefc( ma2, vp3 ); // SMA of CLOSE
ma4 = averagefc( close, vp4 ); //
equ = ma1 – ma2 + ma4;


// *** PLOTTING ***

if currentbar > maxlist(vp1, vp2, vp3, vp4) then
begin
plot1( equ, “EQU” );
end;
.... would recommend to change MA2 with MA3 in your formula, because MC can't calculate a level which will be calculated later or you have to change the proposal into this ....

Code: Select all

ma1 = averagefc( close, vp1 );
ma3 = averagefc( close, vp3 ); // SMA of CLOSE
ma2 = averagefc( ma3, vp2 ); // SMA of SMA
ma4 = averagefc( close, vp4 ); //
equ = ma1 – ma2 + ma4;
Hope it helps.

Regards.

Mike

synonym
Posts: 70
Joined: 20 Feb 2009
Has thanked: 10 times
Been thanked: 3 times

Re: Using a Moving Average as a Data Point

Postby synonym » 08 Jun 2018

Hi Mike,

I'm trying to re-purpose the code you pasted. I'm completely new to coding. I want to be able to add together the ma's based on either the high or low and of different periods. I've a couple of questions if you don't mind. If i was to use your code, what is supposed to go where you have put "EQU" on row 42?

Thanks
Chris

synonym
Posts: 70
Joined: 20 Feb 2009
Has thanked: 10 times
Been thanked: 3 times

Re: Using a Moving Average as a Data Point

Postby synonym » 08 Jun 2018

Hi Mike,
I've done it with the help of the MC syntax guides. Thanks for the code base i used.
Cheers
Chris


Return to “MultiCharts”