DeInitialization Text Reason Code Snip

24 June 2016, 00:40
Denton Hess

Modified from someone else code here (I'll get the name later). For MQL4, Build 971.

Hopefully this will not upset anyone, but... you never know.... 

Your comments and improvement suggestions appreciated. 

DeInitialization Code Snippet For DeInit Reason Text

Use this code function to enhance your Deinitialization journal entry with the actual reason the Expert Advisor was Deinitialized.

Updated For Metatrader 4, Build 971.

If you uncomment ObjectsDeleteAll(), and you later wonder where all your arrows and lines went on your chart, it is because the ObjectsDeleteAll is doing its job. Just Re-comment it to restore your chart objects.

Remember to use Cntrl + "," to align your code for pretty printing.


void OnDeinit(const int reason)


Print(EA_Name," is Deinitialized for Reason ",IntegerToString(reason)," ",func_GetDeInitReasonText(_UninitReason)," on ",Sym,", Time Period",_Period);


// EventKillTimer(); 

}// End OnDeinit

//| DeInit Text Description Function                                    |
string func_GetDeInitReasonText(int reasonCode)
   string text="";
      case REASON_PROGRAM:          //Reason 0
         text="Expert Advisor terminated its operation by calling the ExpertRemove() function."; break;
      case REASON_REMOVE:           // Reason 1
         text="Program "+__FILE__+" was REMOVED from chart.";  break;
      case REASON_RECOMPILE:        // Reason 2
         text="Program "+__FILE__+" was RECOMPILED.";          break;
      case REASON_CHARTCHANGE:      // Reason 3
         text="Symbol or Chart time frame was CHANGED.";       break;
      case REASON_CHARTCLOSE:       // Reason 4
         text="Chart has been CLOSED.";                        break;
      case REASON_PARAMETERS:       // Reason 5
         text="Input-parameter was changed";                   break;
      case REASON_ACCOUNT:          // Reason 6
         text="ACCOUNT was changed";                           break;
      case REASON_TEMPLATE:         // Reason 7
         text="New TEMPLATE was applied to chart";             break;
      case REASON_INITFAILED:       // Reason 8
         text="This value means that OnInit() handler has returned a nonzero value.";break;
      case REASON_CLOSE:            // Reason 9
         text="Terminal has been closed.";                     break;
      default:text=", Another Reason";
   return (text);


Share it with friends: