[ea]TradeCloser_Ron_MT4_v00

Download script
Author: Ron Thompson
[ea]TradeCloser_Ron_MT4_v00

This script is designed to function as a automated "Basket Profit" manager for your trading account. Rather than looking for specific technical patterns or predicting market movements, its primary role is to monitor your total account performance in real-time and execute a clean exit once a specific financial milestone is reached.

Core Functionality

The logic operates on a global level, meaning it looks at your overall account status rather than focusing on the specifics of a single trade. It calculates the current floating profit or loss by comparing your Account Equity (your actual value right now) against your Account Balance (your starting value for the period).

How It Works

  1. Real-Time Monitoring: The script continuously scans your open positions every time the market moves (on every "tick"). It keeps a running tally of whether your currently open trades are in profit or loss.
  2. Profit Target Detection: You set a specific dollar amount as your target goal. The script monitors the total net gain across all your active trades.
  3. Automatic Execution: As soon as the combined profit of all your open positions exceeds your pre-defined target, the script takes action. It will automatically scan every open "Buy" and "Sell" position in your account and close them instantly at the current market price.

Key Features for the User

  • Basket Management: This is ideal for traders who prefer to manage multiple trades simultaneously as a single "basket." Once the goal of that basket is met, everything is cleared out at once.
  • Visual Feedback: The script provides a live update on your chart, displaying your current total profit or loss so you can see how close you are to your target in real-time.
  • Universal Compatibility: Because it monitors the account equity level rather than specific symbols, it works across all currency pairs and assets managed within your trading platform.
  • Simplicity: There are no complex entry rules or risk management filters included; it is a straightforward "take profit" tool designed to secure gains once your desired money goal is achieved.
Orders Execution
Checks for the total of open ordersIt Closes Orders by itself
14 Views
0 Downloads
0 Favorites
[ea]TradeCloser_Ron_MT4_v00
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

/*
+------------+
|FrameTrader |
+------------+

Theory of operation


TIME FRAME
==========
Close at equity level with a profit :)


PAIRS
=====
ALL

ENTRY LONG
==========


ENTRY SHORT
===========


EXIT
====


MONEY MANAGEMENT
================
-none-


RISK MANAGEMENT
===============
-none-


FAILURE MANAGEMENT
==================
-none-


VERSION HISTORY
===============
00    - initial concept

*/


#property copyright "Ron Thompson"
#property link      "http://www.lightpatch.com/forex"

// user input
extern double BasketProfit=50;
extern double Slippage=3;

//+-------------+
//| Custom init |
//|-------------+
// Called ONCE when EA is added to chart or recompiled

int init()
  {
   Print("Init happened ",CurTime());
   Comment(" ");
  }


//+----------------+
//| Custom DE-init |
//+----------------+
// Called ONCE when EA is removed from chart

int deinit()
  {
   Print("DE-Init happened ",CurTime());
   Comment(" ");
  }


//+-----------+
//| Main      |
//+-----------+
// Called EACH TICK and each Bar[]

int start()
  {
   
   int      cnt=0;
   int      gle=0;
   int      OrdersOpenCount=0;

   string mySymbol;
   double myAsk;
   double myBid;   

   double   currBasket=0;

   currBasket=AccountEquity()-AccountBalance();
   Comment("Profit/Loss = ",currBasket);
   
   if(currBasket>BasketProfit)
     {
      // CLOSE order if profit target made
      for(cnt=OrdersTotal(); cnt>=0; cnt--)
        {
         OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
         if( OrderType()==OP_BUY || OrderType()==OP_SELL )
           {
            mySymbol=OrderSymbol();
 
            if(OrderType()==OP_BUY)
              {
               myBid=MarketInfo(mySymbol,MODE_BID);            
               OrderClose(OrderTicket(),OrderLots(),myBid,Slippage,White);
               gle=GetLastError();
               if(gle==0)
                 {
                  Print("CLOSE BUY  Bid=",myBid); 
                 }
                  else 
                 {
                  Print("-----ERROR----- CLOSE BUY  Bid=",myBid," error=",gle);
                 }
              } // if BUY


            if(OrderType()==OP_SELL)
              {
               myAsk=MarketInfo(mySymbol,MODE_ASK);            
               OrderClose(OrderTicket(),OrderLots(),myAsk,Slippage,Red);
               gle=GetLastError();
               if(gle==0)
                 {
                  Print("CLOSE SELL Ask=",myAsk);
                 }
                  else 
                 {
                  Print("-----ERROR----- CLOSE SELL Ask=",myAsk," error=",gle);
                 }
              } //if SELL
           
           } // if(OrderSymbol)
        
        } // for

     } //currBasket

  } // start()




Comments