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

 

How do I empty the indicator high and low values? For example, if I set a maximum of 100 and a minimum of 0, and then I need the indicator to visualise everything, how do I organise that? The matter is that I write an indicator with several modes, one of which uses max and min, but after switching the mode in the input parameters the max remains 100, as well as the min 0


MQL5

 
Alekseu Fedotov:

You have already called and passed the value returned byDeviation(Kanal) to theEnvelopes(........) function

and in theEnvelopes(........) function itself, you declare the last parameter, which will take this value


like this

Thank you, it makes more sense now.

 

Slightly modified the code for MT5 according to your advice, it turned out like this:

input  string Parametrs_Indicator       = "Настройки Индикатора";// Настройки Индикатора

input  ENUM_TIMEFRAMES   Time_Frames    = PERIOD_M5;             // Временной период
       int                Ma_Period     = 120;                   // Период
       int                Ma_Shift      = 0;                     // Cдвиг средней
       ENUM_MA_METHOD     Ma_Method     = MODE_SMMA;             // Mетод усреднения
       ENUM_APPLIED_PRICE Applied_Price = PRICE_CLOSE;           // Tип цены
//************************************************************************************************/
void OnTick()
{
//---------------------------------------------------
   double Signal_Sell = Envelopes(0, Deviation(1)); // Сигнал на Продажу
   Print ("Signal_Sell = ", Signal_Sell);
    if (Signal_Sell < 0) { Print("Signal_Sell error #",GetLastError()); }
   double  Signal_Buy = Envelopes(1, Deviation(1));  // Сигнал на Покупку
   Print ("Signal_Buy = ", Signal_Sell);
     if (Signal_Buy < 0) { Print("Signal_Buy error #",GetLastError()); }
//---------------------------------------------------
   double Signal_Sell_2 = Envelopes(0, Deviation(2));
   Print ("Signal_Sell_2 = ", Signal_Sell);
      if (Signal_Sell_2 < 0) { Print("Signal_Sell_2 error #",GetLastError()); }
   double  Signal_Buy_2 = Envelopes(1, Deviation(2));
   Print ("Signal_Buy_2 = ", Signal_Sell);
       if (Signal_Buy_2 < 0) { Print("Signal_Buy_2 error #",GetLastError()); }
//---------------------------------------------------
}
//************************************************************************************************/
double Envelopes(int buff, double _Deviation)
{
  double buf[1];
  int handle=iEnvelopes(Symbol(), TimeFrames, Ma_Period, Ma_Shift, Ma_Method, Applied_Price, _Deviation);
   if(handle<0)
   {
    Print("Failed to create handle iEnvelopes, Error: ",GetLastError());
    return(WRONG_VALUE);
   } else
   {
    if(CopyBuffer(handle,buff,0,1,buf)<0)
    {
     Print("Failed to copy data from the indicator iEnvelopes, Error: ",GetLastError());
     return(WRONG_VALUE);
    }
   }
   return(buf[0]);
}
//************************************************************************************************/

Only now I don't understand why at every tick the first calculated value is written everywhere.

Calculations

Can you tell me how to fix it ?
 
Alexander Layzerevich:

Slightly modified the code for MT5 according to your advice, it turned out like this:

Only now I don't understand why at every tick one calculated value is written everywhere.

//---------------------------------------------------
   double Signal_Sell = Envelopes(0, Deviation(1)); // Сигнал на Продажу
   Print ("Signal_Sell = ", Signal_Sell);
    if (Signal_Sell < 0) { Print("Signal_Sell error #",GetLastError()); }
   double  Signal_Buy = Envelopes(1, Deviation(1));  // Сигнал на Покупку
   Print ("Signal_Buy = ", Signal_Sell);
     if (Signal_Buy < 0) { Print("Signal_Buy error #",GetLastError()); }
