getting all objects prices

 
Hi everyone.
I have some different objects ( like H_lines and arrows and ....) on my chart and I wanna get all of their prices and set them in an array.
help me plz
thanks
 

Here you have the list of nearly all functions for MT5 with a short description to enable a search with some sot of keywords: https://www.mql5.com/de/docs/function_indices

Look for ObjectsTotal and loop through all of them ...

Dokumentation zu MQL5: MQL5 Funktionenliste
Dokumentation zu MQL5: MQL5 Funktionenliste
  • www.mql5.com
MQL5 Funktionenliste - Nachschlagewerk MQL5 - Nachschlagewerk über die Sprache des algothitmischen/automatischen Handels für MetaTrader 5
 
Carl Schreiber #:

Here you have the list of nearly all functions for MT5 with a short description to enable a search with some sot of keywords: https://www.mql5.com/de/docs/function_indices

Look for ObjectsTotal and loop through all of them ...

thanks

I know ObjectsTotal() but how I can loop through objects ?
when I create a loop like "for (i = 0 ; i < ObjectsTotal(); i++) " , how can I refer to an object by i ??

 

Use the functions on the left side of ObjectsTotal()  like ObjectGetDouble().

For the loop don't despair start to search: https://www.mql5.com/en/search#!keyword=ObjectsTotal&module=mql5_module_codebase

or this: https://www.mql5.com/en/docs/basis/operators/for

Documentation on MQL5: Language Basics / Operators / Loop Operator for
Documentation on MQL5: Language Basics / Operators / Loop Operator for
  • www.mql5.com
Loop Operator for - Operators - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
miladmiladi #:

thanks

I know ObjectsTotal() but how I can loop through objects ?
when I create a loop like "for (i = 0 ; i < ObjectsTotal(); i++) " , how can I refer to an object by i ??

int totalObjects = ObjectsTotal(0, -1, -1);

for(int i = 0; i < totalObjects; i++)
  {
   string objectName = ObjectName(0, i, -1, -1);
   if(ObjectGetInteger(0, objectName, OBJPROP_TYPE) == OBJ_ARROW)
     {
      if(ObjectGetInteger(ChartID(), ObjectName(ChartID(), i, -1, -1), OBJPROP_COLOR, 0) == clrRed)
        {
         datetime arrowTime = (datetime) ObjectGetInteger(0, objectName, OBJPROP_TIME);
         int Bar = iBarShift(_Symbol, _Period, arrowTime);
        }
     }
  }

this code snippet might help. it is used to find the bar number where an object is plotted. Maybe that is what you mean by "i".

 
Chioma Obunadike #:

this code snippet might help. it is used to find the bar number where an object is plotted. Maybe that is what you mean by "i".

I suggest counting down inside the for loop. It is more stable if you remove objects.

And you will start with the last created object this way.

EDIT:
Try to minimize calls to functions in loops, if you have the value already in a variable, use that. It's faster.
Reason: