Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 103
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
If it's 7.43 and I haven't gone to bed... So I guess it's spelled grail!
Nah, no need to swear like that :)) Yusuf gave me the Grail. I'm sitting in my suitcases, waiting for manna from heaven, I'm going to the Maldives :))
So show me what you've done... No telepaths here - they're on holiday.
I have uploaded the general code of the Expert Advisor, to make it clearer what it should do... I know it's a mess, but I haven't learned otherwise yet =)))
I will tell you once again where it is stupid
open a pending order: opens either one pending order without the opposite one or a whole bunch of pending orders in one direction.
It deletes orders: sometimes ok in the evening at a clearly specified time, and sometimes in a day, or does not close at all ...
Well, the condition is :
If the first open pending order closes with a profit, the second one is deleted immediately - I doubt I have written it correctly, but I cannot check it in action as I do not want to open two opposite positions=(((((
When searching for the last closed order, we should first find the most recently closed one but the check for closing it at take should be taken out of the loop, otherwise it will check for closing at take for each closed order and, if so, it will remember the time of the first order closed at take in the loop and not the latest one.
Well, this is code optimization. The result will not change, as I see it. It just takes longer to calculate. I did fix the code, but it's still the same.
Still, there's something wrong with it.
I tried to show you the code of an EA, I know it's a mess, but I've never learned how to do it in another way.)
I will tell you once again where it is stupid
Opening pending orders: it opens either one pending order without the opposite one or a whole bunch of pending orders in one direction.
Deletion of orders: deletes them every time, sometimes ok in the evening at a clearly specified time, and sometimes in a day, or does not close at all...
Well, the condition:
If the first open pending order closes with a profit, the second will be deleted immediately - I also doubt that I wrote it correctly, but I can not check in work, because I do not want to open two opposite positions=(((((
To answer a question with a question. What the hell is that:
Decipher it for me, I don't understand :)
Checks to open a position should be after attempting to open a position. I.e.
You place it after you send an order.
The price has to be higher or lower than the Asc or Bid to open the position. This is how it is for the Buy:
if (OOP > Ask)
Well, this is code optimization. The result will not change, as I see it. It just takes longer to calculate. I did fix the code, but it's still the same.
There's still something wrong with it.
No, it's not code optimization. It's just looking for exactly the last one. Once we have completed the search of all closed orders and found the last closed order of them, only then we should check for closing by the take and, if it is closed by the take, only then it makes sense to continue searching for the rest.
If we check for a close one inside the loop, what will we get? We will get an error of logic:
. Suppose we have chosen an order that was closed a year ago. Its time will anyway be more than -1, so we check it to close it at take (it is checked inside the loop). Yes, it closed on the take... What does your function do next? Right - it continues to work with that order closed at the mark a year ago. Let me see what else is wrong. Just got home...
It was written: 2. If the last open position closes at the take, then close the whole thing!
So, it goes like this:
We pass to the function the symbol we want to check, magic number and delta (distance in pips == difference between order's take and close price), like this:
I have not checked this function, I wrote it on my own hand. Thus, I will leave it to you to search for errors.
You can make it int and use return codes. For example, if the position you are looking for does not exist or exists, but it is closed with a loss, return -1;
if it exists and is closed with a profit, but not within the delta, return 0;
if it exists and is closed with a profit and at Take (within the delta), return 1...
The scope for imagination is enormous...
If, on the other hand, we check for a close on the take, what do we get? We will get a logic error:
Suppose we have selected an order that was closed a year ago. Its time will anyway be higher than -1, so we check it to close it at the take (this check inside the loop is included to the code). Yes, it closed on the take...
So, if we loop on all orders, the loop will anyway loop through all orders. The time of closing of each order will be compared to the previously selected one. But this is where we face a performance problem. TakeProfit will be constantly checked in the loop, with each closed position, instead of only the last one. Isn't it so!?
Right.
But there is Open[], with an opening price.
Got it, thanks :)
So if you cycle through all orders, the cycle will in any case cycle through all orders. The time of closing of each order will be compared to the previous selected one. But this is where we face a performance problem. TakeProfit will be constantly checked in the loop, with each closed position, instead of only the last one. Isn't it so?
So if you cycle through all orders, the cycle will anyway cycle through all orders. The closing time of each order will be compared to the previous selected one. But here we have a performance issue. TakeProfit will be constantly checked in the loop, with each closed position, instead of only the last one. Isn't it so!?
That's a glitch: