Viewing the resource: Crafting a Trade Dashboard Command Center with MQL5 🚀

Crafting a Trade Dashboard Command Center with MQL5 🚀

Allan Munene Mutiiria 2025-06-21 14:31:12 96 Views
Join us for a detailed, professional, and engaging journey through our MQL5 code that automates fore...

Introduction

Greetings, forex commanders! Picture the forex market as a vast galaxy, with prices zipping like starships in a cosmic race. The Dashboard All EA is your state-of-the-art control room, an MQL5 bot that equips you with a slick interface to execute buy and sell orders, adjust trade settings, and manage positions with laser precision. Packed with buttons, dropdowns, and real-time market data, this EA puts you in the captain’s chair, ready to navigate trades manually. This article is your mission log, guiding you through the code with crystal-clear detail for beginners, a flow smoother than a warp drive, and examples—like commanding EURUSD trades—to keep you locked in. We’ll quote variables (e.g., "obj_Trade") and functions (e.g., "OnInit()") for clarity, balancing pro insights with a sprinkle of charm. Ready to take the helm? Let’s launch this trade command center!

Strategy Blueprint

The Dashboard All EA is a manual trading interface:

  • Market Orders: Buttons for instant “Buy” or “Sell” trades with customizable lot sizes, stop losses, and take profits.

  • Position Management: A “Close” button to shut all open positions, with placeholder buttons for “Market,” “Profit,” “Loss,” and “Pending” management.

  • Interface: Input fields for lot size (default 0.01), stop loss (100 pips), and take profit (100 pips), with a dropdown for sizing options (lot size, risk percentage, money balance). Displays real-time bid, ask, and spread.

  • Features: Hover effects, draggable dropdowns, and sharp-edged buttons for a polished user experience. It’s like a starship console, giving you full control to navigate trades with precision, ideal for manual traders seeking flexibility. See below.

Code Implementation

Let’s navigate the MQL5 code like starship pilots plotting a course through the cosmos, building our dashboard step by step. We’ll flow from rigging the control room to wiring buttons, handling trades, adding interactive features, and docking cleanly, with transitions as seamless as a hyperspace jump. Each section includes code blocks, detailed explanations of what we’re doing, and examples to keep you engaged, all while staying beginner-friendly and professional.

Step 1: Rigging the Control Room—Setting Up the Dashboard Framework

We start by assembling our starship’s control room, defining the dashboard’s structure and core components.

//+------------------------------------------------------------------+
//|                                                DASHBOARD ALL.mq5 |
//|      Copyright 2025, ALLAN MUNENE MUTIIRIA. #@Forex Algo-Trader. |
//|                           https://youtube.com/@ForexAlgo-Trader? |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, ALLAN MUNENE MUTIIRIA. #@Forex Algo-Trader"
#property link      "https://youtube.com/@ForexAlgo-Trader?"
#property description "======= IMPORTANT =======\n"
#property description "1. This is a FREE EA."
#property description "2. To get the source code of the EA, follow the Copyright link."
#property description "3. In case of anything, contact developer via the link provided."
#property description "Hope you will enjoy the EA Logic.\n"
#property description "*** HAPPY TRADING! ***"
#property version   "1.00"

#include <Trade/Trade.mqh>
CTrade obj_Trade;

#define MAIN_REC "MAIN_REC"
#define MAIN_SUB_REC "MAIN_SUB_REC"
#define MAIN_LINE_UP "MAIN_LINE_UP"
#define MAIN_LINE_DN "MAIN_LINE_DN"
// ... (other defines)

