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

 
Vitaly Muzichenko:

Well, I have a different goal than saving money.

I have EAs on the charts, and opening additional copies of windows to trade from the panel is not the right thing to do. That's why I wrote the trading panel in the form of an indicator - you can put a lot of them on one chart.

This is a small excerpt, the code is a bit truncated, but the logic is clear:

Indicator

// Открыть позиции
   // Открыть позицию Buy
   if(sparam==prefix+"_openBuy") {
     BroadcastEvent(gMagic,edLots,_symbol);
     ObjectSetInteger(0,prefix+"_openBuy",OBJPROP_STATE,false);
     ChartRedraw();
   }
   // Открыть позицию Sell
   if(sparam==prefix+"_openSell") {
     BroadcastEvent(gMagic,edLots,_symbol);
     ObjectSetInteger(0,prefix+"_openSell",OBJPROP_STATE,false);
     ChartRedraw();
   }

//===============================================================================================
//------------------ Функция посылает сообщение всем открытым графикам -------------------------+
//===============================================================================================
void BroadcastEvent(long lparam,double dparam,string sparam) {
 ushort eventID=9784-CHARTEVENT_CUSTOM;
 long currChart=ChartFirst(); 
 int i=0; 
  while(i<CHARTS_MAX)                // у нас наверняка не больше CHARTS_MAX открытых графиков 
   { 
    EventChartCustom(currChart,eventID,lparam,dparam,sparam); 
    currChart=ChartNext(currChart); // на основании предыдущего получим новый график 
    if(currChart==-1) break;        // достигли конца списка графиков 
    i++;                            // не забудем увеличить счетчик 
   } 
 }

Expert Advisor

// -- Получим нажатие кнопки с индикатора
// Открыть позицию
 if(id==9784)     
  {
   if(UseSound) PlaySound("tick.wav");
   OpenPosition(sparam,OP_BUY,dparam,0,0,"comm",(int)lparam,clrNONE);
  }
 
Aleksei Stepanenko:

Where is the indicator? Please attach it here so you don't have to wander around the forum threads.

indicator
Files:
 
Yes, I was also thinking of having the EA write the ChartID of my chart to a global variable of the terminal, then all the indicators know where to send the event to. Spot without BroadcastEvent.
 
Aleksei Stepanenko:
Yes, I'm thinking to write the ChartID of my chart in global variable of the terminal, then all indicators know where to send the event. Spot without BroadcastEvent.

Glob.variable is the same file, the terminal works hard with it and kills the disk, and it's not useful to check it in a static way, it's the same cycle but in profile :)

 
frank2020:
indicator
And what do you want to get out of this indicator?
 
frank2020:
indicator

If anything, taken from here

Ищу канальные индикаторы для MT5
Ищу канальные индикаторы для MT5
  • 2017.03.28
  • www.mql5.com
Все привет, ищу любые канальные индикаторы, которых нет по умолчанию в MT5 Нужны для оптимизации ТС (какой их индикаторов покажет устойчивые резуль...
 
Vitaly Muzichenko:

Glob.variable is the same file, the terminal works hard with it and kills the disk, and it's not useful to check it in a static way, it's the same cycle but in profile :)

No, no. Once at start of the Expert Advisor, it writes the number of its chart in the global variable. Then once at startup the indicator reads this variable, and every time the object is created, it sends the event only to the chart with the EA.
 
Vitaly Muzichenko:

Glob.variable is the same file, the terminal works hard with it and kills the disk, and it is not reasonable to check it in a static way, it is the same cycle, but in profile :)

the same file if you forcibly flush it, otherwise the ram is mostly working

 

Generally a normal transmitter between EAs/indicators turns out to be

receiver:

int OnInit()
   {
   GlobalVariableSet("A",ChartID());
   return(INIT_SUCCEEDED);
   }

void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) 
   {
   if(id==CHARTEVENT_CUSTOM+777)
      {
      printf("Сообщение принято: "+sparam);
      }
   }

transmitter:

int OnInit()
   {
   long a=(long)GlobalVariableGet("A");
   EventChartCustom(a,777,0,0,"Превед медвед!");
   return(INIT_SUCCEEDED);
   }

No load on the processor.

 
Aleksei Stepanenko:

In general, a normal transmitter between EAs/indicators would work:

not normal, by 8 bytes each, you will be tired to transfer something

although it will work -@fxsaber made a bibloo, it seems TypeToByte uses to exchange more complex structures


ZS: collisions how to handle? - imho, all roads lead to the database on data exchange, 90% of the work is done for you and very qualitatively