[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 276
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
When using (calling) functions from these files (already implemented in mt4), in case of incorrect work of the EA we can see in the log the number of the error made by us in the code.
For example, we call the GetLastError() function :
In this case, if we made an error in the code or set incorrect external parameters, we will see the number of this error in the log.
For example, 130.
And the decoding of the number can be found on the page -https://book.mql4.com/ru/appendix/errors
And we won't have to search through all code, because we already know by this number - where exactly mistake is made !
Let me correct a bit: the GetLastError function can be called without the header file but to get the error description without navigating the sites you should link the library:
You have not called the function correctly.
Your function is called like this: if (NumberOfPositions(NULL,Magic)> 1)
It should look like this:
Feel the difference (you missed the "-1") ! and CHANGE YOUR CODE.
To control it, you can print a comment on the chart. For example, like this (at the beginning of the START function).
As for your second condition, I would ("without thinking cleverly") set a different magician and separate function Open_Buy_2() to open positions by the second condition !The code of the second condition would look like this
rid,
I also understand why the second condition does not work, maybe I explained the problem incorrectly:
I want my EA to be able to check if the orders were opened by it or not, even if they were closed a long time ago. NumberOfPositions works, but it only counts the number of open positions. (that's why it doesn't work)
In the code of my EA, there is a script which opens every next position taking into account the data of the previous position and if there was no previous position, the first order should be opened without this condition (otherwise, the EA will not start). Therefore, there should be a function that understands if at least one order of this EA has been opened or not (even if the order was then closed). If there have not been any orders yet (the beginning of work), then the first order is opened without considering the second condition, and all subsequent orders are opened considering the second condition, i.e. using the data from previous orders.
Is it possible to modify the function in this way?
Please tell me what the iTime function shows.
What is that gibberish of 10 digits? Seconds?
How would it translate to year-month-day-hour-minute?
I see. To determine if there were positions on the history, you can do this:
But then your code will only work in tester. Because otherwise you will have to change the magik every time you turn on the EA online.
Apparently, you need to set the time for which the account history is taken.
I.e. when was the last trade with the given magik opened/closed? Was it six months ago or 24 hours ago?
There are functions that return the bar number (counting from the current bar to the back of the history) of the last trade opened or closed.
To give you an example. I have used these functions in my code like this:
Or like this:
Hmm.struggling with the same simple problem...opens a sea of positions but needs only 1 at the most and when buy closes and a signal comes to open sell... Big request hint and correct what's wrong.in the code below... Where do I need to prescribe a magik? If you don't mind, make a dumb example, when buy cross upwards (not more than 1 order) and sell downwards also not more than 1. I think this will immediately solve the questions of many newbies. Thank you in advance.
Another stupid question:
- How to declare an array whose number of elements is given by an external variable.
It's like this.
Another stupid question:
- How to declare an array whose number of elements is given by an external variable.
https://docs.mql4.com/ru/array/ArrayResize
Hmm.struggling with the same simple problem...opens a sea of positions but needs only 1 at the most and when buy closes and a signal to open sell comes... Big request hint and correct what's wrong.in the code below... Where do I need to prescribe a magik? If you don't mind, make a dumb example, when buy cross upwards (not more than 1 order) and sell downwards also not more than 1. I think this will immediately solve the questions of many newbies. Thanks in advance.
Try it like this:
(you have to be more attentive with NumberOfPositions(), it's written in the header for a reason:
/| Description : | Description : Returns the number of positions.
//| Parameters : |
//| sy - instrument name ("" or NULL - current symbol) |
|| op - operation ( -1 - any position) |
//| mn - MagicNumber ( -1 - any magic number) |
//+----------------------------------------------------------------------------+