int OnInit(){
   ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,true);
   createRecLabel(MAIN_REC,10,30,250,400,clrWhite,1,clrBlack);
   createRecLabel(MAIN_SUB_REC,15,35,240,390,C'245,245,245',1,clrNONE);
   createRecLabel(MAIN_LINE_UP,15,35,240,1,C'245,245,245',1,clrNONE,BORDER_RAISED);
   createRecLabel(MAIN_LINE_DN,15,35-1,1,390+1,C'245,245,245',1,clrNONE,BORDER_RAISED);
   createLabel(ICON_HEART,190,35,"Y",clrRed,15,"Webdings");
   createLabel(ICON_TOOL,210,35,"@",clrBlue,15,"Webdings");
   createLabel(ICON_CAR,230,35,"h",clrBlack,15,"Webdings");
   createLabel(LABEL_NAME,25,35,"DashBoard v1.0",clrBlue,14,"Cooper Black");
   createRecLabel(LINE1,15+10,60,240-10,1,C'245,245,245',1,clrNONE,BORDER_RAISED);
   createLabel(BTN_CLOSE,25,65,"Close",clrBlack,13,"Impact");
   createLabel(BTN_MARKET,70,65,"Market",clrDarkRed,13,"Impact");
   createLabel(BTN_PROFIT,125,65,"Profit",clrGreen,13,"Impact");
   createLabel(BTN_LOSS,170,65,"Loss",clrRed,13,"Impact");
   createLabel(BTN_PENDING,205,65,"Pend'n",clrDarkGray,13,"Impact");
   createRecLabel(LINE2,15+10,87,240-10,1,C'245,245,245',1,clrNONE,BORDER_RAISED);
   // ... (other UI elements)
   createButton(BTN_CONTACT,25,335+62,230-10,25,"https://t.me/Forex_Algo_Trader",clrBlack,10,clrNONE,clrBlack);
   return(INIT_SUCCEEDED);
}

We rig the control room with a #property header, declaring the EA as a free offering by Allan in 2025 with a YouTube link, like calibrating our starship’s comms. We include "Trade/Trade.mqh" for trading via "obj_Trade", and define constants (e.g., "MAIN_REC", "BTN_BUY") for UI elements, like labeling console switches. In "OnInit()", we enable mouse move events with "ChartSetInteger()", then use "createRecLabel()", "createLabel()", and "createButton()" to build a 250x400 white panel ("MAIN_REC") with a gray sub-panel ("MAIN_SUB_REC"), icons ("ICON_HEART", "ICON_TOOL", "ICON_CAR"), a “DashBoard v1.0” title, navigation buttons ("BTN_CLOSE", "BTN_MARKET", etc.), and a Telegram contact button ("BTN_CONTACT"). This creates a sleek console, like the Enterprise’s bridge, ready to command trades.

Step 2: Wiring the Trade Console—Building Input and Trade Controls

We wire the trade console, adding buttons, inputs, and dropdowns to manage trade settings and execute orders.

bool createButton(string objName,int xD,int yD, int xS, int yS,
   string txt="",color clrTxt=clrBlack,int fontSize=12,color clrBG=clrNONE,
   color clrBorder=clrNONE,string font="Arial Rounded MT Bold"){
   ResetLastError();
   if (!ObjectCreate(0,objName,OBJ_BUTTON,0,0,0)){
      Print(__FUNCTION__," FAILED to create the button! Error Code = ",_LastError);
      return (false);
   }
   ObjectSetInteger(0,objName,OBJPROP_XDISTANCE,xD);
   ObjectSetInteger(0,objName,OBJPROP_YDISTANCE,yD);
   ObjectSetInteger(0,objName,OBJPROP_XSIZE,xS);
   ObjectSetInteger(0,objName,OBJPROP_YSIZE,yS);
   ObjectSetInteger(0,objName,OBJPROP_CORNER,CORNER_LEFT_UPPER);
   ObjectSetString(0,objName,OBJPROP_TEXT,txt);
   ObjectSetInteger(0,objName,OBJPROP_COLOR,clrTxt);
   ObjectSetInteger(0,objName,OBJPROP_FONTSIZE,fontSize);
   ObjectSetString(0,objName,OBJPROP_FONT,font);
   ObjectSetInteger(0,objName,OBJPROP_BGCOLOR,clrBG);
   ObjectSetInteger(0,objName,OBJPROP_BORDER_COLOR,clrBorder);
   ObjectSetInteger(0,objName,OBJPROP_BACK,false);
   ObjectSetInteger(0,objName,OBJPROP_STATE,false);
   ObjectSetInteger(0,objName,OBJPROP_SELECTABLE,false);
   ObjectSetInteger(0,objName,OBJPROP_SELECTED,false);
   ChartRedraw(0);
   return (true);
}
bool createEdit(string objName,int xD,int yD, int xS, int yS,
   string txt="",color clrTxt=clrBlack,int fontSize=12,color clrBG=clrNONE,
   color clrBorder=clrNONE,string font="Arial Rounded MT Bold"){
   ResetLastError();
   if (!ObjectCreate(0,objName,OBJ_EDIT,0,0,0)){
      Print(__FUNCTION__," FAILED to create the edit! Error Code = ",_LastError);
      return (false);
   }
   ObjectSetInteger(0,objName,OBJPROP_XDISTANCE,xD);
   ObjectSetInteger(0,objName,OBJPROP_YDISTANCE,yD);
   ObjectSetInteger(0,objName,OBJPROP_XSIZE,xS);
   ObjectSetInteger(0,objName,OBJPROP_YSIZE,yS);
   ObjectSetInteger(0,objName,OBJPROP_CORNER,CORNER_LEFT_UPPER);
   ObjectSetString(0,objName,OBJPROP_TEXT,txt);
   ObjectSetInteger(0,objName,OBJPROP_COLOR,clrTxt);
   ObjectSetInteger(0,objName,OBJPROP_FONTSIZE,fontSize);
   ObjectSetString(0,objName,OBJPROP_FONT,font);
   ObjectSetInteger(0,objName,OBJPROP_BGCOLOR,clrBG);
   ObjectSetInteger(0,objName,OBJPROP_BORDER_COLOR,clrBorder);
   ObjectSetInteger(0,objName,OBJPROP_ALIGN,ALIGN_LEFT);
   ObjectSetInteger(0,objName,OBJPROP_READONLY,false);
   ObjectSetInteger(0,objName,OBJPROP_BACK,false);
   ObjectSetInteger(0,objName,OBJPROP_STATE,false);
   ObjectSetInteger(0,objName,OBJPROP_SELECTABLE,false);
   ObjectSetInteger(0,objName,OBJPROP_SELECTED,false);
   ChartRedraw(0);
   return (true);
}
void createDropDown(){
   createRecLabel(BTN_DROP_DN,25,95+25,130,70,clrWhite,2,clrBlack);
   createLabel(LABEL_OPT1,25+10,95+25,"LotSize",clrBlack,12,"stencil");
   createLabel(LABEL_OPT2,25+10,95+25+20,"Risk Percent %",clrBlack,12,"calibri italic");
   createLabel(LABEL_OPT3,25+10,95+25+20+20,"Money Balance",clrBlack,12,"Arial Bold");
   createLabel(ICON_DRAG,25+10+95,95+25,"d",clrRoyalBlue,15,"WEBDINGS");
}
int OnInit(){
   // ... (main panel setup)
   createButton(BTN_LOTS,25,95,130,25,"",clrBlack,12,C'210,210,210',C'150,150,150');
   createLabel(LABEL_LOTS,25+10,95+5,"LotSize",clrBlack,9);
   createLabel(ICON_DROP_DN1,130,95+5,CharToString(240),C'070,070,070',20,"Wingdings 3");
   createEdit(EDIT_LOTS,165,95,60,25,"0.01",clrBlack,14,clrWhite,C'100,100,100',"Callibri");
   createButton(BTN_P1,225,95,20,12,"5",clrBlack,12,clrLightGray,C'100,100,100',"Webdings");
   createButton(BTN_M1,225,95+12,20,12,"6",clrBlack,12,clrLightGray,C'100,100,100',"Webdings");
   createButton(BTN_SL,25,95+30,130,25,"",clrBlack,12,C'210,210,210',C'150,150,150');
   createLabel(LABEL_SL,35,95+30,"SL Pips",clrBlack,14);
   createLabel(ICON_DROP_DN2,130,100+30,CharToString(240),C'070,070,070',20,"Wingdings 3");
   createEdit(EDIT_SL,165,95+30,60,25,"100.0",clrBlack,13,clrWhite,C'100,100,100',"Callibri");
   createButton(BTN_P2,225,95+30,20,12,"5",clrBlack,12,clrLightGray,C'100,100,100',"Webdings");
   createButton(BTN_M2,225,107+30,20,12,"6",clrBlack,12,clrLightGray,C'100,100,100',"Webdings");
   createButton(BTN_TP,25,95+30+30,130,25,"",clrBlack,12,C'210,210,210',C'150,150,150');
   createLabel(LABEL_TP,35,95+30+30,"TP Pips",clrBlack,14);
   createLabel(ICON_DROP_DN3,130,100+30+30,CharToString(240),C'070,070,070',20,"Wingdings 3");
   createEdit(EDIT_TP,165,95+30+30,60,25,"100.0",clrBlack,13,clrWhite,C'100,100,100',"Callibri");
   createButton(BTN_P3,225,95+30+30,20,12,"5",clrBlack,12,clrLightGray,C'100,100,100',"Webdings");
   createButton(BTN_M3,225,107+30+30,20,12,"6",clrBlack,12,clrLightGray,C'100,100,100',"Webdings");
   createRecLabel(BTN_SELL,25,335,105,60,clrRed,1,clrNONE);
   createLabel(LABEL_SELL,35,335,"Sell",clrWhite,15,"ARIAL black");
   createLabel(LABEL_SELL_PRICE,35,335+30,DoubleToString(Bid(),_Digits),clrWhite,13,"ARIAL black");
   createRecLabel(BTN_BUY,140,335,105,60,clrGreen,1,clrNONE);
   createLabel(LABEL_BUY,150+35,335,"Buy",clrWhite,15,"ARIAL black");
   createLabel(LABEL_BUY_PRICE,150,335+30,DoubleToString(Ask(),_Digits),clrWhite,13,"ARIAL black");
   createRecLabel(BTN_OVERLAY,90,335,90,25,C'245,245,245',0,clrNONE);
   createButton(BTN_SPREAD,95,335,80,20,(string)Spread(),clrBlack,13,clrWhite,clrBlack);
   // ... (other UI elements)
}

