SMC eur usd(28AUG05)

Profit factor:
0.75

This script is designed to automatically trade the EUR/USD currency pair in the MetaTrader platform. It uses several technical indicators to decide when to open and close trades.

Here's a breakdown of its logic:

  1. Initialization: When the script starts, it sets some initial values. Most notably, it doesn't do much in its init() function.

  2. Main Trading Loop: The start() function is the heart of the script. It runs repeatedly, checking for new trading opportunities and managing existing trades.

    • Check for New Bar: First, it ensures that a new price bar has formed on the chart before proceeding. This prevents the script from executing the same logic multiple times on the same price bar.

    • Indicator Setup: It calculates the values of several technical indicators, including:

      • ATR: Average True Range, which measures market volatility.
      • SMA: Simple Moving Average, which is a basic way to smooth out price data.
      • EMA: Exponential Moving Averages, which give more weight to recent prices. Two EMAs with different periods (5 and 8) are calculated.
      • MACD: Moving Average Convergence Divergence, which identifies momentum by comparing two moving averages.
      • RSI: Relative Strength Index, which measures the magnitude of recent price changes to evaluate overbought or oversold conditions.
    • Order Closure (Exit Logic): It checks if there are any open trades. If so, it looks at the relationship between the 5 and 8 period EMAs.

      • For Buy Orders: If the 8-period EMA is greater than the 5-period EMA, it closes the buy order.

      • For Sell Orders: If the 5-period EMA is greater than the 8-period EMA, it closes the sell order.

    • New Order Logic (Entry Logic): This section determines when to open new trades.

      • Check for Existing Trades: It makes sure there are no existing trades for the EUR/USD pair before opening a new one. This aims to have only one open trade at a time.

      • Check Free Margin: It verifies that the trading account has enough free margin to open a new trade.

      • Buy Order Conditions: To open a buy order, all of the following conditions must be met:

        • The 5-period EMA is greater than the 8-period EMA.

        • The RSI is greater than 50.

        • The MACD line is greater than the signal line.

      • Sell Order Conditions: To open a sell order, all of the following conditions must be met:

        • The 5-period EMA is greater than the 8-period EMA.

        • The RSI is less than 50.

        • The MACD line is less than the signal line.

  3. Order Execution: If the conditions for opening a buy or sell order are met, the script sends an order to the MetaTrader platform. It includes the lot size and a comment to identify the order. It checks if it was opened correctly and prints a message if not.

In summary, this script is a momentum-based trading system that uses moving averages, RSI, and MACD to identify potential buy and sell signals for the EUR/USD currency pair. It manages only one trade at a time and includes basic risk management by checking for sufficient free margin. It also exits positions when there is a possible trend change based on moving average crossovers.

Orders Execution
Checks for the total of open ordersIt Closes Orders by itself It automatically opens orders when conditions are reached
Indicators Used
Indicator of the average true rangeMoving average indicatorMACD HistogramRelative strength index
7 Views
0 Downloads
0 Favorites
SMC eur usd(28AUG05)
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                      SMC Autotrader Momentum.mq4 |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//+ Eur / USD
 extern double TakeProfit = 20;
 extern double Lots = 1.0;
 extern double InitialStop = 80;
 extern double TrailingStop = 40;
 datetime BarTime;

//#####################################################################
int init()
{
//---- 
//----
   return(0);
  }
//#####################################################################

int start()
  {
   int cnt,total,ticket,MinDist,tmp;
   double Spread;
   double ATR;
   double StopMA;
   double SetupHigh, SetupLow;
   
 
//############################################################################
  if(Bars<100){
     Print("bars less than 100");
     return(0);  
  }
  //exit if not new bar
 if(BarTime == Time[0]) {return(0);}
//new bar, update bartime
 BarTime = Time[0]; 
//#########################################################################################
//~~~~~~~~~~~~~~~~Miscellaneous setup stuff~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 ATR =iATR(NULL,0,10,0); // BE CAREFUL OF EFFECTING THE AUTO TRAIL STOPS
 StopMA=iMA(NULL,0,24,0,MODE_SMA,PRICE_CLOSE,0);
 MinDist=MarketInfo(Symbol(),MODE_STOPLEVEL);
 Spread=(Ask-Bid);
//#########################################################################################
 double MA1P1,MA1P2,MA2P1,MA2P2;
 MA1P1= iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,1);
 MA1P2= iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,2);
 MA2P1= iMA(NULL,0,8,0,MODE_EMA,PRICE_CLOSE,1);
 MA2P2= iMA(NULL,0,8,0,MODE_EMA,PRICE_CLOSE,2);

 int MACDMA1,MACDMA2,MACDMA3;
 MACDMA1=12;
 MACDMA2=26;
 MACDMA3=9;
 double MACDP1,MACDP2,MACDSP1,MACDSP2;
 MACDP1  = iMACD(NULL,0,MACDMA1,MACDMA2,MACDMA3,PRICE_CLOSE,MODE_MAIN,1);
 MACDP2  = iMACD(NULL,0,MACDMA1,MACDMA2,MACDMA3,PRICE_CLOSE,MODE_MAIN,2);
 MACDSP1 = iMACD(NULL,0,MACDMA1,MACDMA2,MACDMA3,PRICE_CLOSE,MODE_SIGNAL,1);
 MACDSP2 = iMACD(NULL,0,MACDMA1,MACDMA2,MACDMA3,PRICE_CLOSE,MODE_SIGNAL,2);

 double RSIvalP1,RSIvalP2;
 RSIvalP1 = iRSI(NULL,0,12,PRICE_CLOSE,1);
 RSIvalP2 = iRSI(NULL,0,12,PRICE_CLOSE,2);

//########################################################################################
//##################     ORDER CLOSURE  ###################################################
// If Orders are in force then check for closure against Technicals LONG & SHORT
//CLOSE LONG Entries
  total=OrdersTotal();
  if(total>0)
   { 
   for(cnt=0;cnt<total;cnt++)
   {
    OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
    if(OrderType()==OP_BUY && OrderSymbol()==Symbol())
     {
     if(MA2P1 > MA1P1 && MA2P2 > MA1P2)
      {                                 
       OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close LONG position
     }}

//CLOSE SHORT ENTRIES: 
    OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); 
    if(OrderType()==OP_SELL && OrderSymbol()==Symbol()) // check for symbol
     {
     if(MA1P1 > MA2P1 && MA1P2 > MA2P2)
      {   
       OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close SHORT position
     }}
    }  // for loop return
    }   // close 1st if 
//##############################################################################
//~~~~~~~~~~~ END OF ORDER Closure routines & Stoploss changes  ~~~~~~~~~~~~~~~~~~~~~~~~~~~
//##########################################################################################
//~~~~~~~~~~~~START of NEW ORDERS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//#########################  NEW POSITIONS ?  ######################################
//Possibly add in timer to stop multiple entries within Period
// Check Margin available
// ONLY ONE ORDER per SYMBOL
// Loop around orders to check symbol doesn't appear more than once
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 total=OrdersTotal();
  if(total>0)
   { 
    for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
       if(OrderSymbol()==Symbol()) return(0);
   }
   }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   if(AccountFreeMargin()<(1000*Lots))
   {Print("We have no money. Free Margin = ", AccountFreeMargin());
    return(0);}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//#########################################################################################
//ENTRY RULES: LONG 
 if(MA1P1 > MA2P1 && MA1P2 > MA2P2 
    &&
    RSIvalP1 > 50
    &&
    MACDP1 > MACDSP1
    )
  {
   ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"MaxMin Long",16384,0,Orange); //Bid-(Point*(MinDist+2))
   if(ticket>0)
    {
    if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
     }
     else Print("Error opening BUY order : ",GetLastError()); 
     return(0); 
   } 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//ENTRY RULES: SHORT                                     //################################
 if(MA1P1 > MA2P1 && MA1P2 > MA2P2 
    &&
    RSIvalP1 < 50
    &&
    MACDP1 < MACDSP1
    )
  {
   ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"MaxMin Short",16384,0,Red);
   if(ticket>0)
    {
     if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
      }
      else Print("Error opening SELL order : ",GetLastError()); 
      return(0); 
   }

//####################################################################################
//############               End of PROGRAM                  #########################   
   return(0);
}

Profitability Reports

USD/CHF Jul 2025 - Sep 2025
0.77
Total Trades 46
Won Trades 15
Lost trades 31
Win Rate 32.61 %
Expected payoff -31.67
Gross Profit 4969.47
Gross Loss -6426.40
Total Net Profit -1456.93
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
0.78
Total Trades 45
Won Trades 16
Lost trades 29
Win Rate 35.56 %
Expected payoff -18.48
Gross Profit 2950.99
Gross Loss -3782.41
Total Net Profit -831.42
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.37
Total Trades 46
Won Trades 10
Lost trades 36
Win Rate 21.74 %
Expected payoff -94.02
Gross Profit 2490.00
Gross Loss -6815.00
Total Net Profit -4325.00
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
0.92
Total Trades 41
Won Trades 16
Lost trades 25
Win Rate 39.02 %
Expected payoff -14.66
Gross Profit 6575.00
Gross Loss -7176.00
Total Net Profit -601.00
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.67
Total Trades 42
Won Trades 13
Lost trades 29
Win Rate 30.95 %
Expected payoff -46.65
Gross Profit 3903.44
Gross Loss -5862.75
Total Net Profit -1959.31
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.71
Total Trades 44
Won Trades 14
Lost trades 30
Win Rate 31.82 %
Expected payoff -39.31
Gross Profit 4165.52
Gross Loss -5894.97
Total Net Profit -1729.45
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.88
Total Trades 40
Won Trades 14
Lost trades 26
Win Rate 35.00 %
Expected payoff -10.43
Gross Profit 3174.00
Gross Loss -3591.00
Total Net Profit -417.00
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
0.37
Total Trades 61
Won Trades 19
Lost trades 42
Win Rate 31.15 %
Expected payoff -150.76
Gross Profit 5515.99
Gross Loss -14712.22
Total Net Profit -9196.23
-100%
-50%
0%
50%
100%
USD/CHF Jan 2025 - Jul 2025
0.58
Total Trades 102
Won Trades 33
Lost trades 69
Win Rate 32.35 %
Expected payoff -66.65
Gross Profit 9443.87
Gross Loss -16241.78
Total Net Profit -6797.91
-100%
-50%
0%
50%
100%
USD/CAD Jan 2025 - Jul 2025
0.66
Total Trades 106
Won Trades 34
Lost trades 72
Win Rate 32.08 %
Expected payoff -43.02
Gross Profit 8841.12
Gross Loss -13400.95
Total Net Profit -4559.83
-100%
-50%
0%
50%
100%

Comments