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?
200 Period Moving Average
-
- Posts: 51
- Joined: 24 Feb 2011
- Location: Atlanta, GA
- Has thanked: 5 times
- Been thanked: 8 times
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: 200 Period Moving Average
Do all the MA indicators have the same MaxBarsBack setting?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?
-
- Posts: 51
- Joined: 24 Feb 2011
- Location: Atlanta, GA
- Has thanked: 5 times
- Been thanked: 8 times
Re: 200 Period Moving Average
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.
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2958 times
-
- Posts: 51
- Joined: 24 Feb 2011
- Location: Atlanta, GA
- Has thanked: 5 times
- Been thanked: 8 times
Re: 200 Period Moving Average
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);
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);
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2958 times
-
- Posts: 51
- Joined: 24 Feb 2011
- Location: Atlanta, GA
- Has thanked: 5 times
- Been thanked: 8 times
Re: 200 Period Moving Average
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.
- furytrader
- Posts: 354
- Joined: 30 Jul 2010
- Location: Chicago, IL
- Has thanked: 155 times
- Been thanked: 217 times
Re: 200 Period Moving Average
I saw some strange behavior as well, when using variables in place of "Close". I started with this code:
If I place the following line at the end of this code:
... 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.
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);
Code: Select all
Print(Date," ",value1, " ", value2);
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2958 times
Re: 200 Period Moving Average
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.