Questions from a "dummy" - page 216

 
2 Yedelkin, I told you that the Expert Advisor just falls asleep, stops working. The only way to wake it up is to restart the terminal and it works.

2 sergeev, In MQL5, when the clock stops, it means it fell asleep.

 
Yedelkin: ..And the thought comes back to the infinite loop again as the simplest example of explicit delayed event handling.

Here's a question: what function do you use to send trade requests?

G001 : 2 Yedelkin, I told you that the Expert Advisor simply falls asleep and stops working. And it only wakes up by reloading the terminal and it works.

Everything must have a reason and an explanation, including the phenomenon that seems to "stop working" for now.

 
G001:
2 Yedelkin, I told you that the Expert Advisor just falls asleep, stops working. The only way to wake it up is to restart the terminal and it works.

2 sergeev, In MQL5, when the clock stops, it means it fell asleep.

In what MQL event (which function in your EA) do you "catch it when it falls asleep" ?
 
Yedelkin:

This is a question: what function do you use to send trade requests?

There must be a reason and an explanation for everything, including the phenomenon that so far seems to have "stopped working".

//+------------------------------------------------------------------+
//| Open Orders                                                      |
//+------------------------------------------------------------------+
// Perform analysis and open orders on new candle/bar 
  if((TradeNewBar != true)||(IsNewBar() == true))
  {
//----- Open BUY_STOP
    if(TrendDetection() == BULL && TotalBullStopOrders() < 1 && TotalBullPositions() < 1)
    {
      request.action = TRADE_ACTION_PENDING;
      request.magic = Magic;
      request.symbol = Symbol();
      request.volume = Volume();
      request.price=NormalizeDouble(Ask+OrderDrive*_Point,_Digits);
      request.sl = NormalizeDouble(request.price - StopLoss*_Point,_Digits);
      request.tp = NormalizeDouble(request.price + TakeProfit*_Point,_Digits);
      request.type=ORDER_TYPE_BUY_STOP;
      request.type_filling=ORDER_FILLING_RETURN;
      request.comment=Coments;
      int ResBull = -1;
      while(ResBull < 1)
      {
        if(OrderCheck(request,check))
        {
          ResBull = OrderSend(request,result);
        }
        if((MQL5InfoInteger(MQL5_TESTING)||MQL5InfoInteger(MQL5_OPTIMIZATION)))break;
      }
      Print("BuyStop Order Set ");
      if(UseSound == true){PlaySound(OrderSound);}
      Print(ResultRetcodeDescription(result.retcode));
    }
//----- Open SELL_STOP
    if(TrendDetection() == BEAR && TotalBearStopOrders() < 1 && TotalBearPositions() < 1)
    {
      request.action = TRADE_ACTION_PENDING;
      request.magic = Magic;
      request.symbol = Symbol();
      request.volume = Volume();
      request.price=NormalizeDouble(Bid-OrderDrive*_Point,_Digits);
      request.sl = NormalizeDouble(request.price + StopLoss*_Point,_Digits);
      request.tp = NormalizeDouble(request.price - TakeProfit*_Point,_Digits);
      request.type=ORDER_TYPE_SELL_STOP;
      request.type_filling=ORDER_FILLING_RETURN;
      request.comment=Coments;
      int ResBear = -1;
      while(ResBear < 1)
      {
        if(OrderCheck(request,check))
        {
          ResBear = OrderSend(request,result);
        }
        if((MQL5InfoInteger(MQL5_TESTING)||MQL5InfoInteger(MQL5_OPTIMIZATION)))break;
      }
      Print("SellStop Order Set ");
      if(UseSound == true){PlaySound(OrderSound);}
      Print(ResultRetcodeDescription(result.retcode));                             
    }
  }
 
sergeev:
In what MQL event (which function in your EA) do you "catch it when it goes to sleep" ?

Sorry, I don't really know what you're asking... :(

The clock is right aftervoid OnTick()

void OnTick()
{
  Comment("Local Time: "+TimeToString(TimeLocal(),TIME_MINUTES|TIME_SECONDS));
 
sergeev:
In what MQL event (which function in your EA) do you "catch it when it falls asleep" ?
Yes, it visually detects that the Expert Advisor has "fallen asleep". It compares the time in comments on the chart with its own time. It does not use any events.
 

Can anyone help with a condition for an EA?

I want to make an EA that after closing a position it would immediately open the same position with the opposite position

For example, there were open only 2 positions 1 Sell and 1 Buy. One of them is closed, eg Buy at TP or SL , I would like the EA to reopen a Buy position and a new Sell position with it

There are 2 Sell positions and 1 Buy position

May someone come up with some formula that will open a closed position with an opposite one.

or any other way... I've tried everything I know(((( does not work :, (

Files:
SellBuY.mq4  3 kb
 
Yedelkin:
Yes it visually detects that the expert has "fallen asleep". It compares the time in the commentary on the chart with its computer time. It does not use any events.
Right. That was my request, how to find out programmatically when the EA stops working.
 

G001 ResBear = OrderSend(request,result);

I see. You useOrderSend() function. The version is that the delay in OnTick() event processing by NewTick( ) function may be caused by lack of server's response, because theOrderSend() function must wait for this response. If interesting, try touse its asynchronous copy instead ofOrderSend() functionwhich doesn't wait for the server's reply. Will it cause the Expert Advisor to stop working?
 
Yedelkin:
Got it. You are usingOrderSend() function. The version is that the delay may be due to server's no response, because theOrderSend() function has to wait for this response. If you are interested, try touse its asynchronous copy instead ofOrderSend() function, which does not wait for the server's reply.Will it hang in this case too?

Thank you. I also thought of using asynchronous version, but I do not know if the broker will not consider the trades. But I will try.
Reason: