Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

Monitoring position closing panel - source code download and deployment instructions | Foreign exchange EA download | MT4/MT5 download - MetaTrader 5 resources

author EAcpu | 2 reads | 0 comments |

Monitor the position closing panel - the source code optimization target records the position closing log in detail: record the specific time of each position closing, order ticket number, closing price, profit and loss and other information. Record the triggering reasons for batch closing (profit or loss), the total number of orders and the number of positions. Enhanced position closing monitoring: Check whether the order is actually closed successfully. If closing the position fails, detailed error information will be recorded. Optimize the position closing logic: Ensure the position closing operation is more stable and avoid repeated position closing or missing orders. Reduce unnecessary calculations and improve performance. cpp //+------------------------------------------------------------------+ //| Trading Panel System.mq4 | //| Copyright © 2023-2025, AI Programming zblog | //| http://www.eawalk.com| //+----------------------------------------------------------------+ #propertycopyright "Copyright 2024, eawalk.com" #propertylink "http://www.eawalk.com" stringver = "basket 1.1"; // Trading panel system.mq4 #propertyversion "1.00" #propertystrict //---Input parameters inputdouble Profit = 50; // Profit target (unit: currency) inputdouble TotalCloseValue = 10000; // Total loss value (close position when this value is reached, unit: currency) inputint MonitorTickInterval = 8; // Monitor TICK interval (unit: tick) inputcolor TextColor = White; // Text color inputint TextSize = 12; // Text font size inputint PanelWidth = 200; // Panel width (pixels, used for positioning) inputint PanelHeight = 100; // Panel height (pixels, used for positioning) inputint PanelXOffset = 10; // Panel offset from the right side (pixels) inputint PanelYOffset = 10; // Panel offset from the top (pixels) //---Global variable datetimelastTickTime = 0; intgMonitorTickInterval; // Store a modifiable copy of MonitorTickInterval intgPanelWidth; // Store a modifiable copy of PanelWidth intgPanelHeight; // Store a modifiable copy of PanelHeight intcloseCount = 0; // Record the number of batch closings intgPanelXOffset; // Store PanelXOffset Modifiable copy of intgPanelYOffset; // Store a modifiable copy of PanelYOffset //+------------------------------------------------------------------+ //|Expert initialization function| //+------------------------------------------------------------------+ intOnInit() { // Check parameters during initialization and assign values to global variables gMonitorTickInterval = MonitorTickInterval; if (gMonitorTickInterval < 1) gMonitorTickInterval = 1; // Make sure the gap is valid gPanelWidth = PanelWidth; if (gPanelWidth < 100) gPanelWidth = 100; // Make sure the panel width is valid gPanelHeight = PanelHeight; if (gPanelHeight < 50) gPanelHeight = 50; // Make sure the panel height is valid gPanelXOffset = PanelXOffset; if (gPanelXOffset < 0) gPanelXOffset = 0; // Ensure the offset is valid gPanelYOffset = PanelYOffset; if (gPanelYOffset < 0) gPanelYOffset = 0; // Ensure the offset is valid return(INIT_SUCCEEDED); } //+--------------------------------------------------------------------------------+ //|Expert deinitialization function | //+--------------------------------------------------------------------------------+ voidOnDeinit(const int reason) { // Clean up all panel-related objects ObjectsDeleteAll(0, "Panel_"); } //+------------------------------------------------------------------+ //|Execute function every tick| //+------------------------------------------------------------------+ voidOnTick() { // Execute every gMonitorTickInterval ticks if (TimeCurrent() - lastTickTime < gMonitorTickInterval * Point)return; lastTickTime = TimeCurrent(); // Draw information panel DrawInfoPanel(); // Check trading logic (profit/loss) CheckTradingLogic(); } //+------------------------------------------------------------------+ //|Draw information panel (only text, no background) | //+------------------------------------------------------------------+ voidDrawInfoPanel() { // Get the chart width to dynamically position it to the upper right corner int chartWidth = (int)ChartGetInteger(0, CHART_WIDTH_IN_PIXELS); int panelX = chartWidth - gPanelWidth - gPanelXOffset; // Offset from the right // Display profit information if (!ObjectCreate(0, "Panel_Profit", OBJ_LABEL, 0, 0, 0)) return; ObjectSetInteger(0, "Panel_Profit", OBJPROP_XDISTANCE, panelX +10); ObjectSetInteger(0, "Panel_Profit", OBJPROP_YDISTANCE,gPanelYOffset + 20); ObjectSetString(0, "Panel_Profit", OBJPROP_TEXT, "Profit: " + DoubleToString(Profit,2)); ObjectSetInteger(0, "Panel_Profit", OBJPROP_COLOR, TextColor); ObjectSetInteger(0, "Panel_Profit", OBJPROP_FONTSIZE,TextSize); // Display the total loss value if (!ObjectCreate(0, "Panel_TotalClose", OBJ_LABEL, 0, 0, 0)) return; ObjectSetInteger(0, "Panel_TotalClose", OBJPROP_XDISTANCE,panelX + 10); ObjectSetInteger(0, "Panel_TotalClose", OBJPROP_YDISTANCE,gPanelYOffset + 40); ObjectSetString(0, "Panel_TotalClose", OBJPROP_TEXT, "Total loss value: " +DoubleToString(TotalCloseValue, 2)); ObjectSetInteger(0, "Panel_TotalClose", OBJPROP_COLOR,TextColor); ObjectSetInteger(0, "Panel_TotalClose", OBJPROP_FONTSIZE,TextSize); // Display the number of closing positions if (!ObjectCreate(0, "Panel_CloseCount", OBJ_LABEL, 0, 0, 0)) return; ObjectSetInteger(0, "Panel_CloseCount", OBJPROP_XDISTANCE,panelX + 10); ObjectSetInteger(0, "Panel_CloseCount", OBJPROP_YDISTANCE,gPanelYOffset + 60); ObjectSetString(0, "Panel_CloseCount", OBJPROP_TEXT, "Number of positions closed: " +IntegerToString(closeCount)); ObjectSetInteger(0, "Panel_CloseCount", OBJPROP_COLOR,TextColor); ObjectSetInteger(0, "Panel_CloseCount", OBJPROP_FONTSIZE,TextSize); } //+--------------------------------------------------------------------------------+ //|Check transaction logic| //+--------------------------------------------------------------------------------+ voidCheckTradingLogic() { // Calculate the total loss of all current orders double totalLoss = 0; for (int i = OrdersTotal() - 1; i >= 0; i--) { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() == Symbol()) { double orderProfit = OrderProfit() +OrderSwap() + OrderCommission(); if (orderProfit < 0) // Only losing orders are calculated { totalLoss += MathAbs(orderProfit);// Accumulated loss value (take absolute value) } } } } // Close all orders when the total loss reaches TotalCloseValue if (totalLoss >= TotalCloseValue) { bool batchClosed = false; // Mark whether batch closing occurs for (int i = OrdersTotal() - 1; i >= 0; i--) { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() == Symbol()) { bool closed =OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 3, clrRed); if (closed) { batchClosed = true; // As long as one order is successfully closed, it is marked as batch closing Print("Closed due to total loss: ",totalLoss); } else { Print("Failed to close the position, error code #",GetLastError()); } } } } if (batchClosed) { closeCount++; // After batch closing is successful, the count increases by 1 Print("Batch closing is completed, total number of closings: ", closeCount); } } // Profit-based closing conditions double currentProfit = AccountProfit(); if (currentProfit >= Profit) { bool batchClosed = false; // Mark whether batch closing occurs for (int i = OrdersTotal() - 1; i >= 0; i--) { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() == Symbol()) { bool closed = OrderClose(OrderTicket(),OrderLots(), OrderClosePrice(), 3, clrRed); if (closed) { batchClosed = true; // As long as one order is successfully closed, it will be marked as batch closing Print("Closing due to profit: ",currentProfit); } else { Print("Closing failed, error code #",GetLastError()); } } } } if (batchClosed) { closeCount++; // After the batch closing is successful, the count will be increased by 1 Print("Batch closing completed, total number of closings: ", closeCount); } } } //+------------------------------------------------------------------+ 2018080503263266.jpg

