Errors, bugs, questions - page 2932
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
Error in description:
Structure of a trade transaction (MqlTradeTransaction)
This field is called: time_type
I am trying to allow the user to select both timeframes and their number from the menu of the indicator setup window:
and I want the selected periods to go directly to PArray. But from the above example it turns out that I assign to the array the values pre-set in the program and not the values entered by a user. In addition, the compiler generates warnings:
When I try to replace the last line with:
the compiler generates an error altogether:
Also, NO_PERIOD=0 meansPERIOD_CURRENT, and I don't need that, I need something like false or EMPTY_VALUE, but they don't fit at all.
How do I fix it?
Almost fixed it.
Tell me, what methods of fighting exist for catching and correcting "array out of range" error?
ArrayResize() do before writing an array element, count and enter there the number of elements that should be in the array, or use a dynamic array that itself gets fat. You're just going outside the array, for example you specify a size of 100 elements, but since the first element is #0 some people get confused, if you write the numbers in a row you'll fit 0-99. I'm not a professional programmer if anything(but I can), the first thing that came into my head, it works)))
Do ArrayResize() before writing an element of the array, count and enter there the number of elements that should be in the array, or use a dynamic array that grows itself.
Actually, it's dynamic anyway. From the help:"The function can only be applied to dynamic arrays. Note that dynamic arrays assigned as indicator buffers by the SetIndexBuffer() function should not be resized. For indicator buffers, all resizing operations are performed by the executing subsystem of the terminal. "But it is not an indicator buffer, so you have to think with your hands and head...
Actually, it's already dynamic. From the help:"The function can only be applied to dynamic arrays. You should bear in mind that dynamic arrays assigned as indicator buffers by the SetIndexBuffer() function cannot be resized. For indicator buffers, all resizing operations are performed by the executing subsystem of the terminal. "But it's not an indicator buffer, so you'll have to think with your hands and head...
The problem of catching such errors is only solved by using "layers", such as a custom array class that intercepts addressing.
When launching the EA when algotrading is disabled and then turning on the algotrading:
According to the error code, the trade ban remains, although the TERMINAL_TRADE_ALLOWED property is true
The result should be as follows:
Obviously, it should always be ArraySize(Arr)=1. This is in the case of successful copying. But in what cases the copying of the bar might fail? When the"array out of range" error occurs, the terminal points to Arr[0].
Caught the error after all, quote from the help:
4401
Requested history not found.
Printed it to the Logbook - got it:
What do I do with it now, where do I go? Am I a bad hand or...? I'm only copying one bar from 0 to 1, after all. How can it (history) not be? The more so, the error doesn't always reveal itself. Or is it necessary to forcibly check and load the history beforehand?