teikee

Newbie
Feb 5, 2023
7
1
4
34
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:

Enivid

Administrator
Staff member
Nov 30, 2008
18,620
1,367
144
Odesa
www.earnforex.com
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.
That should work fine. Just make sure you are setting correct colors for it to detect.
 

teikee

Newbie
Feb 5, 2023
7
1
4
34
That should work fine. Just make sure you are setting correct colors for it to detect.
I have tried few times and the colors setting is correct. But my EA is still not able to interact with this indicator even i have changed the object selectable to true. Not sure what goes wrong.
 

Enivid

Administrator
Staff member
Nov 30, 2008
18,620
1,367
144
Odesa
www.earnforex.com
I have tried few times and the colors setting is correct. But my EA is still not able to interact with this indicator even i have changed the object selectable to true. Not sure what goes wrong.
The objects being selectable or not doesn't matter here. Could you please attach your entire EA here, so I could test this issue?
 

teikee

Newbie
Feb 5, 2023
7
1
4
34
The objects being selectable or not doesn't matter here. Could you please attach your entire EA here, so I could test this issue?
After recheck my EA and indicator coding, I have found the problem and have solved it finally.

The problem is on the rectangle upper value and lower value. My EA retrieve the object price1 as upper value and price2 as lower value. But the indicator's object price1 is lower value and price2 is upper value. So it caused my trade conditions cannot be met.

Thanks admin for your time to look into my issue. :)
 
  • 🎉
Reactions: Enivid

Farhad@@

Trader
Mar 5, 2024
1
0
6
26
Sir in H4 i says no resistance found.. WHat to do in that case ?. and is i to be used only in buy positions or sell too ?
Post automatically merged:

Sir is this to be used only for buying entries ? or sell to
 

Enivid

Administrator
Staff member
Nov 30, 2008
18,620
1,367
144
Odesa
www.earnforex.com
Sir in H4 i says no resistance found.. WHat to do in that case ?. and is i to be used only in buy positions or sell too ?
Post automatically merged:

Sir is this to be used only for buying entries ? or sell to
This means that it couldn't find any recent resistances (within 1000 bars by default). This can happen in major uptrends. You can either increase that parameter or switch to a different timeframe.