EA won't restart after ChartSetSymbolPeriod - page 2

 
Rogerio Celentano Szterling #:

Yes, regardless of ChartSetSymbolPeriod() being called from OnTick() or from OnTimer(), the symbol/TF changes correctly, the EA de-initializes, but doesn't restart - in other words, the EA dettaches from the chart.

So the function ChartSetSymbolPeriod() is apparently working, but whatever it is that should trigger the EA to restart isn't - and that's what is puzzling. I can't use the function as it is removing the EA without starting again.

At my own risk of being Captain Obvious, do you have this Option checked?

Options

 
Ryan L Johnson #:

At my own risk of being Captain Obvious, do you have this Option checked?


Yes. And no worries about being Captain Obvious, sometimes it is needed.

 

if it gives you any comfort I had the same issue last night in one of my terminals but it worked two nights ago in other two terminals. To be fair, when it worked two nights ago, the terminals were running version 5 build 5120 and with the one that DID NOT work last night it was running the latest build 5200(in case any the versions matter)

As you mentioned deInit() was called correctly, you can see the last of the notification in the logs below showing it was unloaded from the chart. and there is just silence after that. no failure of any kind. it's like it didn't even try to reload the EA onto the new chart. 


2025.08.07 17:59:44.464 Trades  'YYYYYY': deal #532210670 sell 0.32 TickerA at 136665 done (based on order #614802326)
2025.08.07 17:59:44.477 Trades  'YYYYYY': deal #532210671 sell 0.32 TickerA at 136665 done (based on order #614802327)
2025.08.07 17:59:44.491 Trades  'YYYYYY': deal #532210672 sell 0.32 TickerA at 136665 done (based on order #614802328)
2025.08.07 17:59:44.506 Trades  'YYYYYY': failed modify #0 buy 0  sl: 0, tp: 0 -> sl: 0, tp: 136655 [Position doesn't exist]
2025.08.07 17:59:44.635 Experts expert MyEA-2025Jul10 (TickerA,M1) removed
2025.08.07 17:59:44.656 Notifications   notification 'MyEA(v.2025Jul10) - TickerA  489 positions have just been closed' sent to 'XXXXXXX'
2025.08.07 17:59:44.677 Notifications   notification 'MyEA(v.2025Jul10) - TickerA  <redacted>' sent to 'XXXXXXX'
2025.08.07 17:59:44.689 Notifications   notification 'MyEA(v.2025Jul10) - TickerA  <redacted>' sent to 'XXXXXXX'
2025.08.07 17:59:44.708 Notifications   notification 'MyEA(v.2025Jul10) - TickerA  <redacted>' sent to 'XXXXXXX'
2025.08.07 17:59:44.719 Notifications   notification 'MyEA(v.2025Jul10) - TickerA  <redacted>' sent to 'XXXXXXX'
2025.08.07 17:59:44.742 Notifications   notification 'MyEA(v.2025Jul10) - TickerA  <redacted>' sent to 'XXXXXXX'
2025.08.07 17:59:44.752 Notifications   notification 'MyEA(v.2025Jul10) - TickerA  MyEA has been removed from TickerA with timeframe M1 Message ID: 14435' sent to 'XXXXXXX'
2025.08.07 19:57:41.461 Network 'YYYYYY': scanning network for access points


this is the code I'm running to make the switch:

/*
makes the switch by reloading the EA on the new symbol
*/
void changeToNewSymbol(string newSymbol)
  {
//adding new symbol to marketwatch window
   if(!SymbolSelect(newSymbol, true))
     {
      addLogEntryPlusNotification(StringFormat("Symbol Rotation - Failed to add Symbol \"%s\" in the Market Watch window. Can't make the switch!", newSymbol));
      return;
     }

//setting this GV so we'll know if the rotation completed
// this will be checked on SymbolRotationValidations()
   string gvName = SymbolRotationStartedGVName + newSymbol;
   SetGV(gvName, TimeTradeServer());

   ResetLastError();
   if(!ChartSetSymbolPeriod(ChartID(), newSymbol, 0))
     {
      string msg = StringFormat("Error calling the function to switch symbols error. error code: %d", GetLastError());
      log(msg, ERROR, __FILE__, __FUNCTION__);
      return;
     }
  }


I call the code above when all positions have been closed(were greater than zero and recently switched to zero open positions) and some other conditions are true.


things I observed after the incident:

  • the new symbol was added to the market watch window
  • the GV was set
  • there is no error in the EA tab. So we know ChartSetSymbolPeriod() was called successfully. 


my only guess is something like an internal timeout. Something like it must complete the chart reload and load the EA in this amount of time otherwise it gives up. just to give you context, my terminal was probably busy at that time. in a fraction of a second it was processing and CTrade was logging 400+ positions being closed, it sent out a few push notifications, reloaded the chart in a new symbol, unloaded the current EA. My VM isn't a beefy machine and has two other terminals running that were likely idle, but still consuming memory from the machine. I was also reloading the chart in M1 and it was a newly released symbol by the broker, maybe pulling all the tick info just took a while and caused it to time out silently? I don't know, just speculating here.

by the way, you know that you must have the symbol in the market watch window otherwise ChartSetSymbolPeriod() fails, right?