[ea]TradeCloser_Ron_MT4_vrt2
Download scriptThis automated trading tool, known as the FrameTrader, is designed to manage your trading portfolio based on a "basket" approach. Rather than focusing on individual trades or complex technical indicators, this script monitors the overall health of your account equity in real-time.
Core Logic Overview
The primary objective of this script is to protect your capital and secure gains by monitoring the net profit or loss of all currently open positions simultaneously. It treats all active trades as a single unit (a "basket").
How It Works
- Real-Time Monitoring: The script constantly calculates the difference between your Account Equity (the current value of your trading account) and your Account Balance. This difference represents your floating profit or loss.
- Profit Targeting: You can set a specific profit goal (BasketProfit). Once the combined profit of all open trades reaches this target, the script will automatically trigger an exit, closing every active position to lock in your gains.
- Loss Protection: Similarly, you can define a maximum loss limit (BasketLoss). If the combined drawdown of your open trades hits this threshold, the script will immediately close all positions to prevent further losses.
- Universal Application: The tool is designed to work across all currency pairs and does not require specific entry signals; it acts as an overarching safety net for your existing trades.
Key Features
- Automated Execution: Once the profit or loss limits are reached, the script handles the closing of all Buy and Sell orders automatically, ensuring quick execution regardless of market fluctuations.
- Slippage Control: It includes a built-in slippage tolerance to ensure that trades are closed efficiently even during periods of high market volatility.
- Visual Feedback: The script provides an on-screen display that constantly updates you on your current "Profit/Loss" status, allowing you to see how close you are to your targets at any given moment.
Summary for the User
In simple terms, this is a Safety and Profit Management tool. It does not decide when to enter a trade; instead, it sits in the background and watches your total portfolio. When your combined trades hit your desired profit goal or your predefined risk limit, it "flattens" your position by closing everything out instantly.
/*-----------------------------+
| |
| 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 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;
//Basket profit or loss
currBasket=AccountEquity()-AccountBalance();
Comment("Profit/Loss = ",currBasket);
if(currBasket>=BasketProfit || currBasket<=(BasketLoss*(-1)) )
{
// 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