Author: Copyright � 2008, MetaQuotes Software Corp.
Profit factor:
0.80

Here's a breakdown of what this MetaTrader script does, explained in a way that someone without programming knowledge can understand:

Overall Purpose:

This script is designed to automatically place and manage pending trades on a currency pair at specific times of the day and then close any open positions at another specific time. It's essentially a simple automated trading strategy.

Key Components and How They Work:

  1. Settings (External Variables):

    • Lots: This determines the size of the trades the script will place. Think of it as how much of the currency you are buying or selling.
    • ChasStart: This is the hour of the day when the script will start placing pending orders.
    • ChasStop: This is the hour of the day when the script will close any open positions and delete any pending orders.
    • Step: This value determines how far away from the current price the pending orders will be placed.
    • TP: This sets the desired profit level for the trades.
  2. Initialization (init() function):

    • This part of the script runs once when the script is first loaded onto the chart. In this case, it doesn't actually do anything.
  3. Deinitialization (deinit() function):

    • This part of the script runs when the script is removed from the chart or the trading platform closes. Like the init() function, it also doesn't do anything in this script.
  4. Main Execution Loop (start() function): This is where the "brain" of the script resides. It runs repeatedly, checking conditions and taking actions.

    • Order Management (Early Section):

      • It checks if there is one pending order with the script's unique identifier (12321). If it finds one, it deletes all other pending orders with that same identifier. This is likely a mechanism to ensure only one set of orders is active at a time.
    • Time Check (Time Logic):

      • The script keeps track of the last time it ran. If the current time is the same as the last time it ran, it does nothing. This prevents the script from executing the same actions multiple times per minute.
      • It also checks if trading is allowed. If not, it skips the trading logic.
    • Order Placement (Buy/Sell Stop Orders):

      • If the current hour matches the ChasStart time and the minute is exactly zero, the script places two pending orders:
        • A Buy Stop order is placed slightly above the current market price (Ask). This means the order will only activate if the price rises to that level. The Step variable determines the distance above the current price where this order is placed. The TP variable then sets the target profit for that order.
        • A Sell Stop order is placed slightly below the current market price (Bid). This means the order will only activate if the price falls to that level. Again, the Step variable determines the distance below the current price. And TP set the target profit for that order.
      • These "stop" orders are designed to enter the market if the price starts moving strongly in either direction.
    • Position Closure (Closing Open Trades and Deleting Pending Orders):

      • If the current hour matches the ChasStop time and the minute is zero, the script will:
        • Close any open trades that were placed by this script (identified by the unique number 12321).
        • Delete any pending orders placed by this script.

In essence, this script is a simple automated system that tries to catch potential price breakouts during a specific time window and then closes everything down at another specified time.

Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt Closes Orders by itself
16 Views
0 Downloads
0 Favorites
21hour
//+------------------------------------------------------------------+
//|                                                       21hour.mq4 |
//|                      Copyright © 2008, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

extern double Lots = 0.1;
extern int ChasStart = 10;
extern int ChasStop  = 22;
extern int Step      = 15;
extern int TP        = 200;
int prevtime;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----


   


   int OrderCountOtl=0;
      int i=0; 
   int total = OrdersTotal();   
   for(i = 0; i <= total; i++) 
     {
            
       OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
       if(OrderMagicNumber() == 12321) 
         {
         if (OrderType()>1) OrderCountOtl++;
         }

      }
      
          if (OrderCountOtl==1) 
     {
   for(i = 0; i <= total; i++) 
     {
       OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
       if(OrderMagicNumber() == 12321) 
         {
         if (OrderType()>1) OrderDelete(OrderTicket());
         }
      }
     } 


   if(Time[0] == prevtime) 
       return(0);
   prevtime = Time[0];
   if(!IsTradeAllowed()) 
     {
       prevtime = Time[1];
       return(0);
     }



if (TimeHour(TimeCurrent())==ChasStart && TimeMinute(TimeCurrent())==0)
  {
  OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+Step*Point,3,0,Ask+(Step+TP)*Point,"",12321,0,Green);
  OrderSend(Symbol(),OP_SELLSTOP,Lots,Bid-Step*Point,3,0,Bid-(Step+TP)*Point,"",12321,0,Red);
  }

if (TimeHour(TimeCurrent())==ChasStop && TimeMinute(TimeCurrent())==0)
  {
   i=0;  
  total = OrdersTotal();   
   for(i = 0; i <= total; i++) 
     {
       OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
       if(OrderMagicNumber() == 12321) 
         {
          if (OrderType()==OP_BUY)OrderClose(OrderTicket(),OrderLots(),Bid,3,Green);
          if (OrderType()==OP_SELL)OrderClose(OrderTicket(),OrderLots(),Ask,3,Green);
          if (OrderType()>1)OrderDelete(OrderTicket());
         }
      }  
  }
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

Profitability Reports

GBP/USD Jul 2025 - Sep 2025
1.86
Total Trades 58
Won Trades 44
Lost trades 14
Win Rate 75.86 %
Expected payoff 6.70
Gross Profit 841.40
Gross Loss -452.90
Total Net Profit 388.50
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
1.29
Total Trades 58
Won Trades 36
Lost trades 22
Win Rate 62.07 %
Expected payoff 2.18
Gross Profit 567.80
Gross Loss -441.30
Total Net Profit 126.50
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
1.21
Total Trades 58
Won Trades 37
Lost trades 21
Win Rate 63.79 %
Expected payoff 1.67
Gross Profit 557.40
Gross Loss -460.40
Total Net Profit 97.00
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
1.13
Total Trades 58
Won Trades 42
Lost trades 16
Win Rate 72.41 %
Expected payoff 1.57
Gross Profit 805.60
Gross Loss -714.80
Total Net Profit 90.80
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
1.10
Total Trades 67
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff 1.29
Gross Profit 936.80
Gross Loss -850.70
Total Net Profit 86.10
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
1.05
Total Trades 58
Won Trades 37
Lost trades 21
Win Rate 63.79 %
Expected payoff 0.44
Gross Profit 523.69
Gross Loss -498.09
Total Net Profit 25.60
-100%
-50%
0%
50%
100%
EUR/USD Jan 2025 - Jul 2025
0.96
Total Trades 128
Won Trades 86
Lost trades 42
Win Rate 67.19 %
Expected payoff -0.59
Gross Profit 1673.00
Gross Loss -1748.20
Total Net Profit -75.20
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
0.94
Total Trades 58
Won Trades 34
Lost trades 24
Win Rate 58.62 %
Expected payoff -0.88
Gross Profit 744.38
Gross Loss -795.19
Total Net Profit -50.81
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
0.88
Total Trades 58
Won Trades 38
Lost trades 20
Win Rate 65.52 %
Expected payoff -1.74
Gross Profit 745.10
Gross Loss -846.20
Total Net Profit -101.10
-100%
-50%
0%
50%
100%
USD/CAD Jan 2025 - Jul 2025
0.86
Total Trades 128
Won Trades 91
Lost trades 37
Win Rate 71.09 %
Expected payoff -1.54
Gross Profit 1189.00
Gross Loss -1386.35
Total Net Profit -197.35
-100%
-50%
0%
50%
100%
USD/CAD Oct 2024 - Jan 2025
0.85
Total Trades 67
Won Trades 38
Lost trades 29
Win Rate 56.72 %
Expected payoff -1.37
Gross Profit 526.24
Gross Loss -618.07
Total Net Profit -91.83
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
0.85
Total Trades 58
Won Trades 36
Lost trades 22
Win Rate 62.07 %
Expected payoff -2.23
Gross Profit 720.00
Gross Loss -849.60
Total Net Profit -129.60
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
0.82
Total Trades 58
Won Trades 31
Lost trades 27
Win Rate 53.45 %
Expected payoff -1.62
Gross Profit 425.06
Gross Loss -518.77
Total Net Profit -93.71
-100%
-50%
0%
50%
100%
USD/CHF Jan 2025 - Jul 2025
0.81
Total Trades 128
Won Trades 76
Lost trades 52
Win Rate 59.38 %
Expected payoff -2.96
Gross Profit 1571.97
Gross Loss -1951.28
Total Net Profit -379.31
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
0.80
Total Trades 67
Won Trades 33
Lost trades 34
Win Rate 49.25 %
Expected payoff -1.80
Gross Profit 475.80
Gross Loss -596.20
Total Net Profit -120.40
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
0.79
Total Trades 128
Won Trades 89
Lost trades 39
Win Rate 69.53 %
Expected payoff -2.43
Gross Profit 1183.58
Gross Loss -1494.44
Total Net Profit -310.86
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.79
Total Trades 58
Won Trades 40
Lost trades 18
Win Rate 68.97 %
Expected payoff -2.30
Gross Profit 490.21
Gross Loss -623.55
Total Net Profit -133.34
-100%
-50%
0%
50%
100%
GBP/USD Jan 2025 - Jul 2025
0.78
Total Trades 128
Won Trades 88
Lost trades 40
Win Rate 68.75 %
Expected payoff -3.76
Gross Profit 1717.20
Gross Loss -2198.00
Total Net Profit -480.80
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.74
Total Trades 58
Won Trades 28
Lost trades 30
Win Rate 48.28 %
Expected payoff -2.71
Gross Profit 442.10
Gross Loss -599.30
Total Net Profit -157.20
-100%
-50%
0%
50%
100%
AUD/USD Jan 2025 - Jul 2025
0.72
Total Trades 128
Won Trades 68
Lost trades 60
Win Rate 53.13 %
Expected payoff -3.68
Gross Profit 1234.90
Gross Loss -1705.60
Total Net Profit -470.70
-100%
-50%
0%
50%
100%
GBP/CAD Jan 2025 - Jul 2025
0.70
Total Trades 128
Won Trades 92
Lost trades 36
Win Rate 71.88 %
Expected payoff -4.40
Gross Profit 1328.93
Gross Loss -1892.71
Total Net Profit -563.78
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
0.69
Total Trades 58
Won Trades 31
Lost trades 27
Win Rate 53.45 %
Expected payoff -4.99
Gross Profit 637.64
Gross Loss -927.25
Total Net Profit -289.61
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
0.68
Total Trades 58
Won Trades 29
Lost trades 29
Win Rate 50.00 %
Expected payoff -3.38
Gross Profit 408.94
Gross Loss -604.96
Total Net Profit -196.02
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.64
Total Trades 58
Won Trades 37
Lost trades 21
Win Rate 63.79 %
Expected payoff -4.34
Gross Profit 448.25
Gross Loss -700.17
Total Net Profit -251.92
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.53
Total Trades 58
Won Trades 32
Lost trades 26
Win Rate 55.17 %
Expected payoff -6.54
Gross Profit 435.33
Gross Loss -814.72
Total Net Profit -379.39
-100%
-50%
0%
50%
100%
GBP/AUD Jan 2025 - Jul 2025
0.50
Total Trades 128
Won Trades 90
Lost trades 38
Win Rate 70.31 %
Expected payoff -9.01
Gross Profit 1147.34
Gross Loss -2301.21
Total Net Profit -1153.87
-100%
-50%
0%
50%
100%
NZD/USD Jan 2025 - Jul 2025
0.50
Total Trades 128
Won Trades 55
Lost trades 73
Win Rate 42.97 %
Expected payoff -7.28
Gross Profit 937.40
Gross Loss -1868.90
Total Net Profit -931.50
-100%
-50%
0%
50%
100%
USD/JPY Jul 2025 - Sep 2025
0.49
Total Trades 58
Won Trades 40
Lost trades 18
Win Rate 68.97 %
Expected payoff -9.39
Gross Profit 533.66
Gross Loss -1078.25
Total Net Profit -544.59
-100%
-50%
0%
50%
100%
USD/JPY Jul 2025 - Sep 2025
0.40
Total Trades 58
Won Trades 37
Lost trades 21
Win Rate 63.79 %
Expected payoff -12.18
Gross Profit 470.80
Gross Loss -1177.29
Total Net Profit -706.49
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.31
Total Trades 58
Won Trades 19
Lost trades 39
Win Rate 32.76 %
Expected payoff -10.52
Gross Profit 268.40
Gross Loss -878.40
Total Net Profit -610.00
-100%
-50%
0%
50%
100%
USD/CHF 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%

Comments