The expert runs again

 

Hello.

When I run an expert on a chart, whenever I change the time frame, the expert runs again. What is the problem?

 

Hello,

Take a look at "Options" menu on "Experts Advisor"

 
janareza:Hello.When I run an expert on a chart, whenever I change the time frame, the expert runs again. What is the problem?

There is no problem. That is normal! Every time the chart changes time-frame or symbol, all Indicators and EAs on it will be restarted.

You need to program your EA to take that into account.

 
Fernando Carreiro #:

There is no problem. That is normal! Every time the chart changes time-frame or symbol, all Indicators and EAs on it will be restarted.

You need to program your EA yo take that into account.

Thank you.

I wrote the expert in     int OnInit()     function. In wich function should i write the command so that it is excuted only once?

 
int OnInit()
  {
   MqlTradeRequest request={1};
   MqlTradeResult  result={0};
   request.symbol   =Symbol();
   double price;
   double stoplimit;
   double point=SymbolInfoDouble(_ Symbol,SYMBOL_POINT);
   int digits=SymbolInfoInteger(_ Symbol,SYMBOL_DIGITS);
   
   request.action   =TRADE_ACTION_PENDING;
   
      request.type=ORDER_TYPE_SELL_LIMIT;
      request.volume   =1;
      price     =SymbolInfoDouble(Symbol(), SYMBOL_BID)+(point*100);
      request.price=NormalizeDouble( price,digits);
        if(!OrderSendAsync(request, result))
      PrintFormat("OrderSend error %d",GetLastError());
     
   return(INIT_SUCCEEDED);
}
 
janareza #:

You should not use any trade function in on OnInit(). Use them in OnTick() instead. Do only initialisation and preparations in OnInit().

Also, you need to have recovery procedures in place to rebuild your state, in case of a restart of the EA.

 
Fernando Carreiro #:

You should not use any trade function in on OnInit(). Use them in OnTick() instead. Do only initialisation and preparations in OnInit().

Also, you need to have recovery procedures in place to rebuild your state, in case of a restart of the EA.

Tkanks.