SMC MACD new idea

Profit factor:
0.99

Okay, here's a breakdown of what this MetaTrader script does, explained in a way that doesn't require any programming knowledge:

Overall Purpose

This script is designed to automatically place and manage buy and sell orders in the Forex market based on a specific trading strategy. It analyzes price charts, looks for certain patterns, and then executes trades according to those patterns. It also attempts to manage existing trades based on the same indicators.

Key Steps and Logic

  1. Setup and Configuration:

    • The script starts by defining some settings that you, the user, can adjust. These include:
      • Lots: The size of each trade (how much currency to buy or sell).
      • TakeProfit: A target profit level for each trade, expressed in points (a unit of price movement).
      • RiskPercent: How much of your account balance you're willing to risk on each trade.
      • SignalLifeBars: How long a buy or sell signal is considered valid.
      • PVoffset: An offset value.
  2. Market Analysis:

    • The script calculates values from various technical indicators (MACD and PSAR). Think of these indicators as tools that analyze price movements and suggest potential buy or sell opportunities.
    • It uses these indicators in the buy and sell rules.
  3. Buy and Sell Signal Generation:

    • The script has a set of rules to determine when to generate buy or sell signals based on indicator values.
    • The rules essentially look for specific patterns in the indicator values to identify potential upward (buy) or downward (sell) trends.
  4. Order Placement:

    • If a buy signal is triggered, the script sends a "buy" order to the trading platform. If a sell signal is triggered, it sends a "sell" order.
    • Before placing an order, the script checks if you have enough money in your account to cover the trade.
  5. Order Management (Stop Loss and Take Profit)

    • The script attempts to manage positions setting a stop loss and take profit prices based on indicator values.
  6. Order Closure

    • The script checks if the current indicator values conflict with the trade in place, indicating a change of trend. If this is the case the script closes the current trade.

Important Considerations

  • Automated Trading: This script automates the trading process. Once it's running, it will place and manage orders without your direct intervention.
  • Risk: Trading Forex involves risk. This script is based on a specific trading strategy, but there's no guarantee that it will be profitable. It's essential to understand the risks involved before using it.
  • Customization: The settings at the beginning of the script can be adjusted to fine-tune the trading strategy. Experimenting with these settings can impact the script's performance.
  • Complexity: The trading strategy itself is complex, relying on several technical indicators and specific rules. Understanding the logic behind these indicators is important for effective use.

In simple terms, this script is like a robot trader that watches the market, looks for patterns, and automatically buys or sells currency based on those patterns. It also attempts to manage existing trades based on the indicator patterns.

Orders Execution
Checks for the total of open ordersIt can change open orders parameters, due to possible stepping strategyIt Closes Orders by itself It automatically opens orders when conditions are reached
Indicators Used
MACD HistogramParabolic Stop and Reverse system
Miscellaneous
It issuies visual alerts to the screenIt sends emails
13 Views
0 Downloads
0 Favorites
SMC MACD new idea
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                                           SMC.mq4 
//|                                                                  +
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+

 extern double Lots = 0.1; 

 extern int    TakeProfit = 100;
 extern double RiskPercent = 1;
 extern int    SignalLifeBars =24;
 extern int    PVoffset = 2;
 
 bool   BuySignal,SellSignal;
 string  LastOrder;
 string  Trend;
 datetime BarTime;
//#####################################################################
int init()
{
//----
LastOrder="xxxx";
//----
   return(0);
  }
//#############################################################################

int start()
  {
   double SL,TP,Spread, ATR, MinDist,MaxRisk;

   double PSARP0,PSARP1;
   double VSMAP0,VSMAP1,SMAP1,MMAP1,LMAP1,VLMAP1,VSMAP1Low,VSMAP1High;

   string MaxRiskStr;
   string Trading;

   bool   Buy,Sell;

   int    total,ticket,err,tmp,cnt;
   int    NumberofPositions;

  if(Bars<100){Print("bars less than 100"); return(0); }
   
//################################################################################
//~~~~~~~~~~~~~~~~Miscellaneous setup stuff~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 MinDist=(MarketInfo(Symbol(),MODE_STOPLEVEL)*Point);
 Spread=(Ask-Bid);
 MaxRisk=(AccountFreeMargin()*RiskPercent/100)*Point;
 MaxRiskStr=DoubleToStr(MaxRisk,4);

//~~~~~~~~~~~~~~~~~~INDICATOR CALCULATIONS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

double LMACDHP1,LMACDSP1,SMACDHP1,SMACDSP1;
double LMACDHP2,LMACDSP2,SMACDHP2,SMACDSP2;

LMACDHP1=iMACD(NULL,0,89,144,22,PRICE_CLOSE,MODE_MAIN,1);
LMACDSP1=iMACD(NULL,0,89,144,22,PRICE_CLOSE,MODE_SIGNAL,1);
LMACDHP2=iMACD(NULL,0,89,144,22,PRICE_CLOSE,MODE_MAIN,2);
LMACDSP2=iMACD(NULL,0,89,144,22,PRICE_CLOSE,MODE_SIGNAL,2);

SMACDHP1=iMACD(NULL,0,8,21,5,PRICE_CLOSE,MODE_MAIN,1);
SMACDSP1=iMACD(NULL,0,8,21,5,PRICE_CLOSE,MODE_SIGNAL,1);
SMACDHP2=iMACD(NULL,0,8,21,5,PRICE_CLOSE,MODE_MAIN,2);
SMACDSP2=iMACD(NULL,0,8,21,5,PRICE_CLOSE,MODE_SIGNAL,2);

PSARP1=iSAR(NULL,0,0.02,0.2,1);

 if(BarTime == Time[0]) {return(0);}
 BarTime = Time[0];

//##############################################################################
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~         
//BUY and SELL rules:
//~~~~~~~~~~~~BUY~~~~~~~~~~~~~~~~~~~~~~~~
SL=0;
TP=0;
 if((LMACDHP1>0&&LMACDHP1>LMACDSP1&&SMACDHP2<SMACDSP2&&SMACDHP1>SMACDSP1)//Long Term UP new Short term signal
     ||
    (LMACDHP2<0&&LMACDHP1>0)  //Long trend changes
     ||
    (LMACDHP1>0&&LMACDHP1>LMACDSP1&&SMACDHP2<0&&SMACDHP1>0))  //Long term trend UP and Short term change top UP
   {
   Buy = true;
    LastOrder = " Buy ";
    }

//~~~~~~~~~~~SELL~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 if((LMACDHP1<0&&SMACDHP1<0&&LMACDHP1<LMACDSP1&&SMACDHP2>SMACDSP2&&SMACDHP1<SMACDSP1)//Long Term UP new Short term signal
     ||
    (LMACDHP2>0&&LMACDHP1<0)  //Long trend changes
     ||
    (LMACDHP1<0&&LMACDHP1<LMACDSP1&&SMACDHP2>0&&SMACDHP1<0))  //Long term trend UP and Short term change top UP

    {Sell=true;
     LastOrder = " Sell ";
     }

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//##################################################################################
//~~~~~~~~~~~~~~~~  POSITION MANAGEMENT  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

if(0==1)
{
total=OrdersTotal();
  if(total>0)
   { 
   for(cnt=0;cnt<total;cnt++)
    { 
     OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
     if(OrderType()==OP_BUY && OrderSymbol()==Symbol())    
     { 
      SL=PSARP1;

      if(SL > OrderStopLoss())
      {OrderModify(OrderTicket(),OrderOpenPrice(),SL,OrderTakeProfit(),0,Orange);}
       }}}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  total=OrdersTotal();
  if(total>0)
   { 
   for(cnt=0;cnt<total;cnt++)
    {
     OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
     if(OrderType()==OP_SELL && OrderSymbol()==Symbol())   
     {
      
      SL=PSARP1;

      if(SL != 0)
       {
       if(SL < OrderStopLoss() || OrderStopLoss()==0 )
        {OrderModify(OrderTicket(),OrderOpenPrice(),SL,OrderTakeProfit(),0,Orange);}
       }}}}
}
//##################################################################################
//~~~~~~~~~~~~~~~~  ORDER CLOSURE  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if(0==0)
{
//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() &&
         LMACDHP1 < LMACDSP1)
       {
        OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); 
   }}}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//CLOSE SHORT ENTRIES: 
 
   total=OrdersTotal();
   if(total>0)
    { 
    for(cnt=0;cnt<total;cnt++)
     {  
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); 
      if(OrderType()==OP_SELL && OrderSymbol()==Symbol() &&
         LMACDHP1 > LMACDSP1)
       {
        OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close SHORT position
   }}}
}
//##########################################################################################
//##########################################################################################
//~~~~~~~~~~~ END OF ORDER Closure routines & Stoploss changes  ~~~~~~~~~~~~~~~~~~~~
//##################################################################################
//~~~~~~~~~~~~START of NEW ORDERS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

   if(AccountFreeMargin()<(1000*Lots))
   {Print("Insufficient funds available. Free Margin = ", AccountFreeMargin());
    return(0);}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 NumberofPositions = 0;
 total=OrdersTotal();
  if(total>0)
   { 
    for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
       if(OrderSymbol()==Symbol()) NumberofPositions=NumberofPositions+1;
       }
//may require extra code to determine exposure on any one pair
       if (NumberofPositions >=50) return(0);
   }

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//OPEN ORDER: LONG 
 if(Buy==true) 
  {Buy=false;

   ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,SL,TP,LastOrder,070177,0,Orange); //Bid-(Point*(MinDist+2))
   if(ticket>0)
    { 
     if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) 
      {Print("BUY order opened : ",OrderOpenPrice());
       Alert("Buy Order for ",Symbol());
       SendMail("Buy Order "+Symbol()+" "+Ask,SL);     
       }
     }
     else Print("Error opening BUY order : ",GetLastError()); 
     return(0); 
   } 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//OPEN ORDER: SHORT                                   
 if(Sell==true) 
  {Sell=false;

   ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,SL,TP,"Flying Knives" + LastOrder,070177,0,Red);
   if(ticket>0)
    {
      if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) 
       {Print("SELL order opened : ",OrderOpenPrice());
        Alert("Sell Order for ",Symbol());
        SendMail("Sell Order "+Symbol()+" "+Bid,Bid); 
        }
      }
      else Print("Error opening SELL order : ",GetLastError()); 
      return(0); 
   }

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

Profitability Reports

USD/JPY Jul 2025 - Sep 2025
0.13
Total Trades 61
Won Trades 9
Lost trades 52
Win Rate 14.75 %
Expected payoff -26.54
Gross Profit 231.84
Gross Loss -1850.50
Total Net Profit -1618.66
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
0.07
Total Trades 49
Won Trades 4
Lost trades 45
Win Rate 8.16 %
Expected payoff -27.30
Gross Profit 105.89
Gross Loss -1443.63
Total Net Profit -1337.74
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
0.24
Total Trades 62
Won Trades 14
Lost trades 48
Win Rate 22.58 %
Expected payoff -14.79
Gross Profit 290.18
Gross Loss -1207.39
Total Net Profit -917.21
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.55
Total Trades 55
Won Trades 13
Lost trades 42
Win Rate 23.64 %
Expected payoff -8.12
Gross Profit 535.60
Gross Loss -982.40
Total Net Profit -446.80
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
0.78
Total Trades 51
Won Trades 17
Lost trades 34
Win Rate 33.33 %
Expected payoff -6.47
Gross Profit 1171.90
Gross Loss -1502.00
Total Net Profit -330.10
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
4.08
Total Trades 45
Won Trades 27
Lost trades 18
Win Rate 60.00 %
Expected payoff 23.15
Gross Profit 1379.79
Gross Loss -338.09
Total Net Profit 1041.70
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
1.69
Total Trades 54
Won Trades 24
Lost trades 30
Win Rate 44.44 %
Expected payoff 11.71
Gross Profit 1551.30
Gross Loss -918.90
Total Net Profit 632.40
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
0.00
Total Trades 3
Won Trades 0
Lost trades 3
Win Rate 0.00 %
Expected payoff -35085.07
Gross Profit 0.00
Gross Loss -105255.20
Total Net Profit -105255.20
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.53
Total Trades 63
Won Trades 17
Lost trades 46
Win Rate 26.98 %
Expected payoff -7.23
Gross Profit 513.90
Gross Loss -969.70
Total Net Profit -455.80
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
0.60
Total Trades 117
Won Trades 42
Lost trades 75
Win Rate 35.90 %
Expected payoff -12.81
Gross Profit 2246.12
Gross Loss -3744.87
Total Net Profit -1498.75
-100%
-50%
0%
50%
100%

Comments