ZigZagEvgeTrofi 1

Author: Copyright � 2008, Trofimov Evgeniy
Profit factor:
0.72

This script is designed to automatically trade on the market based on signals generated by the "ZigZag" indicator. Here's how it works in simple terms:

  1. Checks Trade Permissions: First, the script verifies if trading is allowed by the broker. If not, it pauses and checks again later.

  2. Avoids Duplication: It also ensures that the script doesn't execute the same trading logic multiple times for the same price bar or candle, which could lead to unintended multiple trades.

  3. Identifies ZigZag Points: The script then uses the "ZigZag" indicator to find significant highs and lows on the price chart. This indicator essentially highlights the turning points in the price movement. It looks back at recent price data to locate these points.

  4. Determines Signal: Based on the last calculated ZigZag point the script determines the signal. If the last ZigZag point detected is a high, it interprets this as a potential sell signal. Conversely, if it detects a low, it interprets it as a potential buy signal.

  5. Checks Existing Orders: The script then examines if there are any existing open orders (trades) associated with it (using a unique identifier). It compares the direction of the existing order with the current signal from the ZigZag indicator.

  6. Closes Conflicting Orders: If an order exists and its direction (buy or sell) is opposite to the current signal, the script closes that existing order. For example, if the script has a buy order open, and the ZigZag indicator is now signaling a sell, the buy order will be closed.

  7. Places New Orders: If the detected ZigZag point is within a certain period the script will place an order.If there are no open orders, or an existing order was just closed, the script places a new order based on the ZigZag signal. A buy order is placed if the ZigZag indicator signaled a low (potential upward movement), and a sell order is placed if the ZigZag indicator signaled a high (potential downward movement).

In summary, this script watches for turning points identified by the ZigZag indicator, closes conflicting trades, and opens new trades in the direction suggested by those turning points. The script's goal is to automatically capitalize on potential price swings based on the ZigZag pattern.

Orders Execution
Checks for the total of open ordersIt Closes Orders by itself It automatically opens orders when conditions are reached
9 Views
0 Downloads
0 Favorites
ZigZagEvgeTrofi 1
//+------------------------------------------------------------------+
//|                                            ZigZagEvgeTrofi 1.mq4 |
//|                      Copyright © 2008, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Trofimov Evgeniy"
#property link      "http://www.fracpar.narod.ru/"

#define MAGICMA  20080919
#define Slippage 5

//---- indicator parameters
extern int ExtDepth=17; //10-21 !15 !17
extern int ExtDeviation=7; //!7
extern int ExtBackstep=5;  //!5
extern double Lot=0.10;
//----
static int prevtime = 0;
int Urgency=2;
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   int i, candle;
   double ZigZag;
   int CurrentCondition, Signal;
   
   if (! IsTradeAllowed()) {
      prevtime = Time[1];
      MathSrand(TimeCurrent());
      Sleep(30000 + MathRand());
      return(0);
   }
   if (Time[0] == prevtime) return(0);
   prevtime = Time[0];  
   while(candle<100)
     {
      ZigZag=iCustom(NULL,0,"ZigZag",   ExtDepth,ExtDeviation,ExtBackstep,   0,candle);
      if(ZigZag!=0) break;
      candle++;
     }
   if(candle>99) return(0);
   if(ZigZag==High[candle])
      Signal=1;
   else if(ZigZag==Low[candle])
      Signal=2;
   int total = OrdersTotal();
   for (i = 0; i < total; i++) {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MAGICMA) {
         CurrentCondition=OrderType()+1;
         break;
      } 
   }
   
   if(Signal==CurrentCondition) return(0);
   if(Signal!=CurrentCondition && CurrentCondition>0)
     {
      if(CurrentCondition==1)
         OrderClose(OrderTicket(),OrderLots(),Bid,Slippage);
      else
         OrderClose(OrderTicket(),OrderLots(),Ask,Slippage);
      Sleep(20000);
      RefreshRates();
     }

   if(candle<=Urgency)
     {
      if(Signal==1)
         OrderSend(Symbol(), OP_BUY, Lot, Ask, Slippage, 0, 0, "ZigZag", MAGICMA, 0, Blue);
      else
         OrderSend(Symbol(), OP_SELL, Lot, Bid, Slippage, 0, 0, "ZigZag", MAGICMA, 0, Red);
      Sleep(20000);
      prevtime = Time[1];
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Profitability Reports

USD/CAD Oct 2024 - Jan 2025
1.31
Total Trades 61
Won Trades 23
Lost trades 38
Win Rate 37.70 %
Expected payoff 3.35
Gross Profit 861.59
Gross Loss -657.50
Total Net Profit 204.09
-100%
-50%
0%
50%
100%
GBP/CAD Oct 2024 - Jan 2025
1.16
Total Trades 77
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff 2.61
Gross Profit 1427.24
Gross Loss -1226.52
Total Net Profit 200.72
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
1.11
Total Trades 67
Won Trades 23
Lost trades 44
Win Rate 34.33 %
Expected payoff 1.25
Gross Profit 872.00
Gross Loss -788.15
Total Net Profit 83.85
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
0.96
Total Trades 73
Won Trades 25
Lost trades 48
Win Rate 34.25 %
Expected payoff -0.81
Gross Profit 1261.00
Gross Loss -1320.20
Total Net Profit -59.20
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
0.96
Total Trades 120
Won Trades 41
Lost trades 79
Win Rate 34.17 %
Expected payoff -0.55
Gross Profit 1512.40
Gross Loss -1578.60
Total Net Profit -66.20
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.96
Total Trades 122
Won Trades 44
Lost trades 78
Win Rate 36.07 %
Expected payoff -0.28
Gross Profit 884.90
Gross Loss -918.50
Total Net Profit -33.60
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.94
Total Trades 56
Won Trades 20
Lost trades 36
Win Rate 35.71 %
Expected payoff -0.66
Gross Profit 572.30
Gross Loss -609.30
Total Net Profit -37.00
-100%
-50%
0%
50%
100%
GBP/AUD Jan 2025 - Jul 2025
0.93
Total Trades 142
Won Trades 49
Lost trades 93
Win Rate 34.51 %
Expected payoff -1.64
Gross Profit 2943.17
Gross Loss -3175.61
Total Net Profit -232.44
-100%
-50%
0%
50%
100%
USD/JPY Jul 2025 - Sep 2025
0.93
Total Trades 60
Won Trades 23
Lost trades 37
Win Rate 38.33 %
Expected payoff -1.22
Gross Profit 997.13
Gross Loss -1070.40
Total Net Profit -73.27
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
0.90
Total Trades 55
Won Trades 17
Lost trades 38
Win Rate 30.91 %
Expected payoff -1.14
Gross Profit 559.48
Gross Loss -622.05
Total Net Profit -62.57
-100%
-50%
0%
50%
100%
AUD/USD Jan 2025 - Jul 2025
0.83
Total Trades 135
Won Trades 45
Lost trades 90
Win Rate 33.33 %
Expected payoff -2.84
Gross Profit 1862.30
Gross Loss -2245.50
Total Net Profit -383.20
-100%
-50%
0%
50%
100%
GBP/USD Jan 2025 - Jul 2025
0.82
Total Trades 143
Won Trades 47
Lost trades 96
Win Rate 32.87 %
Expected payoff -4.80
Gross Profit 3195.70
Gross Loss -3881.80
Total Net Profit -686.10
-100%
-50%
0%
50%
100%
USD/CHF Jan 2025 - Jul 2025
0.82
Total Trades 154
Won Trades 54
Lost trades 100
Win Rate 35.06 %
Expected payoff -3.82
Gross Profit 2700.85
Gross Loss -3289.02
Total Net Profit -588.17
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.80
Total Trades 73
Won Trades 27
Lost trades 46
Win Rate 36.99 %
Expected payoff -3.53
Gross Profit 1037.89
Gross Loss -1295.68
Total Net Profit -257.79
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
0.79
Total Trades 132
Won Trades 49
Lost trades 83
Win Rate 37.12 %
Expected payoff -5.69
Gross Profit 2778.33
Gross Loss -3529.24
Total Net Profit -750.91
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.79
Total Trades 123
Won Trades 39
Lost trades 84
Win Rate 31.71 %
Expected payoff -1.87
Gross Profit 869.00
Gross Loss -1098.80
Total Net Profit -229.80
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.76
Total Trades 58
Won Trades 18
Lost trades 40
Win Rate 31.03 %
Expected payoff -2.93
Gross Profit 528.80
Gross Loss -698.60
Total Net Profit -169.80
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
0.76
Total Trades 68
Won Trades 15
Lost trades 53
Win Rate 22.06 %
Expected payoff -3.71
Gross Profit 781.21
Gross Loss -1033.18
Total Net Profit -251.97
-100%
-50%
0%
50%
100%
USD/CAD Jan 2025 - Jul 2025
0.72
Total Trades 152
Won Trades 54
Lost trades 98
Win Rate 35.53 %
Expected payoff -4.63
Gross Profit 1787.14
Gross Loss -2491.52
Total Net Profit -704.38
-100%
-50%
0%
50%
100%
GBP/CAD Jan 2025 - Jul 2025
0.70
Total Trades 178
Won Trades 58
Lost trades 120
Win Rate 32.58 %
Expected payoff -6.02
Gross Profit 2529.23
Gross Loss -3601.12
Total Net Profit -1071.89
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
0.67
Total Trades 113
Won Trades 36
Lost trades 77
Win Rate 31.86 %
Expected payoff -2.82
Gross Profit 654.25
Gross Loss -973.30
Total Net Profit -319.05
-100%
-50%
0%
50%
100%
AUD/USD Oct 2024 - Jan 2025
0.61
Total Trades 71
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -5.54
Gross Profit 611.30
Gross Loss -1004.90
Total Net Profit -393.60
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.47
Total Trades 132
Won Trades 36
Lost trades 96
Win Rate 27.27 %
Expected payoff -8.84
Gross Profit 1046.97
Gross Loss -2213.61
Total Net Profit -1166.64
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.41
Total Trades 136
Won Trades 35
Lost trades 101
Win Rate 25.74 %
Expected payoff -9.78
Gross Profit 928.81
Gross Loss -2259.45
Total Net Profit -1330.64
-100%
-50%
0%
50%
100%
EUR/USD Jan 2025 - Jul 2025
0.01
Total Trades 49
Won Trades 18
Lost trades 31
Win Rate 36.73 %
Expected payoff -1982.20
Gross Profit 1051.80
Gross Loss -98179.80
Total Net Profit -97128.00
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
0.00
Total Trades 8
Won Trades 2
Lost trades 6
Win Rate 25.00 %
Expected payoff -13202.81
Gross Profit 31.70
Gross Loss -105654.20
Total Net Profit -105622.50
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
0.00
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
0.00
Total Trades 16
Won Trades 3
Lost trades 13
Win Rate 18.75 %
Expected payoff -6601.23
Gross Profit 43.00
Gross Loss -105662.70
Total Net Profit -105619.70
-100%
-50%
0%
50%
100%

Comments