Alert MACD Slow

Download script
Alert MACD Slow

This automated trading script is designed to monitor financial markets and identify specific entry points for trades based on a combination of momentum, trend analysis, and price action. Instead of making subjective guesses, the logic relies on mathematical indicators to determine when the market is likely moving in a specific direction.

Core Trading Logic

The script evaluates three primary technical components to decide whether to enter a trade:

1. Momentum Analysis (MACD) The tool uses a Moving Average Convergence Divergence (MACD) indicator to track changes in momentum. It specifically looks for "reversal" patterns in the momentum line. Rather than just looking at where the price is now, it compares the current momentum against previous values to see if the market is gaining strength after a temporary dip or peak.

2. Trend Filtering (Moving Averages) To ensure the script doesn't trade against the primary direction of the market, it employs two different Exponential Moving Averages (Fast and Slow).

  • It looks for "bullish" conditions when the fast-moving average is above the slow-moving average.
  • It looks for "bearish" conditions when the fast-moving average is below the slow-moving average. This acts as a safety filter, ensuring that buy signals only occur in an uptrend and sell signals only occur in a downtrend.

3. Price Action Confirmation The script adds a final layer of validation by checking actual price behavior relative to recent highs and lows. It confirms a signal only if the current market price breaks through a specific recent price threshold (a "breakout"). This helps ensure that the trade has enough immediate momentum to succeed.

Operational Safeguards

Before executing any logic, the script performs several automated "health checks" to protect the trading account:

  • Data Integrity: It ensures there is enough historical data on the chart to perform accurate calculations; if the chart history is too short, it will stop and notify the user.
  • Margin Protection: The script automatically checks your available funds. If the account balance is insufficient to cover the cost of a new trade based on your specified lot size, it will refuse to open the position.
  • Parameter Validation: It verifies that the user-defined "Take Profit" targets are set to realistic levels to prevent errors in execution.

Summary of Execution

When all conditions align—meaning the momentum indicates a reversal, the moving averages confirm the trend, and the price breaks through a resistance/support level—the script triggers an alert. It distinguishes between "Long" (Buy) setups and "Short" (Sell) setups, providing the trader with clear notifications of potential opportunities.

Orders Execution
Checks for the total of open orders
Indicators Used
MACD HistogramMoving average indicator
Miscellaneous
It issuies visual alerts to the screen
11 Views
0 Downloads
0 Favorites
Alert MACD Slow
//+------------------------------------------------------------------+ 
//|                                                  MACD Sample.mq4 | 
//|                      Copyright © 2005, MetaQuotes Software Corp. | 
//|                                       http://www.metaquotes.net/ | 
//+------------------------------------------------------------------+ 

extern double TakeProfit = 30; 
extern double StopLoss  =  20; 
extern double Lots = 0.1; 
extern double TrailingStop = 30; 
extern double MACDOpenLevel=3; 
extern double MACDCloseLevel=2; 
extern double MATrendPeriod=26; 

//mia aggiunta 
int NumOrder ; 

//+------------------------------------------------------------------+ 
//|                                                                  | 
//+------------------------------------------------------------------+ 
int start() 
  { 
   double MacdCurrent, MacdPrevious; 
   double Macd_1, Macd_2, Macd_3, Macd_4, Ma_Quick, Ma_Slow; 
   double MaCurrent, MaPrevious; 
   double top, bottom;
   int cnt, ticket, total;
    
// initial data checks 
// it is important to make sure that the expert works with a normal 
// chart and the user did not make any mistakes setting external 
// variables (Lots, StopLoss, TakeProfit, 
// TrailingStop) in our case, we check TakeProfit 
// on a chart of less than 100 bars 
   if(Bars<100) 
     { 
      Print("bars less than 100"); 
      return(0);  
     } 
     
     if( isNewBar()){  NumOrder = 0;} 
      
   if(TakeProfit<10) 
     { 
      Print("TakeProfit less than 10"); 
      return(0);  // check TakeProfit 
     } 
// to simplify the coding and speed up access 
// data are put into internal variables 
   Macd_1 = iMACD(NULL,0,3,20,9,PRICE_CLOSE,MODE_MAIN,1); 
   Macd_2 = iMACD(NULL,0,3,20,9,PRICE_CLOSE,MODE_MAIN,2); 
   Macd_3 = iMACD(NULL,0,3,20,9,PRICE_CLOSE,MODE_MAIN,3); 
   Macd_4 = iMACD(NULL,0,3,20,9,PRICE_CLOSE,MODE_MAIN,4); 
   Ma_Quick = iMA(NULL,0,20,0,MODE_EMA,PRICE_CLOSE,0); 
   Ma_Slow  = iMA(NULL,0,65,0,MODE_EMA,PRICE_CLOSE,0); 
   top      = High[iHighest(NULL,0,MODE_HIGH,10,1)];
   bottom   = Low[iLowest(NULL,0,MODE_LOW,10,1)];


   total=OrdersTotal(); 
   //if(total<1) 
  //   { 
      // no opened orders identified 
      if(AccountFreeMargin()<(1000*Lots)) 
        { 
         Print("We have no money. Free Margin = ", AccountFreeMargin()); 
         return(0);  
        } 
        
        
      // check for long position (BUY) possibility 
      if(Macd_1 > Macd_2 && Macd_2 < Macd_3 && Ma_Quick > Ma_Slow && Ask > High[1] && Macd_2 < 0
         || 
         Macd_2 > Macd_3 && Macd_3 < Macd_4 && Ma_Quick > Ma_Slow && Ask > High[2] && Macd_3 < 0 ) 
        { 
        
       if( NumOrder == 0){ 
        
        Alert("SET UP LONG");
           } 
         
        } 
        
        
       
      // check for short position (SELL) possibility 
      if(Macd_1 < Macd_2 && Macd_2 > Macd_3 && Ma_Quick < Ma_Slow && Bid < Low[1] && Macd_2 > 0
         || 
         Macd_2 < Macd_3 && Macd_3 > Macd_4 && Ma_Quick < Ma_Slow && Bid < Low[2] && Macd_3 > 0  )
        { 
        
        
        
        if( NumOrder == 0){ 
        
         Alert("SET UP SHORT_VALUE");
        
        
           } 
        
        } 
      return(0); 
      } 
    
   
// the end. 











bool isNewBar() 
{ 
   static datetime lastbar=0; 
   datetime curbar = Time[0]; 
   if(lastbar!=curbar) 
   { 

      lastbar=curbar; 
      return (true); 
   } 
   else 
   { 
      return(false); 
   } 
} 

Comments