es_capelast_reversed_ECN_v1

Profit factor:
47.90

Okay, here's a breakdown of what this trading script does, explained in a way that avoids technical jargon and is easy for someone without programming knowledge to understand.

Overall Purpose:

This script is designed to automatically place buy and sell orders on a specific currency pair in the MetaTrader platform. It attempts to identify potential trading opportunities based on a couple of simple moving average calculations. The script also includes basic risk management features like stop-loss and take-profit levels.

Here's a Step-by-Step Explanation:

  1. Setup and Configuration:

    • External Variables: The script starts by defining several settings that you can adjust. These include:
      • Your account number (to ensure it's trading on the correct account).
      • Take-profit levels (how much profit to aim for on each trade).
      • Stop-loss levels (how much loss to tolerate before exiting a trade).
      • Maximum number of total orders and orders per symbol at once.
      • Lot size (the amount of currency to trade in each order).
      • Colors for visualizing trades on the chart.
      • A "magic number" (a unique identifier for orders placed by this script).
      • Slippage: The acceptable price variation for order execution.
      • Reverse logic: a setting to inverse buy and sell.
      • Sound alerts: to notify when an order is opened.
  2. Initialization (One-Time Setup):

    • The init() function runs when the script is first loaded. It does a few things:
      • Checks if you're trading on a demo account. If so, it flags that the account is verified.
      • Verifies the account number to ensure the script is attached to the intended trading account.
      • Calculates the "point size" (smallest price increment) and the number of decimal places for the current currency pair.
  3. The Main Loop (Start Function):

    • The start() function runs repeatedly, constantly checking for trading opportunities. Here's what it does in each cycle:
      • Checks Trading Status: First, it ensures that automated trading is enabled and that it has enough historical price data.
      • Basic Checks: Verifies enough money in the account and also the settings, like minimum values for Take Profit.
      • Calculates Moving Averages:
        • It calculates two simple moving averages (MAs) of the opening price over a specific period (5 periods and 4 periods) on a 5-minute timeframe. Moving averages smooth out price fluctuations, making it easier to identify trends.
      • Checks for Open Positions:
        • The script checks if the maximum number of allowed orders has already been reached. If so, it does nothing and waits for existing trades to close.
      • Trading Logic (Buy/Sell Signals):
        • The "Heart" of the Script: The script uses these moving averages to generate buy or sell signals.
        • If the current closing price is less than the 5-period MA, it considers this a potential sell signal.
        • If the current closing price is greater than the 4-period MA, it considers this a potential buy signal.
        • If the reverseLogic setting is enabled, then the opposite happens: the first rule generates a buy signal, and the second rule generates a sell signal.
      • Placing Orders:
        • If a buy or sell signal is triggered, the script calculates the appropriate lot size, stop-loss level, and take-profit level based on your settings.
        • It then sends an order to the broker to open a new position.
        • If the order is placed successfully, it modifies the order to add the stop-loss and take-profit levels, protecting against excessive losses and automatically taking profits at the desired level.
      • Sound Alert: If enabled, it plays a sound to notify the user when an order is opened.
  4. Helper Functions:

    • The script uses several "helper" functions to make the main logic easier to read and manage. These functions include:
      • ExistPositions(): Checks if the maximum number of allowed orders has been reached.
      • OrderCount(): Counts the number of orders for the current currency pair.
      • OpenBuy(): Opens a buy order.
      • OpenSell(): Opens a sell order.
      • GetCommentForOrder(): Returns a comment to identify orders from this script.
      • GetSizeLot(): Determines the lot size.
      • SetPoint(): Determines the point size for the pair.
      • SetDigit(): Determines the number of decimal places for the pair.
      • GetTakeProfitBuy(): Calculates the take-profit level for a buy order.
      • GetTakeProfitSell(): Calculates the take-profit level for a sell order.
      • GetStopLossBuy(): Calculates the stop-loss level for a buy order.
      • GetStopLossSell(): Calculates the stop-loss level for a sell order.
      • CheckAccountNumber(): Checks if the account number is correct.

In Simple Terms:

Imagine this script as a robot that watches the price movements of a currency pair. It looks at two different moving averages to get a sense of the trend. If the current price crosses these moving averages in a specific way, the robot will either place a buy order (betting the price will go up) or a sell order (betting the price will go down). The robot also sets a stop-loss to limit potential losses and a take-profit to automatically close the trade when a certain profit is reached. The "reverse logic" setting makes the robot do the opposite of what it would normally do.

Important Notes:

  • Risk: This script, like all automated trading systems, involves risk. It's crucial to understand the settings and test the script thoroughly on a demo account before using it with real money.
  • Strategy: The trading strategy used in this script is very basic. It relies on simple moving averages, which may not be effective in all market conditions.
  • Customization: The script allows for a decent amount of customization, which is useful to adapt the settings to your personal trading preferences and risk tolerance.
  • No Guarantee: This explanation is for informational purposes only. There is no guarantee that this script will generate profits.
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
2 Downloads
0 Favorites
es_capelast_reversed_ECN_v1
//+------------------------------------------------------------------+
//|                                  es_capelast_reversed_ECN_v1.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");
   }
   if (gi_accountVerified == FALSE) gi_accountVerified = CheckAccountNumber();
   if (gi_accountVerified == TRUE) {
      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

USD/CHF Jan 2025 - Jul 2025
1134.16
Total Trades 965
Won Trades 961
Lost trades 4
Win Rate 99.59 %
Expected payoff 11.70
Gross Profit 11296.20
Gross Loss -9.96
Total Net Profit 11286.24
-100%
-50%
0%
50%
100%
NZD/USD Jan 2025 - Jul 2025
153.71
Total Trades 417
Won Trades 410
Lost trades 7
Win Rate 98.32 %
Expected payoff 9.74
Gross Profit 4088.70
Gross Loss -26.60
Total Net Profit 4062.10
-100%
-50%
0%
50%
100%
GBP/AUD Oct 2025 - Feb 2026
112.81
Total Trades 870
Won Trades 860
Lost trades 10
Win Rate 98.85 %
Expected payoff 6.92
Gross Profit 6070.18
Gross Loss -53.81
Total Net Profit 6016.37
-100%
-50%
0%
50%
100%
GBP/USD Jan 2025 - Jul 2025
27.72
Total Trades 922
Won Trades 912
Lost trades 10
Win Rate 98.92 %
Expected payoff 9.53
Gross Profit 9120.00
Gross Loss -329.00
Total Net Profit 8791.00
-100%
-50%
0%
50%
100%
AUD/USD Oct 2024 - Jan 2025
11.31
Total Trades 555
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff 8.95
Gross Profit 5450.00
Gross Loss -482.00
Total Net Profit 4968.00
-100%
-50%
0%
50%
100%
USD/CAD Jan 2025 - Jul 2025
10.48
Total Trades 720
Won Trades 710
Lost trades 10
Win Rate 98.61 %
Expected payoff 6.39
Gross Profit 5089.46
Gross Loss -485.78
Total Net Profit 4603.68
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
6.76
Total Trades 814
Won Trades 804
Lost trades 10
Win Rate 98.77 %
Expected payoff 8.42
Gross Profit 8040.00
Gross Loss -1188.70
Total Net Profit 6851.30
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
4.60
Total Trades 2178
Won Trades 2168
Lost trades 10
Win Rate 99.54 %
Expected payoff 5.29
Gross Profit 14729.20
Gross Loss -3201.86
Total Net Profit 11527.34
-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%
USD/JPY Jul 2025 - Sep 2025
2.22
Total Trades 650
Won Trades 640
Lost trades 10
Win Rate 98.46 %
Expected payoff 3.67
Gross Profit 4347.00
Gross Loss -1960.57
Total Net Profit 2386.43
-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.99
Gross Loss -1034.47
Total Net Profit 1148.52
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
1.48
Total Trades 469
Won Trades 459
Lost trades 10
Win Rate 97.87 %
Expected payoff 2.28
Gross Profit 3315.59
Gross Loss -2246.09
Total Net Profit 1069.50
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
1.26
Total Trades 523
Won Trades 513
Lost trades 10
Win Rate 98.09 %
Expected payoff 2.01
Gross Profit 5130.00
Gross Loss -4077.60
Total Net Profit 1052.40
-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.36
Gross Profit 1055.49
Gross Loss -1116.15
Total Net Profit -60.66
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
0.91
Total Trades 90
Won Trades 80
Lost trades 10
Win Rate 88.89 %
Expected payoff -1.13
Gross Profit 1015.41
Gross Loss -1117.52
Total Net Profit -102.11
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
0.88
Total Trades 90
Won Trades 80
Lost trades 10
Win Rate 88.89 %
Expected payoff -1.54
Gross Profit 1015.63
Gross Loss -1154.59
Total Net Profit -138.96
-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.56
Total Trades 240
Won Trades 230
Lost trades 10
Win Rate 95.83 %
Expected payoff -7.40
Gross Profit 2300.00
Gross Loss -4076.00
Total Net Profit -1776.00
-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.50
Gross Profit 1600.00
Gross Loss -6275.00
Total Net Profit -4675.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.56
Gross Profit 2545.26
Gross Loss -12170.85
Total Net Profit -9625.59
-100%
-50%
0%
50%
100%
USD/JPY Jul 2025 - Sep 2025
0.21
Total Trades 120
Won Trades 110
Lost trades 10
Win Rate 91.67 %
Expected payoff -23.46
Gross Profit 767.70
Gross Loss -3582.60
Total Net Profit -2814.90
-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 -14010.50
Total Net Profit -11550.50
-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.33
Gross Loss -1739.05
Total Net Profit -1451.72
-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.30
Gross Loss -1735.43
Total Net Profit -1448.13
-100%
-50%
0%
50%
100%
AUD/USD Jan 2025 - Jul 2025
0.15
Total Trades 187
Won Trades 181
Lost trades 6
Win Rate 96.79 %
Expected payoff -54.53
Gross Profit 1810.00
Gross Loss -12007.20
Total Net Profit -10197.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