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

 

Hello, I want to get an expiry date for futures

EXPIRATION=(datetime)SymbolInfoInteger(Symbol(),SYMBOL_EXPIRATION_TIME);

It gives out 1970 01 01 00 00

 

Hello, Can someone please advise how to make an EA open an order at a certain point of the chart when you click on a certain point? When you install a script or an EA, the function NormalizeDouble(WindowPriceOnDropped(),Digits); defines the point when you click the mouse. But the question is that this can be done at any time from a running EA. Is there such a possibility.

I see a function ChartGetInteger(0,CHART_EVENT_MOUSE_MOVE,0,1) I don't know how to use it yet, is it possible to determine where (to which point) the mouse pointer was directed?

 
Basicprof:

Hello, Can someone please advise how to make an EA open an order at a certain point of the chart when you click on a certain point? When you install a script or an EA, the function NormalizeDouble(WindowPriceOnDropped(),Digits); defines the point when you click the mouse. But the question is that this can be done at any time from a running EA. Is there such a possibility.

I see a function ChartGetInteger(0,CHART_EVENT_MOUSE_MOVE,0,1) But I haven't figured out how to use it yet. Is it possible to determine where (to which point) the mouse pointer has been directed?

Use the "CHARTEVENT_CLICK" event

You can get parts of the code from here

 
Vitaly Muzichenko:

Use the "CHARTEVENT_CLICK" click event

You can get the code snippets from here


Thank you very much !!!

 

One more question : I moved the functions to the library from the EA, when I run the EA, it immediately crashes and the messages shows that the terminal can not load the library Cannot call 'ATP_funkcii.mq4::DrawLABEL', 'ATP_funkcii.mq4' is not loaded

How do I fix this problem?

I noticed one thing! The editor of the EA and the library can be seen, but on the computer, I don't see them in the program files for some reason. Only the Expert Advisor file.

 
Hi, could you please tell me how to know the index of the next element of an array?
 
vikzip:
Hello, Could you please tell me how knowing the index of an array element to know the index of the next element of the array?

The index of any array always starts with zero. I.e., if the size of the array is 1, the index of this cell will be 0.

How do you know the number 5 to know the number 6?

Knowing the digit 6, how do I know the digit 7, knowing that there are only 8 digits?

Knowing index 7, how do you know the next index, knowing that array size = 8 ?

 

Hello, I need help. The indicator does not update, I want it to update on every tick.


//+------------------------------------------------------------------+
//|                                             alx_RSI_BANDS_MA.mq4 |
//|                                                       alx_Babon |
//+------------------------------------------------------------------+
#property copyright "alx_Babon"
#property link      "babon82@gmail.com"

#property indicator_separate_window
#property indicator_buffers 6
#property  indicator_color1 Yellow
#property  indicator_color2 DarkBlue
#property  indicator_color3 White
#property  indicator_color4 White
#property  indicator_color5 White
//---- input parameters
extern int       RSI_Per=8;
extern int       MA_Per=8;
extern int       Bands_Per=20;
extern int       SmoothType=0;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
double Sostoyanie;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   string type;
   switch(SmoothType)
   {
   case MODE_EMA: type="EMA";break;
   case MODE_SMMA: type="SMMA";break;
   case MODE_LWMA: type="LWMA";break;
   default: type="LWMA";SmoothType=0;break; // если ни один вариант не подошел
   }

   SetIndexStyle(0,DRAW_LINE,0,1);
   SetIndexBuffer(0,ExtMapBuffer1);//Свойства RSI
   SetIndexLabel(0,"RSI("+RSI_Per+")");
   SetIndexStyle(1,DRAW_LINE,0,2);
   SetIndexBuffer(1,ExtMapBuffer2);//Свойства MA
   SetIndexLabel(1,"MA ("+MA_Per+"), "+type);
   SetIndexStyle(2,DRAW_LINE,2,1);
   SetIndexBuffer(2,ExtMapBuffer3);//Свойства Bands
   SetIndexLabel(2,"Bands ("+Bands_Per+")");
   SetIndexStyle(3,DRAW_LINE,2,1);
   SetIndexBuffer(3,ExtMapBuffer4);//Свойства Bands
   SetIndexLabel(3,"Bands ("+Bands_Per+")");
   SetIndexStyle(4,DRAW_LINE,2,1);
   SetIndexBuffer(4,ExtMapBuffer5);//Свойства Bands
   SetIndexLabel(4,"Bands ("+Bands_Per+")");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   int limit,cnt;
   int cnt_rsi,cnt_bb,cnt_ma;
   if (counted_bars==0) 
      {
      limit=Bars-RSI_Per-1;
      for(cnt=limit;cnt>=0;cnt--)
         {
          ExtMapBuffer1[cnt]=iRSI(NULL,0,RSI_Per,PRICE_CLOSE,cnt);
         }
      for(cnt=1;cnt<=Bars;cnt++)
         {
          ExtMapBuffer6[cnt]= iMA(NULL,0,MA_Per,0,SmoothType,PRICE_CLOSE,cnt);
                
         }
      for(cnt=limit-MA_Per;cnt>=0;cnt--)
         {
          ExtMapBuffer2[cnt]=iMAOnArray(ExtMapBuffer1,0,MA_Per,0,SmoothType,cnt);
         }          
      for(cnt=limit-Bands_Per;cnt>=0;cnt--)
         {
          ExtMapBuffer3[cnt]=iBandsOnArray(ExtMapBuffer1,0,Bands_Per,2,0,MODE_LOWER,cnt);
         }
      for(cnt=limit-Bands_Per;cnt>=0;cnt--)
         {
          ExtMapBuffer4[cnt]=iBandsOnArray(ExtMapBuffer1,0,Bands_Per,2,0,MODE_UPPER,cnt);
         }  
      for(cnt=limit-Bands_Per;cnt>=0;cnt--)
         {
          ExtMapBuffer5[cnt]=iBandsOnArray(ExtMapBuffer1,0,Bands_Per,2,0,MODE_MAIN,cnt);
         } 
         
      }
      cnt_rsi=limit;
      cnt_bb=limit-Bands_Per;
      cnt_ma=limit-MA_Per;
      Comment(
               "RSI (",RSI_Per,")=",ExtMapBuffer1[1],"\n",
          "Bolinger (",Bands_Per,")=",ExtMapBuffer5[1],"\n",
                "MA (",MA_Per,")=",ExtMapBuffer2[1],"\n"
                //,"MA CNT (",MA_Per,")=",ExtMapBuffer6[8],"\n"
                //,"CNT_MA (",cnt_ma,")"
             );
//----
      //ObjectCreate("Arrow", OBJ_ARROW, 0, 0, 5);
      //ObjectSet("Arrow",OBJPROP_ARROWCODE,OBJ_PERIOD_M15 | OBJ_PERIOD_H1);
      //ObjectSetText("PivotText", "Pivot Point (DJ)", fontsize, "Arial", 
                 //colorPivot);
//----
   return(0);
  }
//+---------------------------------------

 
Artyom Trishkin:

The index of any array always starts with zero. That is, if the array size is 1, then the index of that cell will be 0.

How do you know the number 5 to know the number 6?

How do you know the digit 6 to know the digit 7, knowing that there are only 8 digits?

How, knowing index 7, how can we find out the next index, knowing that array size = 8 ?


Thanks for the detailed explanation )))) So it would be correct to write


double Mas[];                                                                //массив для упорядочивания всех ордеров
  for(int i=0; i<OrdersTotal(); i++)                                           // Цикл перебора ордер
   {
    if(OrderSelect(i,SELECT_BY_POS))                                           // Если есть следующий
     {
       Price=OrderOpenPrice();
       ArrayResize(Mas, i+1);                                                 //задан размер массива
       Mas [i] = Price; 
       ArraySort (Mas,WHOLE_ARRAY,0,MODE_DESCEND);                           // Теперь цены открытия упорядочены по убыванию
     }
   } 
   if(ArraySize(Mas)>1)                                                         //Если массив не пустой
   
         { 
        int Blizko2=ArrayBsearch(Mas,Ask,WHOLE_ARRAY,0,MODE_DESCEND);          //Определен индекс ближайшего большего по значению елемента к текущей цене
             PriceBlizko2 = Mas[Blizko2];                                      // Цена выбранного ордера

       int Blizko1; 

Mas[Blizko1]= Blizko2+1;     Это верно??

                                                      //Определен индекс ближайшего меньшего по значению елемента к текущей цене         PriceBlizko1=Mas[Blizko1];
Can you tell me please?

 
vikzip:

Thanks for the detailed explanation)))) So it would be correct to write


Can you tell me please?

There is no need to sort the array after each addition of an array element. It would be better to move the sorting

double Mas[];                                                                //массив для упорядочивания всех ордеров
  for(int i=0; i<OrdersTotal(); i++)                                           // Цикл перебора ордер
   {
    if(OrderSelect(i,SELECT_BY_POS))                                           // Если есть следующий
     {
       Price=OrderOpenPrice();
       ArrayResize(Mas, i+1);                                                 //задан размер массива
       Mas [i] = Price; 
     }
   } 
   if(ArraySize(Mas)>1)                                                         //Если массив не пустой
   
         { 
       ArraySort (Mas,WHOLE_ARRAY,0,MODE_DESCEND);                           // Теперь цены открытия упорядочены по убыванию
        int Blizko2=ArrayBsearch(Mas,Ask,WHOLE_ARRAY,0,MODE_DESCEND);          //Определен индекс ближайшего большего по значению елемента к текущей цене
             PriceBlizko2 = Mas[Blizko2];                                      // Цена выбранного ордера

       int Blizko1; 
        Mas[Blizko1]= Blizko2+1;     Это верно??
                                                      //Определен индекс ближайшего меньшего по значению елемента к текущей цене
        PriceBlizko1=Mas[Blizko1];

From the help.

Return value

Returns index of the first found element. If the sought value is not found, it returns the index of the closest lesser of the elements between which the sought value is located.

Mas[Blizko2] is the closest smaller value in the array.