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
You must remember though. The EA closes running trades only. You have to open trade yourself.
100%, no problem there, rather thats exactly what I am trying to achieve .. i dont want EA to open any trade, thats MY job .. I just want it to close it if more than 2 orders are open at X profit and must consider spread ! Slowly I am getting towards it .. this programming thing should have been taught in schools.. hehe too bad I am from the 80s, never thought I will have to go through it, but more I read the help file, I find it more and more intriguing .. also, this forum has loads of help, thanks to guys like you.
what if I can add an IF loop and then paste the rest of the code below which starts the loop?
The IF condition should check the OrdersTotal to be => 2 so that control is passed to close all open orders at X profit after spread?
I'm not sure what you really mean by "The IF condition should check the OrdersTotal to be => 2 so that control is passed to close all open orders at X profit after spread"
but I'm pretty sure nothing really bad will happen if you try. And if it doesn't work, there's nothing to lose. At least you tried.
100%, no problem there, rather thats exactly what I am trying to achieve .. i dont want EA to open any trade, thats MY job .. I just want it to close it if more than 2 orders are open at X profit and must consider spread ! Slowly I am getting towards it .. this programming thing should have been taught in schools.. hehe too bad I am from the 80s, never thought I will have to go through it, but more I read the help file, I find it more and more intriguing .. also, this forum has loads of help, thanks to guys like you.
Just include spread in totalprofit.
I'm not sure what you really mean by "The IF condition should check the OrdersTotal to be => 2 so that control is passed to close all open orders at X profit after spread"
but I'm pretty sure nothing really bad will happen if you try. And if it doesn't work, there's nothing to lose. At least you tried.
I'm not sure what you really mean by "The IF condition should check the OrdersTotal to be => 2 so that control is passed to close all open orders at X profit after spread"
Hmm.. Ok what I mean by that is
IF .. total number of open orders is more than or equal to 2 .. only then go ahead and follow rest of the code..
IF total number of open orders .. [ OrdersTotal() ?? ] .. is less than 2 .. that means its either 1 or 0, then do nothing ..
Now, here is a problem for me, that mql 4 help file says OrdersTotal() counts all orders, market AND pending .. I am trying to look for some function which can get only live market orders, not pending ones, OR, it can be mathematically calculated as mostly I only have max 2 trades running at a go anyways.
Is this explanation clearer?
tx for the time you are giving me man.
thrdel wants you to try first and see what happen though I am pretty sure what would likely to happen.
thrdel wants you to try first and see what happen.
yes, going through help file to find the proper function which gives only open orders.
Show us your code when you manage to complete it and we will help you if we can.
Roger that ! Thanks a loads..
..
and I failed to find a function that only returns open trades .. This is ok, so I added the IF loop as below..
I added the IF condition at start which goes if (OrdersTotal()>=2) .. [ Highlighted in above code with comment ]
Now, there was a problem closing the {} as on first attempt I tried it as
so basically as a first time coder, I tried to put that if condition out to be checked FIRST .. didnt compile ..
So I closed the {} by getting the condition inside.. now it compiled with only 2 warnings and no errors..
return value of 'OrderSelect' should be checked Testcode 1.mq4 56 8
not all control paths return a value Testcode 1.mq4 86 2
So it compiles .. is it logically correct?
[Also, not removing any copyright info, I am just adding a line, removing his details would be totally unfair on my part .. whats the rule regarding that? ]
yes, going through help file to find the proper function which gives only open orders.
Really sorry man, as I said before, I'm really not that good at explaining . I understand that you want to find a function that will count only open buy or sell orders, I asked you to look at my code, I explained it to you to the best of my abilities and wasn't as good as I hopped .
Do you remember the first step I mentioned about that code ?
It was : CountMyOrders. Now, if you'd look at the code as I asked you, here's what you 'd find
It says :
You must know what OP_BUY and OP_SELL means.
No pending orders count, no open buy stop, no open sell stop, no buy limit or sell limit, just open buy and open sell.
How else can I explain any better that piece of code and what it does ?
You can keep searching the documentation and get familiar with it but I can tell you, the function you're looking for isn't there.
My EA says if there's no orders yet, wait :
You want your to wait for 2 orders. If you paid a little bit of attention to what I said, you'd probably notice that all you need to do is :
Voilla. Now it waits for the 2 orders to be in place - no pending, buy or sell only !
Please understand that I tried to put the code together to suit others as well who might be looking for a way to manage open trades and not that much a custom designed for a specific purpose.
It is intended as an example, take what you think is good, leave the rest out, improve on it, change it,learn from it if you can and experiment with it.
Hope it makes sense.
Really sorry man, as I said before, I'm really not that good at explaining . I understand that you want to find a function that will count only open buy or sell orders, I asked you to look at my code, I explained it to you to the best of my abilities and wasn't as good as I hopped .
Do you remember the first step I mentioned about that code ?
It was : CountMyOrders. Now, if you'd look at the code as I asked you, here's what you 'd find
It says :
You must know what OP_BUY and OP_SELL means.
No pending orders count, no open buy stop, no open sell stop, no buy limit or sell limit, just open buy and open sell.
How else can I explain any better that piece of code and what it does ?
You can keep searching the documentation and get familiar with it but I can tell you, the function you're looking for isn't there.
My EA says if there's no orders yet, wait :
You want your to wait for 2 orders. If you paid a little bit of attention to what I said, you'd probably notice that all you need to do is :
Voilla. Now it waits for the 2 orders to be in place - no pending, buy or sell only !
Please understand that I tried to put the code together to suit others as well who might be looking for a way to manage open trades and not that much a custom designed for a specific purpose.
It is intended as an example, take what you think is good, leave the rest out, improve on it, change it,learn from it if you can and experiment with it.
Hope it makes sense.