Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 794
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
This is an example of how to do it in an indicator. The question was about Expert Advisor.
Forum on trading, automated trading systems & strategy testing
Any questions from newbies on MQL4, help and discussion on algorithms and codes
Northwest, 2019.03.28 03:54
Good day everyone!
Lost two hours but haven't found anything.
Can you please tell me how in mq4, in the EA, to correctly
I would like to use embedded functions to build one indicator on another one.
and it should be displayed in tests in the subwindow as it should be,
for example MA on RSI data?
But, in general, it is almost right. It is easier to write an indicator and take values from it than to fill an array for iMAOnArray. But why two loops?
But why two cycles?
not to check for the first indicator run or loading of historical data
sometimes it is more compact and efficient to use condition checking in while/for rather than making an additional if and then using the loop operators after the condition is met
if you "stick" the iMAOnArray() calculation code into a loop filling the array with RSI data, it will cause incorrect calculations of not yet filled elements of the rsiBuffer[] array
note, I used in the example calculation iMAOnArray() for all elements of the array (total = 0). I studied this question some months ago, but alas, there is no specific information on how to use correctly iMAOnArray() and parameterhttps://docs.mql4.com/ru/indicators/imaonarray in it
int total, // number of elements
iMAOnArray() topic https://www.mql5.com/ru/forum/303372/page2#comment_10617854
This is an example of how to do it in an indicator. The question was about the Expert Advisor.
Are you sure that this was the question?
You can see it in the sub-window during tests,
)))))
not to check for the first indicator run or loading of historical data
Sometimes it is more compact and efficient to use condition checking in while/ for code than to make an additional if and then use loop operators after the condition is met
Are you sure this is what you wanted to ask?
)))))
)))) It's not the first time I've been caught a bit inattentive. I didn't even get to the end of the indicator.
But about the additional if
it can be written as
Don't use records like this?Igor Makanu:
...I studied this question a few months ago, but alas there is no specific information on how to use iMAOnArray() correctly and its parameterhttps://docs.mql4.com/ru/indicators/imaonarray
int total, // number of elements
The number of elements is important when you don't need a simple average. I can't remember which types of MA use their previous value in their calculations at a glance. In this case, the number of elements will affect the result. Generally speaking, it is solved in mql5 in half a tick and I'm not interested in it anymore.
You don't use such entries?
I use it, but I usually write my codes "in two passes" - when writing from scratch, I use constructions that are clear for "phonetic parsing" (i.e. essentially for reading aloud), with if() conditions it's easier to say it all )))
then, yes, i can "tidy up the code" a bit and make similar constitutions, but usually i use it in my library of ready-made examples (codes)
SZS: I've seen somewhere information about increasing productivity of C# programs. I know for sure it was recommended to try to avoid using foreach() and this operator ? like if() operator is more productive, but I think it's not critical - I use it as I please
The number of elements is important when you don't need a simple average. I can't remember which AIs use their previous value in their calculations at a glance. In this case the number of elements will affect the result. Generally speaking, it is solved in mql5 in half a tick and I'm not interested.
It's a deeper problem, I searched both on this forum and on the English forum, there was a discussion and examples of use, the total = 0 or total !=0 can make a difference in calculations iMAOnArray() - in a discussion with Igor (link above), I decided to use iMAOnArray() only with the parameter total = 0 - in old discussions was the same solution
There is a deeper problem, I searched both on this forum and on the English forum, there was a discussion and examples of use, from the parameter total = 0 or total !=0 the calculation of iMAOnArray() can be different - in the discussion with Igor (link above), I decided to use iMAOnArray() only with the parameter total = 0 - in old discussions the same solution was used
That's right. If you do not take all the elements of the array and try to get even EMA without errors, it will be difficult.
Exponential Moving Average (EMA)
Exponentially smoothed moving average is determined by adding to the previous moving average value a certain portion of the current closing price. With exponentially smoothed moving averages, the latest closing price is given more weight. A P percentage exponential moving average will be of the following form:
EMA = (CLOSE (i) * P) + (EMA (i - 1) * (100 - P))
Where:
CLOSE (i) - closing price of the current period;
EMA (i - 1) - value of the moving average of the previous period;
P - share of using price value.
Consequently, if you read EMA of period 30 from array of 30 elements, you will get simple MA instead of EMA.
Right. If you don't take all elements of an array and try to get even EMA without error, it will be difficult.
Therefore, if you calculate EMA of period 30 from an array of 30 elements, you will get simple MA instead of EMA.
I checkediMAOnArray() - results are unpredictable, sometimes 2 * MA period can be used, sometimes more is needed. If total = 0, you may use it once for calculation, but if you use it too often, the terminal hangs
I seldom use iMAOnArray()
if (response == 0) {
Print("Что-то пошло не так");
// потом уже добавите диагностику из WinAPI
return false;
}
and before the normal return, print the result too
Print(" всё хорошо, результат:" toStr);
return toStr;
and run all the code in a timer, e.g. once a minute. Practice on a resource that is sure not to get banned and gives different but predictable times, so you can check.
----
telepathically - if there really is a problem,
either the initialization is wrong (I don't remember if WinSOCK should be initialized for InternetOpenW or not)
Or some resource is not being freed.
all added! Nothing shows up in Print!!!
How do I make the variable output to the data window without displaying it on the graph?
I can't find it in the documentation for some reason.
How do I make the variable output to the data window without displaying it on the graph?
I can't find it in the documentation for some reason.