4hVegasMetaTraderWeeklyIndicator_v1

Download script
Author: Spiggy
4hVegasMetaTraderWeeklyIndicator_v1

The 4Hour Vegas Model - Weekly Chart Direction Calculator is a specialized technical analysis tool designed to help traders identify the prevailing momentum of the market by calculating trend shifts. Instead of just looking at raw prices, this script focuses on the relationship between two different types of moving averages to determine whether the current market trajectory is leaning upwards or downwards.

How the Logic Works

The script operates by analyzing the "distance" between two mathematical averages: a fast-reacting average (SMA5) and a slower, smoother average (EMA21). By comparing these two, the tool identifies the speed and strength of the current trend.

1. Trend Analysis and Velocity The core logic calculates the difference between these two moving averages at every point in time. It then compares this difference to the previous data point. This allows the script to measure "velocity"—essentially determining if the gap between the price trends is expanding or contracting.

2. Directional Identification The tool automatically categorizes the market movement based on the change in these values:

  • Bullish Momentum: If the gap between the averages increases compared to the previous period, the script identifies an upward trend. This is represented visually as a positive growth value.
  • Bearish Momentum: If the gap between the averages decreases or shrinks, the script identifies a downward trend, marking a shift in momentum toward the downside.

3. Weekly Synchronization and Data Logging A unique feature of this script is its ability to organize data by the calendar week. It identifies the start of the current week and calculates a specific direction value for that period. To ensure this information is accessible across different parts of your trading platform, it performs two specific actions:

  • On-Screen Feedback: It displays a real-time comment on your chart showing the current symbol, the specific week date, the identified direction (UP or DOWN), and the exact numerical strength of that move.
  • Global Data Storage: It saves these weekly direction values into "Global Variables." This means the data is stored in the platform's memory, allowing other tools or scripts to reference the weekly trend data even if they aren't looking at the same chart.

Summary for the Trader

In simple terms, this script acts as a momentum compass. It looks at how quickly the price is pulling away from its historical averages and tells you whether that pull is currently moving toward the ceiling or the floor of the market, while keeping a permanent record of the trend for the current week.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
10 Views
0 Downloads
0 Favorites
4hVegasMetaTraderWeeklyIndicator_v1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//| 4Hour Vegas Model - Weekly Chart Direction Calculator            |
//|                                                           Spiggy |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Spiggy"
#property link      ""

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

//---- input parameters

//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexBuffer(2,ExtMapBuffer3);

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
  int    limit;
  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--)
  {
    //---- Calculate the current weekly trend
    EMA21=iMA(NULL,0,21,0,MODE_EMA,(PRICE_HIGH+PRICE_LOW)/2,i);
    SMA5 =iMA(NULL,0,5,0,MODE_SMA,(PRICE_HIGH+PRICE_LOW)/2,i);
         
    //---- Calculate the previous weekly trend
    EMA21Prev=iMA(NULL,0,21,0,MODE_EMA,(PRICE_HIGH+PRICE_LOW)/2,i+1);
    SMA5Prev =iMA(NULL,0,5,0,MODE_SMA,(PRICE_HIGH+PRICE_LOW)/2,i+1);

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

    // Calculate the difference of the MAs
    if (((SMA5-EMA21) - (SMA5Prev-EMA21Prev)) > 0.0 )
    {
      ExtMapBuffer2[i] = (SMA5-EMA21) - (SMA5Prev-EMA21Prev);
      ExtMapBuffer3[i] = 0.0;
      Direction = "UP";
    }
    
    if (((SMA5-EMA21) - (SMA5Prev-EMA21Prev)) < 0.0 )
    {
      ExtMapBuffer2[i] = 0.0;
      ExtMapBuffer3[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