es_capelast_reversed_ECN_v1.01

Profit factor:
65.74

Here's a breakdown of what this MetaTrader script does, explained in plain language:

This script is designed to automatically place buy and sell orders in the Forex market based on a simple strategy. Think of it as a robot trader that follows a set of rules.

1. Initial Setup and Checks:

  • Account Verification: First, it checks if it's running on a demo account or a real (live) account. If it's a real account, it verifies if the account number you've entered matches the actual account number. This is a safety measure. If they don't match, the script stops.
  • Environment Check: The script checks if trading is allowed. It makes sure there are enough data points available (at least 100 bars). It also checks if the take profit settings are valid.
  • Margin Check: The script assesses your account's free margin (available money). If you don't have enough free margin to place trades based on the lot size you've selected, the script will stop and display a message.

2. Trading Logic:

  • Moving Averages: The core of the strategy involves two "moving averages." A moving average is like a line that smooths out price data over a specific period, helping to identify trends. The script uses a special kind of moving average called an "EMA" (Exponential Moving Average). The script calculates an EMA of the open price for the past 5 periods and compares it with the current close price of the asset. If the current price is above or below the EMA, the script is ready to enter an operation.
  • Buy/Sell Signals:
    • The script looks at how the current price compares to a moving average. If the price is below the moving average, it considers this a potential "sell" signal (because prices may fall). Conversely, if the price is above the moving average, it sees it as a potential "buy" signal (because prices may rise).
    • There's a setting called "reverseLogic."
      • If reverseLogic is set to "true," the script reverses the buy/sell signals. So, if the price is below the moving average, it would buy instead of sell.
      • If reverseLogic is set to "false," the script follows the normal buy/sell signals.
  • Order Placement: Based on these signals (and whether reverseLogic is on or off), the script places a buy or sell order.
  • Order Limits:
    • The script checks if it's already reached the maximum number of allowed open orders across all currency pairs, or if it already has reached the maximum number of orders on a specific currency pair. If it has, it waits until an existing order closes before opening a new one.

3. Order Parameters:

  • Lot Size: The script uses a pre-defined "lot size" which is the amount of currency you are buying or selling.
  • Stop Loss: It sets a "stop loss" level for each order. This is a price point at which the order will automatically close if the market moves against you, limiting your potential losses.
  • Take Profit: It also sets a "take profit" level. This is a price point at which the order will automatically close if the market moves in your favor, securing your profits.
  • Slippage: This setting determines how much the price can move before the order is rejected.
  • Magic Number: It uses a "magic number" to identify orders placed by this particular script, which can be useful for managing and tracking trades.

4. Additional Features:

  • Sound Alert: The script can optionally play a sound alert when it opens a trade.
  • Comments: It adds comments to the trade that help you identify it.

In Summary:

This script automates Forex trading based on a basic moving average strategy. It monitors market conditions, generates buy/sell signals, and places orders according to pre-defined rules and parameters.

Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt can change open orders parameters, due to possible stepping strategy
Miscellaneous
It plays sound alertsIt issuies visual alerts to the screen
17 Views
0 Downloads
0 Favorites
es_capelast_reversed_ECN_v1.01
//+------------------------------------------------------------------+
//|                               es_capelast_reversed_ECN_v1.01.mq4 |
//|                                    Copyright © 2009, OGUZ BAYRAM |
//|                                            es_cape77@hotmail.com |
//+------------------------------------------------------------------+

extern int YourAccountNumber = 123456;
extern double lTakeProfit = 10.0;
extern double sTakeProfit = 10.0;
extern double lStopLoss = 2000.0;
extern double sStopLoss = 2000.0;
extern int max_num_orders = 50;
extern int max_orders_per_symbol = 10;
extern color clOpenBuy = Green;
extern color clOpenSell = Red;
extern string Name_Expert = "es_capelast_reversed_ECN_v1";
extern int magic_number = 789667;
extern int Slippage = 1;
extern bool UseSound = FALSE;
extern string NameFileSound = "Alert.wav";
extern double Lots = 0.1;
extern bool reverseLogic = true;

int gi_ticket_number;
double gd_point;
double gd_digit;
bool gi_accountVerified = FALSE;

int init(){
   if (IsDemo() == TRUE){
      gi_accountVerified = TRUE;
      Comment(Name_Expert + " trading on DEMO account");
   }
   else { //real trading Account
      gi_accountVerified = CheckAccountNumber();
      if (gi_accountVerified == FALSE) return (0);
      Comment(Name_Expert + " trading on LIVE account");
   }
   gd_point = SetPoint();
   gd_digit = SetDigit();
}
void deinit() {
   Comment("");
}

int start() {
   if (IsTradeAllowed() == FALSE) return (0);
   
   if (Bars < 100) {
      Print("bars less than 100");
      return (0);
   }
   if (lTakeProfit < 1.0) {
      Print("TakeProfit less than 1");
      return (0);
   }
   if (sTakeProfit < 1.0) {
      Print("TakeProfit less than 1");
      return (0);
   }
   double diClose0 = iClose(NULL, PERIOD_M5, 0);
   double diMA1 = iMA(NULL, PERIOD_M5, 5, 0, MODE_EMA, PRICE_OPEN, 1);
   double diClose2 = iClose(NULL, PERIOD_M5, 0);
   double diMA3 = iMA(NULL, PERIOD_M5, 4, 0, MODE_EMA, PRICE_OPEN, 1);
   if (AccountFreeMargin() < 1000.0 * Lots) {
      Print("We have no money. Free Margin = ", AccountFreeMargin());
      return (0);
   }
   if (!ExistPositions()) {
      if (diClose0 < diMA1) {
         if (reverseLogic) OpenSell();
         else OpenBuy();
         return (0);
      }
      if (diClose2 > diMA3) {
         if (reverseLogic) OpenBuy();
         else OpenSell();
         return (0);
      }
   }
   return (0);
}

//Wait to exit positions if all order slots are full
bool ExistPositions() {
   if ((OrdersTotal() >= max_num_orders ) || (OrderCount() >= max_orders_per_symbol))
      return (TRUE);
   else
      return (FALSE); 
}

//Count orders on current chart symbol
int OrderCount () {
   int count=0;
   for (int j=0; j<OrdersTotal(); j++) {
      if (OrderSelect(j, SELECT_BY_POS, MODE_TRADES))
         if (OrderSymbol() == Symbol()) count++;
   }
   return (count);
}

void OpenBuy() {
   double ldLot = GetSizeLot();
   double ldStop = GetStopLossBuy();
   double ldTake = GetTakeProfitBuy();
   string lsComm = GetCommentForOrder();
   gi_ticket_number = OrderSend(Symbol(), OP_BUY, ldLot, Ask, Slippage, 0, 0, Name_Expert, magic_number, 0, clOpenBuy);
   OrderSelect(gi_ticket_number, SELECT_BY_TICKET);
   OrderModify(OrderTicket(), OrderOpenPrice(), ldStop, ldTake, 0, Blue);
   if (UseSound) PlaySound(NameFileSound);
}

void OpenSell() {
   double ldLot = GetSizeLot();
   double ldStop = GetStopLossSell();
   double ldTake = GetTakeProfitSell();
   string lsComm = GetCommentForOrder();
   gi_ticket_number = OrderSend(Symbol(), OP_SELL, ldLot, Bid, Slippage, 0, 0, Name_Expert, magic_number, 0, clOpenSell);
   OrderSelect(gi_ticket_number, SELECT_BY_TICKET);
   OrderModify(OrderTicket(), OrderOpenPrice(), ldStop, ldTake, 0, Red);
   if (UseSound) PlaySound(NameFileSound);
}

string GetCommentForOrder() {
   return (Name_Expert);
}

double GetSizeLot() {
   return (Lots);
}

double SetPoint() {
   double ld_point;
   if (Digits < 4) ld_point = 0.01;
   else ld_point = 0.0001;
   return (ld_point);
}

double SetDigit() {
   double ld_digit;
   if (Digits < 4) ld_digit = 2;
   else ld_digit = 4;
   return (ld_digit);
}

double GetTakeProfitBuy() {
   return (Ask + lTakeProfit * gd_point);
}

double GetTakeProfitSell() {
   return (Bid - sTakeProfit * gd_point);
}

double GetStopLossBuy() {
   return (Bid - lStopLoss * gd_point);
}

double GetStopLossSell() {
   return (Ask + sStopLoss * gd_point);
}

bool CheckAccountNumber() {
   if (YourAccountNumber == AccountNumber()) return (TRUE);
   Alert("AccountNumber entered is incorrect.\n You entered ", YourAccountNumber);
   return (FALSE);
}

Profitability Reports

NZD/USD Jan 2025 - Jul 2025
1955.29
Total Trades 420
Won Trades 417
Lost trades 3
Win Rate 99.29 %
Expected payoff 9.77
Gross Profit 4106.10
Gross Loss -2.10
Total Net Profit 4104.00
-100%
-50%
0%
50%
100%
GBP/AUD Oct 2025 - Feb 2026
112.82
Total Trades 870
Won Trades 860
Lost trades 10
Win Rate 98.85 %
Expected payoff 6.91
Gross Profit 6067.45
Gross Loss -53.78
Total Net Profit 6013.67
-100%
-50%
0%
50%
100%
USD/CHF Jan 2025 - Jul 2025
30.44
Total Trades 918
Won Trades 915
Lost trades 3
Win Rate 99.67 %
Expected payoff 11.33
Gross Profit 10750.07
Gross Loss -353.10
Total Net Profit 10396.97
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
11.95
Total Trades 501
Won Trades 491
Lost trades 10
Win Rate 98.00 %
Expected payoff 8.98
Gross Profit 4910.00
Gross Loss -411.00
Total Net Profit 4499.00
-100%
-50%
0%
50%
100%
USD/CAD Jan 2025 - Jul 2025
11.22
Total Trades 710
Won Trades 700
Lost trades 10
Win Rate 98.59 %
Expected payoff 6.44
Gross Profit 5016.80
Gross Loss -447.21
Total Net Profit 4569.59
-100%
-50%
0%
50%
100%
AUD/USD Oct 2024 - Jan 2025
11.18
Total Trades 560
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff 8.94
Gross Profit 5500.00
Gross Loss -491.80
Total Net Profit 5008.20
-100%
-50%
0%
50%
100%
GBP/USD Jan 2025 - Jul 2025
9.36
Total Trades 886
Won Trades 876
Lost trades 10
Win Rate 98.87 %
Expected payoff 8.83
Gross Profit 8760.00
Gross Loss -935.90
Total Net Profit 7824.10
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
4.61
Total Trades 2180
Won Trades 2170
Lost trades 10
Win Rate 99.54 %
Expected payoff 5.30
Gross Profit 14749.98
Gross Loss -3201.44
Total Net Profit 11548.54
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
3.18
Total Trades 251
Won Trades 241
Lost trades 10
Win Rate 96.02 %
Expected payoff 6.58
Gross Profit 2410.00
Gross Loss -757.60
Total Net Profit 1652.40
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
3.18
Total Trades 254
Won Trades 244
Lost trades 10
Win Rate 96.06 %
Expected payoff 6.59
Gross Profit 2440.00
Gross Loss -767.20
Total Net Profit 1672.80
-100%
-50%
0%
50%
100%
GBP/CAD Jan 2025 - Jul 2025
2.52
Total Trades 407
Won Trades 397
Lost trades 10
Win Rate 97.54 %
Expected payoff 4.26
Gross Profit 2867.92
Gross Loss -1136.08
Total Net Profit 1731.84
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
2.11
Total Trades 346
Won Trades 336
Lost trades 10
Win Rate 97.11 %
Expected payoff 3.32
Gross Profit 2182.72
Gross Loss -1034.57
Total Net Profit 1148.15
-100%
-50%
0%
50%
100%
USD/JPY Jul 2025 - Sep 2025
2.05
Total Trades 510
Won Trades 500
Lost trades 10
Win Rate 98.04 %
Expected payoff 3.45
Gross Profit 3429.49
Gross Loss -1671.90
Total Net Profit 1757.59
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
1.25
Total Trades 520
Won Trades 510
Lost trades 10
Win Rate 98.08 %
Expected payoff 1.93
Gross Profit 5100.00
Gross Loss -4095.90
Total Net Profit 1004.10
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.95
Total Trades 170
Won Trades 160
Lost trades 10
Win Rate 94.12 %
Expected payoff -0.32
Gross Profit 1055.52
Gross Loss -1110.32
Total Net Profit -54.80
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
0.92
Total Trades 90
Won Trades 80
Lost trades 10
Win Rate 88.89 %
Expected payoff -1.03
Gross Profit 1015.40
Gross Loss -1108.07
Total Net Profit -92.67
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.83
Total Trades 376
Won Trades 366
Lost trades 10
Win Rate 97.34 %
Expected payoff -1.46
Gross Profit 2643.72
Gross Loss -3192.50
Total Net Profit -548.78
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
0.83
Total Trades 85
Won Trades 75
Lost trades 10
Win Rate 88.24 %
Expected payoff -2.27
Gross Profit 952.16
Gross Loss -1144.69
Total Net Profit -192.53
-100%
-50%
0%
50%
100%
EUR/USD Oct 2025 - Feb 2026
0.75
Total Trades 236
Won Trades 226
Lost trades 10
Win Rate 95.76 %
Expected payoff -3.18
Gross Profit 2260.00
Gross Loss -3010.50
Total Net Profit -750.50
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.72
Total Trades 150
Won Trades 140
Lost trades 10
Win Rate 93.33 %
Expected payoff -3.67
Gross Profit 1400.00
Gross Loss -1950.70
Total Net Profit -550.70
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.72
Total Trades 150
Won Trades 140
Lost trades 10
Win Rate 93.33 %
Expected payoff -3.67
Gross Profit 1400.00
Gross Loss -1950.70
Total Net Profit -550.70
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
0.55
Total Trades 240
Won Trades 230
Lost trades 10
Win Rate 95.83 %
Expected payoff -7.70
Gross Profit 2300.00
Gross Loss -4148.20
Total Net Profit -1848.20
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.39
Total Trades 192
Won Trades 182
Lost trades 10
Win Rate 94.79 %
Expected payoff -10.80
Gross Profit 1299.60
Gross Loss -3372.66
Total Net Profit -2073.06
-100%
-50%
0%
50%
100%
AUD/USD Oct 2025 - Feb 2026
0.25
Total Trades 170
Won Trades 160
Lost trades 10
Win Rate 94.12 %
Expected payoff -27.60
Gross Profit 1600.00
Gross Loss -6292.00
Total Net Profit -4692.00
-100%
-50%
0%
50%
100%
GBP/AUD Jan 2025 - Jul 2025
0.21
Total Trades 392
Won Trades 382
Lost trades 10
Win Rate 97.45 %
Expected payoff -24.55
Gross Profit 2544.31
Gross Loss -12169.79
Total Net Profit -9625.48
-100%
-50%
0%
50%
100%
USD/JPY Jul 2025 - Sep 2025
0.21
Total Trades 119
Won Trades 109
Lost trades 10
Win Rate 91.60 %
Expected payoff -23.79
Gross Profit 760.72
Gross Loss -3592.22
Total Net Profit -2831.50
-100%
-50%
0%
50%
100%
EUR/USD Jan 2025 - Jul 2025
0.18
Total Trades 253
Won Trades 246
Lost trades 7
Win Rate 97.23 %
Expected payoff -45.65
Gross Profit 2460.00
Gross Loss -14009.80
Total Net Profit -11549.80
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
0.17
Total Trades 49
Won Trades 39
Lost trades 10
Win Rate 79.59 %
Expected payoff -29.55
Gross Profit 287.29
Gross Loss -1735.43
Total Net Profit -1448.14
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
0.17
Total Trades 49
Won Trades 39
Lost trades 10
Win Rate 79.59 %
Expected payoff -29.63
Gross Profit 287.31
Gross Loss -1739.12
Total Net Profit -1451.81
-100%
-50%
0%
50%
100%
AUD/USD Jan 2025 - Jul 2025
0.14
Total Trades 177
Won Trades 171
Lost trades 6
Win Rate 96.61 %
Expected payoff -58.19
Gross Profit 1710.00
Gross Loss -12009.60
Total Net Profit -10299.60
-100%
-50%
0%
50%
100%
USD/CAD Oct 2024 - Jan 2025
0.11
Total Trades 93
Won Trades 83
Lost trades 10
Win Rate 89.25 %
Expected payoff -52.90
Gross Profit 593.78
Gross Loss -5513.77
Total Net Profit -4919.99
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
0.05
Total Trades 72
Won Trades 66
Lost trades 6
Win Rate 91.67 %
Expected payoff -157.60
Gross Profit 660.00
Gross Loss -12007.20
Total Net Profit -11347.20
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
0.05
Total Trades 72
Won Trades 66
Lost trades 6
Win Rate 91.67 %
Expected payoff -157.61
Gross Profit 660.00
Gross Loss -12007.80
Total Net Profit -11347.80
-100%
-50%
0%
50%
100%

Comments