CLiveTradeInfo - CHistoryTradeInfo

CLiveTradeInfo - CHistoryTradeInfo
Download ALL MT5 experts (1731)
YouTube Video Thumbnail



Similar MetaTrader Tools

CLiveTradeInfo - CHistoryTradeInfo

Info

The CLiveTradeInfo - CHistoryTradeInfo is a Expert Advisor for MetaTrader 5 that introductionmql4tradecompat is a compatibility framework that recreates the classic mql4 order-centric trading model on top of the native mql5 trading architecture. The library allows legacy MQL4-style code to continue using familiar functions such as:OrderSelect()OrderSend()OrderModify()OrderClose()OrderDelete()OrdersTotal()OrdersHistoryTotal()while internally translating all operations into native MQL5 Position, Order, Deal, and History APIs.

Usage

This tool is typically used for automated trading on major forex pairs and gold.

Platform

This Expert Advisor works exclusively on MetaTrader 5 (both build 600+ and newer versions).

Setup

Place the downloaded file in MQL5/Experts folder via File ? Open Data Folder in MetaTrader 5.


How to Install and Use CLiveTradeInfo - CHistoryTradeInfo

1. Installation: Open the "File" menu, select "Open Data Folder," navigate to MQL/Experts, paste your file, and restart the terminal.

2. Activation: Drag the EA from the Navigator onto a chart, ensure "Allow live trading" is checked in the Common tab, and verify the AutoTrading button is green.

3. Optimization: Right-click your chart, choose "Expert List," click "Properties" to adjust inputs, and save your preferred setup as a set file for future use.

4. Maintenance: Regularly check the "Experts" tab in the terminal window to monitor trade logs and potential execution errors.

Frequently Asked Questions

Q: Why is my EA not opening trades? A: Check the "AutoTrading" button, ensure "Allow live trading" is enabled, and verify your broker allows automated trading on your account type.

Q: Can I run multiple EAs on one chart? A: No, each chart can only host one active EA; however, you can open multiple charts for different currency pairs to run several EAs.

Q: What does the "smiley face" icon mean? A: A smiley face in the top-right corner of the chart indicates the EA is successfully running; a frowny face means it is disabled.

What this tool does

IntroductionMQL4TradeCompat is a compatibility framework that recreates the classic MQL4 order-centric trading model on top of the native MQL5 trading architecture.

Typical Use Case

This Expert Advisor excels in automated trading and technical analysis on MetaTrader 5.

Compatible Platform & Setup

This Expert Advisor works on MetaTrader 5. Place the file in the MQL5/Experts folder and restart the terminal.

Description & Settings

Related: Silver Trend Trading System - another powerful expert for MetaTrader 5 traders.

Introduction

MQL4TradeCompat is a compatibility framework that recreates the classic MQL4 order-centric trading model on top of the native MQL5 trading architecture.

Also recommended: price action intraday trading expert for mt5 - similar expert with strong performance on MetaTrader 5.


The library allows legacy MQL4-style code to continue using familiar functions such as:

OrderSelect()

OrderSend()
OrderModify()
OrderClose()
OrderDelete()

OrdersTotal()
OrdersHistoryTotal()

while internally translating all operations into native MQL5 Position, Order, Deal, and History APIs.



Design Goal

MQL4 is based on a single order model:

Open Orders
Pending Orders
History Orders

MQL5 introduced a more complex structure:

Positions
Orders
Deals
History Orders

The primary goal of this framework is to hide this complexity and expose a unified MQL4-compatible interface.



Core Components

1. CMQL4TradeCompat

Role

Public compatibility facade.

Responsibilities

OrderSelect()

OrderSend()
OrderModify()
OrderClose()
OrderDelete()

OrdersTotal()
OrdersHistoryTotal()

Purpose

Provides the same programming experience as MQL4 while internally dispatching requests to MQL5 APIs.

2. CLiveTradeInfo

Role

Live Trade Repository.

Responsibilities

Unifies:

Open Positions
Pending Orders

into a single logical collection.

Key Features

Position aggregation

Pending order aggregation

Unified ticket selection

MQL4-style indexing

Snapshot-based cache

Chronological sorting

3. CHistoryTradeInfo

Role

History Reconstruction Engine.

Responsibilities

Builds logical historical trade records from:

Deals
Closed Positions
Historical Orders

Key Features

Position reconstruction from deal chains

Closed-trade aggregation

Pending-order history support

Profit/commission/swap calculation

Weighted close-price calculation

Historical ticket tracking



Architecture Flow

Legacy MQL4 EA
|
v
+----------------------++
| CMQL4TradeCompat ||
+----------+-----------+
|
+-------+-------++
| |
v v
+--------+ +---------+
| Live | | History |
| Repository | Engine |
+----+---+ +----+----+
| |
+------+------++
|
v
+----------------------++
| Native MQL5 API ||
+----------------------++
| CTrade ||
| CPositionInfo ||
| COrderInfo | |
| CDealInfo | |
| CHistoryOrderInfo | |
+----------------------++



MQL4 Compatibility Mapping

MQL4 Function

Internal MQL5 Layer

OrderSelect

Live/History Repository

OrderSend

CTrade

OrderClose

PositionClose / PartialClose

OrderModify

PositionModify / OrderModify

OrderDelete

OrderDelete

OrdersTotal

Live Repository

OrdersHistoryTotal

History Repository



Repository Strategy

Instead of directly coupling every API call to MQL5 objects, the framework introduces a repository layer.

Live Repository

Positions
+
Pending Orders
↓
Unified Trade Pool

History Repository

Deals
+
Historical Orders
↓
Unified Historical Pool

This design makes MQL4 emulation significantly cleaner and easier to maintain.



Testing Strategy

The framework includes a dedicated integration test suite.

Validated Operations

✅ Market Buy

✅ Pending Order Placement

✅ Order Selection

✅ Order Modification

✅ Position Modification

✅ Position Close

✅ Pending Order Deletion

✅ Live Repository Refresh

✅ History Repository Validation

Test Environment

Demo Account
Real Trading Server
Native MT5 Engine

The framework was validated through actual trade execution rather than mock testing.

Risk:
The demo test is for testing purposes, is not for live trading.

Output:

========== MQL4TradeCompat test started ==========

Symbol
: EURUSD | volume: 0.01 | digits: 5

PASS: Symbol market data is valid
PASS: OrderSend OP_BUY
PASS: OrderSelect opened position by ticket
PASS: Initial SL/TP are zero
PASS: OrderModify open position
PASS: Modified Stop Loss verified
PASS: Modified Take Profit verified
PASS: OrderClose full position
PASS: Closed position is no longer in MODE_TRADES
PASS: OrderSend OP_BUYLIMIT
PASS: OrderSelect pending order by ticket
PASS: OrderModify pending order
PASS: OrderDelete pending order
PASS: Deleted pending order is no longer in MODE_TRADES
========== MQL4TradeCompat test summary ==========

PASS: 14 | FAIL: 0 | SKIP: 0

RESULT: PASS
========== MQL4TradeCompat test finished ==========



Technical Summary

MQL4TradeCompat is not merely a wrapper library. It is a lightweight MQL4 runtime emulation layer that reconstructs the classical MQL4 trading environment on top of the MQL5 execution model. Through dedicated live and historical repositories, the framework provides a unified order-centric view that simplifies migration of legacy Expert Advisors while preserving native MQL5 execution capabilities.

You may also like: Manual Trade Pad for MetaTrader 5 Strategy Tester - excellent alternative for expert users on MetaTrader 5.

Source Code

#property copyright "RobotFX"
#property link "https://robotfx.org"
#property version   "1.00"
#property description "This code is educational. Feel free to use, modify and upgrade as you wish. Visit ROBOTFX.ORG for professional trading tools"
#property strict
#property script_show_inputs
#include <MQL4TradeCompat.mqh>
CMQL4TradeCompat trade;
int passed=0;
int failed=0;

.......

Leave your opinion, ask a question, share some knowledge

⚠ Limitations & Risk Warning

  • This tool is provided for educational and testing purposes only.
  • Past performance does not guarantee future results.
  • Trading involves substantial risk of loss. Use on a demo account first.
  • Results may vary depending on market conditions, broker, and settings.
  • We recommend thorough backtesting and forward testing before using with real funds.
© ROBOTFX Free educational tools by RobotFX. Use entirely at your own risk; we are not liable for any financial losses incurred.