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
Indicator using averages as an input [SOLVED]
- JoshM
- Posts: 2196
- Joined: May 20 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
If I understand you correctly, that would look like: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?
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);
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.
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.
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
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
- TJ
- Posts: 7775
- Joined: Aug 29 2006
- Location: Global Citizen
- Has thanked: 1036 times
- Been thanked: 2233 times
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.
What you want is the the average as of yesterday. To do that, you can use: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.
Code: Select all
Average(Close, 100)[1]
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:
...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.....
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.");
Note that you can use the "[x]" notation for functions too. You can get rid of var0 and use:
Then, var1 is set to the average from the prior bar.
Code: Select all
var1 = AverageFC( Price, Length )[1];
var2 = High[0];
var3 = ((var2 / var1)-1)*100;