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

 
Aleksey Vyazmikin:

Look for an error in the function - it doesn't return the up arrow condition.


Thanks toAleksey Vyazmikin, but the problem is more serious. When the robot finds a pattern, it sets a huge number of arrows at one coordinate. The terminal hangs. How to fix it. Have you tried to run my Expert Advisor on your terminal?

 
voron_026:

Thanks toAleksey Vyazmikin, but there's a bigger problem. When the robot finds a pattern it sets a huge number of arrows at one coordinate. The terminal hangs. How to fix it. Have you tried to run my Expert Advisor on your terminal?


The problem is in the function in the first place - I have not added the code for a reason. The function is matched and it draws the arrows. I have launched the Expert Advisor in the visualizer.

The Expert Advisor will not draw arrows on every tick - just check for a new candle.

 
voron_026:

Thanks toAleksey Vyazmikin, but there's a bigger problem. When the robot finds a pattern it sets a huge number of arrows at one coordinate. The terminal hangs. How to fix it. Have you tried to run my Expert Advisor on your terminal?

If you want to get help from as many people as possible, you should upload the code, not the file. Not everyone wants to download the file, and then you have to open it and then delete it.

 

So, when a new candle appears, the ObjectCreate function must be switched off, am I right?

 
Vitaly Muzichenko:

In order to get as many people as possible to help you, you need to post the code, not the file. Not everyone wants to download the file, and then you have to open it and then delete it, so it's a pain in the ass.

Roger that, I'm sending you the code.
#property copyright "Copyright 2017,UriyGlushko"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

extern string Rodot           = "Параметры робота";
extern double Lots            = 0.2;
extern int    StopLoss        = 20;
extern int    TakeProfit      = 80;
extern int    Magic           = 999999;
extern int    Slippage        = 3; // Проскальзывание

extern bool UseDojiCandles = true; // Использование патерна Доджи
extern int TimeFrame = PERIOD_H4;
int DojiCandle = 0;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
  if (Digits == 3 || Digits ==5 )
  {
   TakeProfit *= 10;
   StopLoss   *= 10;
   Slippage   *= 10;
  }
 return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
  
   
}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
   if(UseDojiCandles = true && Doji() == 1)
     {
      if(!ObjectCreate(ChartID(),"Doji_"+IntegerToString(DojiCandle),OBJ_ARROW_UP,0,TimeCurrent(),Low[1]-300*_Point))
         {
         Print("Не удалось создать метку вверх");
         }
         
     }
   DojiCandle ++;

   
   if(UseDojiCandles = true && Doji() == -1)
     {
      if(!ObjectCreate(ChartID(),"Doji_"+IntegerToString(DojiCandle),OBJ_ARROW_DOWN,0,TimeCurrent(),High[1]+300*_Point))
         {
         Print("Не удалось создать метку вниз");
         }
         
     }
   DojiCandle ++;
 

   
}
//+------------------------------------------------------------------+
//    Поиск всех объектов
//+------------------------------------------------------------------+


 




//+------------------------------------------------------------------+
//    Функция паттерна Доджи
//+------------------------------------------------------------------+
int Doji()
{
//Параметры Дожи
   double Open1 = iOpen(Symbol(), PERIOD_H4,1);
   double Close1 = iClose(Symbol(), PERIOD_H4,1);
   double High1 = iHigh(Symbol(), PERIOD_H4,1);
   double Low1 = iLow(Symbol(), PERIOD_H4,1);
   
//Параметры предыдущей свечи
   double Open2 = iOpen(Symbol(), PERIOD_H4,2);
   double Close2 = iClose(Symbol(), PERIOD_H4,2);
   double High2 = iHigh(Symbol(), PERIOD_H4,2);
   double Low2 = iLow(Symbol(), PERIOD_H4,2);
   
//Параметры индикатора волотильности ATR для нахожденя относительно большой свечи перед Доджи
   double ATR = iATR(Symbol(),PERIOD_H4,14,1);
   
   
//Математическое описание патерна Дожи
   if(Close1 < High1 -0.3*(High1-Low1) && 
      Open1 < High1 -0.3*(High1-Low1) && 
      Close1 > Low1 -0.7*(High1-Low1) && 
      Open1 > Low1 -0.7*(High1-Low1) && 
      MathAbs((Close1-Open1) < 0.2*(High1-Low1))&&
      MathAbs((Close2-Open2) > 0.7*ATR))
      {
         if((Close2 - Open2) > 0)
         { 
         Print ("Down"); return(-1);// Условие для продаж
         }
         if((Close2 - Open2) < 0)
         {
         Print ("Up"); return(1);// Условие для покупок
         }
      }
      return(0);
}
 
voron_026:
Roger that, laying out the code.

Try it this way:

if(!ObjectCreate(ChartID(),"Doji_"+IntegerToString(DojiCandle),OBJ_ARROW_UP,0,Time[0],Low[1]-300*_Point))
 

Hello everyone) I am on the account of the VPN server, I wrote the address of the server to which my account belongs, but here writes that nothing is found, what to do, please help, thank you.

 
Vitaly Muzichenko:

Try it this way:


It didn't work. The Expert Advisor drew 7679 objects, and interestingly enough, with odd numbering

I do not understand what is wrong with the Doji function. Why the up arrows are not drawn

 
voron_026:

It didn't work. The Expert Advisor drew 7679 objects, and interestingly enough, with odd numbering

I do not understand what is wrong with the Doji function. Why the up arrows are not drawn

You have a problem with searching for a pattern. Try to find the right code in the kodobase, there are a lot of them and the problem will resolve itself

MQL5 Code Base
MQL5 Code Base
  • www.mql5.com
Библиотека исходных кодов на языке MQL5 для MetaTrader 5
 
Vitaly Muzichenko:

You have a pattern search problem, try to find the correct code in kodobase, there are many of them and the problem will solve itself


Solved the problem with rendering a large number of objects. I have installed check on new bar. I have got the following code:

//+------------------------------------------------------------------+
//|                                                          111.mq4 |
//|                                       Copyright 2017,UriyGlushko |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017,UriyGlushko"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

extern string Rodot           = "Параметры робота";
extern double Lots            = 0.2;
extern int    StopLoss        = 20;
extern int    TakeProfit      = 80;
extern int    Magic           = 999999;
extern int    Slippage        = 3; // Проскальзывание

extern bool UseDojiCandles = true; // Использование патерна Доджи
extern int TimeFrame = PERIOD_H4;
int DojiCandle = 0;
bool New_Bar = false;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
  if (Digits == 3 || Digits ==5 )
  {
   TakeProfit *= 10;
   StopLoss   *= 10;
   Slippage   *= 10;
  }
 return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
  
   
}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
Fun_New_Bar();

   if(UseDojiCandles = true && Doji() == 1 && New_Bar == true)
     {
      if(!ObjectCreate(ChartID(),"Doji_"+IntegerToString(DojiCandle),OBJ_ARROW_UP,0,Time[0],Low[1]-300*_Point))
         {
         Print("Не удалось создать метку вверх");
         }
         
     }
   DojiCandle ++;

   
   if(UseDojiCandles = true && Doji() == -1 && New_Bar == true)
     {
      if(!ObjectCreate(ChartID(),"Doji_"+IntegerToString(DojiCandle),OBJ_ARROW_DOWN,0,Time[0],High[1]+300*_Point))
         {
         Print("Не удалось создать метку вниз");
         }
         
     }
   DojiCandle ++;
 

   
}
//+------------------------------------------------------------------+
//    Поиск всех объектов
//+------------------------------------------------------------------+


 




//+------------------------------------------------------------------+
//    Функция паттерна Доджи
//+------------------------------------------------------------------+
int Doji()
{
//Параметры Дожи
   double Open1 = iOpen(Symbol(), PERIOD_H4,1);
   double Close1 = iClose(Symbol(), PERIOD_H4,1);
   double High1 = iHigh(Symbol(), PERIOD_H4,1);
   double Low1 = iLow(Symbol(), PERIOD_H4,1);
   
//Параметры предыдущей свечи
   double Open2 = iOpen(Symbol(), PERIOD_H4,2);
   double Close2 = iClose(Symbol(), PERIOD_H4,2);
   double High2 = iHigh(Symbol(), PERIOD_H4,2);
   double Low2 = iLow(Symbol(), PERIOD_H4,2);
   
//Параметры индикатора волотильности ATR для нахожденя относительно большой свечи перед Доджи
   double ATR = iATR(Symbol(),PERIOD_H4,14,1);
   
   
//Математическое описание патерна Дожи
   if(Close1 < High1 -0.3*(High1-Low1) && 
      Open1 < High1 -0.3*(High1-Low1) && 
      Close1 > Low1 -0.7*(High1-Low1) && 
      Open1 > Low1 -0.7*(High1-Low1) && 
      MathAbs((Close1-Open1) < 0.2*(High1-Low1))&&
      MathAbs((Close2-Open2) > 0.7*ATR))
      {
         if((Close2 - Open2) > 0)
         { 
         Print ("Down"); return(-1);// Условие для продаж
         }
         if((Close2 - Open2) < 0)
         {
         Print ("Up"); return(1);// Условие для покупок
         }
      }
      return(0);
}
//+------------------------------------------------------------------+
//    Функция определения нового бара
//+------------------------------------------------------------------+
void Fun_New_Bar()                              // Ф-ия обнаружения .. 
  {                                             // .. нового бара 
   static datetime New_Time=0;                  // Время текущего бара 
   New_Bar=false;                               // Нового бара нет 
   if(New_Time!=Time[0])                        // Сравниваем время 
     { 
      New_Time=Time[0];                         // Теперь время такое 
      New_Bar=true;                             // Поймался новый бар 
     } 
  }  

The only thing is that the serial number of the arrow in the object properties goes not 1 2 3 ... and so on, but 1 850427 1083295 ..... I take it the counter doesn't work correctly?

My question is, how to check for a new bar on H4. So, I want the robot to look for the patterns on H4, while the chart may be of any TF?

Reason: