TrendS
Download scriptThis automated trading script is designed to manage and execute trades based on trend analysis, price action signals, and dynamic risk management. It operates by monitoring the live market to identify specific entry points while automatically closing existing positions when certain technical conditions are met.
Automated Trade Management
The system begins by assessing your account's financial status to determine the appropriate position size. It offers two main methods:
- Fixed Lot Sizing: A standard approach where every trade uses a pre-defined, constant amount of capital.
- Dynamic Risk Management: A more sophisticated mode that calculates your trade size based on a percentage of your current account balance. This ensures that the volume traded is proportional to your available funds, helping to maintain consistent risk levels across different account sizes.
Trade Execution Logic
The script focuses on finding high-probability entries by combining two types of market data: moving averages (which indicate the general trend) and "highest/lowest" price points (which identify immediate price extremes).
For Buying Positions (Long):
- The system looks for a "Bullish" trend, defined as a short-term fast average crossing above a longer-term slower average.
- Simultaneously, it waits for the current price to drop to its lowest point over a specific recent period. This creates a "buy the dip" scenario where the script enters a trade only when the market shows strength but offers a temporary price discount.
For Selling Positions (Short):
- The system looks for a "Bearish" trend, defined as a short-term fast average crossing below a longer-term slower average.
- It then waits for the current price to rise to its highest point over a specific recent period. This allows the script to enter a trade on the "pullback," selling when the market is showing weakness but at a temporary peak.
Automated Exit Strategy
One of the primary functions of this script is its proactive exit logic. It continuously monitors any open positions to see if the market direction has shifted significantly:
- For Buy Orders: If the price climbs above a recent high point, the script assumes the move may have peaked or changed character and will automatically close the position to secure the trade.
- For Sell Orders: If the price drops below a recent low point, the script identifies this as a potential reversal and closes the sell position accordingly.
Safety Features
To protect your capital, every trade initiated by the system is automatically equipped with a "Stop Loss." This ensures that if a trade moves against your ожидания (expectations), the system will automatically exit the position at a pre-determined price point to limit potential losses.
//+------------------------------------------------------------------+
//| TrendS.mq4 |
//| Copyright © 2006, xxx |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "xxx"
#property link "http://www.xxx.ru/"
extern double LotsIfNoMM=0.1;
extern int StopLoss=50;
extern int Slip=5;
extern int MM_Mode=0;
extern int MM_Risk=40;
double Opentrades,orders,first,mode,Ilo,sym,b,tmp,GridCellPoint,OpenOrderStopLoss;
double b4signal,Signal,Triggerline,b4Triggerline,Nowsignal,NowTriggerline,sl,LastOpByExpert,LastBarChecked;
int cnt,cnt2,OpenPosition,notouchbar,PendingOrderTicket,OpenOrderTicket;
bool test;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//return(0);
//if ( ! IsTesting() ) Comment(" Trailingstop ", b, "\n"," Tick no. ", iVolume(NULL,0,0),"\n"," Lots ",Ilo);
if (MM_Mode < 0) {
Ilo = MathCeil(AccountBalance()*MM_Risk/10000)/10;
if (Ilo > 100) {
Ilo = 100;
}
} else {
Ilo = LotsIfNoMM;
}
if (MM_Mode > 0)
{
Ilo = MathCeil(AccountBalance()*MM_Risk/10000)/10;
if (Ilo > 1)
{
Ilo = MathCeil(Ilo);
}
if (Ilo < 1)
{
Ilo = 1;
}
if (Ilo > 100)
{
Ilo = 100;
}
}
Opentrades=0;
for (cnt=0;cnt<OrdersTotal();cnt++)
{
if ( OrderSelect (cnt, SELECT_BY_POS) == false ) continue;
if ( OrderSymbol()==Symbol())
{
Opentrades=Opentrades+1;
}
}
if (Opentrades!=0)
{
if (OrderType()==OP_BUY)
{
if (Bid>=iHigh(Symbol(),0,Highest(Symbol(),0,MODE_HIGH,6,1)))
{
OrderClose(OrderTicket(),OrderLots(),Bid,Slip,Red);
Opentrades--;
}
}
else if (OrderType()==OP_SELL)
{
if (Bid<=iLow(Symbol(),0,Lowest(Symbol(),0,MODE_LOW,6,1)))
{
OrderClose(OrderTicket(),OrderLots(),Ask,Slip,Red);
Opentrades--;
}
}
}
if (Opentrades==0)
{
if (iMA(Symbol(),0,6,0,MODE_EMA,PRICE_CLOSE,1)>iMA(Symbol(),0,12,0,MODE_SMA,PRICE_CLOSE,1) && Bid<=iLow(Symbol(),0,Lowest(Symbol(),0,MODE_LOW,6,1)))
{
OrderSend(Symbol(),OP_BUY,Ilo,Ask,Slip,Ask-StopLoss*Point,0,"CP",0,0,Blue);
}
if (iMA(Symbol(),0,6,0,MODE_EMA,PRICE_CLOSE,1)<iMA(Symbol(),0,12,0,MODE_SMA,PRICE_CLOSE,1) && Bid>=iHigh(Symbol(),0,Highest(Symbol(),0,MODE_HIGH,6,1)))
{
OrderSend(Symbol(),OP_SELL,Ilo,Bid,Slip,Bid+StopLoss*Point,0,"CP",0,0,Blue);
}
}
return(0);
}
Profitability Reports
Expected payoff
Average expected payoff across the available backtests for each symbol.
Comments