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

 
Maxim Kuznetsov:

You don't have to pull bullshit from the reference, write the obvious cycle...you'll have to live with it later :-)

   for(long chartId=ChartNext(0);chartId>0 &&!IsStopped();chartId=ChartNext(chartId)) {

      if (ChartSymbol(chartId)=="") continue;

      DoChart(chartId);

   }

I need to digest this too...
 
Maxim Kuznetsov:

   for(long chartId=ChartNext(0);chartId>0 &&!IsStopped();chartId=ChartNext(chartId)) {

      if (ChartSymbol(chartId)=="") continue;

      DoChart(chartId);

   }

Maxim, I can't figure out how to apply this to my problem(

 
MakarFX:

Please help to find or write a function to search for objects on open charts.

Five open charts, EA is on the first one. MT4

this code should work:

#property strict
#include <Arrays\ArrayLong.mqh>
CArrayLong ChartsID;
//+------------------------------------------------------------------+
int OnInit()
{
   FindChartsBySymbol(_Symbol, ChartsID);
   for(int i = ChartsID.Total() - 1; i >= 0; i--)
   {
      long chart_id = ChartsID.At(i);
      Print("ChertID = ", chart_id, " , symbol = ", ChartSymbol(chart_id));
   }
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
void FindChartsBySymbol(string symbol, CArrayLong &charts)
{
   for(long currChart = ChartFirst(); currChart >= 0; currChart = ChartNext(currChart))
   {
      if(ChartSymbol(currChart) == symbol) charts.Add(currChart);
   }
}
//+------------------------------------------------------------------+

check on cryptocurrencies, they work on weekends

The only thing is to monitor the opening (and closing ? ) of new charts and then update the list
 
Igor Makanu:

this code should work:

check on cryptocurrencies, they work on weekends

Thank you)))

 
MakarFX:

Is it acceptable to run the indicator with minimal code on each chart? Is it possible to do this with a default template.

 
Aleksei Stepanenko:

Is it acceptable to run an indicator or EA with minimal code on each chart? Is it possible to do this with a default template.

EA on the first chart runs the DLL

so there is only one

C# DLL MQ4 построение формы общения
C# DLL MQ4 построение формы общения
  • 2021.04.02
  • www.mql5.com
Еще неделю назад я не знал что такое C#...теперь я знаю что это читается "си шарп"))) Прочитав статьи https://www.mql5...
 

If such an indicator is put on each desired chart, then any change of objects in the controlled area (chart) will send an event to the chart with the expert.

//идентификатор графика с советником
long ID=1;

int OnInit() 
   {
   //установка флага получения событий создания объектов графика 
   ChartSetInteger(ChartID(),CHART_EVENT_OBJECT_CREATE,true); 
   //установка флага получения событий удаления объектов графика 
   ChartSetInteger(ChartID(),CHART_EVENT_OBJECT_DELETE,true); 
   return(INIT_SUCCEEDED); 
   } 

void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) 
   {
   //если объект удалён или создан, или изменён
   if(id==CHARTEVENT_OBJECT_DELETE || id==CHARTEVENT_OBJECT_CREATE || id==CHARTEVENT_OBJECT_CHANGE)
      {
      EventChartCustom(ID,1,lparam,dparam,sparam); 
      }
   }

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(rates_total);
   }
Example as an idea.
 
Aleksei Stepanenko:

If you put such indicator on each desired chart, then any change of objects in the controlled area (chart) will send an event to the chart with the Expert Advisor.

Example as an idea

Thanks, but I checked my code on crypto, everything works as I wanted.

Thank you all for your help!

 
MakarFX:

Here's my problem with Chart_ID()

Did it like this

But you can't check it in the tester(.

...I have to wait so long for Monday(

During initialization, everything seems to work

But how will it work in real life?

While I was away .........

At first glance it seems fine. You can check in the script on any day. But here in the documentation I do not like the example. Here is how I advise to write

#property strict

/********************Script program start function*******************/
void OnStart()
 {
  long chart = ChartFirst();
  while(chart >= 0 && !IsStopped())
   {
    if(ObjectFind(chart, "00") >= 0)
     Print("Symbol ", ChartSymbol(chart), " Period ", EnumToString(ChartPeriod(chart)));
    chart = ChartNext(chart);
   }
 }/******************************************************************/

/*****************************End program****************************/
 
Aleksei Stepanenko:

If such an indicator is put on each desired chart, then any change of objects in the monitored area (chart) will send an event to the chart with the expert.

Example as an idea.

For this task

Forum on trading, automated trading systems and testing trading strategies

Any questions from newbies on MQL4 and MQL5, help and discussion of algorithms and codes

MakarFX, 2021.06.19 21:21

To be honest Alexey, with my knowledge it sounds scary...

If you have not entered the market yet, you cannot go back to the market and buy from a cursor.


the indicator is not suitable.
Reason: