System Trading 게시글

Maximize Your Trading Efficiency with AutoCloseOnProfitLoss EA for MetaTrader 5

첨부파일
59371.zip (1.6 KB, 다운로드 0회)

Introduction

Hey there, fellow traders! If you’re looking to streamline your trading process and manage your positions with ease, let me introduce you to the AutoCloseOnProfitLoss Expert Advisor (EA). This nifty tool for MetaTrader 5 automatically closes all your open trades once you hit your desired profit or loss targets. It's a game-changer for anyone wanting to safeguard their gains or cut losses without having to keep a constant eye on the market. Whether you’re a scalper aiming for quick profits or a long-term investor looking to protect your capital, this EA provides a hassle-free solution.

Key Features

  • Automated Position Closing: Closes all open trades automatically when your total profit or loss hits your set limits.
  • Customizable Targets: Easily set your profit and loss targets in your preferred currency (like USD or GBP).
  • Flexible Options: Choose whether to close trades based on profit, loss, or both.
  • User Notifications: Get alerts and logs in your terminal whenever positions are closed.
  • Efficient and Lightweight: Runs smoothly without hogging your CPU, making it perfect for ongoing trade management.

How It Works

This EA keeps an eye on your total profit or loss using the PositionGetDouble(POSITION_PROFIT) function in MetaTrader 5. It checks your total against the thresholds you’ve set for TargetProfit and MaxLoss. Once one of these conditions is met (and if you've enabled that option), the EA swiftly closes all positions using market orders and sends you an alert (if you’ve turned that feature on).

Installation Guide

  1. Download the AutoCloseOnProfitLoss.mq5 file from the MQL5 CodeBase.
  2. Open MetaTrader 5 and navigate to File > Open Data Folder.
  3. Go to MQL5 > Experts and paste the .mq5 file into this folder.
  4. Restart MetaTrader 5 or refresh the Navigator panel.
  5. Find the EA in the Navigator under Expert Advisors, and drag it onto your chart to activate it.

Input Parameters

  • TargetProfit (default: 100.0): The profit target in your currency to close all positions.
  • MaxLoss (default: -50.0): The maximum loss in your currency (must be a negative value) to close all positions.
  • EnableProfitClose (default: true): Toggle to close positions when your profit target is reached.
  • EnableLossClose (default: true): Toggle to close positions when your maximum loss is hit.
  • ShowAlerts (default: true): Enable or disable alerts in MetaTrader 5 when positions are closed.

How to Use

  1. Drag the AutoCloseOnProfitLoss EA onto any chart in MetaTrader 5.
  2. In the dialog that pops up, adjust the input parameters:
    • Set your preferred TargetProfit and MaxLoss.
    • Decide whether to enable profit/loss closing.
    • Choose if you want to receive alerts.
  3. Click OK to start the EA.
  4. The EA will keep watching your trades and close them if the conditions are met.
  5. Check the Experts or Journal tab in MetaTrader 5 for logs and results.

Example Scenario

Let's say you set TargetProfit = 100.0, MaxLoss = -50.0, EnableProfitClose = true, and EnableLossClose = true. If your open trades reach a total profit of $120, the EA will automatically close all positions and notify you with an alert: "All positions closed! Reason: Target profit reached: 120.00". Conversely, if your total loss reaches -$60, it will also close all positions with an alert: "All positions closed! Reason: Max loss reached: -60.00".

Important Notes

  • The EA needs open positions to take action; if none are open, it will just log the current profit/loss and keep monitoring.
  • Positions are closed using market orders, so keep in mind that slippage might occur depending on market conditions.
  • It's wise to test the EA on a demo account first to make sure it aligns with your trading strategy.
  • This EA runs continuously until you manually stop it or remove it from the chart, unlike a script that executes once.

We Want Your Feedback!

If you have any suggestions or run into issues, feel free to drop a comment on the MQL5 CodeBase page or get in touch with me through the MQL5 community. Your insights are crucial for enhancing this tool!

Author: Duy Van Nguy
Contact: MQL5 Link
Updated: May 14, 2025
Platform: MetaTrader 5
Category: Expert Advisors

연관 포스트

댓글 (0)