Questions from Beginners MQL5 MT5 MetaTrader 5 - page 817

 
pivomoe:
I understand correctly that the Volume method of the CPositionInfo class returns the volume corresponding to the point in time when the Select() method was last called? That is, you can find out the volume that was a month ago for this symbol?
You got it all wrong. The Volume method of the CPositionInfo class returns the volume of a position. The position that was previously selected through PositionSelect.
 

You have explained how to prepare CPositionInfo. I still don't understand two things though:

1) How this recipe follows from the CPositionInfo class help ?

2) Why do we need the class itself, if you can't use more than one object normally, because before each access to the position property, we need to configure the position using the Select method, otherwise suddenly we will use the Select method for another CPositionInfo object somewhere else.

 
pivomoe:

You have explained how to prepare CPositionInfo. I still don't understand two things though:

1) How this recipe follows from the CPositionInfo class help ?

2) Why do we need the class itself, if you can't use more than one object normally, because before each access to the position property, we need to configure its position using the Select method, otherwise suddenly we will use Select method for another CPositionInfo object in some other place.

1). All of this is in the help. With diligence and attention, plus some self-writing, this will give you an understanding.
2). Once again: the CPositionInfo class is not a casket that stores all the data of all positions; it's just a handy tool to access the properties of a position.

And this has always been the case: first, the position is selected, and then we get its properties. After that, the cycle repeats: the position is highlighted and only then the position properties are retrieved.
 

I don't understand what my mistake is in using help.

1) I needed the volume of the position in the program.

2) Through a search I found the Volume method from the CPositionInfo class.

3) It refers to using the Select method before calling Volume.

4) There is no reference in the description of the Select method. To be on the safe side, I study the description of the CPositionInfo class.

5) I write the code. I get a result that doesn't follow from the reference.


Where is the error?

Once again I know about choosing a position and an order before accessing the properties. But this knowledge and knowledge of CPositionInfo in the help do not intersect.

 
pivomoe:

Where is the mistake ?

If you learn to write in more detail, you will be able to see where you are wrong.

Try writing like this:

CPositionInfo PositionInfoKotiryemii,PositionInfoVedygii;
double Volume1=0; Volume2=0;
string Symbol1=""; Symbol2="";

if ( PositionInfoVedygii.Select("SBRF-12.17") ) // Select 1
{ Volume1=PositionInfoVedygii.Volume(); Symbol1=PositionInfoVedygii.Symbol(); } // Use 1
else Print("Не удалось выбрать позицию по символ SBRF-12.17 ");

if ( PositionInfoKotiryemii.Select("SBRF-3.18") ) // Select 2
{ Volume2=PositionInfoKotiryemii.Volume(); Symbol2=PositionInfoKotiryemii.Symbol(); } // Use 2
els Print("Не удалось выбрать позицию по символ SBRF-3.18 ");
 
Print(Symbol2," Объем ",Volume2," ",Symbol1," Объем ",Volime1);
 
pivomoe:

I don't understand what my mistake is in using help.

1) I needed the volume of the position in the program.

2) Through a search I found the Volume method from the CPositionInfo class.

3) It refers to using the Select method before calling Volume.

4) There is no reference in the description of the Select method. To be on the safe side, I study the description of the CPositionInfo class.

5) I write the code. I get a result that doesn't follow from the reference.


Where is the mistake?

Once again about position selection, order, before accessing properties I know. But this knowledge and the CPositionInfo knowledge in the help do not overlap.


It is a code block that bypasses all the positions and prints out information similar to that in the terminal in the "Trade" tab:

   for(int i=PositionsTotal()-1;i>=0;i--)
      if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties
        {
         string str_position_type=(m_position.PositionType()==POSITION_TYPE_BUY)?"buy":"sell";
         Print(m_position.Symbol()+" | "+
               IntegerToString(m_position.Ticket())+" | "+
               TimeToString(m_position.Time(),TIME_DATE|TIME_MINUTES|TIME_SECONDS)+" | "+
               str_position_type+" | "+
               DoubleToString(m_position.Volume(),2)+" | "+
               DoubleToString(m_position.PriceOpen(),2));

}

Algorithm of work: first We select the position (take a jar of jam from the supermarket shelf), then we access the properties of the selected position and print these properties (read the label on the jar of jam).

 
pivomoe:

It turns out that the CPositionInfo class doesn't make any sense, because normally, you can only work with one object of this class.

Yes, it's a wrapper.
 

Ivan Ivanov ,Vladimir Karputov, fxsaber thanks for your help.

 

I retrieve data from indicators in the Expert Advisor. First I calculate the handle, then I copy the last several actual values from the indicator buffers.

Questions:

1. What is the depth of history in these indicators?

2. Is there a method to limit the depth of calculations?
In this case we need only few last values to determine the inflection or direction up/down.
The Expert Advisor is multi-currency, there are dozens of indicators, so I don't need to make unnecessary calculations.

 
User_mt5:

I retrieve data from indicators in the Expert Advisor. First I calculate the handle, then I copy the last several actual values from the indicator buffers.

Questions:

1. How deep is the history in these indicators?

2. Is there a way to limit the depth of calculations?
In this case we only need a few last values to determine the inflection or direction up/down.
The Expert Advisor is multi-currency, there are dozens of indicators, so there is a need not to make unnecessary calculations.


I hope you create indicator handles ONE time in OnInit()?

The calculation depth depends on the indicator. Rare indicators limit the depth forcibly - as a rule, all of them calculate the entire history. Therefore, perhaps the following variant is useful: to introduce the variable responsible for the depth in the indicator, and then to pass this parameter through iCustom in the Expert Advisor.

Reason: