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

 
Andrey Sokolov:

Thank you. So it's only in mt5. If anyone knows how to add an indicator from an EA, please let me know

You can also save Indicators and Expert on a template and as the function works - will install you an Expert together with the Indicators.

//+------------------------------------------------------------------+
//|                                                  DeleteChart.mq4 |
//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property  show_inputs
//---
input string Template = "ADX"; // Имя шаблона(without '.tpl')
//---
ENUM_TIMEFRAMES TimeFrame; // Change TimeFrame - Current = dont changed
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   DeleteChart();
  }
//+------------------------------------------------------------------+
//| start function                                                   |
//+------------------------------------------------------------------+
void DeleteChart(void)
  {
   long currChart,prevChart=ChartFirst();
   int i=0,limit=100;
   bool errTemplate;
   while(i<limit)
     {
      currChart=ChartNext(prevChart);
      if(TimeFrame!=PERIOD_CURRENT)
        {
         ChartSetSymbolPeriod(prevChart,ChartSymbol(prevChart),TimeFrame);
        }
      errTemplate=ChartApplyTemplate(prevChart,Template+".tpl");
      if(!errTemplate)
        {
         Print("Error ",ChartSymbol(prevChart),"-> ",GetLastError());
        }
      if(currChart<0)
         break;
      Print(i,ChartSymbol(currChart)," ID =",currChart);
      prevChart=currChart;
      i++;
     }
  }
//+------------------------------------------------------------------+

mt4 documentationhttps://docs.mql4.com/ru/chart_operations/chartapplytemplate

mt5documentationhttps://www.mql5.com/ru/docs/chart_operations/chartapplytemplate

Документация по MQL5: Операции с графиками / ChartApplyTemplate
Документация по MQL5: Операции с графиками / ChartApplyTemplate
  • www.mql5.com
ChartApplyTemplate - Операции с графиками - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
SanAlex:

You can also save Indicators and Expert on a template and when the function works it will install you an Expert together with the Indicators.

mt4 documentationhttps://docs.mql4.com/ru/chart_operations/chartapplytemplate

mt5 documentationhttps://www.mql5.com/ru/docs/chart_operations/chartapplytemplate

thanks for the answers. But I need it without any preliminaries.

 

Funny glitch in MT4


If you create a duplicate of an object in a chart using the pressed cntrl button, the id == CHARTEVENT_OBJECT_CREATE event is caught in the Expert Advisor

If I delete this object from the Expert Advisor, the error 4202 - Object does not exist will pop up. At the same time, the object is already on the chart.


What to do? How do I delete the object?

   if(id == CHARTEVENT_OBJECT_CREATE)
     {
      Print("New object create", sparam);
      if(!ObjectDelete(sparam))
       {
          Print(" error remove ", GetLastError(), " ",sparam);    //здесь будет ошибка 4202.  Хотя это событие срабатывает когда объект есть на графике! 
       }
}
 
Andrey Sokolov:

Thanks for the answers. But you have to do it without any preliminaries.

First, you take the required indicator and add to it the parameters you need - period, TF, line width, line colour, etc.

You save it under a different name. Compile it. In the Expert Advisor in OnInit() or in any other place (not in OnTick()) add your indicator

handle_newInd = iCustom(Symbol(),Period(),"my_Ind\\new_xxxxx",in_period,in_size,in_from,.....);
   if(handle_newCandles == INVALID_HANDLE)
   {
      return(INIT_FAILED);
   }
   ChartIndicatorAdd(0,1,handle_newInd);
 
Сергей Таболин:

First you take the required indicator and add the required parameters to its input - period, TF, line width, line colour, etc.

Save it under a different name. Compile it. In the Expert Advisor in OnInit() or in any other place (not in OnTick()) add your indicator

MT4 must!
 
Sergey Likho:

Funny glitch in MT4


If you create a duplicate of an object in a chart using the pressed cntrl button, the id == CHARTEVENT_OBJECT_CREATE event is caught in the Expert Advisor

If I delete this object from the Expert Advisor, the error 4202 - Object does not exist will pop up. At the same time, the object is already on the chart.


What to do? How do I delete the object?

This is not a glitch, this is a feature)
The user is holding the object with the mouse - it cannot be deleted.

Wait until the mouse button is released and then delete it.

 
Taras Slobodyanik:

this is not a glitch but a feature)
the user is holding an object with the mouse - there is no way to delete it.

Wait until the mouse button is released and then delete.

Thank you very much! It really is a bug)) Sorted it out. Everything works now!

 
Hi all!
who can help to tweak the code of an indicator...
1. Invert the fibo, i.e. the fibo is stretched towards the formed zigzag stick
2. Add a parameter in the settings to set the allert to a specified level...., i.e. I manually specify the level at which I want it to buzz and show the allert point...
Should be something like 1-2-3



Thanks in advance ....

Example on screenshot, code attached....

//+------------------------------------------------------------------+
//|                                                                  |
//|                 Copyright © 2000-2007, MetaQuotes Software Corp. |
//|                                         http://www.metaquotes.ru |
//+------------------------------------------------------------------+
// 
// 2009.12 - добавлены фибо уровни, "nen"(ом) c форума MQL

#property copyright ""
#property link "ххххх"
#property link "ххххх"
#property description "ххххх"
#property strict

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_color1 clrDarkGray
#property indicator_color2 clrRed
#property indicator_width2 3

//----
extern int    Length          = 6;           // Length
extern int    CountBars       = 300;        // History
extern bool   fibo            = true;        // Use FIBO
extern color  colorFibo       = clrSkyBlue;  // Color FIBO
extern bool   AlertsMessage   = true;        // Alert Message
extern bool   AlertsSound     = false;       // Alert Sound
extern bool   AlertsEmail     = false;       // Alert Email
extern bool   AlertsMobile    = false;       // Alert Mobile
extern string AlertsSoundFile = "alert.wav"; // Alert Sound File
//----
double buffer[];
double lBar, hBar;
datetime tiZZ;
double p1,p2;
datetime t1,t2;
double   fi_1[]={0, 0.236, 0.382, 0.5, 0.618, 0.786, 1.0, 1.272, 1.5, 1.618, 1.854, 2.0, 2.618, 3.5, 4.618, 5.618, 6.854};
string   fitxt100_1[]={"0.0", "23.6", "38.2", "50.0", "61.8", "78.6", "100.0", "127.2", "150.0", "161.8", "185.4", "200.0", "261.8", "350.0", "461.8", "561.8", "685.4"};
int Sizefibo;
string TF[]={"MN","W1","D1","H4","H1","m30","m15","m5","m1"};
string Period_tf;
double Arr[];
int LastSwing;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void init()
  {
   SetIndexStyle (0,DRAW_SECTION,0,1);
   SetIndexBuffer(0,buffer);
   SetIndexLabel (0,"Value");
   SetIndexDrawBegin(0,0);
   
   SetIndexStyle (1,DRAW_ARROW);
   SetIndexBuffer(1,Arr);
   SetIndexArrow (1,159);
   SetIndexLabel (1,"Arr");

   
   Sizefibo=ArraySize(fi_1);
   switch (Period())
     {
      case 1     : {Period_tf=TF[8];break;}
      case 5     : {Period_tf=TF[7];break;}
      case 15    : {Period_tf=TF[6];break;}
      case 30    : {Period_tf=TF[5];break;}
      case 60    : {Period_tf=TF[4];break;}
      case 240   : {Period_tf=TF[3];break;}
      case 1440  : {Period_tf=TF[2];break;}
      case 10080 : {Period_tf=TF[1];break;}
      case 43200 : {Period_tf=TF[0];break;}
     }
    LastSwing = 0;
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function. Начало.              |
//+------------------------------------------------------------------+
int deinit()
  {
   ObjectDelete("_%fibo");
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function. Конец.               |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void start()
  {
   int shift, zu, zd, Swing, Swing_n, i, i1=0, i2=0;
   double HH, LL, BH, BL;
//----
   if (tiZZ!=Time[0] || lBar<Low[0] || hBar>High[0]) // micmed+nen
     {
      tiZZ=Time[0]; lBar=Low[0]; hBar=High[0];
      if ((Bars-IndicatorCounted()-1)>2) ArrayInitialize(buffer,EMPTY_VALUE);
     }
   else return;

   Swing=0;
   Swing_n=0;
   shift=CountBars-1;
   zu=shift;
   zd=shift;
   BH=High[shift];
   BL=Low[shift];
//----
   for(shift=CountBars-1; shift>=0; shift--)
     {
      HH=High[Highest(NULL,0,MODE_HIGH,Length,shift+1)];
      LL=Low [Lowest (NULL,0,MODE_LOW ,Length,shift+1)];
      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];}
         if (Swing== 1) {buffer[zd]=BL; i1=i2; i2=zd;}
         if (Swing==-1) {buffer[zu]=BH; i1=i2; i2=zu;}
         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;
     }
   
    if(LastSwing!=Swing) 
     {
       if(LastSwing!=0)
        { 
          if(AlertsMessage || AlertsEmail || AlertsMobile || AlertsSound)
           {
             string message = (WindowExpertName()+" - "+Symbol()+"  "+PeriodString()+" - Change FIBO");

             if (AlertsMessage) Alert(message);
             if (AlertsEmail)   SendMail(Symbol()+" - "+WindowExpertName()+" - ",message);
             if (AlertsMobile)  SendNotification(message);
             if (AlertsSound)   PlaySound(AlertsSoundFile);
           }
        
          Arr[0] = Close[0]; 
        } 
       LastSwing = Swing;
     }  

   if (fibo)
     {
      p1=buffer[i1]; t1=Time[i1];
      p2=buffer[i2]; t2=Time[i2];

      string nameObj="_%fibo";        
      ObjectDelete(nameObj);
      ObjectCreate(nameObj,OBJ_FIBO,0,t1,p1,t2,p2);

      ObjectSet(nameObj,OBJPROP_LEVELCOLOR,colorFibo);

      ObjectSet(nameObj,OBJPROP_COLOR,CLR_NONE);
      ObjectSet(nameObj,OBJPROP_STYLE,STYLE_DOT);
      ObjectSet(nameObj,OBJPROP_WIDTH,0);
      ObjectSet(nameObj,OBJPROP_LEVELSTYLE,STYLE_DOT);
      ObjectSet(nameObj,OBJPROP_LEVELWIDTH,0);
      ObjectSet(nameObj,OBJPROP_BACK,true);

      ObjectSet(nameObj,OBJPROP_FIBOLEVELS,Sizefibo);
      for (i=0;i<Sizefibo;i++)
        {
         ObjectSet(nameObj,OBJPROP_FIRSTLEVEL+i,fi_1[i]);
         ObjectSetFiboDescription(nameObj, i, fitxt100_1[i]+" "+DoubleToStr((p1-p2)*fi_1[i]+p2, Digits)+"-"+Period_tf); 
        }
     }

  }
//+------------------------------------------------------------------+
//| Period String                                                    |
//+------------------------------------------------------------------+
string PeriodString()
  {
    switch (_Period) 
     {
        case PERIOD_M1:  return("M1");
        case PERIOD_M5:  return("M5");
        case PERIOD_M15: return("M15");
        case PERIOD_M30: return("M30");
        case PERIOD_H1:  return("H1");
        case PERIOD_H4:  return("H4");
        case PERIOD_D1:  return("D1");
        case PERIOD_W1:  return("W1");
        case PERIOD_MN1: return("MN1");
        default: return("M"+(string)_Period);
     }  
    return("M"+(string)_Period); 
  }
//+------------------------------------------------------------------+
Документация по MQL5: Сетевые функции / SendNotification
Документация по MQL5: Сетевые функции / SendNotification
  • www.mql5.com
SendNotification - Сетевые функции - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
Files:
kyucri.jpg  102 kb
 
btc.mmd:
Hi all!
can help me fix the indicator
1. Turn the fibo, i.e. the fibo is stretched towards the formed stick zigzag
2. Add the parameter "set allert to a specified level....", i.e. I manually indicate the level at which I want it to buzz and show the allert point...

Should turn out something like 1-2-3

Thanks in advance ....

Example on screenshot, code attached....




//+------------------------------------------------------------------+
//| |
//| Copyright © 2000-2007, MetaQuotes Software Corp. |
//| http://www.metaquotes.ru |
//+------------------------------------------------------------------+
// ххххххххх
// 2009.12 - added Fibo levels, "nen"(by) from MQL forum.

#property copyright ""
#property link "хххххх"
#property link "xxxxxx"
#property description "xxxxxxxxxx"
#property strict

For starters, remove your spoofing and paste the code in a human way.

//+------------------------------------------------------------------+
//|                                                                  |
//|                 Copyright © 2000-2007, MetaQuotes Software Corp. |
//|                                         http://www.metaquotes.ru |
//+------------------------------------------------------------------+
// хххххххххххх
// 2009.12 - добавлены фибо уровни, "nen"(ом) c форума MQL.

#property copyright ""
#property link "ххххх"
#property link "хххххх"
#property description "ххххххххх"
#property strict
 

Hi folks!

Can you tell me why nothing is displayed on the chart when you put this indicator on?

It compiles without errors, rsi_channel is in the folder...don't understand(

Files: