Okay, here's an explanation of what this MetaTrader script does, in plain language, assuming you're not a programmer:
This script is designed to automate a simple trading strategy that focuses on weekly patterns. It's like setting up a pre-programmed plan to enter and exit trades based on specific days and times of the week.
Here's the breakdown:
-
The Overall Idea: The script aims to place two "pending orders" (orders that will automatically execute when the price reaches a certain level) at the beginning of the week and close all orders at the end of the week. It attempts to profit from typical price movements within that timeframe.
-
Tuesday Entry: On Tuesday morning (specifically at 2 AM GMT), the script automatically sets up two orders:
- Buy Stop Order: This order is placed slightly above the current market price. The idea is that if the price starts to rise, it will trigger this order, and a "buy" trade will be opened.
- Sell Stop Order: This order is placed slightly below the current market price. The idea is that if the price starts to fall, it will trigger this order, and a "sell" trade will be opened.
-
Order Details:
- The distance of these orders from the current price is set by the "Range" parameter (default is 50 "pips", a standard unit of price movement).
- A "Stop Loss" is set for both orders. This is like an emergency exit: if the price moves against the trade by a certain amount (default is 100 pips), the trade will be automatically closed to limit losses.
- "Take Profit" level can be set, but by default is disabled. This is like a target: if the price moves in favor of the trade by a certain amount, the trade will be automatically closed to secure profits.
-
Friday Exit: On Friday evening (specifically at 9 PM GMT), the script automatically closes all open trades and deletes any pending orders that haven't been triggered yet. This ensures that the trading strategy is reset for the next week.
-
Money Management (Optional): The script includes an optional feature for "Money Management." If activated, it automatically calculates the trade size ("Lots") based on a percentage of the available funds in the trading account. This is intended to control risk and potentially increase profits as the account grows. There is a minimum trade size limit.
-
Broker Adjustments: The script has settings to account for the time difference between your broker's server and GMT (Greenwich Mean Time). This is important to ensure that the trades are placed and closed at the correct times.
In Simple Terms:
Imagine you're setting two traps on Tuesday to catch potential price movements. One trap is set above the current price (hoping the price goes up), and the other is set below (hoping the price goes down). If the price hits one of your traps, a trade is automatically opened. Then, on Friday night, you clear all your traps and close any trades that are still running, ready to set up again next week.
/*
Ñèñòåìà íà íåäåëþ.mq4
© 2003-2006 Mandor ®
E-mail: mandorr@gmail.com
Ðåçóëüòàò ðàáîòû ñîâåòíèêà íå çàâèñèò îò èñïîëüçóåìîãî ïåðèîäà
Âî âòîðíèê â íà÷àëå ÷àñà 2 GMT âûñòàâëÿþòñÿ îòëîæåííûå îðäåðà
Öåíà îòêðûòèÿ îðäåðà Buy Stop ðàâíà òåêóùåé öåíå ïëþñ 50 ïèïñîâ
Öåíà îòêðûòèÿ îðäåðà Sell Stop ðàâíà òåêóùåé öåíå ìèíóñ 50 ïèïñîâ
Ñòîï ëîññ îðäåðîâ Buy Stop è Sell Stop ðàâíî 100 ïèïñîâ
Ïåðåíîñ ñòîï ëîññà íà 30 ïèïñîâ îò òåêóùåé öåíû ïåðåä âàæíûìè íîâîñòÿìè -> ïîêà âðó÷íóþ
Âî ïÿòíèöó â íà÷àëå ÷àñà 21 GMT âñå îðäåðà ðàêðûâàþòñÿ (äëÿ FIBO Groupe Ltd. â íà÷àëå ÷àñà 20 GMT)
UseMM: èñïîëüçîâàòü Money Management
PercentMM: ïðîöåíò îò ñâîáîäíûõ ñðåäñòâ äëÿ âû÷èñëåíèÿ íîâîé ïîçèöèè
MinLots: ìèíèìàëüíî äîïóñòèìûé ðàçìåð ïîçèöèè ó äèëåðà
MinStop: ìèíèìàëüíî äîïóñòèìîå ðàññòîÿíèå îò òåêóùåé öåíû äî îòëîæåííîãî îðäåðà, ñòîï ëîññà èëè òåéê ïðîôèòà ó äèëåðà
ShiftGMT: âðåìÿ äèëåðà ìèíóñ âðåìÿ ïî Ãðèíâè÷ó (äëÿ Alpari = +1, äëÿ FXTeam = +2, äëÿ FIBO = +1, äëÿ LiteForex = +2)
*********************************************
Åâðî îòêðûòèå â 5.00 ÌÑÊ, çàêðûòèå ïÿòí.21.00,ÒÏ íå ñòàâèòñÿ, ëîññ=100,
éåíà +9 GMT îòêðûòèå, çàêðûòèå â ïÿòí. 21.00 ÌÑÊ, ÒÏ íå ñòàâèòñÿ, ëîññ-100.
Âñå îòêðûòèÿ âî âòîðíèê íî÷üþ.
*/
// Parametres
extern int StartDayOfWeek=2;
extern int StartHour=2;
extern int StopDayOfWeek=5;
extern int StopHour=21;
extern int Range=50;
extern int TakeProfit=0;
extern int StopLoss=100;
extern double Lots=0.1;
extern bool UseMM=false;
extern int PercentMM=20;
extern double MinLots=0.1;
extern int MinStop=11;
extern int ShiftGMT=1;
// Variables
int result;
int err;
int i;
int time;
int hour;
int day_of_week;
int set_buy_stop=0;
int set_sell_stop=0;
double range;
double volume;
double price;
double loss;
double profit;
// New quotations are received
void start()
{
if (Bars<100 || IsTradeAllowed()==false) return;
if (Range<=0 || ShiftGMT<-23 || ShiftGMT>23) return;
if (StartDayOfWeek<1 || StartDayOfWeek>5 || StartHour<=0 || StartHour>23) return;
if (StopDayOfWeek<1 || StopDayOfWeek>5 || StopHour<=0 || StopHour>23) return;
time=CurTime()-ShiftGMT*3600;
hour=TimeHour(time);
day_of_week=TimeDayOfWeek(time);
if (day_of_week==StartDayOfWeek && hour==StartHour)
{
if (set_buy_stop==0 && TotalBuyStop()==0)
{
if (SetBuyStop()>0) {set_buy_stop=1; return;}
}
if (set_sell_stop==0 && TotalSellStop()==0)
{
if (SetSellStop()>0) {set_sell_stop=1; return;}
}
}
else
{
set_buy_stop=0;
set_sell_stop=0;
}
if (day_of_week==StopDayOfWeek && hour==StopHour)
{
if (CloseAllOrders()>0) return;
}
}
// Set a Buy Stop order
int SetBuyStop()
{
result=0;
volume=LotsCounting();
if (Range<MinStop) range=MinStop*Point; else range=Range*Point;
price=Ask+range;
loss=0; if (StopLoss>0) loss=price-StopLoss*Point;
profit=0; if (TakeProfit>0) profit=price+TakeProfit*Point;
if (OrderSend(Symbol(),OP_BUYSTOP,volume,price,0,loss,profit,"Open by expert",0,0)>0) result=1;
else {err=GetLastError(); Print("Set a pending order failed with error #",err);}
return(result);
}
// Set a Sell Stop order
int SetSellStop()
{
result=0;
volume=LotsCounting();
if (Range<MinStop) range=MinStop*Point; else range=Range*Point;
price=Bid-range;
loss=0; if (StopLoss>0) loss=price+StopLoss*Point;
profit=0; if (TakeProfit>0) profit=price-TakeProfit*Point;
if (OrderSend(Symbol(),OP_SELLSTOP,volume,price,0,loss,profit,"Open by expert",0,0)>0) result=1;
else {err=GetLastError(); Print("Set a pending order failed with error #",err);}
return(result);
}
// Close opened positions & deleting of pending orders
int CloseAllOrders()
{
result=0;
for (i=0;i<OrdersTotal();i++)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if (OrderSymbol()!=Symbol()) continue;
if (OrderType()==OP_BUY)
{
if (OrderClose(OrderTicket(),OrderLots(),Bid,2)) result=1;
else {err=GetLastError(); Print("Close of opened order failed with error #",err);}
break;
}
if (OrderType()==OP_SELL)
{
if (OrderClose(OrderTicket(),OrderLots(),Ask,2)) result=1;
else {err=GetLastError(); Print("Close of opened order failed with error #",err);}
break;
}
if (OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP)
{
if (OrderDelete(OrderTicket())) result=1;
else {err=GetLastError(); Print("Delete of pending order failed with error #",err);}
break;
}
}
return(result);
}
// Buy Stop count
int TotalBuyStop()
{
result=0;
for(i=0;i<OrdersTotal();i++)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if (OrderSymbol()!=Symbol()) continue;
if (OrderType()==OP_BUYSTOP ) result++;
}
return(result);
}
// Sell Stop count
int TotalSellStop()
{
result=0;
for(i=0;i<OrdersTotal();i++)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if (OrderSymbol()!=Symbol()) continue;
if (OrderType()==OP_SELLSTOP) result++;
}
return(result);
}
// Account lots
double LotsCounting()
{
volume=Lots;
if (UseMM) volume=NormalizeDouble((PercentMM*AccountFreeMargin()/100000),1);
if (volume<MinLots) volume=MinLots;
return(volume);
}
// End
Comments