Page 1 of 1

Indicator using averages as an input

Posted: Jun 07 2018
by synonym
Hi
I'm a completely new to MC and coding and i'd really appreciate it if someone could advise on how i'd make an indicator that takes the 3 sma of the high, the 5sma of low and the 5 sma of close, adds them together and then divides by 3?

Also, one that does similar, but where the final figure would be subtracted from an sma and then plotted as a histogram and centred on 0?

Thank you
Syn

Re: Indicator using averages as an input  [SOLVED]

Posted: Jun 11 2018
by JoshM
I'm a completely new to MC and coding and i'd really appreciate it if someone could advise on how i'd make an indicator that takes the 3 sma of the high, the 5sma of low and the 5 sma of close, adds them together and then divides by 3?
If I understand you correctly, that would look like:

Code: Select all

Variables:
highAvg(0),
lowAvg(0),
closeAvg(0),
plotValue(0);

highAvg = AverageFC(High, 3);
lowAvg = AverageFC(Low, 5);
closeAvg= AverageFC(Close, 5);

plotValue = (highAvg + lowAvg + closeAvg) / 3;

plot1(plotValue);
(I didn't really follow your second question.)

Re: Indicator using averages as an input

Posted: Jun 11 2018
by synonym
Thank you for your reply. That's really helpful JoshM. I'll check your site out., it's looks looks very interesting and incredibly helpful.

Sorry, my 2nd question could have been clearer. It was about a similar indicator, but where the sma is subtracted rather than added. I can see how i can easily amend the code you've kindly given me to do that.

The final points on my 2nd question about is being able to plot the result as a histogram rather than a line, which i now know is an option in the formatting indicator box when inserting it in a chart. And i was a little tired when i initially posted. If the indicator gives positive AND negative figures in it's results then the indicator will of course fluctuate around zero...which is what i want.

Thanks again Josh. I really appreciate it.
Cheers
Syn.

Re: Indicator using averages as an input

Posted: Jul 14 2018
by asyx
Hello,
I have a similar question.

I do not want e.g. today to be included but only the days before.
I tried to take the average of high(1), high(2),....etc. this works, but is not really flexible.
That is way I tried : high(1), length (3) ....for example but this does not work.
Then I ran out of ideas. Could you please point e in the right direction?

Thanking you,

asyx

Re: Indicator using averages as an input

Posted: Jul 14 2018
by TJ
Hello,
I have a similar question.

I do not want e.g. today to be included but only the days before.
I tried to take the average of high(1), high(2),....etc. this works, but is not really flexible.
That is way I tried : high(1), length (3) ....for example but this does not work.
Then I ran out of ideas. Could you please point e in the right direction?

Thanking you,

asyx

not sure what you are talking about...

please make examples.

Re: Indicator using averages as an input

Posted: Jul 15 2018
by Xyzzy
I do not want e.g. today to be included but only the days before.
I tried to take the average of high(1), high(2),....etc. this works, but is not really flexible.
That is way I tried : high(1), length (3) ....for example but this does not work.
What you want is the the average as of yesterday. To do that, you can use:

Code: Select all

Average(Close, 100)[1]
The [1] portion indicates that MC should use the average that was calculated yesterday, not today's average. You can also use other values to "go back in time" further.

Re: Indicator using averages as an input

Posted: Jul 31 2018
by asyx
Thanks, Xyzzy and TJ.

e.g. compare today´s high with average of last 5 highs.

Graphically I could solve this with "Displace". I overlookd that - thanks.

If coding I have the following so far. More flexible than my previous attempts but it is still quite static:

Code: Select all


inputs: Price( High ), Length( 5 ) ;

variables:
var0( 1 ),
var1( 0 ),
var2( 0 ),
var3( 0 ) ;

var1 = var0;
var0 = AverageFC( Price, Length ) ;
var2 = High[0];
var3 = ((var2 / var1)-1)*100;

Plot1(var3,"Comp.");
...with static I mean, what if I want to compare today with the average of 5 highs 10 days ago or average of last year etc.....

Re: Indicator using averages as an input

Posted: Jul 31 2018
by Xyzzy
Note that you can use the "[x]" notation for functions too. You can get rid of var0 and use:

Code: Select all


var1 = AverageFC( Price, Length )[1];
var2 = High[0];
var3 = ((var2 / var1)-1)*100;
Then, var1 is set to the average from the prior bar.