[ea]TradeCloser_Ron_MT4_vrt

Download script
Author: Ron Thompson
[ea]TradeCloser_Ron_MT4_vrt

This script, known as FrameTrader, is an automated trading tool designed to manage your open positions based on your overall account equity. Unlike many trading robots that look for complex patterns or technical indicators to enter a trade, this tool focuses specifically on Risk Management and Exit Logic.

Core Functionality

The primary purpose of FrameTrader is to monitor the real-time "Basket Profit/Loss." It calculates the difference between your current Account Equity (the total value of your account including floating profits and losses) and your Account Balance (your cash position).

Essentially, it looks at your entire portfolio to see if you have reached a specific financial threshold.

How It Works

  • Real-Time Monitoring: The script constantly scans your open trades every time the market moves (on every "tick").
  • The Threshold Check: It compares your current floating profit or loss against a user-defined limit called the Basket Loss.
  • Automatic Execution: If the total floating value of your open positions falls below that specific threshold, the script immediately identifies all active Buy and Sell orders across all symbols.
  • Universal Exit: Once the trigger is hit, the script automatically closes every open trade to secure your position and prevent further drawdown beyond your specified limit.

Key Features for the User

  • Multi-Pair Compatibility: It does not restrict itself to a single currency pair; it monitors all active trades on your account simultaneously.
  • Visual Feedback: The script provides a real-time display on your trading chart, showing you your current Profit/Loss status at all times.
  • Safety Net: By automating the closure of trades when a specific loss limit is reached, it serves as an automated "emergency brake," helping to protect your capital from significant swings in the market.

Summary of Operation

In simple terms, FrameTrader acts as a safety supervisor. It doesn't tell you when to buy or sell; instead, it watches your total account balance and ensures that if your open trades collectively reach a certain loss level, all positions are closed instantly to preserve your remaining funds.

14 Views
0 Downloads
0 Favorites
[ea]TradeCloser_Ron_MT4_vrt
/*-----------------------------+
|			       |
| 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 Basketloss=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<Basketloss)
     {
      // 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