ZigZagEvgeTrofi 1

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

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
5 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 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%
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%
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%
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/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%
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%
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%
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%
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%
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%

Comments