When I do a backtest on a composite, I'm getting an error message 8:

"Type mismatch, the value assigned to the array element has to be a number. You can not use array on the right-side of this assignment. (Ln: 35, Col: 31631)"

Line 35 in the file I'm running is an include statement. Within the included file, I've traced the error to the following line,

```
result = IIf(AlmostEqual(mappedROR, 0.5), 0, result);
```

I'll post the full function code at the end of the post.

As you can see, result isn't indexed. This is an assignment of an array to an array. I've checked "mappedROR", and it is a perfectly normal array with no error codes at any bar. I've checked "result" also, and it ends up as an array with no error codes at any bar.

It gets stranger because if I replaced "mappedROR" with mtRandomA() like so,

```
result = IIf(AlmostEqual(mtRandomA(), 0.5), 0, result);
```

then the formula completes without generating the error. I can't find any difference between mappedROR and mtRandomA() except for the fact that mappedROR is an array generated by a calculation on a composite.

At this point, I'm wondering if I'm being misled about where the error is occurring. Even though this is the line where a change makes the error go away, perhaps there's something very unexpected happening in code after where the function exits. But I've put a _Trace() call on the exit point from where the function is called and its output looks perfectly normal (again, no error values in the output array from the function).

Nevertheless, if I knew how to interpret the column number in the error message -- 31631 -- maybe it would help me confirm or disconfirm whether I'm being misdirected by my own investigations.

Anyone know how to do this? Any other ideas? It's extremely mysterious to me. Full function code below,

```
function Bandit( watchListName, sourceArray ) {
local
optyMP, mp, lb, diverge, ROR, mappedROR, alpha, bayta, result, sample;
// Calculate the optimal model and retrieve the parameters
//
mp = 110; lb = 11; diverge = 0.1;
_TRACE("Bandit: Name() is " + Name());
ROR = Nz(ROC_VarPeriods(C, 1) / 100);
mappedROR = Remap(ROR, -1, 1, 0, 1);
mappedROR = IIf(mappedROR < 0, 0, mappedROR);
mappedROR = IIf(mappedROR > 1, 1, mappedROR);
// Initial parameter values for the beta function
// Second parameter spelled "bayta" to not conflict
// with the function name, "Beta"
//
alpha = GetBanditAlpha(watchListName);
bayta = GetBanditBeta(watchListName);
// Use diverge to detect when learning should reset.
// Spike in divergence reset to optimist parameters. Pessimism on reversal.
//
alpha += IIf(Cross(WMA(diverge, lb), MA(diverge, mp)), 1.5, 0.5 + Nz(Sum(mappedROR, BarsSince(Cross(WMA(diverge, lb), MA(diverge, mp))))));
bayta += IIf(Cross(WMA(diverge, lb), MA(diverge, mp)), 1, Nz(Sum(1 - mappedROR, BarsSince(Cross(WMA(diverge, lb), MA(diverge, mp))))));
alpha += IIf(Cross(MA(diverge, mp), WMA(diverge, lb)), 1, Nz(Sum(mappedROR, BarsSince(Cross(MA(diverge, mp), WMA(diverge, lb))))));
bayta += IIf(Cross(MA(diverge, mp), WMA(diverge, lb)), 1.5, 0.5 + Nz(Sum(1 - mappedROR, BarsSince(Cross(MA(diverge, mp), WMA(diverge, lb))))));
// sample from the beta distribution
result = 0;
alpha = Nz(IIf(AlmostEqual(alpha, 0), 0.01, alpha), 0.01);
bayta = Nz(IIf(AlmostEqual(bayta, 0), 0.01, bayta), 0.01);
if ( Status("ActionEx") != actionExEditVerifyFormula )
for (sample = 1; sample <= 100; ++sample)
result += BetaRandomA(alpha, bayta, mtRandomA(sample^2.5));
if (typeof(mappedROR) == "array" AND typeof(result) == "array")
result = IIf(AlmostEqual(mappedROR, 0.5), 0, result); // don't produce a result before asset is trading
return result;
} // End bandit function
```