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.
Using a Moving Average as a Data Point
- TJ
- Posts: 7745
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2224 times
- TJ
- Posts: 7745
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2224 times
- TJ
- Posts: 7745
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2224 times
Re: Using a Moving Average as a Data Point
a simple application example
is it possible to apply a moving average to a moving average
viewtopic.php?f=1&t=32471&p=83725
is it possible to apply a moving average to a moving average
viewtopic.php?f=1&t=32471&p=83725
Re: Using a Moving Average as a Data Point
Something like this should work ...
.... 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 ....
Hope it helps.
Regards.
Mike
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;
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;
Regards.
Mike
Re: Using a Moving Average as a Data Point
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
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