MATimeAuto

This script is designed to act as a visual trend-following tool for trading charts. Its primary purpose is to identify specific momentum shifts by analyzing the relationship between different types of moving averages based on market volatility.

Core Logic and Functionality

1. Dynamic Volatility Analysis Rather than using static values, the script first looks at the "range" of price action over two different timeframes (defined by the SlowEMA and SlowEMA1 settings). It identifies the highest high and the lowest low within these periods to calculate a dynamic volatility value. This allows the indicator to adapt to how much the market is currently swinging.

2. Moving Average Calculation Using the volatility values derived above, the script generates two distinct moving average lines:

  • A "Fast" moving average (based on the shorter timeframe).
  • A "Slow" moving average (based on the longer timeframe). By plotting these, the tool helps visualize whether the current short-term price momentum is leading or lagging behind the broader market trend.

3. Signal Identification The core logic of the script lies in how it identifies specific trading signals. It monitors the "gap" between the Fast and Slow moving averages. A signal is triggered when three specific conditions are met simultaneously:

  • Crossover Detection: The Fast moving average must cross from one side of the Slow moving average to the other (e.g., moving from below to above).
  • Momentum Confirmation: The script checks the position of the moving average two bars back to ensure a definitive change in direction has occurred.
  • Trend Direction: It ensures that the movement is actively moving away from the crossover point, confirming that the momentum is gaining strength rather than just fluctuating.

4. Visual Output When these specific logic conditions are met, the script places a visual marker (an arrow) on the chart. This provides a clear, non-technical signal for the user, highlighting points where the mathematical relationship between short-term and long-term volatility suggests a potential shift in market direction.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
9 Views
1 Downloads
0 Favorites
MATimeAuto
//+------------------------------------------------------------------+
//|                                                  MATimeAuto.mq4 |
//|                                        Copyright ?2007 , Dxdcn. |
//|                                 http://blog.sina.com.cn/FXTrade |
//+------------------------------------------------------------------+
#property  copyright "Copyright 2007 , Dxd, China."
#property  link      "http://blog.sina.com.cn/FXTrade ,  http://www.mql4.com/users/DxdCn"
#property  link      "http://www.waihui.com/bbs/profile.php?action=show&uid=5273"
//---- indicator settings
#property  indicator_chart_window
//#property  indicator_separate_window
#property  indicator_buffers 3
#property  indicator_color1  Silver
#property  indicator_color2  Red
#property  indicator_color3  Lime
#property  indicator_width1  2
//---- indicator parameters
extern int SlowEMA = 24;
extern int SlowEMA1 = 408;
//---- indicator buffers
double DxdnBuffer[];
double DxdcnSlowBuffer[];
double DxdcnFastBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   SetIndexStyle(0, DRAW_LINE); // DRAW_HISTOGRAM);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexBuffer(0, DxdnBuffer);
   SetIndexBuffer(1, DxdcnSlowBuffer);
   SetIndexStyle(2, DRAW_ARROW, STYLE_SOLID, 4);
   SetIndexDrawBegin(1, SlowEMA1);
   SetIndexBuffer(2, DxdcnFastBuffer);
   return(0);
  }
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+
int start()
  {
   SetIndexStyle(2, DRAW_ARROW, STYLE_SOLID, 4);
   int limit;
   limit = Bars - 50;
   int SlowEMAA = SlowEMA;
   int SlowEMAB = SlowEMA1;
   double opD, opD1;
   //---- macd counted in the 1-st buffer
   double hhh, lll;
   for(int i = limit; i >= 0; i--)
     {
       //ѰÕÒij·¶Î§Äڸߵ͵IJîÖµµãÊý
       SlowEMAA = (High[iHighest(NULL, 0, MODE_HIGH, SlowEMA, i)] - 
                   Low[iLowest(NULL, 0, MODE_HIGH, SlowEMA, i)]) / Point;
       SlowEMAB = (High[iHighest(NULL, 0, MODE_HIGH, SlowEMA1, i)] - 
                   Low[iLowest(NULL, 0, MODE_HIGH, SlowEMA1, i)]) / Point;
       //Óô˵ãÊý×öMA
       DxdnBuffer[i] = iMA(NULL, 0, SlowEMAA, 0, MODE_SMA, PRICE_CLOSE, i);
       DxdcnSlowBuffer[i] = iMA(NULL, 0, SlowEMAB, 0, MODE_SMA, PRICE_CLOSE, i);
     }
   //ÅжϽ»²æ
   for(i = limit; i >= 0; i--)
     {
       if(((DxdnBuffer[i] - DxdcnSlowBuffer[i]) > 0) && 
          ((DxdnBuffer[i+2] - DxdcnSlowBuffer[i+2]) < 0) && 
          ((DxdnBuffer[i] - DxdnBuffer[i+2]) > 0))
           DxdcnFastBuffer[i]=DxdnBuffer[i];
       if(((DxdnBuffer[i] - DxdcnSlowBuffer[i]) < 0) && 
          ((DxdnBuffer[i+2] - DxdcnSlowBuffer[i+2]) > 0) && 
          ((DxdnBuffer[i] - DxdnBuffer[i+2]) < 0))
           DxdcnFastBuffer[i] = DxdnBuffer[i];
     }
  }
//+------------------------------------------------------------------+

Comments