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

 
trader781:
Artyom, I threw the code above.
Where? Here's the link to your post I'm replying to: . It's in the stock next to your nickname.

Copy the same link to your code that you threw above and paste it into your post when you refer to any of the participants' posts . Or do you think you want to find it without knowing where it is and what it's about so badly?
 
Artyom Trishkin:
Where? Here's a link to your post that I'm replying to: . It's in the stock area next to your nickname.

Copy the same link to your code that you threw above and paste it in your message when you're referring to a message from any of the participants . Or do you think you want to find it without knowing where it is and what it's about so badly?

https://www.mql5.com/ru/forum/160683/page109

1082 message

I just don't know how on this resource, but usually a moderator sees all posts of any user including edits.

How to do such a link to a post I have no idea.

 
trader781:

https://www.mql5.com/ru/forum/160683/page109

1082 message

I just don't know about this resource, but usually a moderator sees all posts of any user including edits.

How to do such a link to a post I have no idea.

HERE'S WHERE IT GOES:

 
trader781:

https://www.mql5.com/ru/forum/160683/page109

1082 message

No, I have no desire to upload it myself.

Attach it here as code, using the SRC button. Then you can safely look at the code without having to download and place it in the correct terminal folder - why make life difficult for those who can help you?
 
Artyom Trishkin :
No, you don't want to download.

Attach here as a code using the SRC button. Then you can safely look at the code without resorting to downloading and placing it in the right folder of the terminal - why make life difficult for those who can help you?

Please, only I do not understand how to check it without downloading it to my terminal. Please also explain what is the advantage of throwing pieces of code here that clog the page.

//+------------------------------------------------------------------+
//|                                                     Close_MA.mq4 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link        "https://www.mql5.com"
#property version    "1.00"
#property strict

extern bool Uslovie1= false ; //Uslovie 4 6+50 MA

extern bool OpenOrders= false ; //+---Открыть ордер

extern double Lots= 0.01 ; //Oбьем открываемого ордера

extern const string Настройки_работы_советника= "" ;

extern int Period1= 6 ; //Период 1МА
extern ENUM_APPLIED_PRICE PRICE1= PRICE_MEDIAN ;             // 1МА По цене

extern int Period2= 50 ; //Период 2МА
extern ENUM_APPLIED_PRICE PRICE2= PRICE_MEDIAN ;             // 2МА По цене

extern int Period3= 1000 ; //Период 3МА
extern ENUM_APPLIED_PRICE PRICE3= PRICE_MEDIAN ;             // 3МА По цене

extern uint X= 1 ;                                           // отклонение от ма, пунктов
extern bool PlaySound = false ;
extern int M= 1000 ;                                         // миллисекунды в Sleep
extern int R;                                               // раз повторения музыки
extern int count= 0 ;  
extern int Step= 500 ;                                       // счетчик тиков 500макс.
int    i;                                                   // исходный счетчик ордеров
int    p= 0 ;                                                 // внутренняя для playSound
bool   y = false ;                                           // для удобства сравнений условий 1,2,3,4,5,6  
bool   dummy;                                               // для выхода функций в переменную
int    ticket = 0 ;                                           // тикет открываемого ордера
int Magic = 222 ;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+



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

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+



//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick ()
  {
     {
       if ( Bars < 801 || ( IsTradeAllowed ()== false )) //--- Проверим достаточна ли в истории баров для анализа и разрешение торговли
         return ;
     }
//+----------------------------------------------------------------

   double ma1= NormalizeDouble ( iMA ( NULL , 0 ,Period1, 0 , MODE_SMA ,PRICE1, 0 ), 5 );

   double ma2= NormalizeDouble ( iMA ( NULL , 0 ,Period2, 0 , MODE_SMA ,PRICE1, 0 ), 5 );   //три заданных параметра ма

   double ma3= NormalizeDouble ( iMA ( NULL , 0 ,Period3, 0 , MODE_SMA ,PRICE1, 0 ), 5 );
//+-----------------------------------------------------------------  Открытие ордеров


                               //+----Купить


       {
         if ( MathAbs ( Bid -ma3)< 1000 * Point () && (myOrdersTotal()== false ))  
           {
            ticket= OrderSend ( Symbol (), OP_BUY ,Lots, Ask , 50 , 0 , 0 , "" ,Magic, 0 , clrLightGray ); //+------отправка 1 ордера
            HLineCreate();  
           }
         else if (( Ask >=(FindLastOrderOpenPrice()+(Step* _Point )))&& myOrdersTotal()) //+------------если ордер в плюс
              {
            ticket= OrderSend ( Symbol (), OP_BUY ,Lots, Ask , 50 , 0 , 0 , "" ,Magic, 0 , clrLightGray );
            HLineMove();
              }
         else if (( Ask <=(FindLastOrderOpenPrice()-(Step* _Point )))&& myOrdersTotal()) //+------------если ордер вплюс
              {
            ticket= OrderSend ( Symbol (), OP_BUY ,Lots, Ask , 50 , 0 , 0 , "" ,Magic, 0 , clrLightGray );
            HLineMove();
              }
         else if (ticket== 0 )
           {
             return ;
           }          
     /*          
                               //+----Продать

         if(MathAbs(Bid-ma3)>1000*Point() && (myOrdersTotal()==false))
           {
            ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,50,0,0,"",Magic,0,clrLightGray);//+------отправка 1 ордера
            HLineCreate1();  
           }
         else if ((Ask>=(FindLastOrderOpenPrice()+(Step*_Point)))&& myOrdersTotal())//+------------если ордер в минус
              {
            ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,50,0,0,"",Magic,0,clrLightGray);
            HLineMove1();
              }
         else if ((Ask<=(FindLastOrderOpenPrice()-(Step*_Point)))&& myOrdersTotal())//+------------если ордер вплюс
              {
            ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,50,0,0,"",Magic,0,clrLightGray);
            HLineMove1();
              }
         else if(ticket==0)
           {
            return;
           }       */
    
       }
      
    
      
//+------------------------------------------------------------------Условия
   if (Uslovie1== true ) //Bid+ma800
     {
       if (( Bid >=ma3-X* Point && Bid <ma3) || ( Bid <=ma3+X* Point && Bid >ma3))
        {
           {y= true ;}
        }
     }
//+------------------------------------------------------------------закрыть покупки или продажи

   if ((y== true ) && (myOrdersTotal()== true )) //продажа
     {
      dummy=( OrderClose ( OrderTicket (), OrderLots (), Ask , 0 ,White));
     }
   if ((y== true ) && (myOrdersTotal()== false ))
     {
        dummy= false ;
        HLineDelete();
        HLineDelete1();
     //  ExpertRemove();  
     }

  }
//+------------------------------------------------------------------+
bool myOrdersTotal() //если ордера есть
  {
   for (i= OrdersTotal ()- 1 ; i>= 0 ; i--) //   цикл будет работать пока не останется ордеров
     {
       if ((( OrderSelect (i, SELECT_BY_POS , MODE_TRADES ))== true ) && OrderSymbol ()== Symbol () && ( OrderType ()< 2 ))
        {
         return true ;
        }
     }
   return false ;
  }
//-------------------------------------------------------------------
double FindLastOrderOpenPrice()
  {
   double oldorderopenprice= 0 ;
   int     oldticket= 0 ;
   ticket= 0 ;
   for (i= OrdersTotal ()- 1 ; i>= 0 ; i--) //   цикл будет работать пока не останется ордеров
     {
       if (( OrderSelect (i, SELECT_BY_POS , MODE_TRADES )) && OrderSymbol ()== Symbol () && ( OrderMagicNumber ()==Magic)
         && ( OrderType ()== OP_BUY || OrderType ()== OP_SELL ))
        {
         oldticket= OrderTicket ();
         if (oldticket>=ticket)
           {
            ticket=oldticket;
            oldorderopenprice= OrderOpenPrice ();
           }
        }
     }
   return (oldorderopenprice);
  }
//-------------------------------------------------------------------  





//+------------------------------------------------------ часть Buy      bool HLineCreate();

                            
bool HLineCreate( const long             chart_ID= 0 ,           // ID графика
                 const string           name= "Buy" ,           // имя линии
                 const int              sub_window= 0 ,         // номер подокна
                 double                 price1= 0 ,             // цена линии
                 const color            clr= clrAzure ,         // цвет линии
                 const ENUM_LINE_STYLE style= STYLE_DASHDOT , // стиль линии
                 const int              width= 3 ,             // толщина линии
                 const bool             back= false ,           // на заднем плане
                 const bool             selection= true ,       // выделить для перемещений
                 const bool             hidden= false ,         // скрыт в списке объектов
                 const long             z_order= 0 )           // приоритет на нажатие мышью                
    {
   if (!price1)
      price1=FindLastOrderOpenPrice();
   ResetLastError ();
   if (! ObjectCreate (chart_ID,name, OBJ_HLINE ,sub_window, 0 ,price1))
     {
       Print ( __FUNCTION__ ,
             ": не удалось создать горизонтальную линию! Код ошибки = " , GetLastError ());
       return ( false );
           //--- установим цвет линии
   ObjectSetInteger (chart_ID,name, OBJPROP_COLOR ,clr);
//--- установим стиль отображения линии
   ObjectSetInteger (chart_ID,name, OBJPROP_STYLE ,style);
//--- установим толщину линии
   ObjectSetInteger (chart_ID,name, OBJPROP_WIDTH ,width);
//--- отобразим на переднем (false) или заднем (true) плане
   ObjectSetInteger (chart_ID,name, OBJPROP_BACK ,back);
   ObjectSetInteger (chart_ID,name, OBJPROP_SELECTABLE ,selection);
   ObjectSetInteger (chart_ID,name, OBJPROP_SELECTED ,selection);
//--- скроем (true) или отобразим (false) имя графического объекта в списке объектов
   ObjectSetInteger (chart_ID,name, OBJPROP_HIDDEN ,hidden);
//--- установим приоритет на получение события нажатия мыши на графике
   ObjectSetInteger (chart_ID,name, OBJPROP_ZORDER ,z_order);
       ChartRedraw ();
     }
   return ( true );
  }          
//+------------------------------------------------------------------+          HLineMove();
bool HLineMove( const long    chart_ID= 0 ,         // ID графика
               const string name= "Buy" , // имя линии
               double        price1= 0 )           // цена линии
  {
   if (!price1)
      price1=FindLastOrderOpenPrice();
   ResetLastError ();  
   if (! ObjectMove (chart_ID,name, 0 , 0 ,price1))
     {
       Print ( __FUNCTION__ ,
             ": не удалось переместить горизонтальную линию! Код ошибки = " , GetLastError ());
       return ( false );
     }
   return ( true );
  }
//+------------------------------------------------------------------+         bool HLineDelete();
bool HLineDelete( const long    chart_ID= 0 ,   // ID графика
                 const string name= "Buy" ) // имя линии
  {
   ResetLastError ();
   if (! ObjectDelete (chart_ID,name))
     {
       Print ( __FUNCTION__ ,
             ": не удалось удалить горизонтальную линию! Код ошибки = " , GetLastError ());
       return ( false );
     }
   return ( true );
  }        
//+-----------------------------------------------------------------+      





   //+-----------часть SELL                    bool HLineCreate1
  
  
  
  
   //+------------------------------------------------------    
//+------------------------------------------------------                     bool HLineCreate1();
bool HLineCreate1( const long            chart_ID= 0 ,           // ID графика
                 const string           name= "Sell" ,   // имя линии
                 const int              sub_window= 0 ,         // номер подокна
                 double                 price2= 0 ,             // цена линии
                 const color            clr= clrRed ,         // цвет линии
                 const ENUM_LINE_STYLE style= STYLE_DASHDOT , // стиль линии
                 const int              width= 2 ,             // толщина линии
                 const bool             back= false ,           // на заднем плане
                 const bool             selection= true ,       // выделить для перемещений
                 const bool             hidden= false ,         // скрыт в списке объектов
                 const long             z_order= 0 )           // приоритет на нажатие мышью                
    {
   if (!price2)
      price2=FindLastOrderOpenPrice();
   ResetLastError ();
   if (! ObjectCreate (chart_ID,name, OBJ_HLINE ,sub_window, 0 ,price2))
     {
       Print ( __FUNCTION__ ,
             ": не удалось создать горизонтальную линию! Код ошибки = " , GetLastError ());
       return ( false );
           //--- установим цвет линии
   ObjectSetInteger (chart_ID,name, OBJPROP_COLOR ,clr);
//--- установим стиль отображения линии
   ObjectSetInteger (chart_ID,name, OBJPROP_STYLE ,style);
//--- установим толщину линии
   ObjectSetInteger (chart_ID,name, OBJPROP_WIDTH ,width);
//--- отобразим на переднем (false) или заднем (true) плане
   ObjectSetInteger (chart_ID,name, OBJPROP_BACK ,back);
   ObjectSetInteger (chart_ID,name, OBJPROP_SELECTABLE ,selection);
   ObjectSetInteger (chart_ID,name, OBJPROP_SELECTED ,selection);
//--- скроем (true) или отобразим (false) имя графического объекта в списке объектов
   ObjectSetInteger (chart_ID,name, OBJPROP_HIDDEN ,hidden);
//--- установим приоритет на получение события нажатия мыши на графике
   ObjectSetInteger (chart_ID,name, OBJPROP_ZORDER ,z_order);
       ChartRedraw ();
     }
   return ( true );
  }          
//+------------------------------------------------------------------+          HLineMove1();
bool HLineMove1( const long    chart_ID= 0 ,         // ID графика
               const string name= "Sell" ,         // имя линии
               double        price2= 0 )             // цена линии
  {
   if (!price2)
      price2=FindLastOrderOpenPrice();
   ResetLastError ();  
   if (! ObjectMove (chart_ID,name, 0 , 0 ,price2))
     {
       Print ( __FUNCTION__ ,
             ": не удалось переместить горизонтальную линию! Код ошибки = " , GetLastError ());
       return ( false );
     }
   return ( true );
  }
//+------------------------------------------------------------------+         bool HLineDelete1();
bool HLineDelete1( const long    chart_ID= 0 ,   // ID графика
                 const string name= "Sell" ) // имя линии
  {
   ResetLastError ();
   if (! ObjectDelete (chart_ID,name))
     {
       Print ( __FUNCTION__ ,
             ": не удалось удалить горизонтальную линию! Код ошибки = " , GetLastError ());
       return ( false );
     }
   return ( true );
  }        

 
Artyom Trishkin:
PUT IT IN HERE:
Artyom, is this for the particularly gifted video?
 
Vitaly Muzichenko:
Artyom, is that for the particularly gifted video?
Yeah, it is.
 
trader781:

Please, only I don't understand how to check it without uploading it to my terminal. Also, please explain what is the advantage of throwing pieces of code clogging the page here.

trader781, what is your question about code?

The advantage of chunks of code is that, for example, I have a test file where I just copy a piece of code from the forum and paste it into the file. Otherwise, you have to download your file with the code, then open a folder in the folder and paste your file, after that you have to delete it. Do you feel the difference?

 
trader781:

Please, only I don't understand how to check it without uploading it to my terminal. Also please explain what is the advantage of throwing pieces of code here, clogging up the page.

Fucking hell...

Actually people usually make minimal code to reproduce the error you claim.

But judging by the code, you don't really understand what it does at all.

You have parameters in your functions that can be passed into them. In particular the colour of the line. But you have made them all with default values and don't ask "what's inside my function, what parameters does it get?" but you start saying that the terminal fails. That's fine...

Remove all default parameters from the function that creates the line - the compiler will make you think about setting them when calling the function - this is necessary for your own education. And remove duplicate functions - those where you put 1 at the end of the name - use one function with different parameters.
 
Vitaly Muzichenko:

trader781, what exactly is the question about the code?

The advantage of pieces of code is that, for example, I have a test file where I just have to copy a piece of code from the forum and paste it into the file. Otherwise, you have to download your file with the code, then open a folder in the folder and paste your file, after that you have to delete it. Feel the difference?

ok, I get it

Artyom Trishkin:
Fucking division ...

I understand that it's all far from acceptable at the moment, but can you show me why in the case of a purchase I can't get a given dashedline of a specified colour, although white or just plain green it will quietly give out.

and

double OP = 5.00000

TP = (OP/100);

Print("TP= ",TP);

2017.02.09 21:36:03.650 2015.01.05 04:00:00 martin H1-1 USDJPY,H1: TP= 0.5

don't understand since when do you divide 5 by 100 is 0. 5

Reason: