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

 
Alexandr Ivanov:

Well, I haven't found it either...

Sadness. So you have to estimate how many ticks come in 1 bar, and from that conclude - whether these are opening prices or all ticks.

Making an MT4 EA cross-platform is five minutes (once!) with the right skill. Then you test (many times) in MT5 on real or custom ticks and trade in MT4.

 

Hi all. Have a script that changes the TF on all open charts by choice

Need to make an approved one that changes the patterns

But for that, at least show me what a pattern is in terms of code

 

Hello. There is a ready-made SMI indicator. But it doesn't work. When I run it for the first time, it does, but then I have to press refresh or switch to another timeframe with every new bar. Why? Maybe this issue has already been raised here, can I just get the link? Thank you in advance.

Files:
SMI.mq4  8 kb
 

Please explain why the order did not open.

Here are the lines from the log:

2017.11.24 20:00:00.061 '5390918': requote 1.19357 / 1.19368 for open sell 0.01 EURUSD at 1.19361 sl: 1.19848 tp: 1.18402

2017.11.24 19:59:59.515 '5390918': instant order to sell 0.01 EURUSD at 1.19361 sl: 1.19848 tp: 1.18402

The slippage is 11 pips. Slippage was set at 27 pips in the EA. Checking the order opening resulted in error 138 (new prices).

Please explain why the order did not open?

 
RichLux:

Please explain why the order did not open.

Here are the lines from the log:

2017.11.24 20:00:00.061 '5390918': requote 1.19357 / 1.19368 for open sell 0.01 EURUSD at 1.19361 sl: 1.19848 tp: 1.18402

2017.11.24 19:59:59.515 '5390918': instant order to sell 0.01 EURUSD at 1.19361 sl: 1.19848 tp: 1.18402

The slippage is 11 pips. Slippage was set at 27 pips in the EA. Checking the order opening resulted in error 138 (new prices).

Please explain why the order did not open?

Change dealing or account type to avoid these problems. You should get an account with market execution - forget about instant.

 

Please advise how to write a code to close the deal was not on the opposite of the signal indicator, and take profit, and the advisor would not open after closing immediately

for example a signal to enter the crossing of moving averages with different periods, take profit 50 pips. if possible in mql5

I have a code that once it reaches take profit and closes the deal immediately opens a new one, even though there is no new signal/crossing.

 
Good day. Please look at the code. The robot does not remove horizontal lines when new ones appear
 //+------------------------------------------------------------------+
//|                                                          2.0.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.1 ;
extern int     StopLoss        = 20 ;
extern int     TakeProfit      = 80 ;
extern int     Magic           = 568422685 ;
extern int     Slippage        = 3 ; // Проскальзывание
extern int     Shag            = 40 ; // Шаг для трейлингстопа
extern int     Tral_dist       = 40 ; // Дистанция трейлингстопа
extern bool    Use_traling     = true ; // Использование трейлингстопа true - Включено, false - Выключено
extern bool    Use_shag        = false ; // Использование шага. true - Включено, false - Выключено
extern bool    Use_bezubitok   = true ; // Использование безубытка. true - Включено, false - Выключено



//      Параметры индикатора moving_averages
extern string   MA             = "Параметры Скользащей средней" ;
extern int      MA_Period      = 3 ; // Период
extern int      MA_Shift       = 0 ; // Сдвиг
extern int      MA_Method      = 0 ; // 0-простая, 1-экспонециальная, 2-сглаженная, 3-линейно-взвешенная

//      Параметры разворотных свечей
extern string Comment2 = "Параметры разворотных свечей" ;
extern bool _Doji           = false ;
extern ENUM_TIMEFRAMES      TimeFrame       = PERIOD_M5 ; // Период разворотной свечи
extern ENUM_TIMEFRAMES      LittleTimeFrame = PERIOD_M1 ; // Период точки входа
extern int                  ATR_period      = 14 ;         // Период индикатора волотильности

//      Параметры уровней области разворота
extern string Comment3 = "Параметры уровней области разворота" ;
extern int UpLineSell = 4 ;     // Верхняя линия ОР для продаж (пункт от High)
extern int DownLineSell = 4 ;   // Нижняя линия ОР для продаж (пункт от High)
extern int UpLineBuy = 4 ;     // Верхняя линия ОР для покупок (пункт от Low)
extern int DownLineBuy = 4 ;   // Нижняя линия ОР для покупок (пункт от Low)

