Introduction
Greetings, forex commanders! Picture the forex market as a bustling galaxy, with prices zooming like starships in a cosmic dance. The Control Panel EA is your high-tech cockpit, a slick interface packed with buttons and fields to execute market orders, set pending trades, and manage positions with laser precision. Built with MQL5βs control libraries, this EA puts you in the captainβs chair, letting you steer trades manually while tracking account vitals like a starshipβs dashboard. 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 a fleet on EURUSDβto keep you locked in. Weβll quote functions (e.g., "OnInit()") and variables (e.g., "obj_Btn_MAIN") for clarity, balancing pro insights with a sprinkle of charm. Ready to take the helm? Letβs launch this trade command powerhouse!
Strategy Blueprint
The Control Panel EA is a manual trading interface, not an automated signal generator:
Market Orders: Buttons for instant βBuyβ or βSellβ trades, allowing you to jump into the market with custom lot sizes, stop losses, and take profits.
Pending Orders: Options for βBuy Stop,β βSell Stop,β βBuy Limit,β and βSell Limitβ to set trades at specific prices, checked against broker stop levels.
Position Management: Buttons to close all trades, specific buy/sell trades, or filter by profit/loss, plus a pending order closer, offering surgical control.
Interface: A panel with input fields for risk, price, lots, stop loss, and take profit, plus real-time account info (equity, balance, leverage, server time). Itβs like a spaceship dashboard, giving you full control to navigate the market galaxy with precision, ideal for traders who love calling the shots. See below.

Code Implementation
Letβs navigate the MQL5 code like starship pilots plotting a course through the cosmos, building our control panel step by step. Weβll flow from rigging the cockpit to wiring buttons, handling trade commands, managing positions, 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 CockpitβSetting Up the Panel Framework
We start by rigging our spaceshipβs cockpit, defining the panelβs structure and core components to command our trades.
//+------------------------------------------------------------------+
//| CONTROL PANEL.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;
#include <Controls/Button.mqh>
CButton obj_Btn_MAIN;
CButton obj_Btn_HEADER;
CButton obj_Btn_X;
CButton obj_Btn_TRADE;
CButton obj_Btn_CLOSE;
CButton obj_Btn_INFO;
// ... (other button, edit, and label definitions)
#define Btn_MAIN "Btn_MAIN"
#define Btn_HEADER "Btn_HEADER"
#define Btn_X "Btn_X"
#define Btn_TRADE "Btn_TRADE"
#define Btn_CLOSE "Btn_CLOSE"
#define Btn_INFO "Btn_INFO"
// ... (other defines)
int OnInit() {
obj_Btn_MAIN.Create(0, Btn_MAIN, 0, 30, 30, 0, 0);
obj_Btn_MAIN.Size(310, 300);
obj_Btn_MAIN.ColorBackground(C'070,070,070');
obj_Btn_MAIN.ColorBorder(clrBlack);
obj_Btn_HEADER.Create(0, Btn_HEADER, 0, 30, 30, 0, 0);
obj_Btn_HEADER.Size(310, 25);
obj_Btn_HEADER.ColorBackground(clrLightBlue);
obj_Btn_HEADER.ColorBorder(clrBlack);
obj_Btn_X.Create(0, Btn_X, 0, 30 + 280, 30 + 1, 0, 0);
obj_Btn_X.Size(30 - 1, 25 - 1 - 1);
obj_Btn_X.ColorBackground(clrLightBlue);
obj_Btn_X.ColorBorder(clrLightBlue);
obj_Btn_X.Text(CharToString(255));
obj_Btn_X.Color(clrBlack);
obj_Btn_X.Font("Wingdings");
obj_Btn_X.FontSize(17);
obj_Lbl_HEADER.Create(0, Lbl_HEADER, 0, 40, 30, 0, 0);
obj_Lbl_HEADER.Text("Control Panel");
obj_Lbl_HEADER.Color(clrRed);
obj_Lbl_HEADER.Font("Cooper black");
obj_Lbl_HEADER.FontSize(14);
obj_Btn_TRADE.Create(0, Btn_TRADE, 0, 40, 60, 0, 0);
obj_Btn_TRADE.Size(90, 30);
obj_Btn_TRADE.ColorBackground(clrYellow);
obj_Btn_TRADE.ColorBorder(clrYellow);
obj_Btn_TRADE.Text("Trade");
obj_Btn_TRADE.Color(clrBlack);
obj_Btn_TRADE.Font("Arial Black");
obj_Btn_TRADE.FontSize(13);
obj_Btn_CLOSE.Create(0, Btn_CLOSE, 0, 40 + obj_Btn_TRADE.Width() + 10, 60, 0, 0);
obj_Btn_CLOSE.Size(90, 30);
obj_Btn_CLOSE.ColorBackground(clrSilver);
obj_Btn_CLOSE.ColorBorder(clrSilver);
obj_Btn_CLOSE.Text("Close");
obj_Btn_CLOSE.Color(clrBlack);
obj_Btn_CLOSE.Font("Arial Black");
obj_Btn_CLOSE.FontSize(13);
obj_Btn_INFO.Create(0, Btn_INFO, 0, 40 + obj_Btn_TRADE.Width() + 10 + obj_Btn_CLOSE.Width() + 10, 60, 0, 0);
obj_Btn_INFO.Size(90, 30);
obj_Btn_INFO.ColorBackground(clrSilver);
obj_Btn_INFO.ColorBorder(clrSilver);
obj_Btn_INFO.Text("Inform'n");
obj_Btn_INFO.Color(clrBlack);
obj_Btn_INFO.Font("Arial Black");
obj_Btn_INFO.FontSize(13);
createSection_Trade();
obj_Btn_FOOTER.Create(0, Btn_FOOTER, 0, 30 + 1, 305 - 1, 0, 0);
obj_Btn_FOOTER.Size(310 - 1 - 1, 25);
obj_Btn_FOOTER.ColorBackground(C'070,070,070');
obj_Btn_FOOTER.ColorBorder(C'070,070,070');
obj_Btn_FOOTER.Text(ShortToString(0x23F0) + "https://t.me/Forex_Algo_Trader");
obj_Btn_FOOTER.Color(clrWhite);
obj_Btn_FOOTER.Font("Calibri bold italic");
obj_Btn_FOOTER.FontSize(12);
ChartRedraw(0);
return(INIT_SUCCEEDED);
}Weβre building the cockpitβs framework, like wiring a starshipβs control console. We include MQL5βs trade and control libraries ("Trade/Trade.mqh", "Controls/Button.mqh", "Controls/Edit.mqh", "Controls/Label.mqh") to create buttons, input fields, and labels, defining objects like "obj_Btn_MAIN", "obj_Btn_HEADER", and "obj_Lbl_HEADER". We use #define directives (e.g., "Btn_MAIN") for clean naming, like labeling console switches. In "OnInit()", we create the main panel (310x300 pixels, dark gray), a light blue header with a red βControl Panelβ label in Cooper Black font, a Wingdings βXβ close button, and navigation buttons (βTrade,β βClose,β βInformβnβ) in yellow and silver. The footer flashes our Telegram link, like a shipβs comms beacon. We call "createSection_Trade()" to load the trade section by default, and "ChartRedraw()" paints it all on the chart. This sets up our command center, ready to steer trades, like Captain Kirk prepping the Enterprise bridge!
Step 2: Wiring the Trade ConsoleβBuilding the Trade Section
With the cockpit rigged, we wire the trade console, adding buttons and fields to fire off market and pending orders.
void createSection_Trade(){
obj_Btn_RISK.Create(0,Btn_RISK,0,40,100,0,0);
obj_Btn_RISK.Size(210,25);
obj_Btn_RISK.ColorBackground(clrTurquoise);
obj_Btn_RISK.ColorBorder(clrTurquoise);
obj_Btn_RISK.Text("Risk based on Equity (%)");
obj_Btn_RISK.Color(clrBlack);
obj_Btn_RISK.Font("Arial Black");
obj_Btn_RISK.FontSize(11);
obj_Edit_RISK.Create(0,Edit_RISK,0,40+220,100,0,0);
obj_Edit_RISK.Size(70,25);
obj_Edit_RISK.ColorBackground(clrWhite);
obj_Edit_RISK.ColorBorder(clrBlack);
obj_Edit_RISK.Text("78");
obj_Edit_RISK.Color(clrBlack);
obj_Edit_RISK.Font("Times new roman bold");
obj_Edit_RISK.FontSize(15);
obj_Lbl_PRICE.Create(0,Lbl_PRICE,0,40,130,0,0);
obj_Lbl_PRICE.Text("Price");
obj_Lbl_PRICE.Color(clrWhite);
obj_Lbl_PRICE.Font("Arial black");
obj_Lbl_PRICE.FontSize(13);
obj_Edit_PRICE.Create(0,Edit_PRICE,0,40+60,130,0,0);
obj_Edit_PRICE.Size(90,25);
obj_Edit_PRICE.ColorBackground(clrWhite);
obj_Edit_PRICE.ColorBorder(clrBlack);
obj_Edit_PRICE.Text(DoubleToString(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits));
obj_Edit_PRICE.Color(clrBlack);
obj_Edit_PRICE.Font("Times new roman bold");
obj_Edit_PRICE.FontSize(13);
obj_Lbl_LOTS.Create(0,Lbl_LOTS,0,40+160,130,0,0);
obj_Lbl_LOTS.Text("Lot size");
obj_Lbl_LOTS.Color(clrWhite);
obj_Lbl_LOTS.Font("Arial black");
obj_Lbl_LOTS.FontSize(13);
obj_Edit_LOTS.Create(0,Edit_LOTS,0,40+60+180,130,0,0);
obj_Edit_LOTS.Size(50,25);
obj_Edit_LOTS.ColorBackground(clrWhite);
obj_Edit_LOTS.ColorBorder(clrBlack);
obj_Edit_LOTS.Text("0.01");
obj_Edit_LOTS.Color(clrBlack);
obj_Edit_LOTS.Font("Times new roman bold");
obj_Edit_LOTS.FontSize(13);
obj_Lbl_SL.Create(0,Lbl_SL,0,40,160,0,0);
obj_Lbl_SL.Text("SL");
obj_Lbl_SL.Color(clrWhite);
obj_Lbl_SL.Font("Arial black");
obj_Lbl_SL.FontSize(13);
obj_Edit_SL.Create(0,Edit_SL,0,40+30,160,0,0);
obj_Edit_SL.Size(70,25);
obj_Edit_SL.ColorBackground(clrWhite);
obj_Edit_SL.ColorBorder(clrBlack);
obj_Edit_SL.Text("300");
obj_Edit_SL.Color(clrBlack);
obj_Edit_SL.Font("Times new roman bold");
obj_Edit_SL.FontSize(13);
obj_Lbl_TP.Create(0,Lbl_TP,0,40+190,160,0,0);
obj_Lbl_TP.Text("TP");
obj_Lbl_TP.Color(clrWhite);
obj_Lbl_TP.Font("Arial black");
obj_Lbl_TP.FontSize(13);
obj_Edit_TP.Create(0,Edit_TP,0,40+30+190,160,0,0);
obj_Edit_TP.Size(70,25);
obj_Edit_TP.ColorBackground(clrWhite);
obj_Edit_TP.ColorBorder(clrBlack);
obj_Edit_TP.Text("750");
obj_Edit_TP.Color(clrBlack);
obj_Edit_TP.Font("Times new roman bold");
obj_Edit_TP.FontSize(13);
obj_Btn_POINTS.Create(0,Btn_POINTS,0,40+110,160,0,0);
obj_Btn_POINTS.Size(70,25);
obj_Btn_POINTS.ColorBackground(clrGoldenrod);
obj_Btn_POINTS.ColorBorder(clrGoldenrod);
obj_Btn_POINTS.Text("Points");
obj_Btn_POINTS.Color(clrBlack);
obj_Btn_POINTS.Font("Calibri bold");
obj_Btn_POINTS.FontSize(14);
obj_Btn_SELL.Create(0,Btn_SELL,0,40,210,0,0);
obj_Btn_SELL.Size(100,25);
obj_Btn_SELL.ColorBackground(clrOrangeRed);
obj_Btn_SELL.ColorBorder(clrOrangeRed);
obj_Btn_SELL.Text("Sell");
obj_Btn_SELL.Color(clrWhite);
obj_Btn_SELL.Font("Calibri bold");
obj_Btn_SELL.FontSize(14);
obj_Btn_ENTRY.Create(0,Btn_ENTRY,0,150,210,0,0);
obj_Btn_ENTRY.Size(70,25);
obj_Btn_ENTRY.ColorBackground(clrGoldenrod);
obj_Btn_ENTRY.ColorBorder(clrGoldenrod);
obj_Btn_ENTRY.Text("Entry");
obj_Btn_ENTRY.Color(clrBlack);
obj_Btn_ENTRY.Font("Calibri bold");
obj_Btn_ENTRY.FontSize(14);
obj_Btn_BUY.Create(0,Btn_BUY,0,40+190,210,0,0);
obj_Btn_BUY.Size(100,25);
obj_Btn_BUY.ColorBackground(clrLimeGreen);
obj_Btn_BUY.ColorBorder(clrLimeGreen);
obj_Btn_BUY.Text("Buy");
obj_Btn_BUY.Color(clrWhite);
obj_Btn_BUY.Font("Calibri bold");
obj_Btn_BUY.FontSize(14);
obj_Btn_SELLSTOP.Create(0,Btn_SELLSTOP,0,40,240,0,0);
obj_Btn_SELLSTOP.Size(140,25);
obj_Btn_SELLSTOP.ColorBackground(clrOrangeRed);
obj_Btn_SELLSTOP.ColorBorder(clrOrangeRed);
obj_Btn_SELLSTOP.Text("Sell Stop");
obj_Btn_SELLSTOP.Color(clrWhite);
obj_Btn_SELLSTOP.Font("Calibri bold");
obj_Btn_SELLSTOP.FontSize(14);
obj_Btn_BUYSTOP.Create(0,Btn_BUYSTOP,0,40+190-40,240,0,0);
obj_Btn_BUYSTOP.Size(140,25);
obj_Btn_BUYSTOP.ColorBackground(clrLimeGreen);
obj_Btn_BUYSTOP.ColorBorder(clrLimeGreen);
obj_Btn_BUYSTOP.Text("Buy Stop");
obj_Btn_BUYSTOP.Color(clrWhite);
obj_Btn_BUYSTOP.Font("Calibri bold");
obj_Btn_BUYSTOP.FontSize(14);
obj_Btn_SELLLIMIT.Create(0,Btn_SELLLIMIT,0,40,270,0,0);
obj_Btn_SELLLIMIT.Size(140,25);
obj_Btn_SELLLIMIT.ColorBackground(clrOrangeRed);
obj_Btn_SELLLIMIT.ColorBorder(clrOrangeRed);
obj_Btn_SELLLIMIT.Text("Sell Limit");
obj_Btn_SELLLIMIT.Color(clrWhite);
obj_Btn_SELLLIMIT.Font("Calibri bold");
obj_Btn_SELLLIMIT.FontSize(14);
obj_Btn_BUYLIMIT.Create(0,Btn_BUYLIMIT,0,40+190-40,270,0,0);
obj_Btn_BUYLIMIT.Size(140,25);
obj_Btn_BUYLIMIT.ColorBackground(clrLimeGreen);
obj_Btn_BUYLIMIT.ColorBorder(clrLimeGreen);
obj_Btn_BUYLIMIT.Text("Buy Limit");
obj_Btn_BUYLIMIT.Color(clrWhite);
obj_Btn_BUYLIMIT.Font("Calibri bold");
obj_Btn_BUYLIMIT.FontSize(14);
}Weβre wiring the trade section, like installing thrusters in the cockpit. In "createSection_Trade()", we create buttons and input fields: "obj_Btn_RISK" (turquoise, for equity-based risk), "obj_Edit_RISK" (default 78%), "obj_Edit_PRICE" (set to current ask via "SymbolInfoDouble()", "DoubleToString()"), "obj_Edit_LOTS" (0.01), "obj_Edit_SL" (300 pips), and "obj_Edit_TP" (750 pips). Labels like "obj_Lbl_PRICE" and "obj_Lbl_SL" guide the pilot, styled in white Arial Black. Trade buttons include "obj_Btn_BUY" (lime green), "obj_Btn_SELL" (orange-red), "obj_Btn_ENTRY" (goldenrod, placeholder), and pending order buttons ("obj_Btn_BUYSTOP", "obj_Btn_SELLSTOP", "obj_Btn_BUYLIMIT", "obj_Btn_SELLLIMIT") for setting traps. Each button uses bold fonts (Calibri, Times New Roman) for clarity, like glowing console switches. This section is our launchpad, ready to fire off trades, like setting phasers to stun!
Step 3: Firing the ThrustersβExecuting Trade Commands
With the console wired, we fire thrusters by handling button clicks to execute market and pending orders.
void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam){
if (id == CHARTEVENT_OBJECT_CLICK){
if (sparam==obj_Btn_TRADE.Name()){
Print("OBJECT CLICKED = ", obj_Btn_TRADE.Name());
obj_Btn_TRADE.Pressed(false);
obj_Btn_CLOSE.Pressed(false);
obj_Btn_INFO.Pressed(false);
obj_Btn_TRADE.ColorBackground(clrYellow);
obj_Btn_CLOSE.ColorBackground(clrSilver);
obj_Btn_INFO.ColorBackground(clrSilver);
obj_Btn_TRADE.ColorBorder(clrYellow);
obj_Btn_CLOSE.ColorBorder(clrSilver);
obj_Btn_INFO.ColorBorder(clrSilver);
destroySection_Close();
destroySection_Information();
createSection_Trade();
}
// ... (other navigation button logic)
else if (sparam==obj_Btn_SELL.Name()){
Print("OBJECT CLICKED = ",obj_Btn_SELL.Name());
double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
double lots = StringToDouble(obj_Edit_LOTS.Text());
double entry_price = Bid;
double stopLoss = Ask+StringToDouble(obj_Edit_SL.Text())*_Point;
double takeprofit = Ask-StringToDouble(obj_Edit_TP.Text())*_Point;
Print("Lots = ",lots,", Entry = ",entry_price,", SL = ",stopLoss,", TP = ",takeprofit);
obj_Trade.Sell(lots,_Symbol,entry_price,stopLoss,takeprofit);
}
else if (sparam==obj_Btn_BUY.Name()){
Print("OBJECT CLICKED = ",obj_Btn_BUY.Name());
double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
double lots = StringToDouble(obj_Edit_LOTS.Text());
double entry_price = Ask;
double stopLoss = Bid-StringToDouble(obj_Edit_SL.Text())*_Point;
double takeprofit = Bid+StringToDouble(obj_Edit_TP.Text())*_Point;
Print("Lots = ",lots,", Entry = ",entry_price,", SL = ",stopLoss,", TP = ",takeprofit);
obj_Trade.Buy(lots,_Symbol,entry_price,stopLoss,takeprofit);
}
else if (sparam==obj_Btn_SELLSTOP.Name()){
Print("OBJECT CLICKED = ",obj_Btn_SELLSTOP.Name());
double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
double user_price = StringToDouble(obj_Edit_PRICE.Text());
long stopslevel = SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL);
double valid_price = Bid - stopslevel*_Point;
if (user_price > valid_price){
Print("ERROR: INVALID STOPS PRICE. ",user_price," > ",valid_price);
}
else if (user_price <= valid_price){
double lots = StringToDouble(obj_Edit_LOTS.Text());
double entry_price = user_price;
double stopLoss = user_price+StringToDouble(obj_Edit_SL.Text())*_Point;
double takeprofit = user_price-StringToDouble(obj_Edit_TP.Text())*_Point;
Print("Lots = ",lots,", Entry = ",entry_price,", SL = ",stopLoss,", TP = ",takeprofit);
obj_Trade.SellStop(lots,entry_price,_Symbol,stopLoss,takeprofit);
}
}
else if (sparam==obj_Btn_BUYSTOP.Name()){
Print("OBJECT CLICKED = ",obj_Btn_BUYSTOP.Name());
double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
double user_price = StringToDouble(obj_Edit_PRICE.Text());
long stopslevel = SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL);
double valid_price = Ask + stopslevel*_Point;
if (user_price < valid_price){
Print("ERROR: INVALID STOPS PRICE. ",user_price," < ",valid_price);
}
else if (user_price >= valid_price){
double lots = StringToDouble(obj_Edit_LOTS.Text());
double entry_price = user_price;
double stopLoss = user_price-StringToDouble(obj_Edit_SL.Text())*_Point;
double takeprofit = user_price+StringToDouble(obj_Edit_TP.Text())*_Point;
Print("Lots = ",lots,", Entry = ",entry_price,", SL = ",stopLoss,", TP = ",takeprofit);
obj_Trade.BuyStop(lots,entry_price,_Symbol,stopLoss,takeprofit);
}
}
else if (sparam==obj_Btn_SELLLIMIT.Name()){
Print("OBJECT CLICKED = ",obj_Btn_SELLLIMIT.Name());
double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
double user_price = StringToDouble(obj_Edit_PRICE.Text());
long stopslevel = SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL);
double valid_price = Bid + stopslevel*_Point;
if (user_price < valid_price){
Print("ERROR: INVALID STOPS PRICE. ",user_price," < ",valid_price);
}
else if (user_price >= valid_price){
double lots = StringToDouble(obj_Edit_LOTS.Text());
double entry_price = user_price;
double stopLoss = user_price+StringToDouble(obj_Edit_SL.Text())*_Point;
double takeprofit = user_price-StringToDouble(obj_Edit_TP.Text())*_Point;
Print("Lots = ",lots,", Entry = ",entry_price,", SL = ",stopLoss,", TP = ",takeprofit);
obj_Trade.SellLimit(lots,entry_price,_Symbol,stopLoss,takeprofit);
}
}
else if (sparam==obj_Btn_BUYLIMIT.Name()){
Print("OBJECT CLICKED = ",obj_Btn_BUYLIMIT.Name());
double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
double user_price = StringToDouble(obj_Edit_PRICE.Text());
long stopslevel = SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL);
double valid_price = Ask - stopslevel*_Point;
if (user_price > valid_price){
Print("ERROR: INVALID STOPS PRICE. ",user_price," > ",valid_price);
}
else if (user_price <= valid_price){
double lots = StringToDouble(obj_Edit_LOTS.Text());
double entry_price = user_price;
double stopLoss = user_price-StringToDouble(obj_Edit_SL.Text())*_Point;
double takeprofit = user_price+StringToDouble(obj_Edit_TP.Text())*_Point;
Print("Lots = ",lots,", Entry = ",entry_price,", SL = ",stopLoss,", TP = ",takeprofit);
obj_Trade.BuyLimit(lots,entry_price,_Symbol,stopLoss,takeprofit);
}
}
ChartRedraw(0);
}Weβre firing thrusters in "OnChartEvent()", handling clicks on trade buttons. Clicking "obj_Btn_TRADE" highlights it yellow, resets others to silver via "Pressed()" and "ColorBackground()", and loads the trade section, like flipping to the weapons console. For market orders, "obj_Btn_BUY" uses "SymbolInfoDouble()" for the ask price, grabs "obj_Edit_LOTS.Text()", "obj_Edit_SL.Text()", "obj_Edit_TP.Text()" (e.g., 0.01 lots, 300-pip SL, 750-pip TP), and fires "obj_Trade.Buy()". "obj_Btn_SELL" does the same for sells, using bid price. Pending orders ("obj_Btn_BUYSTOP", "obj_Btn_SELLSTOP", "obj_Btn_BUYLIMIT", "obj_Btn_SELLLIMIT") use "obj_Edit_PRICE.Text()", validated against "SymbolInfoInteger(SYMBOL_TRADE_STOPS_LEVEL)", and execute via "BuyStop()", "SellStop()", "BuyLimit()", "SellLimit()". We log details with "Print()", like βLots = 0.01, Entry = 1.2000, SL = 1.1700, TP = 1.2750.β This is like launching a starship salvo, precise and ready, say, to buy EURUSD at 1.2000 when you spot a breakout. The same logic continues.
Complete files are attached below. Final result should be as below.

Happy algo trading!