EA that places an order when a line is reached?

 

Hello,


Is it possible to write an Expert Advisor that sends an Order when a line or a special price is reached that can be edited while it is running? If yes, how?


Thank you very much,

Eggat

 

See this post:


https://www.mql5.com/en/code/7066

 

Thank you!

But I still didn't get it working :/

I just wanted to try a buy order when the price is near the Line, but what's wrong with this code?


int start()
{
   if(ObjectFind("Line") == 0)
   { 
   Line = NormalizeDouble(ObjectGetValueByShift("Line", 0), Digits);
   
      if ((Bid+5*Point) <= Line && (Bid+5*Point) >= Line)
      {
         OrderSend(Symbol(),OP_BUY,volume,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point);
         ObjectDelete("Line");
      }
   }
   
   return(0);
}
 

If the object is a horizontal type line, I had difficulties getting its value before.

Try defining it as a trend_line type and try again the code. You can still draw it horizontally.

Furthermore, add the following line, just to see what value is obtained:

Line = NormalizeDouble(ObjectGetValueByShift("Line", 0), Digits);
Print("Line = ", Line);

The condition : if ((Bid+5*Point) <= Line && (Bid+5*Point) >= Line)
seems not to be ok. I think what you want is:

double Line0 = NormalizeDouble(ObjectGetValueByShift("Line", 0), Digits);
double Line1 = NormalizeDouble(ObjectGetValueByShift("Line", 1), Digits);

Print("Line0 = ", Line0, " Line1 = ", Line1," Bid=", Bid);

if ( Close[1] +5*Point<= Line1 && (Close[0]-5*Point) >= Line0) { // if there is a cross up through the line, go long
OrderSend(Symbol(),OP_BUY,volume,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point);
ObjectDelete("Line");
}

Reason: