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

 

Hello. Can you tell me how to organise an execution delay? So that after a new candle, 10 seconds elapse before the update is done.

#define   WM_COMMAND                    0x0111
#property indicator_chart_window
#import "user32.dll"
int RegisterWindowMessageA(string lpstring);
int PostMessageA(int  hWnd,int  Msg,int  wParam,string lParam);
int New_Bar;
datetime Time_0;
#import
int start()
 {
     New_Bar=0;                   // Для начала обнулимся
  if (Time_0 != Time[0])          // Если уже другое время начала бара
      {
      New_Bar= 1;                 // А вот и новый бар
      Time_0 = Time[0];           // Запомним время начала нового бара
      PostMessageA (WindowHandle (Symbol(), Period()), WM_COMMAND, 33324, 0);
      PostMessageA (WindowHandle (Symbol(), 0), RegisterWindowMessageA ("MetaTrader4_Internal_Message"), 2, 1);
      } 
 return(0);
 }
 
Hello, please write code on the condition that if you delete 1 object from the chart, then the rest (a choice) will be deleted

I have other objects attached to 1 object, and when you delete this object, the rest just hang on the chart
 
Dmitry Ivkin:
Hello, I'm asking you to write code on the condition that if you remove one object from the chart, then the rest (as you choose) will be removed

I have other objects attached to one object, and when you remove this object, the rest just hang on the chart
When creating objects, I use prefixes, i.e. names beginning. For example: ObjectCreate("777_a" ... ObjectCreate("777_z" and then delete the group ObjectsDelete(0, "777_")
 
werter:

Hello. Can you tell me how to organise an execution delay? I want to wait 10 seconds after new candlestick before executing update.

The easiest way is to add Sleep(10000); after Time_0 = Time[0]; and I think the lower #import directive should be raised 2 lines up

 
STARIJ:

The easiest way is to insert Sleep(10000); after Time_0 = Time[0]; and I think the lower #import directive should be raised 2 lines higher

Yes, that would be an Expert Advisor... You can't in Sleep indicator, alas.
 
STARIJ:
At creation of objects I use a prefix, i.e. the beginning of a name. For example: ObjectCreate("777_a" ... ObjectCreate("777_z" and then I delete the group ObjectsDelete(0, "777_")

Thank you for replying, no you do not understand, I have other objects attached to the object, and if you delete the indicator then all is normal, but if you right click and delete then delete exactly 1 object and need all attached, I hope you understand)

 
Dmitry Ivkin:

Thank you for replying, no you don't understand, I have other objects attached to the object and if you delete the indicator then everything is fine, but if you right click and delete then 1 object will be deleted and I need all the attached ones, I hope you understand)

Periodically(every tick?) check the presence of the main object and remove child objects by the prefix if it is absent
 
werter Yeah, well, if it were an expert... You can't in the Sleep indicator, alas.
datetime Time_0=0;

void ...
{
   if (Time_0 < TimeCurrent())
   {
      Alert(TimeCurrent());
      Time_0 = Time[0]+PeriodSeconds()+10; 
   }
 

It's been a long time since I wrote in MQL4, now I need to rewrite my EA from MQL5. Is the code that should open 1 trade on the symbol where the EA stands, is it correct?

In the Strategy Tester 2 trades are opened for some reason

...
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;
}
 

I came across another nuance that I hadn't thought of before

1) We have a lot of Expert Advisors installed on the pairs

2) When opening an order by any Expert Advisor with its own settings (some EA opens 0.1 or 0.5, for example), this record will appear in the EAs line

3) The line "Experts" is read and other robots will delete themselves if there are open positions for more than x lots.


The question is how to read and process it ? it is not included in the log files.

Reason: