Download MetaTrader 5
To add comments, please log in or register
All Code Base apps are available from MetaTrader 5. You can publish your own one!
steve
7
steve 2016.01.27 22:45 

Hey all, I am writing an EA that uses the Dialog class to display a nice floating window for the user to interact with. Problem is whenever the time frame is changed the panel bugs out creating artifacts on the chart. When testing the basic dialog code(below) I get a failed to initialize message which removes the EA and crashes the chart. When running my code, the panel scatters randomly across my chart leaving ghost images on the chart of the buttons and panel. If you find the real buttons the EA still functions correctly. When that happens I don't get the failed initialize message or any errors. It also seems to break the second time I change time frames not the first in both cases.

Here is an image of what happens to my EA after loading on the 1hour and changing time frames 3 times. The Expert log shows each time change and no errors:


Now when I switch timeframes the EA destroy()s the window in uninit giving "reason 3"(meaning period was changed) and then re-initializes but I can't tell what is going wrong in between that. All the create fuctions in OnInit have failure modes but I never get any indication of failures just a bugged EA. Is there any way to tell what is breaking, or has anyone used this class before and encountered this issue?


Now the sample code(below) returns the error "failed to initialize" (reason 8) when it crashes but I still don't know why it is failing to create the dialog on the second attempt to change time frames and not the first.

If you want to try it yourself this is the sample code for the simple panel that comes with MT4. I moved PanelDialog.mqh to the Experts folder so it can find it for this test and removed the on calc expression so it can run as an EA.

//+------------------------------------------------------------------+
//|                                                  SimplePanel.mq4 |
//|                   Copyright 2009-2014, MetaQuotes Software Corp. |
//|                                              https://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2009-2014, MetaQuotes Software Corp."
#property link      "https://www.mql4.com"
#property version   "1.00"
#property strict

#include "PanelDialog.mqh"
//+------------------------------------------------------------------+
//| Global Variables                                                 |
//+------------------------------------------------------------------+
CPanelDialog ExtDialog;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
  {
//--- create application dialog
   if(!ExtDialog.Create(0,"Title",0,50,50,390,200))
     return(INIT_FAILED);
//--- run application
   if(!ExtDialog.Run())
     return(INIT_FAILED);
//--- ok
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy application dialog
   ExtDialog.Destroy(reason);
  }

//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
   ExtDialog.ChartEvent(id,lparam,dparam,sparam);
  }
//+------------------------------------------------------------------+
/
To add comments, please log in or register