RndTrade
Download scriptThis script is an automated trading tool designed to manage trades on the MetaTrader 4 platform using a randomized execution logic combined with specific time-based exit rules. It functions by constantly monitoring your account status to determine whether it should be looking for new opportunities or managing existing positions.
Core Operational Logic
1. Position Monitoring The script operates on a binary logic: if there are no open trades, it focuses on opening a new one; if there is already an active trade, it shifts its focus to monitoring that position for closure. This prevents the system from opening multiple simultaneous trades.
2. Randomized Entry Mechanism When the system is ready to open a trade, it uses a randomized "draw" process. Instead of relying on traditional technical indicators (like moving averages or RSI), it generates a series of random numbers. It specifically looks for a result within a certain statistical threshold:
- Buy Order: If the random number exceeds a specific high value, the system executes a "Buy" order.
- Sell Order: If the random number falls below that threshold, the system executes a "Sell" order.
This means the direction of the trade is determined by chance rather than market trends, making it a probabilistic trading tool.
3. Automated Exit Strategy Once a trade is successfully opened, the script switches to a monitoring mode. It tracks the duration of the open position based on the local time of your computer. The logic dictates a fixed timeframe for the trade:
- The script checks if the elapsed time since the trade was opened has reached 14,400 seconds (which is exactly 4 hours).
- Once this 4-hour duration is met, the script automatically triggers an order to close the position.
Summary for the User
In simple terms, this tool acts as a "set and forget" automated trader that makes a random decision on whether to buy or sell a position. Once that trade is active, the tool will hold it for exactly four hours before automatically closing it, regardless of market fluctuations or profit levels.
//+------------------------------------------------------------------+
//| RndTrade.mq4 |
//| Copyright © 2008 Grib |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008 Grib"
#property link ""
#define NUM_BUY 20050611
#define NUM_SELL 20050612
int ticket;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
if(OrdersTotal() == 0)
{
checkForOpen();
}
else
{
checkForClose();
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| Ïðîâåðêà íà îòêðûòèå ïîçèöèè |
//+------------------------------------------------------------------+
void checkForOpen()
{
int a = 0;
MathSrand(TimeLocal());
// Îòîáðàæàåò 10 ÷èñåë.
for(int i=0;i<10;i++ )
if(i==5)
{
a = MathRand();
if(a > 16383.5)
{
// Ñîâåðøàåì ïîêóïêó
ticket = OrderSend(Symbol(),OP_BUY,1,Ask,3,0,0,"TestDrawSell",NUM_BUY);
if (ticket == -1) Alert("Îøèáêà ïðè ñîâåðøåíèè îïåðàöèè ïîêóïêè");
}
else
{
//Ñîâåðøàåì ïðîäàæó
ticket = OrderSend(Symbol(),OP_SELL,1,Bid,3,0,0,"TestDrawBuy",NUM_SELL);
if (ticket == -1) Alert("Îøèáêà ïðè ñîâåðøåíèè îïåðàöèè ïðîäàæè");
}
}
else
{
a = MathRand();
}
}
//+------------------------------------------------------------------+
//| Ïðîâåðêà íà çàêðûòèå ïîçèöèè |
//+------------------------------------------------------------------+
void checkForClose()
{
if(OrderSelect(0, SELECT_BY_POS)==true)
{
if( (OrderOpenTime()+14400) < TimeLocal() )
if(OrderClose(OrderTicket(),1,Ask,3) == false)
Print("Îøèáêà ïðè çàêðûòèè ïîçèöèè");
}
else
{
Print("OrderSelect() âåðíóë îøèáêó - ",GetLastError());
}
}
//+------------------------------------------------------------------+
Profitability Reports
Expected payoff
Average expected payoff across the available backtests for each symbol.
Comments