How to draw a horizontal line in OnCalculate function

25 views Asked by At

The question is about MQL4 language for MetaTraders 4 platform. I want to draw a horizontal line. I found the below mentioned snippet somewhere online and am trying to use it inside OnCaculate() function to draw a horizontal line on, let's say the maximum value in last 5 minutes.

int i; //let's assume it has a valid value for the highest value index
if (!ObjectCreate(0, "HLine", OBJ_HLINE, 0, 0, High[i]))
{
         Print(__FUNCTION__, ": Failed to create a horizontal line! Error code =", GetLastError());
         return (false);
}

I see this error in the log window:

OnCalculate: Failed to create a horizontal line! Error code = 4200

What is wrong in this snippet? If it is incorrect, please guide me with a correct way.

1

There are 1 answers

0
Mark SdS On

Error 4200 means Object already exists: see error codes

So you'll need to ObjectDelete(0, "HLine") first.