Mt5 event process

 

Hello, I have written a code, it's something like this:

void OnTick()
  { 
   if(isNewBar())
      {
      buy_signal=false;
      sell_signal=false;
      
      if(...)
         {
         buy_signal=true;
         }
      else if(...)
         {
         sell_signal=true;
         }
      }
  }
//+------------------------------------------------------------------+
void OnTrade()
  {
  ...
    
  if (buy_signal==true)
   {
   trade_execution.Buy(trade_volume,_Symbol,trade_price,stop_loss,take_profit);
   buy_signal=false;
   }
  else if (sell_signal==true)
   {
   trade_execution.Sell(trade_volume,_Symbol,trade_price,stop_loss,take_profit);
   sell_signal=false;
   }
  }

I have 2 questions about the process:

1/ Assump that I don't to turn the buy signal off after the buy/sell execution, will it keep buying/selling each time the price touch the price I set for buy/sell?

2/ Assump that a position is open, and then it's closed by stop loss or take profit, and then the buy/sell signal turn true again, will it buy/sell again?

Thanks for any help.

Basic Principles - Trading Operations - MetaTrader 5 Help
Basic Principles - Trading Operations - MetaTrader 5 Help
  • www.metatrader5.com
is an instruction given to a broker to buy or sell a financial instrument. There are two main types of orders: Market and Pending. In addition, there are special Take Profit and Stop Loss levels. is the commercial exchange (buying or selling) of a financial security. Buying is executed at the demand price (Ask), and Sell is performed at the...
 
You do not trade in OnTrade. You trade in OnTick. OnTrade tell you something happened (new pending, pending/market opened, position closed, etc.)
 
William Roeder:
You do not trade in OnTrade. You trade in OnTick. OnTrade tell you something happened (new pending, pending/market opened, position closed, etc.)

Thanks a lot, it would be easier for me to understand the process if I trade OnTick.

 
William Roeder:
You do not trade in OnTrade. You trade in OnTick. OnTrade tell you something happened (new pending, pending/market opened, position closed, etc.)
We CANNOT trade in OnTrade OR we SHOULD NOT trade in OnTrade?
Reason: