Deinitializing with Visualization Tool in Mind

 

I am trying to debug my deinitialization with the visualizer, but I don't see any evidence of deinitialization in the visualizer's Journal. Is there a way to get normal deinitialization in the Visualizer Tool? 

Here is the basic EA I wrote to check to see if I could get any reactionary print in the journal: 


//+------------------------------------------------------------------+
//|                                               deinit_example.mq5 |
//|                                  Copyright 2024, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"

#include <Trade\Trade.mqh> 


struct error_struct{
   int arr[1]; 
   
   error_struct(){}
   ~error_struct(){
      Print("Came here!");
      PrintFormat(arr[1]);
   }
};

CTrade trader;
error_struct error_causer;
bool made_trade = false;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
      
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
      Print("Deinitializing!");
  }
  
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- 
      int total_positions = PositionsTotal();
      
      if(total_positions <= 0 && !made_trade){
         made_trade = trader.Buy(0.01);
         trader.PositionClose(_Symbol);
      }
      
      if(IsStopped()){
         ExpertRemove();
      }
      
  }
//+------------------------------------------------------------------+

Order of Testing: 

1. At first I had the DeInit print and got nothing 

2. Then I tried seeing if opening a trade would trigger something and got nothing still printed 

3. Then I tried to inserting an error in deinitialization and no error was raised. 

4. Finally I tried to see if IsStopped would do anything to catch the shutdown then call ExpertRemove() (as this gives me the expected reaction in the journal). However, IsStopped doesn't catch the Visualizer shutdown (maybe something else does?)


Thanks in Advanced

 
What is Visualizer ? 
 
Soewono Effendi #:
What is Visualizer ? 

Strategy Tester's Visualization Mode (My Apologies if that wasn't clear).

 
You might want to refer to this



Not sure why you need this:
if(IsStopped()){
         ExpertRemove();
      }
 
Soewono Effendi #:
You might want to refer to this



Not sure why you need this:

Maybe you misunderstood, I know that deinitialization occurs in in OnDeInit(). However, I see no evidence of it being called when I click stop in the visualization mode. See the following photo for the print in the journal for the sample program above when you close the visualization part-way through the backtest: 


No Evidence of Deinitialization


If it was a normal closure, I should see a lot of things printed.

 
TraderTogami #:

Maybe you misunderstood, I know that deinitialization occurs in in OnDeInit(). However, I see no evidence of it being called when I click stop in the visualization mode. See the following photo for the print in the journal for the sample program above when you close the visualization part-way through the backtest: 



If it was a normal closure, I should see a lot of things printed.

MQ deliberately decided to not call this event handler OnDeinit() in the visual tester.

Their reasoning is not intuitive for me, but they do what they want. We can only accept it.

 
Stanislav Korotky #:

MQ deliberately decided to not call this event handler OnDeinit() in the visual tester.

Their reasoning is not intuitive for me, but they do what they want. We can only accept it.

Thanks for this information. Also, do you know if this also means that all destructors are not called as well? 

 
TraderTogami #:

Thanks for this information. Also, do you know if this also means that all destructors are not called as well? 

Yes. There are no workarounds.

This website uses cookies. Learn more about our Cookies Policy.