Hello everyone,
I'm trying to get the last two objects from an indicator that draws horizontal trend lines on the chart, after searching the web, I came up with the following code to cycle through the objects on the current chart and choose the OBJ_TREND ones.
I have a problem with it, as it finds too many objects even when I limit it using StringFind().
I would also like to know if this code can be made simpler and or better (no OO, please, I'm not yet advanced enough to use OOP in MQL4), I thought about storing the Up trend lines on even indexes and the Down trend lines on odd indexes but until I've found out what's wrong with my code I'm using two arrays for simplicity.
I'm attaching a screenshot in which it is clearly seen that the if statements are also catching the "Buy" button, I don't know why, I looked at the examples and my code seems OK but is obviously not.
Thanks
I'm trying to get the last two objects from an indicator that draws horizontal trend lines on the chart, after searching the web, I came up with the following code to cycle through the objects on the current chart and choose the OBJ_TREND ones.
I have a problem with it, as it finds too many objects even when I limit it using StringFind().
I would also like to know if this code can be made simpler and or better (no OO, please, I'm not yet advanced enough to use OOP in MQL4), I thought about storing the Up trend lines on even indexes and the Down trend lines on odd indexes but until I've found out what's wrong with my code I'm using two arrays for simplicity.
I'm attaching a screenshot in which it is clearly seen that the if statements are also catching the "Buy" button, I don't know why, I looked at the examples and my code seems OK but is obviously not.
Thanks
Inserted Code
double UpObjectsArray[][2]; double DownObjectsArray[][2]; int total=ObjectsTotal(0,0,OBJ_TREND); if(total>1) { ArrayResize(UpObjectsArray,total); ArrayResize(DownObjectsArray,total); for(int i=0; i<total; i++) { string name=ObjectName(i); if (StringFind(name, "prob_U", 0) > -1) { UpObjectsArray[i][0]=ObjectGet(name,OBJPROP_PRICE1); UpObjectsArray[i][1]=i; } if (StringFind(name, "prob_D", 0) > -1) { DownObjectsArray[i][0]=ObjectGet(name,OBJPROP_PRICE1); DownObjectsArray[i][1]=i; } } } ArraySort(UpObjectsArray,MODE_DESCEND); ArraySort(DownObjectsArray,MODE_DESCEND); for(int i=0; i<total; i++) { Alert("i1: "+" ObjectName: "+ObjectName(UpObjectsArray[i][1])+" Price: "+UpObjectsArray[i][0]); Alert("i2: "+" ObjectName: "+ObjectName(DownObjectsArray[i][1])+" Price: "+DownObjectsArray[i][0]); }