user1451111
user1451111

Reputation: 1943

How to draw a horizontal line in OnCalculate function

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.

Upvotes: 0

Views: 171

Answers (1)

Mark SdS
Mark SdS

Reputation: 119

Error 4200 means Object already exists: see error codes

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

Upvotes: 1

Related Questions