Author: Copyright � 2008, MetaQuotes Software Corp.

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
5 Views
0 Downloads
0 Favorites

Profitability Reports

GBP/USD Oct 2024 - Jan 2025
110.00 %
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%
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);
  }
//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---