Not sure if code is safe to run

 
void Test_Run() // Program 
  {
   double CurrBid=SymbolInfoDouble("GOLD",SYMBOL_BID);
   double CurrAsk=SymbolInfoDouble("GOLD",SYMBOL_ASK);

   if(CurrAsk==BuyAt) buy();
   if(CurrBid==SellAt) sell();
   else Test_Run();
  }

Hello everyone,

I quickly put this code together to run on my demo account, but I am not sure if it will constantly run properly.

 

Not sure if code is safe to run.

May be not as the function Test_Run() calls itself again and again? That might run into a loop that increases the mem.-usage until the pc or the terminal crashes.

(But I don't know how mt4/mt5 handles this!)

It might be better to return either true or false and start this function again e.g. in case the prev. call returned false.

 
Carl Schreiber:

May be not as the function Test_Run() calls itself again and again? That might run into a loop that increases the mem.-usage until the pc or the terminal crashes.

(But I don't know how mt4/mt5 handles this!)

It might be better to return either true or false and start this function again e.g. in case the prev. call returned false.

Thank you, Carl

Yes, the terminal crashes. I will have a look into a conditional return. I used the "else" statement to test the code. I wanted to use a "while" statement, but its meant to be true not false.

 
Doubles are rarely equal. The == operand. - MQL4 forum