Getting Horizontal Level Values Placed by the User

 

Dear Mql4ers,

I would like to create some code that will read all the horizontal price levels that was placed by the user via the horizontal line tool in the terminal.

I have some code that knows there are levels on the chart... 

int totalLevels;
totalLevels = ObjectsTotal((int) OBJ_HLINE);
Alert("There are currently " + IntegerToString(totalLevels) + " on the chart");

 

Now how do I tap into each level and get the price value?

I did some searching and one suggestion was to use ObjectGet();

double  ObjectGet(
   string   object_name,   // object name
   int      index          // object property
   );

 

I am stuck here: 

double test = ObjectGet("????", OBJPROP_PRICE1);
Alert("Level Value =  " + DoubleToString(test, Digits));

 

What are you meant to use for the object name? 

Thanks 

 

I actually worked it out for anyone interested...

 

    // Support and resistance level testing
    int totalLevels;
    totalLevels = ObjectsTotal((int) OBJ_HLINE);
    Alert("There are currently " + IntegerToString(totalLevels) + " on the chart");
    
    //loop through all horizontal level objects and grab values
    for(int i=0;i<totalLevels;i++) {
      string name = ObjectName(i);
      double levelval = ObjectGet(name, OBJPROP_PRICE1);
      Alert("Level Value =  " + DoubleToString(levelval, Digits));
    }
 
dazamate:

I actually worked it out for anyone interested...

    // Support and resistance level testing
    int totalLevels;
    totalLevels = ObjectsTotal((int) OBJ_HLINE);
    Alert("There are currently " + IntegerToString(totalLevels) + " on the chart");
    
    //loop through all horizontal level objects and grab values
    for(int i=0;i<totalLevels;i++) {
      string name = ObjectName(i);
      double levelval = ObjectGet(name, OBJPROP_PRICE1);
      Alert("Level Value =  " + DoubleToString(levelval, Digits));
    }

 

 

That won't work properly if there are other object types on the chart.

your code will output the value of any object type and may miss some horizontal lines

You have to loop through all objects and check the object type.