How do I check details of an open trade?

 
Hello, I am new to coding with MQL4 and Expert Advisers. I have been writing my own EA for a couple days now and it has been running well however I would like to know how I could check the details of all the currently open trades individually and close then if a certain condition is met (Such as if the trade is taking too many losses then it should exit) Been looking through the Reference with no luck, Can anyone help? I would really appreciate it 🙏
 
Lazy Forex:
Hello, I am new to coding with MQL4 and Expert Advisers. I have been writing my own EA for a couple days now and it has been running well however I would like to know how I could check the details of all the currently open trades individually and close then if a certain condition is met (Such as if the trade is taking too many losses then it should exit) Been looking through the Reference with no luck, Can anyone help? I would really appreciate it 🙏

Read the documentation available in MetaEditor (Menu->Help-MQL4 Reference) and navigate to Trade Functions. There are functions to find out current state of an Order, such as it volume, current price, stop-loss and take-profit, etc.

There are examples in the documentation, but there are also many examples in the CodeBase.

Alternatively read a good book on MQL4 programming:

Forum on trading, automated trading systems and testing trading strategies

Something Interesting to Read

Sergey Golubev, 2017.09.16 05:40

Expert Advisor Programming for MetaTrader 4


This book will teach you the following concepts:

  • The basic of the MLQ4 language, including variables and data types, operations, conditional and loop operators, functions, classes and objects, event handlers and more.
  • Place, modify and close market and pending orders.
  • Add a stop loss and/or take profit price to an individual order, or to multiple orders.
  • Close orders individually or by order type.
  • Get a total of all currently opened orders.
  • Work with OHLC bar data and locate basic candlestick patterns.
  • Find the highest high and lowest low of recent bars.
  • Work with MetaTrader’s built-in indicators, as well as custom indicators.
  • Add a trailing stop or break even stop feature to an expert advisor.
  • Use money management and lot size verification techniques.
  • Add a flexible trading timer to an expert advisor.
  • Construct several types of trading systems, including trend, counter-trend and breakout systems.
  • Add alert, emails, sounds and other notifications.
  • Add and manipulate chart objects.
  • Read and write to CSV files.
  • Construct basic indicators, scripts and libraries.
  • Learn how to effective debug your programs, and use the Strategy Tester to test your strategies.

All of the source code in this book is available for download, including an expert advisor framework that allows you to build robust and fully-featured expert advisors with minimal effort.