Questions from Beginners MQL5 MT5 MetaTrader 5 - page 383
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 not external - there is PositionClose
You can also open a position with the same volume in the opposite direction, which will result in a close.
We set two local variables in the OnTick function of the bool type: buyExist = false and sellExist = false.
When a new tick comes, you check if there are any orders that belong to this EA. If there is a sell order, sellExist = true and the same thing with the buy order. And then you check if buyExist = true - do not open a buy order. The same is true for sell. That is all.
What for do we need unnecessary variables if we are going to check anyway if there are open positions?
We have checked if there are any Buy positions - no open Buy, we have opened one. Why do we need variables?
Why do we need extra variables if we are checking for open positions anyway?
We check for Buy - no Buy open - we open one, we check for Sell - no Sell open - we open one. Why do we need variables?
Why do we need extra variables if we are checking for open positions anyway?
We check for Buy - no Buy open - we open one, we check for Sell - no Sell open - we open one. Why do we need variables?
I thought it would be something like OrderTotal, but here you have to do the rebound and write the function to recognise orders?
You could do that. I just imagined it in my head as a separate check function, where flags are passed by reference. In this case, my variant, performs only one function - check for orders, not check+open. It would be easier to extend the program. In short - one function - one action.
Well, the check is a function call that returns a flag:
if(!Function_check_open_position(symbol, OP_BUY,magic)) function_open_position(symbol,OP_BUY,Lots,stop_loss,take_profit,magic,comment);
if(!Function_check_open_position(symbol,OP_SELL,magic)) Function_open_position(symbol,OP_SELL,Lots,stop_loss,take_profit,magic,comment);
I thought it would be something like OrderTotal.
no such function ?
How can you do it without trying too hard? You may have a heap of orders from a heap of Expert Advisors on a heap of symbols at once. And you want your EA to process only your orders, don't you?
it is an initial addition to the main robot . the main robot always has two open orders in both directions (the main robot picks them up, but the main robot itself can not start . When the main robot finishes one of the directions it closes it) and then this EA should again open an order in the market direction where there is no order.
we just need to add order opening conditions to it
extern double Lots = 1.00;
extern int MagicNumb = 698541; //Magic
int start ()
{
if(OrdersTotal() == 0 && ********** )
OrderSend("USDCHF",OP_BUY,Lots,Ask,0,0,0, "5891",MagicNumb,0,Red);
if (OrdersTotal() == 0 && ***********)
OrderSend("USDCHF",OP_SELL,Lots,Bid,0,0,0, "58892",MagicNumb,0,Red);
}
it is an initial addition to the main robot . the main robot always has two open orders in both directions (the main robot picks them up, but the main robot itself can not start . When the main robot finishes one of the directions it closes it) and then this EA should again open an order in the market direction in which there is no order.