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

 

Hi all!

What is the easiest way to write (modify) an order in my simple Expert Advisor to delete Take Profit and Stop Loss in it when a certain condition occurs, the maximum is supposed to be no more than three orders in one direction (if that's important), order counting, as I understand it is used, should I write it up again? I am waiting for someone who cares.

 
Порт-моне тв #:

Hi all!

What is the easiest way to write (modify) an order in my simple Expert Advisor to delete Take Profit and Stop Loss in it when a certain condition occurs, up to a maximum of three orders in one direction (if that's important), I assume the order count is used, should I write a new one? I am waiting for someone who cares.

OrderModify(OrderTicket(), OrderOpenPrice(), 0, 0, 0);
 
Ivan Butko #:

Unfortunately, it's hard to understand how to use such code.


Tried to put a flag in 1 when opening a buy order, and a flag in 0 when closing it, and added the latter to the open condition. It didn't work)
It is strange, in fact the rule is broken: open if the flag==0. And it still opened at 1 on the same candle anyway.

Show me how you did it.
 
Alexey Viktorov #:

Why so complicated?

Don't get clever. That's not what the question was about.

 
MakarFX #:
Show me how you did it.

It seems to be working, I've redone it like this. Now I will try it on the sell and see if they can be independent of each other

int Buy=0,
    Sell=0;

void OnTick(void)
  {
    double 
    ma=iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0),
    ma2=iMA(NULL,0,80,0,MODE_SMA,PRICE_CLOSE,0);

    if (ma>ma2 && Buy==0) 
      { 
        OrderSend(Symbol(), OP_BUY, lots, Ask, 3, Bid - SL * Point, 0, NULL, 888, 0, Blue);
        Buy=1; 
      }
      
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderMagicNumber()!=888 || OrderSymbol()!=Symbol()) continue;
      //--- check order type 
      if(OrderType()==OP_BUY)
        {
         if(perceptron_B() < Porog_B)
           {
            if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,White))
               Print("OrderClose error ",GetLastError());
            Buy=1;
           }
           
         break;
        }

UPD
Phew, it worked) I did the same for sell, now they can open independently of each other and have different logic.

 
Ivan Butko #:

It seems to be working, I've redone it like this. Now I will try it on the sell and see if they can be independent of each other

UPD
Phew, design worked) I did the same for sell, now they can open independently and be accompanied by different logic.

Probably gets swiped when compiling))))

 
MakarFX #:

Probably gets swore at compilation))))

Right! A bit,"return value of 'OrderSend' should be checked AI (2).mq4 34 9"

But it seems to work)
 
Ivan Butko #:

Right! A little bit,"return value of 'OrderSend' should be checked AI (2).mq4 34 9"

But it seems to work)

Make it like this

    if (ma>ma2 && Buy==0) 
      { 
        if(OrderSend(Symbol(), OP_BUY, lots, Ask, 3, Bid - SL * Point, 0, NULL, 888, 0, Blue))
        Buy=1; 
      }
 
MakarFX #:

Make it so!

Thank you!

 
MakarFX #:

Thank you!

Reason: