Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 650

 
sergeev:

If it's from a different chart, let it use a function variant with a chart identifier.

no problem either.

Absolutely right, but I haven't needed to use a chart identifier yet and I'm only theoretically familiar with it, that's why I suggested the option of mapping objects to the current chart.
 
rov_kvn:



That's great! That was exactly the point. Thank you, dear comrade!
 
sergeev:

If it's from a different chart, let it use a function variant with a chart identifier.

No problem either.


As I understand it, the only options are ObjectGetDouble() for price and ObjectGetInteger() for date in my case.

I try to get the price in the current TF with chart_id = 0

double price1 = ObjectGetDouble(0,"Supply",3);

- value as it should be. I tried both IDs and values from here https://docs.mql4.com/ru/constants/chartconstants/enum_timeframes instead of 0, but it returns 0. What should a "correct" chart_id look like?

 
.roman.:

As I understand it, the only options are ObjectGetDouble() for price and ObjectGetInteger() for date in my case.

I'm trying to get the price in the current TF with chart_id = 0

- value as it should be. I tried both IDs and values from here https://docs.mql4.com/ru/constants/chartconstants/enum_timeframes instead of 0, but it returns 0. What should a "correct" chart_id look like?

chart_id = 0 is not the TF, it is the current chart. You need to find the chart_id for the chart that has the desired object. That's what I didn't do due to temporary lack of necessity.
 
.roman.:

As I understand it, the only options are ObjectGetDouble() for price and ObjectGetInteger() for date in my case.

Trying to get the price in the current TF with chart_id = 0

double price1 = ObjectGetDouble(0,"Supply",3);


what is 3?



- The value is as it should be. I tried both IDs and values from here https://docs.mql4.com/ru/constants/chartconstants/enum_timeframes instead of 0, but it returns 0. What should a "correct" chart_id look like?

What do TF periods have to do with chart_id?


you have an unrealistic hole in your understanding of what to use


Describe your problem, don't get too obscure and around the gut.

What do I need? To retrieve data from an object?

- ObjectGet Why didn't you like it?

 
sergeev:

what is 3?


The price value of the lower limit of the rectangle. https://docs.mql4.com/constants/objectconstants/enum_object_property


what do the TF periods have to do with the chart ID?

I have no idea how. That's why I'm trying to do it myself and ask, since I failed.

sergeev:
describe your task, don't get dark and groping around. what exactly do you need? get data from an object? - ObjectGet What's wrong with it?

Are you seriously asking? I've already written 3 times that I need to get rectangle data (2 price coordinates and two time coordinates used to build rectangles) from two other timeframes(H4 and D), while being on the third(H1).

ObjectGet is not suitable because it cannot receive anything from another timeframe.

The indicator draws rectangles on all timeframes and I have added code to it, it will transmit rectangle coordinates of other timeframes without switching to them. I don't know how to explain it any other way.

 
.roman.:

The value of the price of the lower limit of the rectangle. https://docs.mql4.com/constants/objectconstants/enum_object_property



I have no idea how. That's why I'm trying to do it by gut feeling and asking, because it didn't work.

Are you seriously asking? I've already written 3 times that I need to get rectangle data (2 price coordinates and two time coordinates to build rectangles on) from two other timeframes(H4 and D), while being on the third(H1).

ObjectGet is not suitable because I cannot get anything from another timeframe with it.

It draws rectangles on all timeframes and I am adding code to it, by which it will pass the coordinates of rectangles of other timeframes without switching to them. I don't know how to explain it any other way.

Just understand, another timeframe and another chart or chart are different concepts and, accordingly, different approaches to solving problems.
 
AlexeyVik:
Understand that a different TF and a different chart or chart are different concepts and therefore different approaches to solving problems.

So I am only happy to understand and accept any solution, if I have ideas. That is why I am asking for advice on how to implement it.
 
Top2n:

Thank you! Roger that. Except that with the OrderSelect error, it's not clear how to stop except tocontinue.

Deleted late message, did almost the same as described.

Sometimes you can combine return value and error sign. When it makes sense to take some value as a sign of error. For example, an averaging price equal to 0.

Then, as soon as OrderSelect() returns a sign of error, our function will return a sign of error:

#property strict

/******************************************************************************/
double CenaUsrednenija(const int type,const int Magic){
  double nn = 0, bb = 0;

  for(int i = OrdersTotal() - 1; i >= 0; i--)
  {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
      if(OrderSymbol() == Symbol() && OrderType() == type && OrderMagicNumber() == Magic)
      {
        double op = OrderOpenPrice();
        double llot = OrderLots();

        bb += op * llot;
        nn += llot;
        Print("  type = ", type, " Цена открытия = ", op, " Лот = ", llot, " itog = op * llot = ", op * llot, " factb = bb / nn = ", bb / nn);
      }
    } else {
      return 0; // Цена == 0 - признак ошибки (OrderSelect() не смогла выбрать ордер)
    }
  }

  return nn != 0 ? NormalizeDouble(bb / nn, _Digits) : 0; // Делить на 0 не следует
}

/******************************************************************************/
void OnStart() {
  Print("CenaUsrednenija(OP_BUY, 536525) = ", CenaUsrednenija(OP_BUY, 536525));
}

Run it on my own, I got it:

23:32:03 Script 1 EURUSD,H1: loaded successfully
23:32:03 1 EURUSD,H1: initialized
23:32:03 1 EURUSD,H1:   type = 0 Цена открытия = 1.36626 Лот = 0.1 itog = op * llot = 0.136626 factb = bb / nn = 1.36626
23:32:03 1 EURUSD,H1:   type = 0 Цена открытия = 1.36931 Лот = 0.1 itog = op * llot = 0.136931 factb = bb / nn = 1.367785
23:32:03 1 EURUSD,H1: CenaUsrednenija(OP_BUY, 536525) = 1.36779
23:32:03 1 EURUSD,H1: uninit reason 0
23:32:03 Script 1 EURUSD,H1: removed

It seems to be true...

Yes, I did not use a conditional expression in Print() to avoid hypothetical division by 0 because this Print() is a debug one...

 
.roman.:

As I understand it, the only options are ObjectGetDouble() for price and ObjectGetInteger() for date in my case.

I try to get the price in the current TF with chart_id = 0

- value as it should be. I have tried IDs and values from here https://docs.mql4.com/ru/constants/chartconstants/enum_timeframes instead of 0, but it returns 0. What should a "correct" chart_id look like?

.roman.:

I am only glad to understand and accept any solution, if you have ideas. That is why I am asking for advice on how to implement it.

Here's how chart_id ChartFirst ChartNext should look like

Use ChartNext ChartSymbol and ChartPeriod to determine if it is the right chart and use this chart_id.