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

 


#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Yellow
//---- input parameters
//extern double    TakeProfit=250.0;
//extern double    Lots=1;
extern int       barn=1000;
extern int       Length=10;
extern int       PatternLength=10;
extern int        PatternWidth=4;
extern color       PatternColor = Red;
extern bool       DrawZigZag = true;
extern bool    ShowValues = true;
extern color   ValueColor = Blue;
//---- buffers
double ExtMapBuffer1[];
//double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexEmptyValue(0,0.0);
  //SetIndexDrawBegin(0, barn);
  if (DrawZigZag == true)  {SetIndexStyle(0,DRAW_SECTION);}
  else {SetIndexStyle(0,DRAW_NONE);}
   SetIndexBuffer(0,ExtMapBuffer1);
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
ObjectsDeleteAll();
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
 
   int shift,Swing,Swing_n,alf,uzl,i,zu,zd,mv;
   double LL,HH,BH,BL,NH,NL; 
   double Uzel[10000][3]; 
   string text;
    
    ObjectDelete(OBJ_TREND);
    

// loop from first bar to current bar (with shift=0) 
      Swing_n=0;Swing=0;uzl=0; 
      BH =High[barn];BL=Low[barn];zu=barn;zd=barn; 



for (shift=barn;shift>=0;shift--) { 
      LL=10000000;HH=-100000000; 
   for (i=shift+Length;i>=shift+1;i--) { 
         if (Low[i]< LL) {LL=Low[i];
           
         } 
         if (High[i]>HH) {HH=High[i];} 

  }
 
   if (Low[shift]<LL && High[shift]>HH){ 
      Swing=2; 
      if (Swing_n==1) {zu=shift+1;} 
      if (Swing_n==-1) {zd=shift+1;
 
      } 
      
   } else { 
      if (Low[shift]<LL) {Swing=-1;} 
      if (High[shift]>HH) {Swing=1;} 
   } 

   if (Swing!=Swing_n && Swing_n!=0) { 
   if (Swing==2) {
      Swing=-Swing_n;BH = High[shift];BL = Low[shift]; 
   } 
   uzl=uzl+1; 
   if (Swing==1) {
      Uzel[uzl][1]=zd;
      Uzel[uzl][2]=BL;
      NewSid(i,zd,BL);
     
   } 
   if (Swing==-1) {
      Uzel[uzl][1]=zu;
      Uzel[uzl][2]=BH; 
       NewSid(i,zu,BH);
   } 
      BH = High[shift];
      BL = Low[shift]; 
      

   } 
 
   
/*

 */
   
   

   if (Swing==1) { 
      if (High[shift]>=BH) {BH=High[shift];zu=shift;}} 
      if (Swing==-1) {
          if (Low[shift]<=BL) {BL=Low[shift]; zd=shift;}} 
      Swing_n=Swing; 
   } 

   

   
   for (i=1;i<=uzl;i++) { 
         mv=StrToInteger(DoubleToStr(Uzel[i][1],0));
      ExtMapBuffer1[mv]=Uzel[i][2];
      

   
   } 


   return(0);
  }
  
  void NewSid(int i, int re,  double Uzels)
{

int zed=re-PatternLength;

if (zed < 0)
   {
   ObjectCreate("priceLine1_"+i,OBJ_TREND,0,0,0,0,0);
   ObjectSet("priceLine1_"+i ,OBJPROP_TIME1,Time[re]);
   ObjectSet("priceLine1_"+i ,OBJPROP_PRICE1,Uzels);
  
   ObjectSet("priceLine1_"+i ,OBJPROP_TIME2,Time[re+PatternLength]); 
   ObjectSet("priceLine1_"+i ,OBJPROP_PRICE2,Uzels);   
    
   ObjectSet("priceLine1_"+i ,OBJPROP_COLOR,PatternColor);
   ObjectSet("priceLine1_"+i,OBJPROP_RAY, false);
   ObjectSet("priceLine1_"+i,OBJPROP_WIDTH,PatternWidth);
   

   }
   
   
   
   
  else {

   ObjectCreate("priceLine1_"+i,OBJ_TREND,0,0,0,0,0);
   ObjectSet("priceLine1_"+i ,OBJPROP_TIME1,Time[re]);
   ObjectSet("priceLine1_"+i ,OBJPROP_PRICE1,Uzels);
  
   ObjectSet("priceLine1_"+i ,OBJPROP_TIME2,Time[re-PatternLength]); 
   ObjectSet("priceLine1_"+i ,OBJPROP_PRICE2,Uzels);   
    
   ObjectSet("priceLine1_"+i ,OBJPROP_COLOR,PatternColor);
   ObjectSet("priceLine1_"+i,OBJPROP_RAY, false);
   ObjectSet("priceLine1_"+i,OBJPROP_WIDTH,PatternWidth);
}

      string high  = DoubleToStr(High[re],4);
      string low   = DoubleToStr(Low[re],4);
      string open  = DoubleToStr(Open[re],4);
      string close = DoubleToStr(Close[re],4);

 Comment(low,"   ",high);

if (ShowValues == true)

{
   ObjectCreate("price_text"+i,OBJ_TEXT,0,0,0);
   //ObjectSetText("price_text"+i,"Date: "+TimeToStr(Time[re],TIME_DATE | TIME_MINUTES)+" | Time: ",10,"Calibri", Green);
   
   ObjectSetText("price_text"+i,"Open: "+open+" | High: "+high+" | Low: "+low+" | Close: "+close,10,"Calibri", ValueColor);
   ObjectSet("price_text"+i ,OBJPROP_TIME1,Time[re]);
   ObjectSet("price_text"+i ,OBJPROP_PRICE1,Uzels);
   
};
}


Why does Comment(low," ",high) output
only the value high?
 
Can anyone advise how in the text of the indicator you can put restrictions on use in different timeframes. When loading the indicator it is in the properties, but how to limit it programmatically????
 
Vladimir Pavlov:
Can you advise how to place restrictions on the use of different timeframes in the indicator text? When loading the indicator it is in the properties, but how to limit this programmatically????
if(InpTimeframeWork!=Period())
  {
   // Здесь действия, которые нужно выполнить если период графике не совпадает с заданным в настройках
  }

If it is checked in OnInit(), you can output a message about the chart mismatch and either return INIT_FAILED; or tune the terminal chart to the desired one: ChartSetSymbolPeriod(0,NULL,InpTimeframeWork);

 

Good afternoon!
Please help me with the problem of activating the copier. I bought a copier on the market a long time ago for 25$. I would like to use it on VPS, but it cannot be loaded into MT4 from Market for some reason. Offers only to buy. I still have 7 free activations. I can't figure out what's wrong, can you advise me what i should do to activate copier https://www.mql5.com/ru/market/product/4319 ?

Thank you in advance.

 
Artyom Trishkin:

If it is checked in OnInit(), you can output a message about chart mismatch and either return INIT_FAILED; or adjust the terminal chart to the required one: ChartSetSymbolPeriod(0,NULL,InpTimeframeWork);

I know this variant, but I don't know how to use properties. How to configure in the program tab "Display" not to let in unnecessary levels.

 
//+------------------------------------------------------------------+
//| eeeeee.mq4 |
//| Copyright 2018, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
#property indicator_chart_window
extern int ExtDepth = 12;
extern int ExtDeviation = 5;
extern int ExtBackstep = 3;
extern inttern ShiftBars = 2;
//+------------------------------------------------------------------+
//| Custom indicator initialisation function|
//+------------------------------------------------------------------+
int OnInit()
{// in the module

//in the function
double y3=0, y2=0, y1=0, zz; // extremums
int x3, x2, x1, sh=ShiftBars;// numbers of bars
// Take three extrema of the Zig-Zag
while (y3==0) {
zz=iCustom(NULL, 0, "ZigZag", ExtDepth, ExtDeviation, ExtBackstep, 0, sh);
if (zz!=0 && zz!=EMPTY_VALUE) {
if (y1==0) { x1=sh; y1=zz; }
else if (y2==0) { x2=sh; y2=zz; }
else if (y3==0) { x3=sh; y3=zz; }
}
sh++;

}

How do I get the value of the current extremum?

Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5
Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5
  • www.mql5.com
Задавайте вопросы по техническому анализу, обсуждайте торговые системы и улучшайте свои навыки программирования торговых стратегий на языке MQL5. Общайтесь и обменивайтесь опытом на форуме с трейдерами всего мира и помогайте ответами новичкам — наше сообщество развивается вместе с вами. Как эффективно продвигать свой продукт в Маркете...
 
02031986dima:

How to get the value of the current extremum?

Insert the code correctly:


 
02031986dima:
//+------------------------------------------------------------------+
//| eeeeee.mq4 |
//| Copyright 2018, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
#property indicator_chart_window
extern int ExtDepth = 12;
extern int ExtDeviation = 5;
extern int ExtBackstep = 3;
extern inttern ShiftBars = 2;
//+------------------------------------------------------------------+
//| Custom indicator initialisation function|
//+------------------------------------------------------------------+
int OnInit()
{// in the module

//in the function
double y3=0, y2=0, y1=0, zz; // extremums
int x3, x2, x1, sh=ShiftBars;// numbers of bars
// Take three extrema of the Zig-Zag
while (y3==0) {
zz=iCustom(NULL, 0, "ZigZag", ExtDepth, ExtDeviation, ExtBackstep, 0, sh);
if (zz!=0 && zz!=EMPTY_VALUE) {
if (y1==0) { x1=sh; y1=zz; }
else if (y2==0) { x2=sh; y2=zz; }
else if (y3==0) { x3=sh; y3=zz; }
}
sh++;

}

How do I get the value of the current extremum?

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 07.10.2006                                                     |
//|  Описание : Возвращает экстремум ЗигЗага по его номеру.                    |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (NULL или "" - текущий символ)          |
//|    tf - таймфрейм                  (      0     - текущий ТФ)              |
//|    ne - номер экстремума           (      0     - последний)               |
//|    dp - ExtDepth                                                           |
//|    dv - ExtDeviation                                                       |
//|    bs - ExtBackstep                                                        |
//+----------------------------------------------------------------------------+
double GetExtremumZZPrice(string sy="", int tf=0, int ne=0, int dp=12, int dv=5, int bs=3) {
  if (sy=="" || sy=="0") sy=Symbol();
  double zz;
  int    i, k=iBars(sy, tf), ke=0;

  for (i=0; i<k; i++) {
    zz=iCustom(sy, tf, "ZigZag", dp, dv, bs, 0, i);
    if (zz!=0) {
      ke++;
      if (ke>ne) return(zz);
    }
  }
  Print("GetExtremumZZPrice(): Экстремум ЗигЗага номер ",ne," не найден");
  return(0);
}
 

how many attachments if allowed?

if
{
   if
     {

     }
}
 
multiplicator:

how many attachments are allowed?

Until you get tired of writing them

Reason: