Skip to content
ModernUI A DaneTrades developer library

Quick Start

This page shows the minimum recommended ModernUI Expert Advisor lifecycle.

The goal is to compile an EA that creates a simple panel, forwards timer events, forwards chart events, handles button clicks through the event bus, and shuts down cleanly.

Full EA example

Full EA example
#property strict
#include <ModernUI\ModernUI.mqh>

enum DEMO_ACTION
  {
   DEMO_ACTION_SAVE,
   DEMO_ACTION_RESET
  };

class CQuickStartPanel : public MuiEventSink
  {
private:
   MuiRoot          m_ui;
   MuiLabel        *m_lStatus;
   MuiButtonAction *m_bSave;
   MuiButtonAction *m_bReset;

public:
   CQuickStartPanel(void)
     {
      m_lStatus=NULL;
      m_bSave=NULL;
      m_bReset=NULL;
     }

   ENUM_INIT_RETCODE OnInitEvent(void)
     {
      if(!m_ui.Init(ChartID(),0,"QuickStart_",512,16))
         return INIT_FAILED;

      m_ui.SetEventSink((MuiEventSink*)GetPointer(this));
      CreateGUI();
      EventSetMillisecondTimer(16);
      return INIT_SUCCEEDED;
     }

   void OnDeinitEvent(const int reason) { EventKillTimer(); m_ui.Shutdown(); }
   void OnTimerEvent(void) { m_ui.OnTimer(); }
   void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam)
     {
      m_ui.OnChartEvent(id,lparam,dparam,sparam);
     }

   void CreateGUI(void)
     {
      MuiAppWindow app=Mui::AppWindow(m_ui,"Quick Start",20,40,320,240,true);
      MuiContainer *body=Mui::Column(app.content,8.0);
      body.FullWidth(true);

      m_lStatus=Mui::Label(body,"Ready");

      MuiContainer *row=Mui::Row(body,8.0);
      row.FullWidth(true);

      m_bSave=Mui::ButtonPrimary(row,"Save");
      m_bSave.Id(DEMO_ACTION_SAVE);
      m_bSave.Flex(1.0);

      m_bReset=Mui::Button(row,"Reset");
      m_bReset.Id(DEMO_ACTION_RESET);
      m_bReset.Flex(1.0);
     }

   virtual void OnMuiEvent(MuiRoot &root,const MuiEventData &event)
     {
      if(event.EventId()!=MUI_EVENT_CLICK)
         return;

      if(event.ControlId()==DEMO_ACTION_SAVE)
        {
         m_lStatus.Text("Saved");
         Mui::ToastSuccess(root,"Settings saved");
         root.RefreshAll();
        }
      else if(event.ControlId()==DEMO_ACTION_RESET)
        {
         m_lStatus.Text("Reset");
         Mui::Toast(root,"Settings reset");
         root.RefreshAll();
        }
     }
  };

CQuickStartPanel Panel;

int OnInit() { return Panel.OnInitEvent(); }
void OnDeinit(const int reason) { Panel.OnDeinitEvent(reason); }
void OnTimer() { Panel.OnTimerEvent(); }
void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam)
  {
   Panel.OnChartEvent(id,lparam,dparam,sparam);
  }

Compile the EA and attach it to a chart.

What each part does

Code Purpose
class CQuickStartPanel : public MuiEventSink Keeps UI, state, and event routing in one class.
MuiRoot m_ui; Owns the ModernUI root, renderer, event bridge, and UI tree.
m_ui.Init(...) Initialises ModernUI for the current chart.
m_ui.SetEventSink(...) Connects central app-level UI events.
.Id(DEMO_ACTION_SAVE) Gives a control an app-level event ID.
OnMuiEvent(...) Receives button clicks and value/check changes from controls.
m_ui.OnTimer() Lets ModernUI process timer-driven rendering.
m_ui.OnChartEvent(...) Forwards mouse, keyboard, chart, and custom events.
m_ui.Shutdown() Releases UI resources and native text input helpers.

Common mistakes

Forgetting the event sink

Reference excerpt
m_ui.SetEventSink((MuiEventSink*)GetPointer(this));

Forgetting control IDs

Reference excerpt
m_bSave.Id(DEMO_ACTION_SAVE);

Forgetting the timer or chart events

Forward OnTimer and OnChartEvent to ModernUI or controls may not repaint or respond.

API reference

Topic Page
Mui::AppWindow, Mui::ButtonPrimary Factory helpers (reference)
MUI_EVENT_CLICK, .Id(...) Event Bus · Buttons
Full control lookup Controls reference
Runnable counterparts Showcase trade panel · Examples index

Next step

Continue with Build your first panel, then read Recommended EA Structure.