Getting Horizontal Level Values Placed by the User

Back to topics list To post a new topic, please log in or register
avatar
71
dazamate 2015.09.17 13:39
 

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 

 

 

avatar
71
dazamate 2015.09.17 13:58 #
 

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));
    }

 

avatar
Moderator
3412
GumRai 2015.09.18 00:01 #
 
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. 

Back to topics list  

To add comments, please log in or register