Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
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[1] to AXvg[8] 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.
Can you help answer these questions from other members on NexusFi?
Thanks everyone. Insideday, I can't access the link, which might be caused by my not having a TradeStation account. (I'm using MultiCharts instead.)
Regardless, I found a post here that describes the source of my problem. Specifically, there's some bad juju with using recursive functions within a For... next loop.
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.