4hVegasMetaTraderWeeklyIndicator-V11_v1

Download script
Author: Spiggy
4hVegasMetaTraderWeeklyIndicator-V11_v1

The 4Hour Vegas Model is a technical analysis tool designed to identify and visualize the prevailing market direction based on weekly price trends. Instead of looking at minor, rapid price fluctuations that can often be misleading, this script focuses on the "big picture" by calculating specific averages over longer timeframes.

How the Logic Works

The tool operates by comparing two different types of moving averages to determine momentum:

  • The Short-Term Average (SMA 5): This tracks the price movement over a 5-period window on a weekly basis, providing a sense of current price flow.
  • The Long-Term Average (EMA 21): This tracks the price movement over a 21-period window on a weekly basis, representing the broader, established trend.

By calculating the distance between these two averages, the script determines the "strength" of the current trend.

Identifying Trend Direction

The core logic relies on measuring the change in the difference between these two averages from one week to the next:

  1. Upward Momentum: If the gap between the short-term and long-term averages is widening in a positive direction compared to the previous week, the script identifies this as an "UP" trend. It visually highlights this growth as a green histogram.
  2. Downward Momentum: If the gap is shrinking or widening in a negative direction compared to the previous week, it identifies a "DOWN" trend, represented by a red histogram.
  3. Neutral State: If there is no significant change in the difference between these two averages, the script remains neutral.

Data Reporting and Integration

To ensure this information is easily accessible to the user, the script performs three specific actions:

  • Visual Feedback: It plots a line showing the difference between the averages and uses colored histograms to clearly signal whether the current momentum is bullish (up) or bearish (down).
  • On-Screen Comments: It automatically prints a real-time summary on your chart, displaying the current symbol, the specific week being analyzed, the determined direction, and the exact numerical value of the momentum change.
  • Global Storage: The script saves these trend values into the platform's "Global Variables." This allows other automated tools or scripts to "read" the weekly direction calculated by this model to make their own trading decisions.
14 Views
0 Downloads
0 Favorites
4hVegasMetaTraderWeeklyIndicator-V11_v1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+--------------------------------------------------------------------+
//| 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