double sl, tp, dist, shag, ma1, ma2;
int ticket;



int DojiCandle = 0 ;               //Счетчик баров "Дожи"
int DojiCandleBuy = 0 ;             //Счетчик входных баров на разворотном баре "Дожи" Buy
int DojiCandleSell = 0 ;           //Счетчик входных баров на разворотном баре "Дожи" Sell
int lineDojiCandle = 0 ;           //Счетчик уровней области разворота по паттерну "Дожи"


// Переменные функции "Новый бар"
bool New_Bar = false ;



// Переменные функции паттерна "Дожи"
bool BuyDoji = false ;
bool SellDoji = false ;
bool TradeUpDoji = false ;
bool TradeDownDoji = false ;
double UpLine_Doji;
double DownLine_Doji;


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit ()
  {
   if ( Digits == 3 || Digits == 5 )
  {
   TakeProfit *= 10 ;
   StopLoss   *= 10 ;
   Slippage   *= 10 ;
   UpLineSell *= 10 ;
   DownLineSell *= 10 ;
   UpLineBuy *= 10 ;
   DownLineBuy *= 10 ;
  }

   return ( INIT_SUCCEEDED );
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit ( const int reason)
  {

   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick ()
  {
   int magic = Magic;
   int shag_ = Shag;
   
   double Open1 = NormalizeDouble ( iOpen ( Symbol (), TimeFrame, 1 ), Digits );
   double Close1 = NormalizeDouble ( iClose ( Symbol (), TimeFrame, 1 ), Digits );
   double High1 = NormalizeDouble ( iHigh ( Symbol (), TimeFrame, 1 ), Digits );
   double Low1 = NormalizeDouble ( iLow ( Symbol (), TimeFrame, 1 ), Digits );
   
   Fun_New_Bar();
   Doji();

     ma1 = iCustom ( NULL , 0 , "moving_averages" ,MA_Period, MA_Shift, MA_Method, 0 , 1 );
     ma2 = iCustom ( NULL , 0 , "moving_averages" ,MA_Period, MA_Shift, MA_Method, 0 , 2 );
     

   if (_Doji == true )
     {
     if (SellDoji == true )
       {
           if (! ObjectCreate ( ChartID (), "Arrow_Down_Doji" + IntegerToString (DojiCandle), OBJ_ARROW_DOWN , 0 , TimeCurrent (), High [ 1 ] + 70 * Point ))
             {
             Print ( "Не удалось создать метку вниз" );
             }
             ObjectSetInteger ( ChartID (), "Arrow_Down_Doji" + IntegerToString (DojiCandle), OBJPROP_COLOR , clrChocolate ); //--- установка цвета
             ObjectSetInteger ( ChartID (), "Arrow_Down_Doji" + IntegerToString (DojiCandle), OBJPROP_STYLE , STYLE_SOLID ); //--- установка стиля линии
             ObjectSetInteger ( ChartID (), "Arrow_Down_Doji" + IntegerToString (DojiCandle), OBJPROP_WIDTH , 1 ); //--- установка толщины линии
             ObjectSetInteger ( ChartID (), "Arrow_Down_Doji" + IntegerToString (DojiCandle), OBJPROP_BACK , false ); //--- отображение на переднем (false) или заднем (true) плане
             DojiCandle ++;
             
           if (! ObjectCreate ( ChartID (), "UpLine_Doji" + IntegerToString (lineDojiCandle), OBJ_HLINE , 0 , TimeCurrent (),UpLine_Doji))
             {
             Print ( "Не удалось создать верхнюю линию" );
             }
             ObjectSetInteger ( ChartID (), "UpLine_Doji" + IntegerToString (lineDojiCandle), OBJPROP_COLOR , clrChocolate ); //--- установим цвет прямоугольника 
             ObjectSetInteger ( ChartID (), "UpLine_Doji" + IntegerToString (lineDojiCandle), OBJPROP_STYLE , STYLE_SOLID ); //--- установим стиль линий прямоугольника 
             ObjectSetInteger ( ChartID (), "UpLine_Doji" + IntegerToString (lineDojiCandle), OBJPROP_WIDTH , 1 ); //--- установим толщину линий прямоугольника 
             ObjectSetInteger ( ChartID (), "UpLine_Doji" + IntegerToString (lineDojiCandle), OBJPROP_BACK , false ); //--- отобразим на переднем (false) или заднем (true) плане 
             
           if (! ObjectCreate ( ChartID (), "DownLine_Doji" + IntegerToString (lineDojiCandle), OBJ_HLINE , 0 , TimeCurrent (),DownLine_Doji))
             {
             Print ( "Не удалось создать нижнюю линию" );
             }
             ObjectSetInteger ( ChartID (), "DownLine_Doji" + IntegerToString (lineDojiCandle), OBJPROP_COLOR , clrBrown ); //--- установим цвет прямоугольника 
             ObjectSetInteger ( ChartID (), "DownLine_Doji" + IntegerToString (lineDojiCandle), OBJPROP_STYLE , STYLE_SOLID ); //--- установим стиль линий прямоугольника 
             ObjectSetInteger ( ChartID (), "DownLine_Doji" + IntegerToString (lineDojiCandle), OBJPROP_WIDTH , 1 ); //--- установим толщину линий прямоугольника 
             ObjectSetInteger ( ChartID (), "DownLine_Doji" + IntegerToString (lineDojiCandle), OBJPROP_BACK , false ); //--- отобразим на переднем (false) или заднем (true) плане 
             lineDojiCandle ++;
           
         if (Open1 == Close1)
           {
             if (! ObjectCreate ( ChartID (), "Arrow_Down_Doji" + IntegerToString (DojiCandle), OBJ_ARROW_DOWN , 0 , TimeCurrent (), High [ 1 ] + 70 * Point ))
               {
               Print ( "Не удалось создать метку вниз" );
               }
               ObjectSetInteger ( ChartID (), "Arrow_Down_Doji" + IntegerToString (DojiCandle), OBJPROP_COLOR , clrChocolate ); //--- установка цвета
               ObjectSetInteger ( ChartID (), "Arrow_Down_Doji" + IntegerToString (DojiCandle), OBJPROP_STYLE , STYLE_SOLID ); //--- установка стиля линии
               ObjectSetInteger ( ChartID (), "Arrow_Down_Doji" + IntegerToString (DojiCandle), OBJPROP_WIDTH , 1 ); //--- установка толщины линии
               ObjectSetInteger ( ChartID (), "Arrow_Down_Doji" + IntegerToString (DojiCandle), OBJPROP_BACK , false ); //--- отображение на переднем (false) или заднем (true) плане
               DojiCandle ++;
               Print ( "Дожи крест Down" );
            
             if (! ObjectCreate ( ChartID (), "UpLine_Doji" + IntegerToString (lineDojiCandle), OBJ_HLINE , 0 , TimeCurrent (),UpLine_Doji))
               {
               Print ( "Не удалось создать верхнюю линию" );
               }
               ObjectSetInteger ( ChartID (), "UpLine_Doji" + IntegerToString (lineDojiCandle), OBJPROP_COLOR , clrOrangeRed ); //--- установим цвет прямоугольника 
               ObjectSetInteger ( ChartID (), "UpLine_Doji" + IntegerToString (lineDojiCandle), OBJPROP_STYLE , STYLE_SOLID ); //--- установим стиль линий прямоугольника 
               ObjectSetInteger ( ChartID (), "UpLine_Doji" + IntegerToString (lineDojiCandle), OBJPROP_WIDTH , 1 ); //--- установим толщину линий прямоугольника 
               ObjectSetInteger ( ChartID (), "UpLine_Doji" + IntegerToString (lineDojiCandle), OBJPROP_BACK , false ); //--- отобразим на переднем (false) или заднем (true) плане 
                  
             if (! ObjectCreate ( ChartID (), "DownLine_Doji" + IntegerToString (lineDojiCandle), OBJ_HLINE , 0 , TimeCurrent (),DownLine_Doji))
               {
               Print ( "Не удалось создать нижнюю линию" );
               }
               ObjectSetInteger ( ChartID (), "DownLine_Doji" + IntegerToString (lineDojiCandle), OBJPROP_COLOR , clrBrown ); //--- установим цвет прямоугольника 
               ObjectSetInteger ( ChartID (), "DownLine_Doji" + IntegerToString (lineDojiCandle), OBJPROP_STYLE , STYLE_SOLID ); //--- установим стиль линий прямоугольника 
               ObjectSetInteger ( ChartID (), "DownLine_Doji" + IntegerToString (lineDojiCandle), OBJPROP_WIDTH , 1 ); //--- установим толщину линий прямоугольника 
               ObjectSetInteger ( ChartID (), "DownLine_Doji" + IntegerToString (lineDojiCandle), OBJPROP_BACK , false ); //--- отобразим на переднем (false) или заднем (true) плане 
               lineDojiCandle ++; 
            }
        }
         
       static int switch12 = 0 ;
       static int switch22 = 0 ;
       static int switch32 = 0 ;
      
       if (ma2 > UpLine_Doji && ma2 > DownLine_Doji && ma1 > UpLine_Doji && ma1 > DownLine_Doji)
        {
        UpLine_Doji = 0 ;
        DownLine_Doji = 0 ;
        }
      
       if (ma2 > DownLine_Doji)
        {
         if (ma1 < DownLine_Doji)
          {
          switch12 = 1 ;
           Print ( "пересечение дожи 1" );
          }
        }
         
       if (ma2 < DownLine_Doji)
        {
         if (ma1 > DownLine_Doji)
          {
           if (switch12 == 1 )
            {
            switch22 = 1 ;
             Print ( "пересечение дожи 2" );
            }
          }
        }
         
       if (ma2 > DownLine_Doji)
         {
         if ( Close [ 1 ] < DownLine_Doji)
           {
           if (switch12 == 1 )
             {
             if (switch22 == 1 )
               {
               switch32 = 1 ;
               Print ( "пересечение дожи 3" );
               }
             }
           }
         }
         
       if (switch12 == 1 )
         {
         if (switch22 == 1 )
           {
           if (switch32 == 1 )
             {
             if (! ObjectCreate ( ChartID (), "Arrow_Sell_Doji" + IntegerToString (DojiCandleSell), OBJ_ARROW_SELL , 0 , TimeCurrent (), Low [ 1 ] + 50 * Point ))
               {
               Print ( "Не удалось создать метку вниз" );
               }
               ObjectSetInteger ( ChartID (), "Arrow_Sell_Doji" + IntegerToString (DojiCandleSell), OBJPROP_COLOR , clrChocolate ); //--- установка цвета
               ObjectSetInteger ( ChartID (), "Arrow_Sell_Doji" + IntegerToString (DojiCandleSell), OBJPROP_STYLE , STYLE_SOLID ); //--- установка стиля линии
               ObjectSetInteger ( ChartID (), "Arrow_Sell_Doji" + IntegerToString (DojiCandleSell), OBJPROP_WIDTH , 1 ); //--- установка толщины линии
               ObjectSetInteger ( ChartID (), "Arrow_Sell_Doji" + IntegerToString (DojiCandleSell), OBJPROP_BACK , false ); //--- отображение на переднем (false) или заднем (true) плане
               DojiCandleSell ++;
               Print ( "Точка входа SELL по разворотной свече 'Дожи'" );
               UpLine_Doji = 0 ;
               DownLine_Doji = 0 ;
               
             if ( ObjectFind ( ChartID (), "Arrow_Sell_Doji" + IntegerToString (DojiCandleSell)))
               {
               switch12 = 0 ;
               switch22 = 0 ;
               switch32 = 0 ;
               }
                         
             if ( ObjectFind ( ChartID (), "UpLine_Doji" + IntegerToString (lineDojiCandle)) && ObjectFind ( ChartID (), "DownLine_Doji" + IntegerToString (lineDojiCandle)))
               {
               ObjectDelete ( "UpLine_Doji" + IntegerToString (lineDojiCandle));
               ObjectDelete ( "DownLine_Doji" + IntegerToString (lineDojiCandle));
               Print ( "Линии удалены" );
               }
               Print ( "Не удалось удалить верхнюю и нижнюю линии" ); 
             }
           }
         }
     
     }
   

      
   
 }
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
//+------------------------------------------------------------------+
//    Функция определения нового бара                                |
//+------------------------------------------------------------------+
void Fun_New_Bar()
{ 
   datetime TimeBar0 = iTime ( Symbol (),TimeFrame, 0 );
   static datetime New_Time= 0 ;                     // Время текущего бара
   New_Bar= false ;                                 // Нового бара нет 
   if (New_Time != TimeBar0)                       // Сравниваем время 
   { 
      New_Time = TimeBar0;                         // Теперь время такое 
      New_Bar = true ;                             // Поймался новый бар 
   } 
}

//+------------------------------------------------------------------+
//    Функция паттерна Дожи для бычьего и медвежьего рынка          |
//+------------------------------------------------------------------+
void Doji()
{
//Параметры Дожи
   double Open1 = NormalizeDouble ( iOpen ( Symbol (), TimeFrame, 1 ), Digits );
   double Close1 = NormalizeDouble ( iClose ( Symbol (), TimeFrame, 1 ), Digits );
   double High1 = NormalizeDouble ( iHigh ( Symbol (), TimeFrame, 1 ), Digits );
   double Low1 = NormalizeDouble ( iLow ( Symbol (), TimeFrame, 1 ), Digits );
   double Open2 = NormalizeDouble ( iOpen ( Symbol (), TimeFrame, 2 ), Digits );
   double Close2 = NormalizeDouble ( iClose ( Symbol (), TimeFrame, 2 ), Digits );
   double High2 = NormalizeDouble ( iHigh ( Symbol (), TimeFrame, 2 ), Digits );
   double Low2 = NormalizeDouble ( iLow ( Symbol (), TimeFrame, 2 ), Digits );
   
//Параметры индикатора волотильности ATR для нахожденя относительно большой свечи перед Доджи
   double ATR = iATR ( Symbol (),TimeFrame,ATR_period, 1 );
   
   BuyDoji = false ;
   SellDoji = false ;
   
//Математическое описание патерна Дожи
   if (Close1 < High1 - NormalizeDouble ( 0.3 *(High1-Low1), Digits )&& 
      Open1 < High1 - NormalizeDouble ( 0.3 *(High1-Low1), Digits )&& 
      Close1 > High1 - NormalizeDouble ( 0.7 *(High1-Low1), Digits )&& 
      Open1 > High1 - NormalizeDouble ( 0.7 *(High1-Low1), Digits )&& 
       MathAbs (Close1-Open1) <= NormalizeDouble ( 0.4 *(High1-Low1), Digits )&&
       MathAbs (Close2-Open2) > 0.8 *ATR && MathAbs (High1-Low1) > 0.6 *ATR)
      {
         if ((Close2 - Open2) > 0 && New_Bar)
         { 
            UpLine_Doji = High1 + UpLineSell* Point ();
            DownLine_Doji = High1 - DownLineSell* Point ();
            SellDoji = true ;
             Print ( "Down Doji" ); // Условие разворота в медвежий тренд
         }
         if ((Close2 - Open2) < 0 )
         {
            UpLine_Doji = High1 + UpLineBuy* Point ();
            DownLine_Doji = High1 - DownLineBuy* Point ();
            BuyDoji = true ;
             Print ( "Up Doji" ); // Условие разворота в бычий тренд
         }
      }
      
}

Using variables

       static int switch12 = 0 ;
       static int switch22 = 0 ;
       static int switch32 = 0 ;

the entry point condition is written

 
voron_026:
Good afternoon. Please take a look at the code. The robot does not remove horizontal lines when new ones appear

Using the variables

to write the condition of the entry point

The reason is that a counter is added to the line name which increases the value by one before it is deleted.

 
I see your point. How to implement line removal then. I need the lines to be deleted as soon as a new pattern appears with its own lines
 
voron_026:
I see your point. How to implement line removal then. I need the lines to be deleted as soon as a new pattern with its own lines appears

Do you have any suggestions of your own?

Maybe delete first and then create? Or not delete and only change coordinates? What is the point of deleting and creating new ones?

Reason: