A simple program

 
Hello, I am a beginner in programming and at the moment I am trying to learn to code with the mql4 language. I am trying to understand the concepts of function variables, predefined variables...  But I get stuck on my program and I can't find the errors... I wanted to create take profit and stop loss lines that are erased as soon as one of them is touched but I notice that it doesn't work every time... There are times when the price is well below these lines or well above them... This is my programme:


extern double price=0;
extern int SL=100;
extern int TP=100;
extern int Signal=1;
long chart_id=ChartID();


void first()
  {
    if(Signal==1)
        {
          price=Bid;
          ObjectCreate(chart_id,"ligne1",OBJ_HLINE,0,0,price-SL*_Point);
          ObjectCreate(chart_id,"ligne2",OBJ_HLINE,0,0,price+TP*_Point);
          Signal=0;

        }
  }

void second()
  {
if(Bid== price+TP*_Point || Bid==price-SL*_Point)
        {
          ObjectDelete(chart_id,"ligne1");
          ObjectDelete(chart_id,"ligne2");
          Signal=1;

        }
  }






void OnTick()
  {
  first();
  second();

  }

Thank you in advance for your answers

 
if(Bid== price+TP*_Point || Bid==price-SL*_Point)

Doubles are rarely equal. Understand the links in:
          The == operand. - MQL4 programming forum #2 (2013)

 
Good evening Mr Roeder, 

Thank you for your reply, I have just read the messages in the other conversations and they have helped me a lot! 

Thank you very much and have a nice evening :-)
 

Do not use == for comparing doubles. It's better to write it like this:

Bid >= price+TP*_Point
Bid <= price-SL*_Point

and also keep in mind that you have to account for Spread.

you buy on Ask, and sell on Bid.