SLR_MoneyRain
Download scriptThis automated trading script is designed to manage and execute trades on the MetaTrader platform by reacting to specific price movements. It follows a logic centered around identifying market volatility and managing a set of active positions to capitalize on small price fluctuations.
Core Trading Mechanism
The script operates by constantly monitoring the current market price against the prices at which it last "checked" the market.
- Entry Logic: The system looks for a specific minimum price movement (defined as a "Shift"). If the price moves in favor of a potential sell position or against a potential buy position by this amount, it opens a trade.
- Position Management: The script limits the total number of open trades at any given time to ensure the account is not over-exposed to a single direction.
Profit and Loss Handling
The system includes automated rules for when to exit a trade based on two primary targets:
- Profit Taking: If a trade reaches a predefined small profit margin (the "Take" value), the script will automatically close that position to secure the gain.
- Stop Loss/Risk Management: The script also monitors trades that move against the desired direction. If a trade loses beyond a specific limit (the "Limit" value), the script identifies it as a loss and closes it immediately to prevent further capital erosion.
Dynamic Position Sizing
A key feature of this script is its ability to calculate how much money to risk on each new trade.
- Reinvestment Mode: When enabled, the script calculates the trade size based on the available "Free Margin" (the uninvested cash in your trading account). This allows the script to potentially increase the position size as your account balance grows, seeking to compound gains.
- Fixed Lot Mode: Alternatively, it can be set to trade a consistent, predetermined volume regardless of the account balance.
Operational Flow
Every time the market updates, the script performs a continuous cycle:
- It refreshes the latest market prices.
- It checks if there is room to open new trades based on the price movement since the last update.
- It scans all currently open positions to see if any have hit the profit or loss targets.
- It executes the necessary closures or modifications instantly to keep the portfolio aligned with the strategy's goals.
//+------------------------------------------------------------------+
//| SHE_Lucky.mq4 |
//| Copyright © 2006, strategy.alfamoon |
//| http://expertmillionaire.ru/ |
//+------------------------------------------------------------------+
double a, b;
bool first=true;
int Shift = 3;
double Lot=0.1;
int Limit = 11;//6;
int Take = 1;
int NumOrd=4;
bool Reinvest=true;
int z;
//----------------------------------------------------------------------------
int start(){
RefreshRates();
if (first) {a=Ask; b=Bid; first=false; return(0);}
z=MarketInfo(Symbol(),MODE_STOPLEVEL);
if (OrdersTotal()<NumOrd)
{
if (Ask-a>=Shift*Point)
{OrderSend(Symbol(),OP_SELL,GetLots(),Bid,1,Bid+Limit*Point,0,"LC",0,0,Red);}
if (b-Bid>=Shift*Point)
{OrderSend(Symbol(),OP_BUY,GetLots(),Ask,1,Ask-Limit*Point,0,"LC",0,0,Blue);}
}
a=Ask;
b=Bid;
ModifyAll();
CloseAll();
return(0);}
//-----------------------------------------------------------------------------
void CloseAll() {
int j=OrdersTotal()-1;
for (int cnt = j; cnt >= 0; cnt--) {
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
RefreshRates();
if (OrderSymbol() == Symbol()) {
if(OrderType()==OP_BUY && Bid-OrderOpenPrice()>=Take*Point) OrderClose(OrderTicket(),OrderLots(),Bid,2,CLR_NONE);
if(OrderType()==OP_SELL && OrderOpenPrice()-Ask>Take*Point) OrderClose(OrderTicket(),OrderLots(),Ask,2,CLR_NONE);
if((OrderType()==OP_BUY) && (((OrderOpenPrice()-Ask)/Point) > Limit)) OrderClose(OrderTicket(),OrderLots(),Bid,3,Green);
if((OrderType()==OP_SELL) && (((Bid-OrderOpenPrice())/Point) > Limit)) OrderClose(OrderTicket(),OrderLots(),Ask,3,Green);
}
}
}
//-----------------------------------------------------------------------------
void ModifyAll() {
int j=OrdersTotal()-1;
/* for (int cnt = j; cnt >= 0; cnt--) {
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if (OrderSymbol() == Symbol() && OrderTakeProfit()==0) {
{
if((OrderType()==OP_BUY) && (((OrderOpenPrice()-Ask)/Point) >= z-Take))
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderOpenPrice()+Take*Point,0,Gold);
if((OrderType()==OP_SELL) && (((Bid-OrderOpenPrice())/Point) >= z-Take))
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderOpenPrice()-Take*Point,0,Gold);
}
}
} */
}
//--------------------------------------------------------------------------
double GetLots() {
if(Reinvest) return (NormalizeDouble(AccountFreeMargin()/3000,1)); else return (Lot);
}
//-------------------------------------------------------------------------
Profitability Reports
Expected payoff
Average expected payoff across the available backtests for each symbol.
Comments