I apologize in advance for a newbie question -- I have a C# background, but I'm just getting started with MultiCharts/EasyLanguage.
I'm trying to create a modified version of the built-in "Mov Av Exp Ribbon" indicator. I've defined a numeric array of eight elements called "XAvg." The program then assigns each element an exponential moving average of a different length based on the inputs "Price" and "Length," and then plots the contents of that array.
This code works fine, and gives me the results I expect:
However, I tried to shorten the block of array-assignment code with a for loop, below. When I comment out that code and use the for loop instead, I get completely different and unpredicted results.
At least in C#, the comparable code for these two blocks of code are equivalent and would give the same results. However, they don't seem to be working that way here. In particular, in the "for loop" code, it looks like XAvg to AXvg are each getting assigned the same value (i.e., the same moving average), rather than different moving averages. Consequently, I'm not seeing a ribbon effect plotted on the graph, but just eight lines that all have the same value.
Is there some difference here that I'm missing between these two blocks of code? Perhaps is there some difference in the way that the XAverage function is being called, or that results from that function are getting assigned to the array elements? I'm stumped. Many thanks.
I'm still trying to figure out the subtleties of EasyLanguage programming, but for now the short answer seems to be don't use loops for situations like this. It makes the code a bit less elegant, but oh well.
The following 2 users say Thank You to Xyzzy for this post: