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

 
Rewerpool:

Why even write it that way?

If you only put the EA on one symbol, but it will work on all of them? And the magician will see his own!

I'm confused!

In old mql4 the condition was checked from the beginning to the end, regardless of the result of checking the first in the list of conditions. Hence this ugly writing, desire to reduce processing time.

Nowadays, it's written somewhere, but I don't remember where, if the first condition is not met, then the check stops. Accordingly, scratching the left ear with the little finger of the right foot makes no sense.

 

@Konstantin Nikitin So if I write at the beginning of the iteration like this


 for (int i=OrdersTotal()-1; i>=0; i--)
   {
   if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
  
   if (OrderSymbol() != Symbol()) continue;
   
   if (OrderMagicNumber() != Magic) continue;

Выставляться будут стопы и тейки любым ордерам? И не надо делать опрос на предмет кто торгует Бот или человек?
 
Rewerpool:

So if I write at the beginning of the iteration like this

void STOP_TAKE(void)
{
   int SPREAD    = (int)MarketInfo(Symbol(),MODE_SPREAD);
   if (stoploss<STOPLEVEL) stoploss=0; 
   if (takeprofit<STOPLEVEL) takeprofit=0;

     for(int i=0; i<OrdersTotal(); i++)
     {
          if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
          if(OrderSymbol()!=Symbol()) continue;
     
          int tip = OrderType();
          if(  tip!=OP_BUY && tip!=OP_BUYSTOP && tip!=OP_BUYLIMIT &&
               tip!=OP_SELL && tip!=OP_SELLSTOP && tip!=OP_SELLLIMIT ) continue;
     
          // переменные которые будут использоваться в любых ордерах
          int Ticket = OrderTicket();
          double    OOP = OrderOpenPrice(),
                    OSL = OrderStopLoss(),
                    OTP = OrderTakeProfit();
     
          //---
/* Если это удалить/заблокировать то будет работать со всеми ордерами не обращая внимания эксперта они или нет. Разблокировать, то сначала проверит ордера эксперта их нет то все остальные
          if( OrderMagicNumber() == Magic )
          { //----------Если Ордера Советника
               switch(tip)
               {
                    case OP_BUY:
                    case OP_BUYSTOP:
                    case OP_BUYLIMIT:
                         {
                              if (takeprofit!=0) TP = NormalizeDouble(OOP + takeprofit*Point,Digits); else TP=OTP;
                              if (stoploss!=0)   SL = NormalizeDouble(OOP - (stoploss+SPREAD)* Point,Digits); else SL=OSL;
                              if (OrderModify(Ticket,OOP,SL,TP,0,White)) Print("STOP_TAKE",Ticket," SL ",OSL," -> ",SL,"   TP ",OTP," -> ",TP);
                              else Print(Symbol()," Error STOP_TAKE",GetLastError(),"  Ticket ",Ticket);
                         }
                         break;
                         // end case
                         
                    default:
                         {
                              if (takeprofit!=0) TP = NormalizeDouble(OOP - takeprofit*Point,Digits); else TP=OTP;
                              if (stoploss!=0)   SL = NormalizeDouble(OOP + (stoploss+SPREAD)* Point,Digits); else SL=OSL;             
                              if (OrderModify(Ticket,OOP,SL,TP,0,White)) Print("STOP_TAKE",Ticket," SL ",OSL," -> ",SL,"   TP ",OTP," -> ",TP);
                              else Print(Symbol()," Error STOP_TAKE",GetLastError(),"  Ticket ",Ticket);
                         } // end case
               } // end switch
               
               continue;
          }
*/
          switch(tip)
          {
               case OP_BUY:
               case OP_BUYSTOP:
               case OP_BUYLIMIT:
                    {
                         if (takeprofit!=0) TP = NormalizeDouble(OOP + takeprofit*Point,Digits); else TP=OTP;
                         if (stoploss!=0)   SL = NormalizeDouble(OOP - (stoploss+SPREAD)* Point,Digits); else SL=OSL;       
                         if (OrderModify(Ticket,OOP,SL,TP,0,White)) Print("STOP_TAKE",Ticket," SL ",OSL," -> ",SL,"   TP ",OTP," -> ",TP);
                         else Print(Symbol()," Error STOP_TAKE",GetLastError(),"  Ticket ",Ticket);
                    }
                    break;
                    // end case
                         
               default:
                    {
                         if (takeprofit!=0) TP = NormalizeDouble(OOP - takeprofit*Point,Digits); else TP=OTP;
                         if (stoploss!=0)   SL = NormalizeDouble(OOP + (stoploss+SPREAD)* Point,Digits); else SL=OSL;             
                         if (OrderModify(Ticket,OOP,SL,TP,0,White)) Print("STOP_TAKE",Ticket," SL ",OSL," -> ",SL,"   TP ",OTP," -> ",TP);
                         else Print(Symbol()," Error STOP_TAKE",GetLastError(),"  Ticket ",Ticket);
                    } // end case
          } // end switch
     } // end for
} // end STOP_TAKE
Something like this.
 

Good afternoon. This is what they write.

"The product can only contain one EX4 file, no additional files are allowed. The name of the EX4 file and the names of the input parameters must be written in Latin letters. It is recommended to useResources in order to create user-friendly interface.

For security reasons calls to any DLLs are not allowed in the program. If test data are required for the demonstration program, the program should create the required file by itself and inform the user about it. You may also add the required files using the ResourceLoad function, but be aware that all products are checked for possible malicious activity before they are published on the Marketplace.

It is prohibited to build in any restrictions on the Product depending on the time, type or number of the trading account, financial instrument, etc. All such actions will be regarded as unfriendly to the Buyer and will not be tolerated."

Say HOW..... Make an EA request to an indicator.

 
Oleksandr Kulibaba:

Good afternoon. This is what they write.

"The product can only contain one EX4 file, no additional files are allowed. The name of the EX4 file and the names of the input parameters must be written in Latin letters. It is recommended to useResources in order to create user-friendly interface.

For security reasons calls to any DLLs are not allowed in the program. If test data are required for the demonstration program, the program should create the required file by itself and inform the user about it. You may also add the required files using the ResourceLoad function, but be aware that all products are checked for possible malicious activity before they are published on the Marketplace.

It is prohibited to build in any restrictions on the Product depending on the time, type or number of the trading account, financial instrument, etc. All such actions will be regarded as unfriendly to the Buyer and will not be tolerated."

Say HOW..... Make an EA request to the indicator.

You yourself have written the answer: Use a resource

//+------------------------------------------------------------------+ 
#resource "\\Indicators\\SampleIndicator.ex5" 
int handle_ind; 
//+------------------------------------------------------------------+ 
//| Expert initialization function                                   | 
//+------------------------------------------------------------------+ 
int OnInit() 
  { 
//--- 
   handle_ind=iCustom(_Symbol,_Period,"::Indicators\\SampleIndicator.ex5"); 
   if(handle_ind==INVALID_HANDLE) 
     { 
      Print("Expert: iCustom call: Error code=",GetLastError()); 
      return(INIT_FAILED); 
     } 
//--- 
   return(INIT_SUCCEEDED); 
  }
Документация по MQL5: Программы MQL5 / Ресурсы
Документация по MQL5: Программы MQL5 / Ресурсы
  • www.mql5.com
В данном примере показано как проигрывать звуки из файлов Ok.wav и timeoit.wav, входящих в стандартную поставку терминала. Эти файлы находятся в папке означает папку, из которой запущен клиентский терминал MetaTrader 5.  Программным путем из mql5-программы каталог терминала можно узнать следующим образом: Расположение каталога данных терминала...
 
Vitaly Muzichenko:

You wrote the answer yourself: Use the resource

Thanks for the answer. But I've already read it and tried to insert it. I can't get it. I'm doing something wrong or putting it in the wrong place. I am calling to three indicators. Please, describe this script in more details.

What, where, what parameters... Thank you in advance.

//+------------------------------------------------------------------+ 
#resource "\\Indicators\\SampleIndicator.ex5" 
int handle_ind; 
//+------------------------------------------------------------------+ 
//| Expert initialization function                                   | 
//+------------------------------------------------------------------+ 
int OnInit() 
  { 
//--- 
   handle_ind=iCustom(_Symbol,_Period,"::Indicators\\SampleIndicator.ex5"); 
   if(handle_ind==INVALID_HANDLE) 
     { 
      Print("Expert: iCustom call: Error code=",GetLastError()); 
      return(INIT_FAILED); 
     } 
//--- 
   return(INIT_SUCCEEDED); 
  }
 
Oleksandr Kulibaba:

Thanks for the reply. But I've already read it and tried to put it in. I can't get it to work. I'm either doing it wrong or putting it in the wrong place. I am calling to three indicators. Please, describe this script in more details.

What, where, what parameters... Thank you in advance.

Create three or as many variables as you need and call them as in the examplehandle_ind=iCustom(_Symbol,_Period,"::Indicators\\blah-blah-blah) Insert code. Just so people understand!

iCustom is THIS!

iCustom

Возвращает значение указанного пользовательского индикатора. 



double  iCustom( 
   string       symbol,           // имя символа 
   int          timeframe,        // таймфрейм 
   string       name,             // папка/имя_пользовательского индикатора 
   ...                            // список входных параметров индикатора 
   int          mode,             // источник данных 
   int          shift             // сдвиг 
   );
 
If
if(handle_ind==INVALID_HANDLE) то это значит - не корректный хэндл
 
Rewerpool:

Create three variables or as many as you need and poll them as in the examplehandle_ind=iCustom(_Symbol,_Period,"::Indicators\\blah-blah-blah) Insert code. Just so people understand!

iCustom is THIS!

If

I'll give it a try. Thank you.

 
@Oleksandr Kulibaba Insert your code, errors! To have understanding! Good people will help! It's not clear what your problem is!
 
@Konstantin Nikitin Nice work. Removed from the code
if ((OSL==0&&stoploss!=0)||(OTP==0&&takeprofit!=0))

Stop is now twitching on every tick )))))


In post you pointed out the code closure for the magician ! I understand that ! Just the situation is like this: I trade by hand, but suddenly I need to step back and give control to the EA (search for a pattern and entry point). I want to separate all the operations. But the stop and take out, as required by all. Maybe I'm not digging it right yet!

Reason: