Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 455

 

Hello!


The robot opens and closes orders based on certain signals, but there is a need for a pending order to be placed in the same direction, but only one, after the order is closed.

I.e., after the pending order is placed, triggered and closed, nothing else has to happen and the robot is waiting for a signal to open a regular order.


Can you tell me how to implement this?

 
Snower: Good day!

The robot opens and closes orders based on certain signals, so I need the robot to place a pending order in the same direction, but only one.

I.e., after the pending order is placed, triggered and closed, nothing else needs to happen, the robot is waiting for a signal to open a normal order.

Can you tell me how this can be implemented?

It is very simple. In two for loops you analyze 1) the history of orders and 2) the orders in progress. Based on the analysis you figure out the situation and use conditional if statements to perform the desired action. or do you need more detail?

 
STARIJ:

It's as simple as that. In two for loops, you analyze 1) the history of orders and 2) the orders in progress. Based on the analysis, you figure out the situation and use conditional if statements to perform the required action. or do you need more details?

I'd be very grateful if you could elaborate.

 
Snower: I'd be very grateful if you could elaborate.

Which part do you want me to spell out? Or all of it?

 
LRA:

Which part do you want me to write? Or all of them?

the loops themselves, the ifs, I can set up

 
Vladislav Andruschenko:
))) I've been working for 10 years and I've never had such thoughts. You like tough situations.

now they will be

 

What is the problem with this code? Sometimes it opens 1 trade, sometimes 2?

I'm supposed to have max 1 trade per pair, but I must have messed up somewhere


...
if(!Orderex(_Symbol))
{
   OrderSend(NULL,OP_SELL,lot,Bid,30,Bid+stop*Point,Bid-take*Point,NULL,magicf,0,clrRed);
}
...
bool Orderex(string symbol)
{
   for(int i=OrdersTotal(); i>0; i--)
      {
         OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
         if(OrderSymbol()==symbol && OrderMagicNumber()==magicf) return true;
      
      
      
      }


   return false;
}
 
Roman Sharanov:

What is the problem with this code? Sometimes it opens 1 trade, sometimes 2?

I'm supposed to have max 1 trade per pair, but I must have messed up somewhere


for(int i=OrdersTotal()-1; i>=0; i--)
 
Konstantin Nikitin:

And even more interesting is this

for(int i = OrdersTotal(); i-- >=0;)
 
Ahhhh, yes, the account is from scratch :)
Reason: