Author: Dan
Profit factor:
0.83

This script is designed to automatically trade on the Forex market, based on a set of rules and calculations. Here's a breakdown of what it does, without getting into technical jargon:

1. Initial Setup and User Preferences:

  • The script starts by defining some settings that the user can adjust. These settings include:
    • MAGICMA: A unique identification number for the script, helping it manage its own trades separately from others.
    • lots: The size of each trade (e.g., 0.1 represents a standard lot size).
    • StopLoss: How much the price needs to move against the trade before it's automatically closed to limit losses.
    • TakeProfit: How much the price needs to move in favor of the trade before it's automatically closed to secure profits.
    • checkhour and checkminute: The specific time of day (hour and minute) when the script will perform its analysis and potentially place new trades.
    • days2check: How many past days the script should consider when calculating the average price range.
    • checkmode: A setting that determines how the average price range is calculated using past days, offering two different methods.
    • profitK, lossK, offsetK: These are factors used to adjust the TakeProfit, StopLoss, and price levels at which the script considers placing trades, based on the calculated average price range.
    • closemode: A setting that, when enabled, automatically closes trades at the end of the day.

2. Core Logic and Timing:

  • The script primarily focuses on trading during a specific time each day, defined by checkhour and checkminute.
  • It waits for the specified time, and when that time arrives, it starts calculating the average price movement.
  • It uses either checkmode==1 which calculate the hightest and lowest for the period or checkmode==2 which calculates the difference between closing prices in that period.
  • It looks at the price data from the past days2check days to determine the typical price range for the currency pair.

3. Calculating Trade Entry Points:

  • The script calculates two key price levels: sellprice and buyprice.
  • These levels are calculated by taking into account the highest and lowest prices of the current day up to the set time (checkhour and checkminute), and then adding or subtracting an offset, determined by the average price range and offsetK.
  • This offset creates a buffer zone around the high and low, aiming to avoid entering trades prematurely.

4. Trade Management:

  • The script checks if there are any existing trades open with its specific MAGICMA number.
  • If it finds any trades, it will close any existing open orders if the Hour() matches the set checkhour.
  • If closemode is enabled, it closes all its existing trades at the end of the day before the next day's trading starts.
  • The script also monitors existing trades for profit and loss levels:
    • It checks if the trade has reached either the TakeProfit or StopLoss levels.
    • If either level is reached, it closes the trade to either secure profits or limit losses.

5. Placing New Trades:

  • The script checks if the current time is within a certain window (Hour()<=lastopenhour) and that there are not already too many trades open.
  • It checks if the current price has reached the precalculated buyprice or sellprice levels.
  • If the price reaches buyprice, the script will place a "buy" order (betting the price will go up).
  • If the price reaches sellprice, the script will place a "sell" order (betting the price will go down).
  • When placing these orders, it uses the user-defined StopLoss and TakeProfit levels.

In simple terms: The script waits for a specific time each day, calculates where it thinks the price might move based on past price action, and then places buy or sell orders. It manages those trades by closing them when they reach a certain profit or loss level, or automatically at the end of the day. It acts based on predetermined rules set by the user.

Orders Execution
Checks for the total of open ordersIt Closes Orders by itself It automatically opens orders when conditions are reached
7 Views
0 Downloads
0 Favorites
tttttt
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|   9-0-7-1-2-2-2-1                                        ttt.mq4 |
//|   9-0-2-1-2-1-2.5                                            Dan |
//|   9-0-9-2-1-1-1-1                                                |
//|   9-0-6-1-2-2-2-1(m15)                 http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Dan"
#property link      "http://www.metaquotes.net"


//---- input parameters
extern int MAGICMA  = 20050610;
extern double    lots=0.1;
extern int		  StopLoss=200;
extern int		  TakeProfit=200;
extern int       checkhour=8;
extern int       checkminute=0;
extern int       days2check=7;
extern int       checkmode=1;
extern double    profitK=2;
extern double    lossK=2;
extern double    offsetK=2;
extern int       closemode=1;

//+------------------------------------------------------------------+
int      latestopenhour=23;
int      tradesallowed=1;
double   sellprice;
double   buyprice;
int      profit;
int      loss;
int      offset;
int      avrange;
double   daj[30];
int      i;
int      dd;
int      bb; 
int      d; 
int      pp;
double   hh;
double   ll;
int      p;
double   totalrange;
//============================================================ 
void start() {  
   if (!IsTradeAllowed()) return;
   if (Bars==bb) return;
   bb=Bars;  

 if ( (Hour()==checkhour) && (Minute()==checkminute) )  { 
    dd=Day();
    pp=((checkhour*60)/Period()+checkminute/Period());
    hh=High[Highest(NULL,0,MODE_HIGH,pp,1)];
    ll=Low[Lowest(NULL,0,MODE_LOW,pp,1)];
    p=((24*60)/Period());
    totalrange=0; 
    
    
    if(checkmode==1)   {
        for(i=1;i<=days2check;i++) {
          daj[i]=(High[Highest(NULL,0,MODE_HIGH,p,p*i+1)]-Low[Lowest(NULL,0,MODE_LOW,p,p*i+1)]);
          totalrange=totalrange+daj[i];
          avrange=MathRound((totalrange/i)/Point);
        }
    }
    if(checkmode==2)  {
        for( i=1;i<=days2check;i++) {
          daj[i]=MathAbs(Close[p*i+pp]-Close[p*(i-1)+pp]);
          totalrange=totalrange+daj[i];
          avrange=MathRound((totalrange/i)/Point);
        }
    }   
    offset=MathRound((avrange)/offsetK);  
    sellprice=ll-offset*Point;
    buyprice=hh+offset*Point;
  if   (CalculateCurrentOrders()>0)  {
    for(i=0;i<OrdersTotal();i++) {
          if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)  break;
          if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
          if (OrderType()==OP_BUY) {
            OrderClose(OrderTicket(),lots,Bid,3,White);
            break;
          }
          if (OrderType()==OP_SELL) {
            OrderClose(OrderTicket(),lots,Ask,3,White);
            break;
          }
     }
   }
 }
  
  if (closemode==2  && Day()!=dd && (CalculateCurrentOrders()>0))    {
      for(i=0;i<OrdersTotal();i++) {
          if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)  break;
          if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
          if (OrderType()==OP_BUY) {
            OrderClose(OrderTicket(),lots,Bid,3,White);
            break;
          }
          if (OrderType()==OP_SELL) {
            OrderClose(OrderTicket(),lots,Ask,3,White);
            break;
          }
      }
  }
  
  
  for(i=0;i<OrdersTotal();i++) {
    if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)  break;
    if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
    if ((OrderType()==OP_BUY) && (((Close[1]-OrderOpenPrice())>=profit*Point) || ((OrderOpenPrice()-Close[1])>=loss*Point))) {
      OrderClose(OrderTicket(),lots,Bid,3,White);
      break;
    }
    if ((OrderType()==OP_SELL) && (((Close[1]-OrderOpenPrice())>=loss*Point) || ((OrderOpenPrice()-Close[1])>=profit*Point)))  {
      OrderClose(OrderTicket(),lots,Ask,3,White);
      break;
    }
  }
          
  
  int lastopenhour=23;

  if ((Hour()<=lastopenhour)  &&  (Day()==dd) &&  (Day()!=d) && (CalculateCurrentOrders()<tradesallowed))  {
    if (Close[1]>=buyprice) { 
      profit=MathRound((avrange)/profitK);
      loss=MathRound((avrange)/lossK);
      OrderSend(Symbol(),OP_BUY,lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"ttt",MAGICMA,0,Blue);
      dd=Day();
      if (tradesallowed==1)  {d=Day();}
//      return(d);
    }
       
    if (Close[1]<=sellprice) {  
      profit=MathRound((avrange)/profitK);
      loss=MathRound((avrange)/lossK);
      OrderSend(Symbol(),OP_SELL,lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"ttt",MAGICMA,0,Red);
      dd=Day();
      if (tradesallowed==1)  {d=Day();}
    }
    return;
  } 
}


int CalculateCurrentOrders()  {
   int ord=0;
   string symbol=Symbol();
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
        {
         ord++;
        }
     }
   return(ord);
}

Profitability Reports

USD/CHF Jul 2025 - Sep 2025
0.50
Total Trades 25
Won Trades 8
Lost trades 17
Win Rate 32.00 %
Expected payoff -7.32
Gross Profit 183.82
Gross Loss -366.77
Total Net Profit -182.95
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
1.34
Total Trades 20
Won Trades 10
Lost trades 10
Win Rate 50.00 %
Expected payoff 1.85
Gross Profit 145.34
Gross Loss -108.30
Total Net Profit 37.04
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.97
Total Trades 16
Won Trades 7
Lost trades 9
Win Rate 43.75 %
Expected payoff -0.21
Gross Profit 105.80
Gross Loss -109.20
Total Net Profit -3.40
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
0.74
Total Trades 22
Won Trades 9
Lost trades 13
Win Rate 40.91 %
Expected payoff -2.91
Gross Profit 180.00
Gross Loss -244.00
Total Net Profit -64.00
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.92
Total Trades 23
Won Trades 11
Lost trades 12
Win Rate 47.83 %
Expected payoff -0.55
Gross Profit 149.52
Gross Loss -162.18
Total Net Profit -12.66
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
1.33
Total Trades 14
Won Trades 8
Lost trades 6
Win Rate 57.14 %
Expected payoff 1.88
Gross Profit 105.29
Gross Loss -78.96
Total Net Profit 26.33
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
1.44
Total Trades 23
Won Trades 14
Lost trades 9
Win Rate 60.87 %
Expected payoff 3.04
Gross Profit 228.30
Gross Loss -158.30
Total Net Profit 70.00
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.37
Total Trades 17
Won Trades 5
Lost trades 12
Win Rate 29.41 %
Expected payoff -8.18
Gross Profit 81.70
Gross Loss -220.80
Total Net Profit -139.10
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
0.36
Total Trades 34
Won Trades 9
Lost trades 25
Win Rate 26.47 %
Expected payoff -6.41
Gross Profit 121.37
Gross Loss -339.35
Total Net Profit -217.98
-100%
-50%
0%
50%
100%
USD/CHF Jan 2025 - Jul 2025
0.63
Total Trades 44
Won Trades 19
Lost trades 25
Win Rate 43.18 %
Expected payoff -4.27
Gross Profit 318.22
Gross Loss -506.28
Total Net Profit -188.06
-100%
-50%
0%
50%
100%

Comments