200 Period Moving Average

Questions about MultiCharts and user contributed studies.
shadrock55
Posts: 51
Joined: 24 Feb 2011
Location: Atlanta, GA
Has thanked: 5 times
Been thanked: 8 times

200 Period Moving Average

Postby shadrock55 » 05 Jan 2015

I'm sure there is a simple reference guide for this, but I can't seem to find it.

I have an indicator that utilizes a 50 and 200 period moving average. All it does is colors the bars when its in the middle. To check the indicator, I put on the built in indicator (Mov Avg 2 lines) in conjunction with my indicator.

It looks like the indicator and moving averages are not working in conjunction until ~400 bars have passed. Does this have to do with the calculation or is there something wrong with what I'm doing? It almost has to be the calculation since it appears to be spot on after 400 bars, but I would like to sync up the results. How do I do that?

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: 200 Period Moving Average

Postby JoshM » 06 Jan 2015

It looks like the indicator and moving averages are not working in conjunction until ~400 bars have passed. Does this have to do with the calculation or is there something wrong with what I'm doing? It almost has to be the calculation since it appears to be spot on after 400 bars, but I would like to sync up the results. How do I do that?
Do all the MA indicators have the same MaxBarsBack setting?

shadrock55
Posts: 51
Joined: 24 Feb 2011
Location: Atlanta, GA
Has thanked: 5 times
Been thanked: 8 times

Re: 200 Period Moving Average

Postby shadrock55 » 06 Jan 2015

Yes, I've tried that. I set them both at 200, but I got the same affect. It was slightly different than when I had it set to automatic, but it was not correct from the first bar that I could see the moving average.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: 200 Period Moving Average

Postby Henry MultiСharts » 06 Jan 2015

Hello shadrock55,

I believe this post should address your concerns.

shadrock55
Posts: 51
Joined: 24 Feb 2011
Location: Atlanta, GA
Has thanked: 5 times
Been thanked: 8 times

Re: 200 Period Moving Average

Postby shadrock55 » 06 Jan 2015

It wasn't the maxbarback. I was something even weirder or maybe related indirectly.

I was assigning the closing price to a variable in case I wanted to change the formula. When I used the assigned variable in the average calculation, it was wrong. When I changed the average calculation to the word close instead of the assigned variable, then it calculated correctly.

The results should have been exactly the same given that I was initializing the variable with the close as well. Either way, it was weird. I would love to know why this occurred.

The code is this simple.
Var: PriceHold(Close);

PriceHold = Close;
Trigger = average(PriceHold, 200);

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: 200 Period Moving Average

Postby Henry MultiСharts » 08 Jan 2015

shadrock55, we will check that.

shadrock55
Posts: 51
Joined: 24 Feb 2011
Location: Atlanta, GA
Has thanked: 5 times
Been thanked: 8 times

Re: 200 Period Moving Average

Postby shadrock55 » 08 Jan 2015

I think the variable didn't start computing until after 200 bars. It was 200 bars for maxbarsback then another 200 bars for it to calculate correctly. That's why it looked right at bar 400.

User avatar
furytrader
Posts: 354
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

Re: 200 Period Moving Average

Postby furytrader » 08 Jan 2015

I saw some strange behavior as well, when using variables in place of "Close". I started with this code:

Code: Select all

Var: PriceHold(0);

PriceHold = Close;

value1 = Average(PriceHold,50);
value2 = Average(PriceHold,200);

condition1 = PriceHold < value1 and PriceHold > value2;
condition2 = PriceHold > value1 and PriceHold < value2;

If (Condition1 OR Condition2) Then PlotPB(H,L,O,C,"",darkred,darkred,2);
If I place the following line at the end of this code:

Code: Select all

Print(Date," ",value1, " ", value2);
... I get very weird numbers for value1 and value2 at the beginning of the time series, even when I set the MaxBarsBack to 200. It appears as though the PriceHold variable doesn't begin storing the value of the closing price correctly until more bars have passed than the maxbars setting. It's peculiar.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: 200 Period Moving Average

Postby Henry MultiСharts » 13 Jan 2015

Variables are being assigned a value only after MaxBarsBack. While price series (close) values assigned through inputs are available for calculation even when done on MaxBarsBack bars.


Return to “MultiCharts”