# Moving Average not calculating

Hello,
I'm getting a blank column output for the 2nd column (smaT) when I run Exploration. I'm probably missing something obvious. Thank you for any input on how to debug this.

``````newHi = Foreign("#NYSEHI","C");
newLow = Foreign("#NYSELO","C");
ratio = newHi/(newHi + newLow);
smaT = MA(ratio,10);

Filter = 1;
``````

Generally, code like MA doesn't start calculating from the first bar.

Thats because the first 10 bars are used for the real computed bar #11.
So check that you have enough bars. This is most likely your problem.

TJ had posted something like this though I couldn't find the post but you could give it a try

``````smaT = MA( ratio, Min( 10, BarIndex() ));
``````

Note that you will not have 10 MA for bars less than 10

Thanks travick. I'm not getting output even after 11 bars.
If I change the formula to

``````smaT = LLV(ratio,10);
``````

That works. However, the following also produces no output:

``````smaT = Sum(ratio,10);
``````

If I change the symbol for newHi to SPY, it works fine. So I assumed it was the data for newLo. But if I change only the newLo symbol to SPY, it also works fine. I have pad and align checked in the settings. I'm baffled.

You need to check if you are NOT feeding the MA with invalid numbers (such as NaN - not a number or Infinity, etc). Typical and most common coding error that leads to invalid numbers is division by zero. If you aren't certain just use Nz() function before you feed MA with input:

``````newHi = Foreign("#NYSEHI","C");
newLow = Foreign("#NYSELO","C");
ratio = newHi/(newHi + newLow);
ratio = Nz( ratio ) ; // remove Nans, Infinity and all kind of problematic stuff
smaT = MA(ratio,10);

Filter = 1;