Yes, they are rectangles. How do you let your EA know which rectangle to use? Is there an input parameter for the name or something?
The names for the S/R zone rectangles is set as IndicatorName + "-HLINE-Z-" + LineNumber, where IndicatorName is the input parameter of the indicator and LineNumber is generated from the S/R level's price (e.g., if it's on 1.06425, the LineNumber will be equal 106425).
MQL4:
double resistanceTop = 0; double resistanceBottom = 0; double supportTop = 0; double supportBottom = 0; int totalObjects = ObjectsTotal(); double minDistanceResist = 1.0e+10; double minDistanceSupport = 1.0e+10; // Search for rectangles on the chart and check their colors for (int i = 0; i < totalObjects; i++) { string objectName = ObjectName(i); color objectColor = (color)ObjectGetInteger(0, objectName, OBJPROP_COLOR, i); if (objectColor == ResistanceRectangleColor) { double rectTop = ObjectGet(objectName, OBJPROP_PRICE1); double rectBottom = ObjectGet(objectName, OBJPROP_PRICE2); double distance = MathMin(MathAbs(currentPrice - rectTop), MathAbs(currentPrice - rectBottom)); if (distance < minDistanceResist) { minDistanceResist = distance; resistanceTop = rectTop; resistanceBottom = rectBottom; } } if (objectColor == SupportRectangleColor) { double rectTop = ObjectGet(objectName, OBJPROP_PRICE1); double rectBottom = ObjectGet(objectName, OBJPROP_PRICE2); double distance = MathMin(MathAbs(currentPrice - rectTop), MathAbs(currentPrice - rectBottom)); if (distance < minDistanceSupport) { minDistanceSupport = distance; supportTop = rectTop; supportBottom = rectBottom;
This is my code. It will search for the nearest object and match with object color.
Appreciated if you could advise me on my coding.
Last edited by a moderator: