SMC MACD new idea

Profit factor:
1.19

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
2 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

EUR/USD Jan 2025 - Jul 2025
1.03
Total Trades 96
Won Trades 42
Lost trades 54
Win Rate 43.75 %
Expected payoff 0.66
Gross Profit 2358.10
Gross Loss -2294.60
Total Net Profit 63.50
-100%
-50%
0%
50%
100%
AUD/USD Jan 2025 - Jul 2025
0.32
Total Trades 107
Won Trades 23
Lost trades 84
Win Rate 21.50 %
Expected payoff -16.05
Gross Profit 801.80
Gross Loss -2519.60
Total Net Profit -1717.80
-100%
-50%
0%
50%
100%
USD/CAD Oct 2024 - Jan 2025
2.25
Total Trades 64
Won Trades 32
Lost trades 32
Win Rate 50.00 %
Expected payoff 16.99
Gross Profit 1959.24
Gross Loss -872.04
Total Net Profit 1087.20
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
1.00
Total Trades 47
Won Trades 15
Lost trades 32
Win Rate 31.91 %
Expected payoff -0.02
Gross Profit 847.10
Gross Loss -848.10
Total Net Profit -1.00
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
1.25
Total Trades 34
Won Trades 16
Lost trades 18
Win Rate 47.06 %
Expected payoff 7.15
Gross Profit 1203.90
Gross Loss -960.90
Total Net Profit 243.00
-100%
-50%
0%
50%
100%
AUD/USD Oct 2024 - Jan 2025
1.13
Total Trades 55
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff 2.50
Gross Profit 1181.00
Gross Loss -1043.60
Total Net Profit 137.40
-100%
-50%
0%
50%
100%

Comments