Drawing a line based on a price level

 

I am writing an EA and want the EA to draw a horizontal line at a specific price level that is entered through an external variable.

I have looked at using the function e.g. SetLevelStyle(0,1,clrBlack); but it seems to require a SetIndexBuffer which stipulates an array. In my case I want a line on just one specific level.

Will anyone be so kind and help me with a solution?

 
These links on ObjectCreate and OBJ_HLINE should get you started, with examples.
 
ernest02: . SetLevelStyle(0,1,clrBlack); but it seems to require a SetIndexBuffer which stipulates an array.
It does not stipulate an array. It stipulates a buffer and EA's don't have buffers.
 
honest_knave:
These links on ObjectCreate and OBJ_HLINE should get you started, with examples.

Thanks for that guidance. I have written a snippet of code and it draws the required horizontal line, but it want to draw the line with every pass. I wrote some code that I thought would stop it from happening - but to no avail.

How can I stop this attempts at redrawing? (Getting 4200 error codes all the time which means the object already exists)

Here is the code:

if (ObjectName (0) != "pricelevel");
        {
if (!ObjectCreate(
   "pricelevel",
   OBJ_HLINE,
   0,    
   0,
   PriceLevel,
   0,
   0,
   0,
   0
   ))
   {
      Print("Error: can't create line! code #",GetLastError());
      return(0);
   }
}
 
ernest02:

Thanks for that guidance. I have written a snippet of code and it draws the required horizontal line, but it want to draw the line with every pass. I wrote some code that I thought would stop it from happening - but to no avail.

How can I stop this attempts at redrawing? (Getting 4200 error codes all the time which means the object already exists)

Here is the code:

 

// if (ObjectName (0) != "pricelevel");
   if (ObjectFind(0,"pricelevel") < 0)
        {
if (!ObjectCreate(
   "pricelevel",
   OBJ_HLINE,
   0,    
   0,
   PriceLevel,
   0,
   0,
   0,
   0
   ))
   {
      Print("Error: can't create line! code #",GetLastError());
      return(0);
   }
}

 

Untested / uncompiled. 

 
honest_knave:

 

 

Untested / uncompiled. 

Thank you SO much! Greatly appreciate your assistance!
 
You're most welcome
Reason: