Search code examples
mql4

MQL4 adjusted bid line


here goes a programming question only...

I'm trying to display an adjusted bid line with every tick.

In my EA I included the following code to create a horizontal line object and then move it every time around.

The problem is that the line doesn't show up to start.

Could you please help me to show the line on my chart?

if (!ObjectFind(0,"Hline"))
  {
     ObjectCreate(0,"HLine", OBJ_HLINE , 0 , 0, Bid + dBidAdjustLine * dPoint);
     ObjectSet("HLine", OBJPROP_STYLE, STYLE_SOLID);
     ObjectSet("HLine", OBJPROP_COLOR, Red);
     ObjectSet("HLine", OBJPROP_WIDTH, 2);     

  }
  else
     ObjectMove(0,"HLine",0,0,Bid + dBidAdjustLine * dPoint);
  ChartRedraw();

Thanks!

Jean


Solution

  • create the object in OnInit() and then move in OnTick() only. Also ObjectCreate returns a bool so it is better to check if that function returns true, and then move to your level, not immediately