real scenario... I have coded ea for grid trading with main closing strategies using various averaging math, which requires saving of at least 3 prices for both buys and sells, including first trade, last trade, 2nd closest to last trade, etc etc. I currently am using 3 variables on the global environment to save these prices.
Question for the pro's and forum gods... Is there any advantage or reason that I might change these to a single array with 3 or more prices in the 1 array? ie buys[first_price, last_price, 2ndlast_price];
It seems obvious to me that it could make the code look cleaner, but is there any other reason that I might consider doing this change?
Is the current code slow?
Is the current code hard to read?
If you answer no to both questions, don't refactor it.
As for performance, I don't think in this case will matter since you are dealing with a small amount of data.
i am starting to think it is a pain sometimes scrolling down past the reinitialisation lines haha, otherwise, the code is still straight forward and logical order, even if i do say so myself haha, including headings separating these initialsing lines etc. Thanks for your questions.
EDIT. there has been a couple times during high volatility in the markets that trades had more slippage than i would expect, but that could be just that: just sudden spike in prices. It didnt happen enuf times for me to worry about or to investigate more, but it could be either/or the code or volatile prices. In any case, it didnt happen enuf times for me to think it was obviously a code issue.i am starting to think it is a pain sometimes scrolling down past the reinitialisation lines haha, otherwise, the code is still straight forward and logical order, even if i do say so myself haha, including headings separating these initialsing lines etc. Thanks for your questions.
EDIT. there has been a couple times during high volatility in the markets that trades had more slippage than i would expect, but that could be just that: just sudden spike in prices. It didnt happen enuf times for me to worry about or to investigate more, but it could be either/or the code or volatile prices. In any case, it didnt happen enuf times for me to think it was obviously a code issue.I do refactor my code if navigating through it starts to become a pain too lol I completely understand the feeling.
real scenario...
It seems obvious to me that it could make the code look cleaner, but is there any other reason that I might consider doing this change?
yes that will do it fine just use a double array.
if you choose not to use an enum then keep the index the same as chart bars for easier understanding, so 0=latest 1=the previous and so on.
my original idea, before i created this thread was to do the array without the enums, but i like the idea of yours with the enums. i have created clear names for the variables, but I think i like your idea with the enums, so elegant! If i dont use my ea for a year, the enums will make it so easy to get "the hang of the code again". lol thanks a whole bunch.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
real scenario... I have coded ea for grid trading with main closing strategies using various averaging math, which requires saving of at least 3 prices for both buys and sells, including first trade, last trade, 2nd closest to last trade, etc etc. I currently am using 3 variables on the global environment to save these prices.
Question for the pro's and forum gods... Is there any advantage or reason that I might change these to a single array with 3 or more prices in the 1 array? ie buys[first_price, last_price, 2ndlast_price];
It seems obvious to me that it could make the code look cleaner, but is there any other reason that I might consider doing this change?