Download MetaTrader 5
To add comments, please log in or register
Take active part in the life of the community. Improve your rating!
dazamate
503
dazamate 2015.09.17 11: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 

dazamate
503
dazamate 2015.09.17 11: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));
    }
Keith Watford
Moderator
7904
Keith Watford 2015.09.17 22: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. 

/
To add comments, please log in or register