My_30minTrend

Download script
Author: Copyright � 2009, InvestMoneyLab.com
My_30minTrend

This tool is designed to analyze the prevailing market direction by examining historical price movements on a broader timeframe. Instead of looking at rapid, localized fluctuations, it aims to identify the "big picture" momentum to help traders understand whether the market is trending upward, downward, or moving sideways.

How the Logic Works

The script evaluates the market trend by combining two different types of mathematical analysis: Rate of Change (ROC) and Moving Average Differentials (MADiff). By looking at these two perspectives simultaneously, it can distinguish between a forceful move and a lingering, weaker shift.

1. The Rate of Change Analysis (ROC)

The tool first looks at the overall momentum by comparing current moving averages against historical ones from a set period in the past. This tells the script the general direction:

  • If the current average is higher than the past average, it signals an upward move.
  • If it is lower, it signals a downward move.

2. The Moving Average Differential (MADiff)

Next, the tool compares two different moving averages—one "short" and one "long"—to see how they are interacting with each other. By calculating the distance between these two lines and observing how that distance changes from one candle to the next, it detects the immediate speed and intensity of the price movement.

3. The Final Trend Classification

The script then merges these two perspectives into a single "Overall Trend" score. This results in five possible market states:

  • Strong Up Trend (+2): Both the long-term momentum (ROC) and the immediate speed (MADiff) are moving upward together.
  • Weak Up Trend (+1): The immediate speed is moving up, but the long-term momentum is currently leaning downward.
  • No Trend (0): The indicators are neutral or conflicting, suggesting a sideways or consolidating market.
  • Weak Down Trend (-1): The immediate speed is moving down, but the long-term momentum is still leaning upward.
  • Strong Down Trend (-2): Both the long-term momentum (ROC) and the immediate speed (MADiff) are moving downward together.

By providing these specific levels, the tool helps users identify not just where the market is going, but how much strength is behind that movement.

8 Views
0 Downloads
0 Favorites
My_30minTrend
//+------------------------------------------------------------------+
//|                                                 My_HourTrend.mq4 |
//|                             Copyright © 2009, InvestMoneyLab.com |
//|                                    http://www.investmoneylab.com |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Checking the overall market trend based on the hourly chart      |
//| Return 2 if it is STRONG UP Trend                                |
//| Return 1 if it is WEAK UP Trend                                  |
//| Return 0 if it is NO Trend                                       |
//| Return -1 if it is WEAK DOWN Trend                               |
//| Return -2 if it is STRONG DOWN Trend                             |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, InvestMoneyLab.com"
#property link      "http://www.investmoneylab.com"

#property indicator_separate_window
#property indicator_minimum -3
#property indicator_maximum 3
#property indicator_buffers 1
#property indicator_color1 Red
//---- input parameters
extern int       ROCMA_Period=200;
extern int       ROC_Period=200;
extern int       Hist_ShortPeriod=80;
extern int       Hist_LongPeriod=200;
//---- buffers
double Buf_0[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,Buf_0);   
   SetIndexDrawBegin(0,Hist_LongPeriod);

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    i, counted_bars=IndicatorCounted();
   double ROC_MA, ROC_MA_Lag;   
   double MADiff_Current, MADiff_Previous;
   int HourIndex, ROCTrend, MADiff_Trend, Overall_Trend;
   static int MADiff_Trend_Previous;
   
//----
   if(Bars<=Hist_LongPeriod) return(0);
   
   i=Bars-counted_bars-1;
   
   Print("Bar is ", Bars);
   Print("Counted Bars is ", counted_bars);
   
   while(i>=0) 
   {
      // Obtain the corresponding bar index on the hourly chart
      HourIndex = iBarShift(NULL,PERIOD_M30,iTime(NULL,0,i));   
      
      if (HourIndex != -1)
      {  
         // Compute ROC Trend
         ROC_MA = iMA(NULL,PERIOD_M30,ROCMA_Period,0,1,PRICE_OPEN,HourIndex);
         ROC_MA_Lag = iMA(NULL,PERIOD_M30,ROCMA_Period,0,1,PRICE_OPEN,HourIndex+ROC_Period);
   
         if (ROC_MA > ROC_MA_Lag) ROCTrend = 1;
         else if (ROC_MA < ROC_MA_Lag) ROCTrend = -1;
         else ROCTrend = 0;
         
         // Compute MADiff Trend
         MADiff_Current = (iMA(NULL,PERIOD_M30,Hist_ShortPeriod,0,1,PRICE_OPEN,HourIndex) - iMA(NULL,PERIOD_M30,Hist_LongPeriod,0,1,PRICE_OPEN,HourIndex));             
         MADiff_Previous = (iMA(NULL,PERIOD_M30,Hist_ShortPeriod,0,1,PRICE_OPEN,HourIndex+1) - iMA(NULL,PERIOD_M30,Hist_LongPeriod,0,1,PRICE_OPEN,HourIndex+1));
      
         if (MADiff_Current > MADiff_Previous && MathAbs(MADiff_Current - MADiff_Previous) < 0.0002 && MADiff_Trend_Previous == -1)
         {
            MADiff_Trend = -1;       
         }     
         else if (MADiff_Current > MADiff_Previous)
         {
            MADiff_Trend = 1;
            MADiff_Trend_Previous = 1;
         }
         else if (MADiff_Current < MADiff_Previous && MathAbs(MADiff_Current - MADiff_Previous) < 0.0002 && MADiff_Trend_Previous == 1)
         {
            MADiff_Trend = 1;              
         }
         else if (MADiff_Current < MADiff_Previous)
         {
            MADiff_Trend = -1;
            MADiff_Trend_Previous = -1;
         }         
         
         if (ROCTrend == 1 && MADiff_Trend == 1) Overall_Trend = 2;    // Strong Up Trend
         else if (ROCTrend == -1 && MADiff_Trend == 1) Overall_Trend = 1;  // Weak Up Trend
         else if (ROCTrend == -1 && MADiff_Trend == -1) Overall_Trend = -2; // Strong Down Trend
         else if (ROCTrend == 1 && MADiff_Trend == -1) Overall_Trend = -1; // Weak Down Trend
         else Overall_Trend = 0;

         Buf_0[i] = Overall_Trend;
      }
            
      i--;
   } 
  
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments