Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1362

 
And you can't put the 2 files separately in the Market. That's the policy.
 
Aleksei Stepanenko #:

Here's the indicator:

Here's the expert:

Here is everything in one file:

Four is true, but so is five.

You have compiled only Expert file.

Try to fill the indicator, at least with a simple graphic object, so that it is called by the Expert Advisor. Then, after compilation, rename or delete Res_Ind.ex4, as if you have sent to the Market only the Expert Advisor file. The client will receive a non-functional programme.

 
Aleksei Stepanenko #:
And you can't put the 2 files separately in the Market. That's the policy.
That's what it's all about...
 
Dmitriy VC #:

You have only the Expert file compiled.

Try to fill the indicator with at least simple graphical object, so that it is called by Expert Advisor. Then after compilation, rename or delete Res_Ind.ex4, as if you have sent to the Market only Expert file. The client will get a non-working program.

You can not be so stubborn ... It says that the indicator connected by the resource is included in the executable file of the Expert Advisor, so it is.

But the fact that your indicator draws graphical objects and EA has to read them is a big problem. Graphic objects are only available when testing with visualization and the autovalidator is testing without it, so it doesn't see the properties of objects...

 
Alexey Viktorov #:

It is said that the indicator connected by the resource is included in the EA's executable file, so it is.

Indicator in a separate window

//+------------------------------------------------------------------+
//|                                                          win.mq5 |
//|                                  Copyright 2021, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_plots 0
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {

   IndicatorSetString(INDICATOR_SHORTNAME,"win");

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

Compile Indicator --> win.ex5.

Expert with the indicator in the resource

//+------------------------------------------------------------------+
//|                                                          exp.mq5 |
//|                                  Copyright 2021, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"

#resource "\\Indicators\\win.ex5"
char      number    = -1;
int       handle    = INVALID_HANDLE;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {

   if(number<0)
     {
      handle=iCustom(_Symbol,_Period,"win.ex5");
      number=char(ChartGetInteger(0,CHART_WINDOWS_TOTAL));

      if(handle!=INVALID_HANDLE)
        {
         ChartIndicatorAdd(0,number,handle);
        }
     }

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   if(reason==REASON_REMOVE)
     {
      ChartIndicatorDelete(0,int(ChartWindowFind(0,"win")),"win");
     }
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

  }
//+------------------------------------------------------------------+

Compile the Expert Advisor --> exp.ex5.

Run the Expert Advisor, there is an indicator window on the chart.

Publish one file of the Expert Advisor exp.ex5 in the Market (actually delete the indicator file win.ex5)

Launch the Expert Advisor, there is no indicator window in the chart.

Restore the deleted file win.ex5.

Restore the Expert Advisor, there is an indicator window in the chart.


Conclusion: The indicator code is not included in the Expert code. For the normal operation of the Expert Advisor with a resource Indicator, we need an executable file of the Indicator specified in the resource.


I repeat my question:

how to publish in the Market when there is Expert with custom Indicator, library, i.e. more than one file is needed for normal work of the Expert?

Files:
win.mq5  2 kb
exp.mq5  4 kb
 
Dmitriy VC #:

Indicator in a separate window

Compile Indicator --> win.ex5.

Expert with this Indicator in the resource

Compile the Expert --> exp.ex5.

Run the Expert Advisor, there is an indicator window on the chart.

Publish one file of the Expert Advisor exp.ex5 in the Market (actually delete the indicator file win.ex5)

Launch the Expert Advisor, there is no indicator window in the chart.

Restore the deleted file win.ex5.

Restore the Expert Advisor, the chart has the indicator window.


Conclusion: The indicator code is not included in the Expert code. For the normal operation of the Expert Advisor with a resource Indicator, we need an executable file of the Indicator specified in the resource.


I repeat my question:

how to publish in the Market when there is an Expert Advisor with a custom Indicator, library, i.e. more than one file is needed for normal operation of the Expert Advisor?

How many times have you been given a link to documentation? Your mother doesn't let you read it?

      handle=iCustom(_Symbol,_Period,"win.ex5"); // Это делается не так!!!!

Read it at last...

 
Alexey Viktorov #:

How many times have you been given a link to documentation? Your mother won't let you read it?

Read it at last...

Alexey, thanks for pointing out the error directly.

I read the documentation, but it was "out of my sight".

I apologise to everyone - I was wrong.

I've got it now.

 

Can you give me a hint please.

Added calculation of bar count(:RatesTotal(void)) to class, can't figure out how to fit into structure correctly. Got something like this. Can you please tell me how to make it more colorful.

#include <Arrays\ArrayObj.mqh>
/********************************************************************\
|   Класс Новый бар                                                  |
\********************************************************************/
class CNewBar : public CObject
  {
private:
   string            m_symbol;
   ENUM_TIMEFRAMES   m_timeframe;
   datetime          m_time;
   long              m_rt;
   datetime          Time(void);  
   long              RatesTotal(void);   
   string            Symbol(void)         { return this.m_symbol;    }
public:
   ENUM_TIMEFRAMES   Timeframe(void)      { return this.m_timeframe; }
   datetime          GetTime(void)        { return this.m_time;      } //  Возвращает время последнего обращения
   long              GetRatesTotal(void)     { return this.m_rt; }
   bool              IsNewBar(void);                                   //  Основная функция класса
                     CNewBar(const string symbol,const ENUM_TIMEFRAMES timeframe);
                    ~CNewBar(void) {;}
  };
//+------------------------------------------------------------------+
//|    Конструктор                                                   |
//+------------------------------------------------------------------+
CNewBar::CNewBar(const string symbol,const ENUM_TIMEFRAMES timeframe) : m_time(0)
  {
   this.m_symbol = symbol;
   this.m_timeframe = (timeframe == PERIOD_CURRENT ? Period() : timeframe);
  }

//+------------------------------------------------------------------+
//|  Возвращает количество баров в истории                           |
//+------------------------------------------------------------------+
long CNewBar::RatesTotal(void)
  {
//---- получим количество баров
  long rt=SeriesInfoInteger(this.m_symbol, this.m_timeframe,SERIES_BARS_COUNT);
//---- Проверка количества
   if(rt<1)
      Print("Error "+__FUNCTION__+" Не определенно кол-во баров ",this.m_symbol," ",this.m_timeframe);
//----
   return(rt);
  };
//+------------------------------------------------------------------+
//| CNewBar IsNewBar Основная функция класса                         |
//+------------------------------------------------------------------+
bool CNewBar::IsNewBar(void)
  {
   m_rt=this.RatesTotal();
   datetime tm=this.Time();
   if(tm==0 || m_rt<1)
      return false;
   if(tm!=this.m_time)
     {
      this.m_time = tm;
      return true;
     }
   return false;
  }
 
Dmitriy VC #:

It's all sorted now.

I didn't, I didn't know. No problem at all :)

 

Can you tell me how to organise an analogue of calculation of prev_calculated, I can't figure it out.


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int CNewBar::PrevCalculated(void)
  {
   int pc=this.m_rt
   return(pc)
  }
//+------------------------------------------------------------------+
//| CNewBar IsNewBar Основная функция класса                         |
//+------------------------------------------------------------------+
bool CNewBar::IsNewBar(void)
  {
   datetime tm=this.Time();

   if(tm==0 || m_rt<1)
      return false;
   if(tm!=this.m_time)
     {
      //--- определяем время
      this.m_time = tm;
      //--- определяем кол-во
      this.m_rt=this.RatesTotal();
      return true;
     }
   return false;
  }
Reason: