OrderTotal Help ?
Hi
I struggled with making my EA do 2 trades max I mean I did It but I need it to do one SELL and if it needs to it can make one BUY so total equals 2 trades but never do the same type twice
(I mean 2 SELL or 2 BUY) I tried OrderType() <=x but it doesn't work any idea how to do it ?
Thanks
Explain what your problem is.
What is the variable CODE and where does it get its value from?
Explain what your problem is.
What is the variable CODE and where does it get its value from?
My problem is with the code
if(OrdersTotal()<=x)
It can make 2 trades Maximum but I don't need it to do 2 Sells or 2 buys so my problem is I need it to make 2 trades Maximum(if it needs to) only if its 1Buy and 1SELL .
My problem is with the code
It can make 2 trades Maximum but I don't need it to do 2 Sells or 2 buys so my problem is I need it to make 2 trades Maximum(if it needs to) only if its 1Buy and 1SELL .
you will able to help ?
you will able to help ?
You just want to allow 1 buy and 1 sell trade ?
Why don't you declare 2 global variables, like :
int buy_trade=0,sell_trade=0;
Then you test them :
if (buy_trade>0) { //close buy //set buy_trade to 0 if closeorder right } else { //open buy //set buy_trade to 1 if sendorder right }
No ?
OrdersTotal() already includes buy and sell so it will be 2 trades max independent of the order type buy or sell.
If you want it to be 1 buy and 1 sell then you have to check the two orders and compare the two order types if they differ it's a buy/sell or sell/buy, and if they are equal its either a buy/buy or a sell/sell.

- www.mql5.com
You just want to allow 1 buy and 1 sell trade ?
Why don't you declare 2 global variables, like :
Then you test them :
No ?
Hi sir
First of all thank you for your answer really appreciated, so you mean like this :
if (buy_trade==0) { //Open Buy Trade } if (buy_trade==1) { //Close the Trade } else { //print error }
Hi sir
First of all thank your answer really appreciated, so you mean like this :
Can't I do it like this ?
if (OrdersTotal()==0) { //Open Buy Trade } if (OrdersTotal()==1) { //Close the Trade } else { //print error }
Can't I do it like this ?
Of course, but how you detect trade type (buy or sell) ?
Maybe you can do a function who tell you is a trade exist ?
Like this :
bool is_exist_trade(int order_operation) { int total=OrdersTotal(); int order_type=0; for(int pos=0;pos<total;pos++) { if(OrderSelect(pos,SELECT_BY_POS)==true) { order_type=OrderType(); if (order_type==order_operation) return true; } } return false; }
And now, you can do :
if (is_exist_trade(OP_BUY)) { //close your buy trade } else { //open your buy trade } if (is_exist_trade(OP_SELL)) { //close your sell trade } else { //open your sell trade }
Of course, but how you detect trade type (buy or sell) ?
Maybe you can do a function who tell you is a trade exist ?
Like this :
And now, you can do :
I think your code is better, I have this one I don't know if it will work:
if (OrdersTotal()==0) { OrderType=OrderType(); //Open Buy Trade } if (OrdersTotal()==1) { //OrderType=OrderType(); //Close the Trade } else { //print error }
int OrderType;
I will try it all and see what works.

- Free trading apps
- Free Forex VPS for 24 hours
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use