Monitoring and Closing Panel - Source Code Download and Deployment Instructions | Important points before downloading and using foreign exchange EA

This page has been reorganized according to the reading path of search users, focusing on the applicable scenarios of EA source code, MQL4/MQL5 platform compatibility, parameter testing methods and real-time risk warnings, so as to quickly judge whether it is worth continuing to test before downloading or deploying.

Suitable for who to use

  • Traders who need to quickly screen EA source code and are willing to do simulation verification first.
  • People who are already familiar with the MT4/MT5 installation process and want to compare different EAs, indicators or source code projects.
  • People who want to record the backtest, parameters and risk control before deciding whether to enter the real market.

Testing and risk control suggestions

  • First use the default parameters for basic backtesting, and then adjust them one by one according to the variety, cycle and spread.
  • Grid, Martin, and scalping strategies should focus on observing maximum drawdown, continuous losses, and trading frequency.
  • It is recommended to observe the simulated trading performance for at least 2-4 weeks before the actual trading, and limit the account risk proportion of a single strategy.

FAQ

Can this file be sold directly?
It is not recommended to make a direct offer. Any EA or indicator requires first checking the source, parameters, platform version and historical performance.

Can MT4 and MT5 be used interchangeably?
Usually it cannot be used directly. MQ4/EX4 corresponds to MT4, MQ5/EX5 corresponds to MT5, and the source code project also needs to be compiled in the corresponding MetaEditor.

What else can I continue to watch?
Forex EA download , foreign exchange indicator download , EA evaluation , GitHub open source EA , MQL5 CodeBase .

English Search Notes

This page is also optimized for English search intent around monitoring and closing panel - source code download and deployment instructions | Forex EA download . Related search terms include: MQL4 source code, MQL5 source code. Test any Forex EA, Expert Advisor, MT4/MT5 indicator or MQL source code with historical data and a demo account before live trading.

Verification code Refresh