Author: Copyright � 2009, MetaQuotes Software Corp.
Profit factor:
3.90

This script is an automated trading robot designed to execute specific buy and sell orders based on a strict time-based schedule. Rather than analyzing complex market trends or technical indicators, the logic operates as a "set-and-forget" system that triggers trades at predetermined hours and minutes during the trading day.

Core Operational Logic

The script monitors the current time and manages two distinct sets of trading rules (identified by unique internal markers):

1. The Sell Sequence:

  • Entry Trigger: The robot looks for a specific moment early in the day (at 04:00). If no position is currently open, it automatically initiates a Sell order. This order includes built-in safety nets: a "Stop Loss" to limit potential losses and a "Take Profit" to secure gains.
  • Exit Trigger: The robot monitors the open position and will automatically close it at a specific late-night time (between 05:55 and 06:00).

2. The Buy Sequence:

  • Entry Trigger: The robot looks for a specific moment later in the day (at 10:00). If no position is currently open, it automatically initiates a Buy order with its own set of Stop Loss and Take Profit parameters.
  • Exit Trigger: The robot monitors this position and will automatically close it at a specific midday time (between 12:55 and 13:00).

Key Functional Features

  • Automated Order Management: The script handles the heavy lifting of opening and closing trades. It calculates the correct pricing for your "Stop Loss" and "Take Profit" levels automatically, ensuring they meet the minimum requirements set by your broker.
  • Smart Error Handling: One of the script's primary features is its ability to deal with common trading obstacles. If an order fails to open due to temporary issues (such as a price change or a busy server), the robot will automatically retry the action several times before giving up. It also provides specific alerts to notify you if there are critical issues, such as a locked account or disabled trading permissions.
  • Position Monitoring: The script is designed to be "aware" of what it is doing. It constantly checks your current open positions to ensure it doesn't create duplicate trades or try to close orders that aren't currently active.
  • Safety Constraints: It includes a built-in safety check to ensure that the distance between your entry price and your stop-loss/take-profit levels is never smaller than what your broker allows, preventing the order from being rejected by the server.

Summary for the User

Essentially, this tool acts as a scheduled executor. You provide the lot size (trade volume), and the script follows a rigid timeline: it sells at 4:00 AM, buys at 10:00 AM, and closes those respective positions at their designated times. It is built to handle the technical "noise" of the market—like price fluctuations and server delays—so that your trades are executed as planned without manual intervention.

Orders Execution
It Closes Orders by itself It automatically opens orders when conditions are reachedChecks for the total of open orders
Miscellaneous
It issuies visual alerts to the screen
8 Views
0 Downloads
0 Favorites
jpytest
//+------------------------------------------------------------------+
//|                                                      jpytest.mq4 |
//|                      Copyright © 2009, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
extern double LotSize=0.1; //Ðàçìåð ëîòà äëÿ òîðãîâëè
int MagicNumber;
int OpenedOrder;

double ExtendPoint=1;   //äëÿ ÄÖ ñ äîïîëíèòåëüíûì çíàêîì ExtendPoint=10


int init()
  {
   return(0);
  }

int deinit()
  {
   return(0);
  }

int start()
 {
  MagicNumber=900;
  datetime curtime=iTime(NULL,PERIOD_M1,0);
  if (ExistPositions(Symbol(),-1 , MagicNumber)) {
   if ((TimeHour(curtime)==5 && TimeMinute(curtime)==55) || (TimeHour(curtime)==6 && TimeMinute(curtime)==0))
   OrderClose(OpenedOrder,LotSize,Ask,3);
  } 
  else {
   if (TimeHour(curtime)==4 && TimeMinute(curtime)==0) 
   iSetOrder(Symbol(), OP_SELL, 20*ExtendPoint,10000);
  }

  MagicNumber=901;
  if (ExistPositions(Symbol(),-1 , MagicNumber)) {
   if ((TimeHour(curtime)==12 && TimeMinute(curtime)==55) || (TimeHour(curtime)==13 && TimeMinute(curtime)==0))
   OrderClose(OpenedOrder,LotSize,Bid,3);
  } 
  else {
   if (TimeHour(curtime)==10 && TimeMinute(curtime)==0) 
   iSetOrder(Symbol(), OP_BUY, 15*ExtendPoint,10000);
  }

  return(0);
 }

bool iSetOrder(string symbol, int cmd, double stoploss, double takeprofit, string comment=""){
int Dist_SL =stoploss; // Çàäàííûé SL (pt)
  int Dist_TP =takeprofit; // Çàäàííûé TP (pt)
  double Prots=0.10; // Ïðîöåíò ñâîá. ñð.
  string Symb=symbol; // Ôèíàíñ. èíñòðóìåíò
  double i=0;
  double SL;
  double TP;
  color arr;
  double price;
   
   
//--------------------------------------------------------------- 2 --
  while(i<5) // Öèêë îòêðûòèÿ îðä.
  {
  if (cmd==OP_BUY) {
  SL=Bid - New_Stop(stoploss)*Point; // Âû÷èñëåíèå SL îòêð.
  TP=Bid + New_Stop(takeprofit)*Point; // Âû÷èñëåíèå TP îòêð.
  Alert("Ïîïûòêà îòêðûòü Buy. Îæèäàíèå îòâåòà..");
  price=Ask;
  arr=Maroon; 
  } else
  {
  SL=Ask + New_Stop(stoploss)*Point; // Âû÷èñëåíèå SL îòêð.
  TP=Ask - New_Stop(takeprofit)*Point; // Âû÷èñëåíèå TP îòêð.
  price=Bid;
  arr=Green; 
 
  }//if else
  if (stoploss==0) SL=0;
  if (takeprofit==0) TP=0;

  int ticket=OrderSend(symbol,cmd,LotSize,price,3,SL,TP,comment,MagicNumber,0,arr);//Îòêðûòèå Buy  
 
  //--------------------------------------------------------- 7 --
  if (ticket>0) // Ïîëó÷èëîñü :)
  {
  Alert ("Îòêðûò îðäåð Buy ",ticket);
  OpenedOrder=ticket;
  return(True);
  break; // Âûõîä èç öèêëà
  }
  //--------------------------------------------------------- 8 --
  int Error=GetLastError(); // Íå ïîëó÷èëîñü :(
  switch(Error) // Ïðåîäîëèìûå îøèáêè
  {
  case 135:Alert("Öåíà èçìåíèëàñü. Ïðîáóåì åù¸ ðàç..");
  RefreshRates(); // Îáíîâèì äàííûå
  i=i+1;
  continue; // Íà ñëåä. èòåðàöèþ
  case 136:Alert("Íåò öåí. Æä¸ì íîâûé òèê..");
  while(RefreshRates()==false) // Äî íîâîãî òèêà
  Sleep(1); // Çàäåðæêà â öèêëå
  continue; // Íà ñëåä. èòåðàöèþ
  case 146:Alert("Ïîäñèñòåìà òîðãîâëè çàíÿòà. Ïðîáóåì åù¸..");
  Sleep(500); // Ïðîñòîå ðåøåíèå
  i=i+0.3;
  RefreshRates(); // Îáíîâèì äàííûå
  continue; // Íà ñëåä. èòåðàöèþ
  }
  switch(Error) // Êðèòè÷åñêèå îøèáêè
  {
  case 2 : Alert("Îáùàÿ îøèáêà.");
  break; // Âûõîä èç switch
  case 5 : Alert("Ñòàðàÿ âåðñèÿ êëèåíòñêîãî òåðìèíàëà.");
  break; // Âûõîä èç switch
  case 64: Alert("Ñ÷åò çàáëîêèðîâàí.");
  break; // Âûõîä èç switch
  case 133:Alert("Òîðãîâëÿ çàïðåùåíà");
  break; // Âûõîä èç switch
  default: Alert("Âîçíèêëà îøèáêà ",Error);// Äðóãèå âàðèàíòû  
  }
  break; // Âûõîä èç öèêëà
  }
//--------------------------------------------------------------- 9 --
  return(False);  
}
int New_Stop(int Parametr) // Ïðîâåðêà ñòîï-ïðèê.
  {
  int Min_Dist=MarketInfo(Symbol(),MODE_STOPLEVEL);// Ìèíèì. äèñòàíöèÿ
  if (Parametr < Min_Dist) // Åñëè ìåíüøå äîïóñò.
  {
  Parametr=Min_Dist; // Óñòàíîâèì äîïóñò.
  Alert("Óâåëè÷åíà äèñòàíöèÿ ñòîï-ïðèêàçà.");
  }
  return(Parametr); // Âîçâðàò çíà÷åíèÿ
  }

bool ExistPositions(string sy="", int op=-1, int mn=-1, datetime ot=0) {
  int i, k=OrdersTotal();

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
  if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
  if (OrderSymbol()==sy || sy=="") {
  if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
  if (op<0 || OrderType()==op) {
  if (mn<0 || OrderMagicNumber()==mn) {
  if (ot<=OrderOpenTime()) return(True);
  }
  }
  }
  }
  }
  }
  return(False);
}

Profitability Reports

EUR/USD Jul 2025 - Sep 2025
56.82
Total Trades 23
Won Trades 4
Lost trades 19
Win Rate 17.39 %
Expected payoff 128.40
Gross Profit 3006.00
Gross Loss -52.90
Total Net Profit 2953.10
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
53.00
Total Trades 23
Won Trades 4
Lost trades 19
Win Rate 17.39 %
Expected payoff 128.20
Gross Profit 3005.20
Gross Loss -56.70
Total Net Profit 2948.50
-100%
-50%
0%
50%
100%
EUR/USD Jan 2025 - Jul 2025
5.95
Total Trades 414
Won Trades 39
Lost trades 375
Win Rate 9.42 %
Expected payoff 13.36
Gross Profit 6646.30
Gross Loss -1116.50
Total Net Profit 5529.80
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
1.50
Total Trades 4
Won Trades 1
Lost trades 3
Win Rate 25.00 %
Expected payoff 1.15
Gross Profit 13.80
Gross Loss -9.20
Total Net Profit 4.60
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
1.44
Total Trades 4
Won Trades 1
Lost trades 3
Win Rate 25.00 %
Expected payoff 1.05
Gross Profit 13.70
Gross Loss -9.50
Total Net Profit 4.20
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
1.04
Total Trades 6
Won Trades 2
Lost trades 4
Win Rate 33.33 %
Expected payoff 0.10
Gross Profit 14.40
Gross Loss -13.80
Total Net Profit 0.60
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
1.03
Total Trades 5
Won Trades 1
Lost trades 4
Win Rate 20.00 %
Expected payoff 0.08
Gross Profit 12.60
Gross Loss -12.20
Total Net Profit 0.40
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
1.02
Total Trades 18
Won Trades 3
Lost trades 15
Win Rate 16.67 %
Expected payoff 0.08
Gross Profit 58.87
Gross Loss -57.47
Total Net Profit 1.40
-100%
-50%
0%
50%
100%
AUD/USD Oct 2025 - Feb 2026
0.81
Total Trades 20
Won Trades 4
Lost trades 16
Win Rate 20.00 %
Expected payoff -0.46
Gross Profit 39.00
Gross Loss -48.30
Total Net Profit -9.30
-100%
-50%
0%
50%
100%
AUD/USD Jan 2025 - Jul 2025
0.75
Total Trades 193
Won Trades 29
Lost trades 164
Win Rate 15.03 %
Expected payoff -0.61
Gross Profit 349.30
Gross Loss -466.40
Total Net Profit -117.10
-100%
-50%
0%
50%
100%
AUD/USD Oct 2024 - Jan 2025
0.64
Total Trades 5
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -0.96
Gross Profit 8.60
Gross Loss -13.40
Total Net Profit -4.80
-100%
-50%
0%
50%
100%
EUR/USD Oct 2025 - Feb 2026
0.61
Total Trades 52
Won Trades 7
Lost trades 45
Win Rate 13.46 %
Expected payoff -1.04
Gross Profit 85.90
Gross Loss -140.00
Total Net Profit -54.10
-100%
-50%
0%
50%
100%
USD/CHF Jan 2025 - Jul 2025
0.48
Total Trades 326
Won Trades 36
Lost trades 290
Win Rate 11.04 %
Expected payoff -1.76
Gross Profit 530.51
Gross Loss -1105.08
Total Net Profit -574.57
-100%
-50%
0%
50%
100%
GBP/USD Jan 2025 - Jul 2025
0.45
Total Trades 405
Won Trades 40
Lost trades 365
Win Rate 9.88 %
Expected payoff -2.56
Gross Profit 848.20
Gross Loss -1885.50
Total Net Profit -1037.30
-100%
-50%
0%
50%
100%
USD/CAD Jan 2025 - Jul 2025
0.44
Total Trades 277
Won Trades 25
Lost trades 252
Win Rate 9.03 %
Expected payoff -1.30
Gross Profit 282.01
Gross Loss -643.26
Total Net Profit -361.25
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
0.38
Total Trades 253
Won Trades 12
Lost trades 241
Win Rate 4.74 %
Expected payoff -1.24
Gross Profit 191.89
Gross Loss -504.85
Total Net Profit -312.96
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.37
Total Trades 124
Won Trades 8
Lost trades 116
Win Rate 6.45 %
Expected payoff -2.39
Gross Profit 172.02
Gross Loss -467.83
Total Net Profit -295.81
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.36
Total Trades 124
Won Trades 8
Lost trades 116
Win Rate 6.45 %
Expected payoff -2.43
Gross Profit 169.67
Gross Loss -470.43
Total Net Profit -300.76
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
0.35
Total Trades 13
Won Trades 1
Lost trades 12
Win Rate 7.69 %
Expected payoff -1.83
Gross Profit 13.00
Gross Loss -36.80
Total Net Profit -23.80
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.22
Total Trades 18
Won Trades 2
Lost trades 16
Win Rate 11.11 %
Expected payoff -7.28
Gross Profit 36.35
Gross Loss -167.37
Total Net Profit -131.02
-100%
-50%
0%
50%
100%
GBP/AUD Jan 2025 - Jul 2025
0.21
Total Trades 291
Won Trades 13
Lost trades 278
Win Rate 4.47 %
Expected payoff -3.04
Gross Profit 238.69
Gross Loss -1123.67
Total Net Profit -884.98
-100%
-50%
0%
50%
100%
GBP/CAD Jan 2025 - Jul 2025
0.21
Total Trades 513
Won Trades 26
Lost trades 487
Win Rate 5.07 %
Expected payoff -2.83
Gross Profit 388.92
Gross Loss -1839.04
Total Net Profit -1450.12
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
0.20
Total Trades 14
Won Trades 1
Lost trades 13
Win Rate 7.14 %
Expected payoff -1.91
Gross Profit 6.70
Gross Loss -33.43
Total Net Profit -26.73
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
0.18
Total Trades 14
Won Trades 1
Lost trades 13
Win Rate 7.14 %
Expected payoff -2.13
Gross Profit 6.48
Gross Loss -36.25
Total Net Profit -29.77
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.09
Total Trades 19
Won Trades 2
Lost trades 17
Win Rate 10.53 %
Expected payoff -2.64
Gross Profit 4.80
Gross Loss -55.00
Total Net Profit -50.20
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.07
Total Trades 19
Won Trades 2
Lost trades 17
Win Rate 10.53 %
Expected payoff -2.94
Gross Profit 4.20
Gross Loss -60.10
Total Net Profit -55.90
-100%
-50%
0%
50%
100%
GBP/AUD Oct 2025 - Feb 2026
0.02
Total Trades 87
Won Trades 2
Lost trades 85
Win Rate 2.30 %
Expected payoff -13.58
Gross Profit 29.90
Gross Loss -1211.53
Total Net Profit -1181.63
-100%
-50%
0%
50%
100%
USD/CAD Oct 2024 - Jan 2025
0.00
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
0.00
Total Trades 5
Won Trades 0
Lost trades 5
Win Rate 0.00 %
Expected payoff -4.52
Gross Profit 0.00
Gross Loss -22.62
Total Net Profit -22.62
-100%
-50%
0%
50%
100%
USD/JPY Jul 2025 - Sep 2025
0.00
Total Trades 12
Won Trades 0
Lost trades 12
Win Rate 0.00 %
Expected payoff -2.70
Gross Profit 0.00
Gross Loss -32.35
Total Net Profit -32.35
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
0.00
Total Trades 5
Won Trades 0
Lost trades 5
Win Rate 0.00 %
Expected payoff -4.90
Gross Profit 0.00
Gross Loss -24.51
Total Net Profit -24.51
-100%
-50%
0%
50%
100%
USD/JPY Jul 2025 - Sep 2025
0.00
Total Trades 12
Won Trades 0
Lost trades 12
Win Rate 0.00 %
Expected payoff -2.29
Gross Profit 0.00
Gross Loss -27.45
Total Net Profit -27.45
-100%
-50%
0%
50%
100%
GBP/CAD Oct 2025 - Feb 2026
0.00
Total Trades 15
Won Trades 0
Lost trades 15
Win Rate 0.00 %
Expected payoff -5.65
Gross Profit 0.00
Gross Loss -84.78
Total Net Profit -84.78
-100%
-50%
0%
50%
100%

Comments