multi_2x2_MA

Download script
Author: Yuriy Tokman
multi_2x2_MA

This tool is designed to track and visualize the relative momentum between two specific currency pairs—EURUSD and GBPUSD—by calculating the mathematical "spread" or distance between different moving averages for each. Instead of looking at price action directly, this indicator focuses on how much the short-term trends are pulling away from the long-term trends in these markets.

How the Logic Works

The script operates by performing a synchronized calculation across two different markets simultaneously:

1. Trend Analysis for EURUSD The tool identifies two different moving averages for the EURUSD pair based on user-defined timeframes (specifically, one short-term and one longer-term period). It calculates the difference between these two averages. This result is then normalized against the smallest price unit of the currency pair to ensure the value is represented accurately as a consistent point measurement.

2. Trend Analysis for GBPUSD Simultaneously, the script performs the exact same calculation for the GBPUSD pair. It looks at its own short-term and long-term moving averages, finds the difference between them, and normalizes that figure accordingly.

3. Visual Output The final result is displayed in a separate window on your trading platform as two distinct lines:

  • The first line (Green) represents the momentum gap for EURUSD.
  • The second line (Red) represents the momentum gap for GBPUSD.

Practical Purpose

By looking at these two lines together, you are essentially viewing a "comparison of strengths." Rather than watching candles move up and down, you are watching how aggressively the short-term trend is deviating from the long-term average in both currencies at the same time. This allows you to see if one currency pair is reacting more violently or showing stronger trend exhaustion compared to the other.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
multi_2x2_MA
//+------------------------------------------------------------------+
//|                                                       2*2_MA.mq4 |
//|                                                     Yuriy Tokman |
//|                                            yuriytokman@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Yuriy Tokman"
#property link      "yuriytokman@gmail.com"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Red

extern int period_1 = 13 ;
extern int period_2 = 55 ;
extern int ma_method = 1;
extern int applied_price = 0;

double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
   
   IndicatorShortName("2*2_MA("+period_1+","+period_2+")");
   
   SetIndexLabel(0,"EURUSD");
   SetIndexLabel(1,"GBPUSD");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
  int limit;
   int counted_bars=IndicatorCounted();
   
   //---- check for possible errors
   if(counted_bars<0) return(-1);
   //---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;

   //---- main loop
   for(int i=0; i<limit; i++)
   {
     double p1 = MarketInfo("EURUSD",MODE_POINT);
     double MA1 = iMA("EURUSD",0,period_1,0,ma_method,applied_price,i);
     double MA2 = iMA("EURUSD",0,period_2,0,ma_method,applied_price,i);
     ExtMapBuffer1[i]=(MA1-MA2)/p1;
     
     double p2 = MarketInfo("GBPUSD",MODE_POINT);
     double MA11 = iMA("GBPUSD",0,period_1,0,ma_method,applied_price,i);
     double MA22 = iMA("GBPUSD",0,period_2,0,ma_method,applied_price,i);
     ExtMapBuffer2[i]=(MA11-MA22)/p2;     
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+


Comments