We wire the trade console using "createButton()", "createEdit()", "createLabel()", and "createDropDown()". For lot size, "BTN_LOTS" (with "LABEL_LOTS", "ICON_DROP_DN1") triggers a dropdown ("BTN_DROP_DN", "LABEL_OPT1", "LABEL_OPT2", "LABEL_OPT3") for sizing options, and "EDIT_LOTS" defaults to 0.01, adjustable via "BTN_P1" (+0.01) and "BTN_M1" (-0.01). Stop loss ("BTN_SL", "EDIT_SL", 100 pips) and take profit ("BTN_TP", "EDIT_TP", 100 pips) follow suit with similar controls. Buy ("BTN_BUY", green) and sell ("BTN_SELL", red) buttons display real-time prices via "LABEL_BUY_PRICE", "LABEL_SELL_PRICE", and spread ("BTN_SPREAD"). This is like installing thrusters and navigation screens, ready to launch EURUSD trades with 0.01 lots and 100-pip settings.

Step 3: Firing the Thrusters—Executing Trade Commands

With the console wired, we handle button clicks to execute buy/sell orders and manage positions.

double Ask(){return (NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits));}
double Bid(){return (NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits));}
int Spread(){return ((int)SymbolInfoInteger(_Symbol,SYMBOL_SPREAD));}
void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam){
   if (id==CHARTEVENT_OBJECT_CLICK){
      if (sparam==BTN_P1){
         Print(sparam+" CLICKED.");
         double trade_lots = (double)ObjectGetString(0,EDIT_LOTS,OBJPROP_TEXT);
         trade_lots+=0.01;
         ObjectSetString(0,EDIT_LOTS,OBJPROP_TEXT,DoubleToString(trade_lots,2));
         ChartRedraw(0);
      }
      if (sparam==BTN_M1){
         Print(sparam+" CLICKED.");
         double trade_lots = (double)ObjectGetString(0,EDIT_LOTS,OBJPROP_TEXT);
         trade_lots-=0.01;
         ObjectSetString(0,EDIT_LOTS,OBJPROP_TEXT,DoubleToString(trade_lots,2));
         ChartRedraw(0);
      }
      if (sparam==BTN_SELL){
         Print("BTN SELL CLICKED");
         ObjectSetInteger(0,BTN_SELL,OBJPROP_STATE,false);
         double trade_lots = (double)ObjectGetString(0,EDIT_LOTS,OBJPROP_TEXT);
         double sell_sl = (double)ObjectGetString(0,EDIT_SL,OBJPROP_TEXT);
         sell_sl = Ask()+sell_sl*_Point;
         sell_sl = NormalizeDouble(sell_sl,_Digits);
         double sell_tp = (double)ObjectGetString(0,EDIT_TP,OBJPROP_TEXT);
         sell_tp = Ask()-sell_tp*_Point;
         sell_tp = NormalizeDouble(sell_tp,_Digits);
         Print("Lots = ",trade_lots,", SL = ",sell_sl,", TP = ",sell_tp);
         obj_Trade.Sell(trade_lots,_Symbol,Bid(),sell_sl,sell_tp);
         ChartRedraw(0);
      }
      else if (sparam==BTN_BUY){
         Print("BTN BUY CLICKED");
         ObjectSetInteger(0,BTN_BUY,OBJPROP_STATE,false);
         double trade_lots = (double)ObjectGetString(0,EDIT_LOTS,OBJPROP_TEXT);
         double buy_sl = (double)ObjectGetString(0,EDIT_SL,OBJPROP_TEXT);
         buy_sl = Bid()-buy_sl*_Point;
         buy_sl = NormalizeDouble(buy_sl,_Digits);
         double buy_tp = (double)ObjectGetString(0,EDIT_TP,OBJPROP_TEXT);
         buy_tp = Bid()+buy_tp*_Point;
         buy_tp = NormalizeDouble(buy_tp,_Digits);
         Print("Lots = ",trade_lots,", SL = ",buy_sl,", TP = ",buy_tp);
         obj_Trade.Buy(trade_lots,_Symbol,Ask(),buy_sl,buy_tp);
         ChartRedraw(0);
      }
      else if (sparam==BTN_CLOSE){
         Print("BTN CLOSE CLICKED");
         long originalColor = ObjectGetInteger(0,BTN_CLOSE,OBJPROP_COLOR);
         ObjectSetInteger(0,BTN_CLOSE,OBJPROP_COLOR,clrRed);
         for (int i=0; i<=PositionsTotal();i++){
            ulong ticket = PositionGetTicket(i);
            if (ticket > 0){
               if (PositionSelectByTicket(ticket)){
                  if (PositionGetString(POSITION_SYMBOL)==_Symbol){
                     obj_Trade.PositionClose(ticket);
                  }
               }
            }
         }
         Print("Resetting the button to original color");
         ObjectSetInteger(0,BTN_CLOSE,OBJPROP_COLOR,originalColor);
         ChartRedraw(0);
      }
      else if (sparam==BTN_LOTS || sparam==LABEL_LOTS || sparam==ICON_DROP_DN1){
         Print(sparam+" LOTS CLICKED");
         ObjectSetInteger(0,BTN_LOTS,OBJPROP_STATE,true);
         createDropDown();
         ChartRedraw(0);
      }
      else if (sparam==LABEL_OPT1){
         Print("LABEL LOTS CLICKED");
         string text = ObjectGetString(0,LABEL_OPT1,OBJPROP_TEXT);
         bool btn_state = ObjectGetInteger(0,BTN_LOTS,OBJPROP_STATE);
         ObjectSetString(0,LABEL_LOTS,OBJPROP_TEXT,text);
         destroyDropDown();
         if (btn_state==true){
            ObjectSetInteger(0,BTN_LOTS,OBJPROP_STATE,false);
         }
         ChartRedraw(0);
      }
      else if (sparam==LABEL_OPT2){
         Print("LABEL RISK % CLICKED");
         string text = ObjectGetString(0,LABEL_OPT2,OBJPROP_TEXT);
         bool btn_state = ObjectGetInteger(0,BTN_LOTS,OBJPROP_STATE);
         ObjectSetString(0,LABEL_LOTS,OBJPROP_TEXT,text);
         destroyDropDown();
         if (btn_state==true){
            ObjectSetInteger(0,BTN_LOTS,OBJPROP_STATE,false);
         }
         ChartRedraw(0);
      }
      else if (sparam==LABEL_OPT3){
         Print("LABEL MONEY CLICKED");
         string text = ObjectGetString(0,LABEL_OPT3,OBJPROP_TEXT);
         bool btn_state = ObjectGetInteger(0,BTN_LOTS,OBJPROP_STATE);
         ObjectSetString(0,LABEL_LOTS,OBJPROP_TEXT,text);
         destroyDropDown();
         if (btn_state==true){
            ObjectSetInteger(0,BTN_LOTS,OBJPROP_STATE,false);
         }
         ChartRedraw(0);
      }
      else if (sparam==ICON_CAR){
         destroyPanel();
         ChartRedraw(0);
      }
   }
}

In "OnChartEvent()", we handle clicks using "CHARTEVENT_OBJECT_CLICK". Clicking "BTN_BUY" or "BTN_SELL" grabs "EDIT_LOTS", "EDIT_SL", "EDIT_TP" values via "ObjectGetString()", calculates stop loss and take profit with "Ask()", "Bid()", "NormalizeDouble()", and "_Point", then executes trades with "obj_Trade.Buy()" or "obj_Trade.Sell()", logging details like “Lots = 0.01, SL = 1.2100, TP = 1.1900” for a EURUSD sell at 1.2000. "BTN_CLOSE" loops through "PositionsTotal()", closing all positions with "PositionGetTicket()", "PositionSelectByTicket()", "PositionGetString()", "obj_Trade.PositionClose()", and flashes red temporarily. Lot size buttons ("BTN_P1", "BTN_M1") adjust "EDIT_LOTS" by ±0.01, and "BTN_LOTS", "LABEL_LOTS", or "ICON_DROP_DN1" trigger "createDropDown()", with options ("LABEL_OPT1", "LABEL_OPT2", "LABEL_OPT3") updating "LABEL_LOTS". This is like firing thrusters for a EURUSD buy or docking the fleet with a single command.

Step 4: Enhancing the Console—Adding Interactive Features

We add hover effects and draggable dropdowns, like upgrading the console with holographic displays. See the attached code for that. You should have the following feature.

Happy trading!

Disclaimer: The ideas and strategies presented in this resource are solely those of the author and are intended for informational and educational purposes only. They do not constitute financial advice, and past performance is not indicative of future results. All materials, including but not limited to text, images, files, and any downloadable content, are protected by copyright and intellectual property laws and are the exclusive property of Forex Algo-Trader or its licensors. Reproduction, distribution, modification, or commercial use of these materials without prior written consent from Forex Algo-Trader is strictly prohibited and may result in legal action. Users are advised to exercise extreme caution, perform thorough independent research, and consult with qualified financial professionals before implementing any trading strategies or decisions based on this resource, as trading in financial markets involves significant risk of loss.

Recent Comments

Go to discussion to Comment or View other Comments

No comments yet. Be the first to comment!