Author: Copyright � 2006, Victor Chebotariov
Profit factor:
0.41

This script is an automated trading program designed for the MetaTrader platform. It's designed to automatically buy and sell a particular currency pair based on a calculated value derived from price movements and volume.

Here's a breakdown of the script's logic:

  1. Initialization:

    • It starts by defining some basic settings like a "magic number" (MAGICMA) to identify orders placed by this specific script and some external parameters that can be adjusted by the user:
      • PERIOD: A length of time used in a moving average calculation
      • MODE: A type of moving average
      • RISK: The percentage of the account balance the script is allowed to risk on any single trade.
      • MAXORDERS: The maximum number of trades the script can have open at the same time.
  2. Lot Size Calculation:

    • The script has a function to calculate the optimal trade size ("LotsOptimized"). This function determines how many units of the currency to trade based on the account balance, risk percentage, available margin (funds available for trading), and the maximum and minimum allowed trade sizes set by the broker. It makes sure the trade size doesn't exceed what the account can handle or what the broker allows.
  3. Main Trading Logic:

    • The start() function contains the core logic that runs repeatedly.
    • It first defines several variables to be used in the subsequent calculations.
    • Moving Average Calculation: The script uses several moving averages (high, low, open, close) over the time period set by the PERIOD variable.
    • GO Calculation: The script then calculates a "GO" value which is a combination of the difference between the open and close prices, the high and open prices, the low and open prices, the close and low prices and the close and high prices, multiplied by the volume of the latest candle.
    • Closing Existing Orders:
      • If the "GO" value is negative, the script iterates through all open orders. If it finds any open buy orders for the specified currency pair placed by this script, it closes them.
      • If the "GO" value is positive, the script iterates through all open orders. If it finds any open sell orders for the specified currency pair placed by this script, it closes them.
    • Opening New Orders:
      • The script checks that either GO is above zero or GO is below zero and also makes sure that a special time-stamp variable is not current. The TimeBuySell global variable is a means of checking that a trade has not already been placed. Finally, it makes sure that the maximum number of orders set by the MAXORDERS variable has not been reached.
      • It then checks if the account has enough funds to place a new trade, given the calculated lot size.
      • If the "GO" value is positive, the script places a buy order for the currency pair, using the calculated lot size.
      • If the "GO" value is negative, the script places a sell order for the currency pair, using the calculated lot size.
      • After attempting to place an order, the script stores a timestamp, the current time, in the global variable Symbol()MAGICMATimeBuySell. This stops an order from being placed in successive iterations of the start() function, until this timestamp is changed in a later iteration.

In summary, this script calculates a value based on price and volume, and uses this value to decide whether to buy or sell a currency pair. It manages risk by calculating an appropriate trade size and limiting the number of open trades. It aims to close out any existing positions which are now contrary to the position determined by the GO value.

Orders Execution
Checks for the total of open ordersIt Closes Orders by itself It automatically opens orders when conditions are reached
Indicators Used
Moving average indicator
3 Views
0 Downloads
0 Favorites
GO_v1
//+------------------------------------------------------------------+
//|                                                           GO.mq4 |
//|                             Copyright © 2006, Victor Chebotariov |
//|                                      http://www.chebotariov.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Victor Chebotariov"
#property link      "http://www.chebotariov.com/"

#define MAGICMA 30072006

int    PERIOD = 174;
int    MODE = 0;
extern double RISK = 30.0;
extern int    MAXORDERS = 5;

//+------------------------------------------------------------------+
//| Ðàñ÷åò îïòèìàëüíîãî îáúåìà ëîòà                                  |
//+------------------------------------------------------------------+
double LotsOptimized()
  {
//----
   double Lots=NormalizeDouble(AccountBalance()*RISK/100000.0,1);
   if(AccountFreeMargin()<(1000*Lots)){Lots=NormalizeDouble(AccountFreeMargin()*RISK/100000.0,1);}
   if(Lots>MarketInfo(Symbol(),MODE_MAXLOT)){Lots=MarketInfo(Symbol(),MODE_MAXLOT);}
   if(Lots<MarketInfo(Symbol(),MODE_MINLOT)){Lots=MarketInfo(Symbol(),MODE_MINLOT);}
//----
   return(Lots);
  }

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----

//+------------------------------------------------------------------+
//if(!IsDemo()){return(0);} //  óäàëèòü äëÿ ðàáîòû íà ðåàëüíîì ñ÷åòå   |
//+------------------------------------------------------------------+

   int cnt,ticket,MODEMA;
   int total=OrdersTotal();

   if(MODE==0){MODEMA=MODE_SMA;}
   if(MODE==1){MODEMA=MODE_EMA;}
   if(MODE==2){MODEMA=MODE_SMMA;}
   if(MODE==3){MODEMA=MODE_LWMA;}
   
   HideTestIndicators(true);
   double high =iMA(NULL,0,PERIOD,0,MODEMA,PRICE_HIGH,0);
   double low  =iMA(NULL,0,PERIOD,0,MODEMA,PRICE_LOW,0);
   double open =iMA(NULL,0,PERIOD,0,MODEMA,PRICE_OPEN,0);
   double close=iMA(NULL,0,PERIOD,0,MODEMA,PRICE_CLOSE,0);
   double GO=((close-open)+(high-open)+(low-open)+(close-low)+(close-high))*Volume[0];
   HideTestIndicators(false);

   if(GO<0)
     {
      for(cnt=total-1;cnt>=0;cnt--)
        {
         OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
         if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
         {OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet);return(0);}
        }
     }

   if(GO>0)
     {
      for(cnt=total-1;cnt>=0;cnt--)
        {
         OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
         if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
         {OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet);return(0);}
        }
     }

   if((GO>0 || GO<0) && (!GlobalVariableCheck("Symbol()"+"MAGICMA"+"TimeBuySell") || GlobalVariableGet("Symbol()"+"MAGICMA"+"TimeBuySell")!=Time[0] && total<MAXORDERS))
     {
      if(AccountFreeMargin()<(1000*LotsOptimized()))
      {Print("Ó Âàñ íåäîñòàòî÷íî äåíåã. Ñâîáîäíîé ìàðæè = ", AccountFreeMargin());return(0);}
      if(GO>0)
        {
         ticket=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0,0,"MoneyPlus",MAGICMA,0,Green);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
            GlobalVariableSet("Symbol()"+"MAGICMA"+"TimeBuySell",Time[0]);
           }
         else Print("Error opening BUY order : ",GetLastError());return(0); 
        }
      if(GO<0)
        {
         ticket=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,0,0,"MoneyPlus",MAGICMA,0,Red);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
            GlobalVariableSet("Symbol()"+"MAGICMA"+"TimeBuySell",Time[0]);
           }
         else Print("Error opening SELL order : ",GetLastError());return(0);
        }
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Profitability Reports

GBP/CAD Jul 2025 - Sep 2025
0.00
Total Trades 5
Won Trades 0
Lost trades 5
Win Rate 0.00 %
Expected payoff -875.30
Gross Profit 0.00
Gross Loss -4376.48
Total Net Profit -4376.48
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.25
Total Trades 19
Won Trades 6
Lost trades 13
Win Rate 31.58 %
Expected payoff -241.79
Gross Profit 1551.93
Gross Loss -6145.92
Total Net Profit -4593.99
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.00
Total Trades 5
Won Trades 0
Lost trades 5
Win Rate 0.00 %
Expected payoff -1402.80
Gross Profit 0.00
Gross Loss -7014.00
Total Net Profit -7014.00
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
0.09
Total Trades 12
Won Trades 3
Lost trades 9
Win Rate 25.00 %
Expected payoff -563.78
Gross Profit 652.32
Gross Loss -7417.73
Total Net Profit -6765.41
-100%
-50%
0%
50%
100%
USD/CHF Jan 2025 - Jul 2025
0.00
Total Trades 5
Won Trades 0
Lost trades 5
Win Rate 0.00 %
Expected payoff -503.47
Gross Profit 0.00
Gross Loss -2517.33
Total Net Profit -2517.33
-100%
-50%
0%
50%
100%
USD/CAD Jan 2025 - Jul 2025
0.04
Total Trades 129
Won Trades 13
Lost trades 116
Win Rate 10.08 %
Expected payoff -76.56
Gross Profit 430.06
Gross Loss -10305.93
Total Net Profit -9875.87
-100%
-50%
0%
50%
100%
NZD/USD Jan 2025 - Jul 2025
0.00
Total Trades 5
Won Trades 0
Lost trades 5
Win Rate 0.00 %
Expected payoff -1481.40
Gross Profit 0.00
Gross Loss -7407.00
Total Net Profit -7407.00
-100%
-50%
0%
50%
100%
GBP/USD Jan 2025 - Jul 2025
0.70
Total Trades 43
Won Trades 10
Lost trades 33
Win Rate 23.26 %
Expected payoff -132.68
Gross Profit 13294.60
Gross Loss -19000.00
Total Net Profit -5705.40
-100%
-50%
0%
50%
100%
GBP/CAD Jan 2025 - Jul 2025
1.81
Total Trades 11
Won Trades 5
Lost trades 6
Win Rate 45.45 %
Expected payoff 1625.59
Gross Profit 40014.16
Gross Loss -22132.63
Total Net Profit 17881.53
-100%
-50%
0%
50%
100%
GBP/AUD Jan 2025 - Jul 2025
0.00
Total Trades 11
Won Trades 0
Lost trades 11
Win Rate 0.00 %
Expected payoff -677.46
Gross Profit 0.00
Gross Loss -7452.10
Total Net Profit -7452.10
-100%
-50%
0%
50%
100%

Comments