Download MetaTrader 5

Some UninitializationReason do not trigger

To add comments, please log in or register
macpee
509
macpee  
Why is it that some UnInitializationReason do not trigger, e.g. REASON_CHARTCHANGE?
whroeder1
17063
whroeder1  
2017.02.28 12:40:26.680    countdown_timer AUDUSD,Daily: uninit reason 3
Certainly does with 1045.
macpee
509
macpee  
whroeder1:
Certainly does with 1045.
I mean changing a chart to the current chart when there are several of them. I do not mean changing chart periodicity. I hope I am right. By the way when is the following example code meant to execute. What is sopposed to call it. Does it execute whenever REASON is triggered. I am using 1045 also. Please help.


string getUninitReasonText(int reasonCode)
  {
   string text="";
//---
   switch(reasonCode)
     {
      case REASON_ACCOUNT:
         text="Account was changed";break;
      case REASON_CHARTCHANGE:
         text="Symbol or timeframe was changed";break;
      case REASON_CHARTCLOSE:
         text="Chart was closed";break;
      case REASON_PARAMETERS:
         text="Input-parameter was changed";break;
      case REASON_RECOMPILE:
         text="Program "+__FILE__+" was recompiled";break;
      case REASON_REMOVE:
         text="Program "+__FILE__+" was removed from chart";break;
      case REASON_TEMPLATE:
         text="New template was applied to chart";break;
      default:text="Another reason";
     }
//---
Print("reason text ", text);
   return text;
  }
Look at how a part of my code looks like. The part that has to do with Uninitilization. I do not know if I coded it properly. Still learning MQL4:

if (UninitializeReason() == REASON_PARAMETERS)
    {
     GlobalVariableSet("AskDistanceTemp", AskDistance);
     GlobalVariableSet("OrderSpacingTemp", OrderSpacing);
     GlobalVariableSet("ProfitLevelTemp", ProfitLevel);
     GlobalVariableSet("LossLevelTemp", LossLevel);
     GlobalVariableSet("LotTemp", Lot);
     GlobalVariableSet("LotStepTemp", LotStep);
     GlobalVariableSet("ArithmeticOrGeometricTemp", ArithmeticOrGeometric);
     GlobalVariableSet("NestTemp", Nest);
    }
whroeder1
17063
whroeder1  
macpee:
I mean changing a chart to the current chart when there are several of them.

I do not mean changing chart periodicity.

I hope I am right.

By the way when is the following example code meant to execute. What is sopposed to call it.
  1. What difference does it make if there are multiple charts?
  2. TF or pair, there is no difference.
  3. Right about what? You haven't made a statement.
  4. Perhaps you should read the manual. Event Handling Functions - Functions - Language Basics - MQL4 Reference
macpee
509
macpee  
whroeder1:
  1. What difference does it make if there are multiple charts?
  2. TF or pair, there is no difference.
  3. Right about what? You haven't made a statement.
  4. Perhaps you should read the manual. Event Handling Functions - Functions - Language Basics - MQL4 Reference
I need to say here that I had read the documentation you sent before I asked the question. If I understood the documentation, I would not be asking. You did not even answer the question I asked concerning whether my example code pasted above is correct or not. Neither did you tell what calls the program I pasted above from the documentation. I need those answers to understand the concept of Initialization.
whroeder1
17063
whroeder1  
  1. You asked what function should call your code. The link answers the question.
  2. You say you had read the documentation, but apparently didn't understand it. Read it again!
macpee
509
macpee  
whroeder1:
  1. You asked what function should call your code. The link answers the question.
  2. You say you had read the documentation, but apparently didn't understand it. Read it again!
But is my code reasonable, as far as running the code is concerned?
whroeder1
17063
whroeder1  
Third and last time, your code is not reasonable, because it is not running, because you don't call it, because you didn't understand the documentation.
macpee
509
macpee  
whroeder1:
Third and last time, your code is not reasonable, because it is not running, because you don't call it, because you didn't understand the documentation.

I have done a little research on this Initialization thing and I have modified the program and it is now running.

extern string enter = "STRING";

void init(){
//void  OnInit(){
int reas;
reas = UninitializeReason();
getUninitReasonText(reas);
}
string getUninitReasonText(int reasonCode)
  {
   string text="";
//---
   switch(reasonCode)
     {
      case REASON_ACCOUNT: //Prints even when EA is not attached to the current chart. Does not print when trying to change to the current EA
         text="Account was changed";Print("reason text ", text, ", Uninit Number ", UninitializeReason(), " Check Number ", REASON_ACCOUNT);break;
      case REASON_CHARTCHANGE: //Prints only when EA is on current chart
         text="Symbol or timeframe was changed";Print("reason text ", text, ", Uninit Number ", UninitializeReason(), " Check Number ",REASON_CHARTCHANGE);break;
      case REASON_CHARTCLOSE: //Prints only when EA is on closed chart
         text="Chart was closed";Print("reason text ", text, ", Uninit Number ", UninitializeReason(), " Check Number ",REASON_CHARTCLOSE);break;
      case REASON_PARAMETERS: //Prints only when the input parameters section of the input parameter window is viewed 
                              //(even without changing any parameter) and OK clicked
         text="Input-parameter was changed";Print("reason text ", text, ", Uninit Number ", UninitializeReason(), " Check Number ",REASON_PARAMETERS);break;
      case REASON_RECOMPILE: //Prints even if EA is not on current chart
         text="Program "+__FILE__+" was recompiled";Print("reason text ", text, ", Uninit Number ", UninitializeReason(), " Check Number ",REASON_RECOMPILE);break;
      case REASON_REMOVE: //Prints fine
         text="Program "+__FILE__+" was removed from chart";Print("reason text ", text, ", Uninit Number ", UninitializeReason(), " Check Number ",REASON_REMOVE);break;
      case REASON_TEMPLATE:
         text="New template was applied to chart";Print("reason text ", text, ", Uninit Number ", UninitializeReason(), " Check Number ",REASON_TEMPLATE);break;
     // default:text="Another reason";
     }
//---
   return text;
  } 

‌My concern is why there is no inclusion of REASON_PROFILE for change of profile.

‌It seems to stand between REASON_CHARTCHANGE and REASON_ACCOUNT yet no inclusion of it. It is between these two because chart is changed within the same profile and profile is changed within the same account. Now I need it to solve a certain problem.

You ask why I need it? I am developing an EA where a part of the task is to input trading parameters via the parameter window and allow the use of such parameters in other profiles, unless such parameters are changed in those profiles.

I will first have to save those parameters to global variables (Immediately it is input in the parameter window, using REASON_PARAMETER in the conditional statement) , then get the values of the global variables in other profiles.

You are asking where the REASON_PROFILE comes in? Ok see, it comes in because I need to get the trading parameters from the global variables immediately a profile is changed, and not wait until a new tick arrives.‌

By so doing those parameters can be made use of (say showing them on some chart objects) even without the EA connected, and without clicking at any button.

NOTE that I can perform this task with REASON_ACCOUNT and REASON_CHARTCHANGE and with any other reason that there is in the documentation for MT4‌.

Documentation on MQL5: Standard Constants, Enumerations and Structures / Named Constants / Uninitialization Reason Codes
Documentation on MQL5: Standard Constants, Enumerations and Structures / Named Constants / Uninitialization Reason Codes
  • www.mql5.com
Standard Constants, Enumerations and Structures / Named Constants / Uninitialization Reason Codes - Reference on algorithmic/automated trading language for MetaTrader 5
macpee
509
macpee  
whroeder1:
Third and last time, your code is not reasonable, because it is not running, because you don't call it, because you didn't understand the documentation.

An idea on how to go about it, for which you may come in, is as follows:

Since changing a profile entails closing all charts (REASON_CHARTCHANGE) in the outgoing profile and opening profile (initialization) in the current profile, an idea is to code the EA by asking that

if (UninitializeReason‌() == REASON_CHARTCLOSE && init())

{

‌blah blah blah;

}

Documentation on MQL5: Standard Constants, Enumerations and Structures / Named Constants / Uninitialization Reason Codes
Documentation on MQL5: Standard Constants, Enumerations and Structures / Named Constants / Uninitialization Reason Codes
  • www.mql5.com
Standard Constants, Enumerations and Structures / Named Constants / Uninitialization Reason Codes - Reference on algorithmic/automated trading language for MetaTrader 5
whroeder1
17063
whroeder1  
You posted init/OnInit code that calls your un-init code. OnInit has no reason for un-Init. Read the documentation.
To add comments, please log in or register