Find if the price is inside an object

 

Hi there,


I have a custom indicator that is drawing objects on the chart (support and resistance) but there are not helpfull buffers and I don't have the mq4 code for it (only ex4).

My question is if there is a way to find if the price is inside an object from the chart.

I'm adding a picture as it is worth more than my 1000 words.


Regards,

Ciprian

SR

 
It's the shved supply and demand, here there is the code: https://www.mql5.com/en/code/14545
Shved Supply and Demand
Shved Supply and Demand
  • www.mql5.com
Info rectangle drawing Example of creating info panels. AfterEffects Trading robot based on the theorem "On the presence of memory (aftereffects) in random sequences". F_RSI The RSI with dynamic levels. CM...
 
Jox90:
It's the shved supply and demand, here there is the code: https://www.mql5.com/en/code/14545

Thank you Jox90.

It is not exactly that one buch are quite identically.

But with that in mind, is it there a way to find if the price is inside that object? The buffers here are empty most of the time and nothing can be automated with that.


Regards,

Ciprian

 
Look in the Object List to find the Object Name and then you can read it's value with ObjectGetDouble() function, and then you can compare this against price.
 
Marco vd Heijden:
Look in the Object List to find the Object Name and then you can read it's value with ObjectGetDouble() function, and then you can compare this against price.

Thank you Marco.


For who is interested I made somethig like this:

bool checkSR() {
    double srZoneNow = iCustom(Symbol(), 0, "name...", ...);
    int AllObjects = ObjectsTotal(OBJ_RECTANGLE);

    for(int i=0; i<AllObjects; i++)
    {
        string ObjName = ObjectName(i);
        double ObjValue = ObjectGetDouble(0, ObjName, OBJPROP_PRICE);
        // BUY
        if (Ask <= ObjValue + 5 * Point || Ask <= ObjValue - 5 * Point)
        {
            return true;
        }
        // SELL
        if (Bid >= ObjValue + 5 * Point || Bid >= ObjValue - 5 * Point)
        {
            return true;
        }
    }

    return false;
}

I'm not too happy but that is what I had in mind.


Regards,

Ciprian

 

That doesn't look bad at all.

If it does the job without bugs your good to go.

It depends on the object name and how many objects there are.

If there are more and they aren't numbered then this can bring problems.

So you can also throw in:

OBJPROP_CREATETIME

Then you can just filter for the latest objects.

I wanted to write some examples but i have too little info to go with.

Do you know the exact object name ? 

Are they numbered with a pre or post fix or a time stamp ?

Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Properties
Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Properties
  • www.mql5.com
All objects used in technical analysis are bound to the time and price coordinates: trendline, channels, Fibonacci tools, etc. But there is a number of auxiliary objects intended to improve the user interface that are bound to the always visible part of a chart (main chart windows or indicator subwindows): – defines the chart corner relative...
 
Marco vd Heijden:

That doesn't look bad at all.

If it does the job without bugs your good to go.

It depends on the object name and how many objects there are.

If there are more and they aren't numbered then this can bring problems.

So you can also throw in:

Then you can just filter for the latest objects.

I wanted to write some examples but i have too little info to go with.

Do you know the exact object name ? 

Are they numbered with a pre or post fix or a time stamp ?

Thanks. I like the idea of `OBJPROP_CREATETIME`

They are numbered like SRE#1, SRE#2 but I think if I can get them by the time then perfect.

Anyway ... there are @40 so not mandatory to change the code.


Thank you again and have a great weekend.

 

Okay so if you know the exact name and they are numbered then you can also use:


int cnt=1;

if(ObjectFind(0,"SRE#"+IntergerToString(cnt))<0)
 {
  // This object does not exist...
 }

if(ObjectFind(0,"SRE#"+IntergerToString(cnt))>=0)
 {
  // This object does exist...
 }

cnt++; // you can increment the counter and try again to see if the next object exists or not. 


https://www.mql5.com/en/docs/objects/objectfind

Documentation on MQL5: Object Functions / ObjectFind
Documentation on MQL5: Object Functions / ObjectFind
  • www.mql5.com
If successful the function returns the number of the subwindow (0 means the main window of the chart), in which the object is found. If the object is not found, the function returns a negative number. To read more about the error call GetLastError(). The function uses a synchronous call, which means that the function waits for the execution of...
 
Marco vd Heijden:

Okay so if you know the exact name and they are numbered then you can also use:



https://www.mql5.com/en/docs/objects/objectfind

Thank you Marco.


Regards,

Ciprian

Reason: