Loading…

Dropdown Select Widget

A panel offering a choice of symbol, timeframe or mode either permanently spends one button per option on screen, or has to fake a dropdown somehow. This widget builds the full option list as real chart objects once, at Create() time - it does not create or destroy a single object when opening or closing. Open() and Close() only flip OBJPROP_TIMEFRAMES between OBJ_ALL_PERIODS and OBJ_NO_PERIODS on the pre-built option buttons, the same visibility mechanism TabContainerWidget.mqh in this catalogue uses for tab content - so a dropdown with a dozen options costs nothing extra to open or close beyond one ObjectSetInteger() call per option. Closed options are OBJ_NO_PERIODS, which means they cannot receive a real mouse click while hidden - so a caller wiring OnChartEvent's CHARTEVENT_OBJECT_CLICK straight to HandleClick() never has to separately guard against an option firing while the dropdown looks collapsed; the platform itself prevents it. Selecting an option collapses the dropdown automatically in the same call, so a caller does not need a second step to close it after a selection. Notes and limitations - Up to 16 options (DSW_MAX_OPTIONS), a fixed-size array sized for a settings-picker scale (timeframes, modes, a short symbol list), not a long scrollable list. - The option list is drawn directly below the header at a fixed height per row; there is no horizontal layout and no scrolling once the list is taller than the visible chart area. - Clicking outside the dropdown (on the chart background rather than on another object) does not collapse it - only clicking the header again or picking an option does. A caller wanting outside-click-to-close would need to additionally handle CHARTEVENT_CLICK for background clicks itself; this widget only wires object clicks. - No trading and no money at risk - the demo only builds and exercises the dropdown, it never sends an order.

Script · MT4 · v1.0 · Free

About Dropdown Select Widget

Dropdown Select Widget is a script for MetaTrader 4. It has 1 setting, such as Prefix. MQL source code included.

Files in the download: DropdownSelectWidget.mqh, DropdownSelectWidget.txt, DropdownSelectWidgetDemo.mq4.

Settings

SettingDefaultWhat it does
PrefixDSWDemo_Object-name prefix for this demo's objects

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria