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

 
Denis Diakonov:

not, for example, pass case 1 first, then case 2, etc.

The cases execute an order opening

The order is opened in more than one place. You have to think exactly how you think in this code, and it's hard.

 
If there is a cycle inside an EA's OnTick that takes a decent amount of time, will it execute completely or will the arrival of a new tick interrupt it all?
 
Alexey Viktorov:

There's more than one opening. In such a code, you have to think exactly how you think, and that's difficult.

      case 2 : // кейс для открытия Sell по AUD/USD
               if(TimeServer() == true)                                     
               {
                  if(Symbol() == AUDUSD)
                  {
                  RefreshRates();
                  Open_Order = OrderSend("AUDUSD",OP_SELL,lot,Bid,0,0,0); 
                  Alert("Тикет открытого ордера ", Open_Order, GetLastError());
//-------------------------------------------------------------------------------------------------------------
// другая функция
//-------------------------------------------------------------------------------------------------------------

int AUDUSD_Analizing()
{    
   if(AUDUSD_Prices_new > AUDUSD_Prices_old)
   {
      s1 = AUDUSD_Prices1;
      s2 = AUDUSD_Prices2;
      s3 = s1 - s2;    
      if(raznica > s5)
      {
         Alert("--- ВРЕМЯ ОТКРЫВАТЬ ОРДЕР НА ПОКУПКУ ---");
вот в этом месте мне необходимо обратиться к case 2 - вызвать его запуск на исполнение, затем
отсюда же необходимо обратиться к case 5 (к примеру), case 9, case 16 и т.д.

и только потом завершить исполнение данной функции и вернуться в старт
 
Yevhenii Levchenko:
If there is a loop inside the EA OnTick that takes a decent amount of time, will it be executed completely or will the arrival of a new tick interrupt all of that?

I don't understand either, in my case the loop is opened and not all orders are opened, some are opened twice and some are skipped, I understand that a new tick triggers the start and the code suspends its execution and starts working again

 
Denis Diakonov:

I understand that a new tick both triggers a start and the code pauses its execution and starts executing again

don't make this up.

read the help, it is clearly written there that if there are complex calculations in EA, the new tick will be skipped

somewhere in the article about event handling functions or maybe in trade operations or in RefreshRates

look for logic error in your code


HH: switch() - case is not used for complex logical conditions, better combinations of if() else - so you get more unambiguous logical branches

 
Igor Makanu:

don't make it up.

read the help, it clearly says that if there are complex calculations in EA, the new tick will be skipped

somewhere in the article about event handling functions or maybe in trade operations or in RefreshRates

look for logic error in your code


SZY: switch() - case is not used for complex logical conditions, better combinations of if() else - so more unambiguous logical branches are obtained

yes, thanks, i've already decided to write everything through if-else as well

 
Denis Diakonov:

Why did you add switch here at all? It's easier to get the direction of the deal and the number of required openings into the function and open as many openings as specified in the loop.

That's why I say that understanding your logic is beyond my mind. Why such a mess?

 
Alexey Viktorov:

Why did you add switch here at all? It's easier to get the direction of the deal and the number of required openings into the function and open as many openings as specified in the loop.

That's why I say that understanding your logic is beyond my mind. Why such a mess?

Well, my code has just increased in size, and I thought it would be much easier.

Actually, it would be simpler and more compact if case could be called as many times as I wanted during execution of one function.

I don't need to open similar deals in a loop and they are opened for different symbols simultaneously (as much as possible) upon occurrence of a signal.

case 1 - audusd buy

case 5 - gbpusd buy

case 9 - eurusd buy

etc.

In the first case I have one sheet with case and the second with analysis, if they interacted, it would be 500 lines.

The second variant implies prescribing a specific order opening inside the function with analysis and the total lines would be 1200+, which would eventually affect the speed of program's execution

 

Can you help me, please! The Expert Advisor uses the Envelopes indicator with dynamic calculation of deviation. But when it is displayed on the chart it shows all the dynamics of indicator deviation on all previous bars.

dynamic envelopes

1. Is there a way to make the indicator draw correctly? I.e. it would draw the indicator with its deviation only on its own bar.

2. How can I disable drawing of the indicator in an Expert Advisor, leaving only its calculations? I want to enable to disable drawing of the indicator in expert settings )

 
Denis Diakonov:

Well, in the end my code just grew in size, while I thought it would be simpler.

Anyway, if it were possible to call case as many times as I want during execution of one function, it would be easier and the code would be more compact.

I don't need to open similar deals in a loop and they are opened for different symbols simultaneously (as much as possible) upon occurrence of a signal.

case 1 - audusd buy

case 5 - gbpusd buy

case 9 - eurusd buy

etc.

In first case I have one sheet with case and the second one with analysis, if they interacted they would have 500 lines.

The second variant implies prescribing a specific order opening inside the function with analysis, which would be stretched into a diaper and the total lines would be 1200+, which would eventually affect the speed of program's execution

What are you typing in so many lines of code with? Here's one of my last EA, it works with a set of securities on FORTS

sinput  string            Symbols           = "GAZP,LKOH,CHMF,MVID";  //  Символы для торговли через запятую

As many securities will be listed, so many will trade. And this EA with control of two trading timeframes, with trailing and of course with analysis, only 326 lines.

If you want to use switch, you don't have to add position opening in each variant. It is enough to specify the symbol name, type of trade operation and the

string symb;
ENUM_ORDER_TYPE ordType;
switch(???)
{
 case 1
  symb = "audusd";
  ordType = OP_BUY;
 break;
 case 5
  symb = "gbpusd";
  ordType = OP_BUY;
 break;
 case 9
  symb = "eurusd";
  ordType = OP_BUY;
 break;
}
// И дальше получение цен, определение СЛ и ТП с последующем открытием ордера.

But it would be better, in my opinion, to wrap it all in a user-defined function.

void openOrder(string symb, ENUM_ORDER_TYPE ordType)
 {
  // Символ и тип ордера передаётся при вызове функции. Здесь достаточно получить соответствующие цены и открыть ордер.
 }
Reason: