4hVegasMetaTraderWeeklyIndicator-V11

Download script
Author: Spiggy
4hVegasMetaTraderWeeklyIndicator-V11

This script is designed to provide traders with a clear visual and data-driven overview of the primary market direction based on weekly trends. Rather than looking at short-term price fluctuations, it focuses on broader momentum by analyzing moving averages on a weekly timeframe.

Core Logic and Methodology

The tool operates by calculating the relationship between two specific types of moving averages: a Short-Term Simple Moving Average (SMA 5) and a Long-Term Exponential Moving Average (EMA 21). By comparing these two indicators, the script determines whether the market's momentum is accelerating, decelerating, or shifting.

To ensure accuracy, the logic follows these specific steps:

  • Weekly Data Alignment: The script specifically pulls data from the weekly chart. This filters out "noise" from daily or hourly price movements, allowing the user to see the "big picture" of where the market is heading over a larger period.
  • Momentum Differential: Instead of simply checking if one average is above the other, the script calculates the difference between them. It then compares this current difference against the difference from the previous week.
  • Directional Detection:
    • Upward Trend: If the gap between the short-term and long-term averages is widening compared to the previous week, the script identifies this as upward momentum.
    • Downward Trend: If that gap is narrowing or decreasing compared to the previous week, it identifies this as downward momentum.

Visual Output and Data Tracking

The script provides three distinct types of feedback to the user:

  1. On-Chart Visuals: It generates a combined display including a trend line (showing the MA difference) and a histogram. The histogram acts as a visual "speedometer," highlighting the strength of the trend in different colors (Green for upward movement, Red for downward).
  2. Real-Time Commentary: The script displays a text comment directly on the trading platform. This provides an instant readout of the current market direction and the specific numerical value of the momentum for the current week.
  3. Global Data Storage: Beyond the visual chart, the script saves these weekly direction values into the platform's global memory. This allows the data to remain accessible even when different charts or windows are open, ensuring consistency across your trading workspace.
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
14 Views
0 Downloads
0 Favorites
4hVegasMetaTraderWeeklyIndicator-V11
//+--------------------------------------------------------------------+
//| 4Hour Vegas Model - Weekly Chart Direction Calculator              |
//|                                                           Spiggy   |
//|                                                                    |
//|Mod by F DCG (20050924):                                            |
//|  - Added PERIOD_W1 to the calc of the MA to get to the proper      |
//|    week figures instead of using the 4h avg.                       |
//|  - Changed some of the variables names to more incurr more meaning |
//+--------------------------------------------------------------------+
#property copyright "Spiggy"
#property link      ""

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Blue
#property indicator_color2 Green
#property indicator_color3 Red

//---- input parameters

//---- buffers
double _maDiff[];
double _upTrend[];
double _downTrend[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,_maDiff);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexBuffer(1,_upTrend);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexBuffer(2,_downTrend);

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
  int    limit, weekIndex;
  double EMA21;
  double SMA5;
  double EMA21Prev;
  double SMA5Prev;
  string ValueIndex;
  string Direction;
   
  // Always prepare all of the information for the other indicators
  limit=Bars;
  
  //---- main loop
  for(int i=limit; i>=0; i--) {
  	weekIndex=i/30;
  	
    //---- Calculate the current weekly trend
    EMA21=iMA(Symbol(), PERIOD_W1, 21, 0, MODE_EMA, PRICE_MEDIAN, weekIndex);
    SMA5 =iMA(Symbol(), PERIOD_W1, 5, 0, MODE_SMA, PRICE_MEDIAN, weekIndex);
         
    //---- Calculate the previous weekly trend
    EMA21Prev=iMA(Symbol(), PERIOD_W1, 21, 0, MODE_EMA, PRICE_MEDIAN, weekIndex+1);
    SMA5Prev =iMA(Symbol(), PERIOD_W1, 5, 0, MODE_SMA, PRICE_MEDIAN, weekIndex+1);

    // Calculate the difference of the MAs
    _maDiff[i] = SMA5-EMA21;

    // Calculate the difference of the MAs
    if (((SMA5-EMA21) - (SMA5Prev-EMA21Prev)) > 0.0 ) {
      _upTrend[i] = (SMA5-EMA21)- (SMA5Prev-EMA21Prev);
      _downTrend[i] = 0.0;
      Direction = "UP";
    } else if (((SMA5-EMA21) - (SMA5Prev-EMA21Prev)) < 0.0 ) {
      _upTrend[i] = 0.0;
      _downTrend[i] = (SMA5-EMA21) - (SMA5Prev-EMA21Prev);
      Direction = "DOWN";
    }
    
    // Calculate the start of the week and publish the value in a global variable
    // Publish this with the previous Sunday as the index
    ValueIndex = TimeToStr(Time[i]-TimeDayOfWeek(Time[i]),TIME_DATE);
    Comment(Symbol() + "-ThisWeekDirection-" + ValueIndex + "\n" + Direction + ":(" + ((SMA5-EMA21) - (SMA5Prev-EMA21Prev)) + ")");
    GlobalVariableSet(Symbol() + "-ThisWeekDirection-" + ValueIndex, ((SMA5-EMA21) - (SMA5Prev-EMA21Prev)));

  }
         
   return(0);
  }
//+------------------------------------------------------------------+

Comments