//---------------------------------------------------
   double Signal_Sell_2 = Envelopes(0, Deviation(2));
   Print ("Signal_Sell_2 = ", Signal_Sell);
      if (Signal_Sell_2 < 0) { Print("Signal_Sell_2 error #",GetLastError()); }
   double  Signal_Buy_2 = Envelopes(1, Deviation(2));
   Print ("Signal_Buy_2 = ", Signal_Sell);
       if (Signal_Buy_2 < 0) { Print("Signal_Buy_2 error #",GetLastError()); }
//---------------------------------------------------

It's immediately apparent. Even without being highlighted.

 
Artyom Trishkin:

It catches the eye immediately. Even without the highlighting.

Thank you.

 

Any questions from newbies on MQL4, help and discussion on algorithms and codes

WinProject, 2019.05.07 18:38

Can you please tell me why the same code works in MT4 but does not work in MT5? In MT5 the strNum variable always =1, but in MT4 the ++ counter works as it should and strNum = number of line items in the file.

int strNum;
void OnStart()
  {
 FileNum();
 Alert1();
  } 

  void FileNum()
{
      int handle=FileOpen("File.csv",FILE_CSV|FILE_READ,';');
      strNum=0; 
      while(!FileIsEnding(handle))
{
      FileReadString(handle);
      strNum++;
      if(FileIsEnding(handle)==true)
      break;
}
      FileClose(handle);
}

      void Alert1()
{
      Alert (strNum);
}

I am answering to myself, it may be useful for those who have no loop in MT5 when opening or reading file into array or structure. In MT5, in contrast to MT4, when reading .csv file, you should additionallyset file open flag FILE_ANSI.

I.e., in MT5 the line should look like this:

int handle=FileOpen("File.csv",FILE_READ|FILE_ANSI|FILE_CSV,";");

Why, I don't know, maybe someone knows?

 
If the EA log displays a notification in this format - uninit reason 3 (the notification is due to the TM being switched), but the robot is not removed from the chart, are the values of the variables and all the calculations that have been received retained?
 

I get "OrderSend error 130" for unknown reason, the program is running in strategy tester on demo account, so there cannot be any restrictions from broker as far as I understand, Stops Level = 30. I get this error at regular intervals during testing and the stop is fixed in percentage of ATR for all trades but some orders are placed successfully while others are not.

      Print("!!!long level = ", level, ", stop = ", NormalizeDouble(level - stop, Digits));
      if(Bid < level) {
         tickets[orders] = OrderSend(symbol, OP_BUYSTOP, volume, level, 5, NormalizeDouble(level - stop, Digits), 
                            NormalizeDouble(level + take, Digits), NULL, magicNum, TimeLocal() - TimeLocal() % 1800 + 7200, clrBlue);                                                                           
         orderLevels[orders] = level;
         directions[orders] = true;
         orderIsTheLast[orders] = lastOrder;          
         firstTouchTimes[orders] = firstTouchTime;
         orders++;                   
      }       
      else { 
         tickets[orders] = OrderSend(symbol, OP_BUYLIMIT, volume, level, 5, NormalizeDouble(level - stop, Digits), 
                            NormalizeDouble(level + take, Digits), NULL, magicNum, TimeLocal() - TimeLocal() % 1800 + 7200, clrBlue);                
         orderLevels[orders] = level;
         directions[orders] = true;
         orderIsTheLast[orders] = lastOrder;
         firstTouchTimes[orders] = firstTouchTime;
         orders++;    
      }

There are times when an order is rejected several times and then passes...



 

How can I publish the same code in CodeBase for different language audiences (e.g. how can I fill in a form in the marketplace for the corresponding language)?


I have already seen this in CodeBase, here is an example


How can I do the same?

 

For example, when you decrease to the limit the size of candlesticks scale with the mouse, then indicator readings change, although none of the thousands of candlesticks in the indicator code says anything about the change of candlesticks size. For example, at 4 o'clock volumes in a reduced form show one value, but if you slightly increase the candlesticks scale, then another setting will be considered as the correct one.


Reason: