Complex_balance____Ext

Download script
Author: SemSemFX@rambler.ru
Complex_balance____Ext

This script is designed as a custom technical analysis tool for the MetaTrader 4 platform. Its primary purpose is to visualize specific price movements and momentum shifts by calculating the difference between two moving averages based on the timeframe you are currently viewing.

Core Functionality

Automatic Timeframe Detection The tool is built with "smart" defaults. It automatically detects which timeframe you are trading (e.g., 1-minute, 15-minute, Daily, Weekly, or Monthly). Based on this detection, it assigns specific calculation periods to ensure the data remains consistent and relevant to that specific scale. For example, if you are looking at a Daily chart, it uses settings optimized for daily cycles; if you switch to an Hourly chart, it automatically adjusts its internal logic to match.

Momentum Calculation The script operates by comparing two different Moving Averages (MA):

  1. A "Fast" average (which reacts quickly to price changes).
  2. A "Slow" average (which represents the broader trend).

By subtracting the Slow average from the Fast average, the script calculates a "balance." When these two averages cross over each other—meaning the fast price action is moving significantly higher or lower than the long-term average—the script identifies a potential shift in momentum.

Visual Representation Rather than simply showing a line for the moving averages, this indicator creates a visual signal on a separate window below your main price chart:

  • Trend Identification: It calculates the average price of each candle (combining the Open, High, Low, and Close prices).
  • Dynamic Positioning: When a crossover occurs (the point where the "Fast" and "Slow" averages switch positions), the script applies a mathematical offset to the visual line. This adjustment is based on the magnitude of the momentum change.
  • Visual Clarity: By using these offsets, the indicator helps traders visualize the intensity of price movements, making it easier to spot whether a trend is gaining strength or losing steam at a glance.

Summary for the User

Think of this tool as a "momentum stabilizer." It looks at the relationship between short-term speed and long-term trends. It automatically tunes itself to your chosen timeframe and highlights the points where the market's immediate momentum pushes away from its average path, providing a visual representation of price "balance" and potential trend shifts.

Price Data Components
Series array that contains the highest prices of each barSeries array that contains the lowest prices of each barSeries array that contains open prices of each barSeries array that contains close prices for each bar
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
11 Views
0 Downloads
0 Favorites
Complex_balance____Ext
//+------------------------------------------------------------------+
//|                                                       EURUSD.mq4 |
//|                                              SemSemFX@rambler.ru |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "SemSemFX@rambler.ru"
#property link      ""
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
//---- input parameters
extern int       PerFast=0;
extern int       PerSlow=0;
extern int       NBars=200;
extern int       TF=0;
extern int Price=6;
extern int Mode=3;
double Buf[],a,b;
int per1,per2;

//---- buffers
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorShortName("Complex_balanceExt("+per2+"/"+per1+")");
   SetIndexStyle(0,DRAW_SECTION);
   SetIndexBuffer(0,Buf);
//---- parameters
// for monthly
int mn_per = 12;
int mn_fast = 3;
// for weekly
int w_per = 9;
int w_fast = 3;
// for daily
int d_per = 5;
int d_fast = 3;
// for H4
int h4_per = 12;
int h4_fast = 2;
// for H1
int h1_per = 24;
int h1_fast = 8;
// for M30
int m30_per = 16;
int m30_fast = 2;
// for M15
int m15_per = 16;
int m15_fast = 4;
// for M5
int m5_per = 12;
int m5_fast = 3;
// for M1
int m1_per = 30;
int m1_fast = 10;
if (TF==0) int TFr=Period(); else TFr=TF;
      if ((PerFast==0)||(PerSlow==0))
      {switch(TFr)
        {
         case 1:     per1 = m1_per; per2 = m1_fast; break;
         case 5:     per1 = m5_per; per2 = m5_fast; break;
         case 15:    per1 = m15_per;per2 = m15_fast; break;
         case 30:    per1 = m30_per;per2 = m30_fast; break;
         case 60:    per1 = h1_per; per2 = h1_fast; break;
         case 240:   per1 = h4_per; per2 = h4_fast; break;
         case 1440:  per1 = d_per;  per2 = d_fast; break;
         case 10080: per1 = w_per;  per2 = w_fast; break;
         case 43200: per1 = mn_per; per2 = mn_fast; break;
        }
      } else {per2=PerFast; per1=PerSlow;}  
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
     int limit;
     int counted_bars=IndicatorCounted();
  //---- ïðîâåðêà íà âîçìîæíûå îøèáêè
     if(counted_bars<0) return(-1);
  //---- ïîñëåäíèé ïîñ÷èòàííûé áàð áóäåò ïåðåñ÷èòàí
     if(counted_bars>0) counted_bars-=10;
     limit=NBars;
  //---- îñíîâíîé öèêë
     for(int i=0; i<limit; i++)
       {
        a=b;
        b=iMA(Symbol(),TF,per2,0,Mode,Price,i)-iMA(Symbol(),TF,per1,0,Mode,Price,i);
        if (i!=0)
        {
        if ((a<0 && b>0) || (a>0 && b<0))
        Buf[i]=(iOpen(0,TF,i)+iHigh(0,TF,i)+iLow(0,TF,i)+iClose(0,TF,i))/4+MathAbs(MathAbs(a)-MathAbs(b))/2*Point;
        }
        else Buf[i]=(iOpen(0,TF,i)+iHigh(0,TF,i)+iLow(0,TF,i)+iClose(0,TF,i))/4;
        
       }
   
//----
   return(0);
  }



//+------------------------------------------------------------------+

Comments