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

 

Can you tell me how to request data from Program.mqh?

there is the following code

//--- Определение точек
double stS=0,opS=0,stB=0,opB=0;
   if(ObjectsTotal(0,0,OBJ_TREND)>0)
      {
      stS=NormalizeDouble(ObjectGet("OrderS",OBJPROP_PRICE1)+5*Point,Digits-1);
      opS=NormalizeDouble(ObjectGet("OrderS",OBJPROP_PRICE2)-5*Point,Digits-1);
      stB=NormalizeDouble(ObjectGet("OrderB",OBJPROP_PRICE1)-5*Point,Digits-1);
      opB=NormalizeDouble(ObjectGet("OrderB",OBJPROP_PRICE2)+5*Point,Digits-1);
      }
how to request point data from EA?
 
MakarFX:

Can you tell me how to request data from Program.mqh?

there is this code

how to request point data from an EA?

All you need to get an object from any chart is an object name and a chart identifier:

#property script_show_inputs

//--- input parameters
input long     chartID = 0;
input string   name = "OrderS";
input int      subwin = 0;

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart() {
//---
  double stS = 0, opS = 0, stB = 0, opB = 0;
  if(ObjectsTotal(chartID, subwin, OBJ_TREND) > 0) {
    stS = NormalizeDouble(ObjectGetDouble(chartID, name, OBJPROP_PRICE1) * Point, Digits);
    opS = NormalizeDouble(ObjectGetDouble(chartID, name, OBJPROP_PRICE2) * Point, Digits);
    stB = NormalizeDouble(ObjectGetDouble(chartID, name, OBJPROP_PRICE1) * Point, Digits);
    opB = NormalizeDouble(ObjectGetDouble(chartID, name, OBJPROP_PRICE2) * Point, Digits);
    Print("stS: ", stS, "; opS: ", opS, "; stB: ", stB, "; opB: ", opB, ".");
  }
}

Thus, you can get the data of any object from any program in MQL4.

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

All you need to get an object from any chart is an object name and a chart identifier:

Thus, you can get data of any object from any program in MQL4.

You misunderstood me...

The above code is in the file Program.mqh =>OnTimerEvent

The values of points are periodically updated and the Expert Advisor needs to receive these values.

Hence the question: How to request data from Program.mqh?

void CProgram::OnTimerEvent(void)
  {
   CWndEvents::OnTimerEvent();
//--- Индикатор выполнения
   static int count1=0;
//--- Пауза между обновлением элементов
   static int count2=0;
   if(count2<200)
     {
      count2+=TIMER_STEP_MSC;
      return;
     }
//--- Обнулить счётчик
   count2=0;
//--- Определение точек
double stS=0,opS=0,stB=0,opB=0;
   if(ObjectsTotal(0,0,OBJ_TREND)>0)
      {
      stS=NormalizeDouble(ObjectGet("OrderS",OBJPROP_PRICE1)+5*Point,Digits-1);
      opS=NormalizeDouble(ObjectGet("OrderS",OBJPROP_PRICE2)-5*Point,Digits-1);
      stB=NormalizeDouble(ObjectGet("OrderB",OBJPROP_PRICE1)-5*Point,Digits-1);
      opB=NormalizeDouble(ObjectGet("OrderB",OBJPROP_PRICE2)+5*Point,Digits-1);
      }
  }
 
MakarFX:

You misunderstand me...

the above code is in the file Program.mqh =>OnTimerEvent

The values of the points are periodically updated and the Expert Advisor needs to receive these values.

So, my question is: How can I request data from Program.mqh?

No one is stopping you from declaring variables,

double stS = 0, opS = 0, stB = 0, opB = 0;

declare variables in public area of the CProgram class and access them from the Expert Advisor without any problems.

MakarFX:

You misunderstood me...

Of course, I didn't understand right away, because the description of the problem must be more complete. Ideally, it is desirable to add source code.

 
Mihail Matkovskij:

Is theProgram.mqh file connected to the EA?

If yes, no one is stopping you from declaring variables,

in global scope of class CProgram and get access to them from Expert Advisor without any problems.

Program.mqh file is connected...

I will now try to declare variables globally

 
MakarFX:

Program.mqh file is connected...

now try to declare the variables gobally

Edited:https://www.mql5.com/ru/forum/160683/page1199#comment_17172497 as you initially confused me...

 
Mihail Matkovskij:

No one is stopping you from declaring variables,

in the public area of the CProgram class and have no problem accessing them from the Expert Advisor.

does not work

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick(void)
  {
  if (program.stS<0)::Print("ERROR");
  }


 
MakarFX:

doesn't work


You need the source code or code of theCProgram class.Otherwise, it won't work...

I meant make it like this:

class CProgram : ... {
...
public:
  double stS, opS, stB, opB;
...
The threesome is something I don't know about your class :)
 
Mihail Matkovskij:

Need source code or code forCProgram class.Otherwise, it won't do the job...

I meant make it like this:

Three dots, that's what I don't know about your class :)

Thank you!!! It worked.

I unknowingly put

public:
  double stS=0, opS=0, stB=0, opB=0;

I took out the zeros and it worked.

Thank you very much.

 
MakarFX:

Thank you!!! It all worked out.

I unknowingly put

I took out the zeros and it worked.

Thank you very much.

One more thing. It's better to perform initialization:

CProgram::CProgram():
  stS(0), opS(0), stB(0), opB(0)
{
  ...
}

Otherwise, the Expert Advisor may receive random data in variables before the timer's tick, if reading is performed in OnTick().