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

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
15 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

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/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%
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%
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/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%
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%
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%
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%
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%

Comments