Author: TraderSeven
Firebird

This custom indicator is designed to provide traders with a visual representation of price trends by calculating a specialized moving average based on historical opening prices. Instead of showing just a single line, it creates a dynamic "channel" or "band" around the price action, helping users identify potential price boundaries and trend momentum.

Core Functionality

The tool operates by analyzing the Opening Price of candles over a specific timeframe (defined by the user as the "Period"). Rather than reacting to every fluctuation within a candle, it focuses on the start of each price movement to establish a baseline.

How the Logic Works

  1. Base Calculation: The script first calculates a standard Simple Moving Average (SMA). It looks back at a set number of previous bars, adds up their opening prices, and divides them by that total number of bars to find the average.
  2. Dynamic Band Creation: Once the base average is established, the script applies a "Percentage" variance. This creates two distinct boundaries:
    • Upper Band: An elevated price level calculated by adding a specific percentage to the average.
    • Lower Band: A lowered price level calculated by subtracting that same percentage from the average.
  3. Visual Tracking: The script continuously recalculates these values as new candles form. On your chart, this results in a visual envelope. When the price stays within these bands, it suggests a stable trend; when the price breaks outside of these boundaries, it may indicate a significant shift in market sentiment or a potential reversal.

Key Features for the User

  • Customizable Sensitivity: You can adjust the "Period" to change how much historical data is considered (shorter periods are more reactive to recent news, while longer periods provide a smoother, broader view of the trend).
  • Volatility Adjustment: By changing the "Percent" value, you can make the bands wider or narrower. This allows you to tailor the indicator to different market conditions—making it tighter for low-volatility markets or wider for highly active trading environments.
  • Automated Processing: The script handles all the heavy lifting of constant price summing and percentage math in real-time, ensuring that the visual bands update automatically as the market moves.
Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
Firebird
//+------------------------------------------------------------------+
//|                                        Custom Moving Average.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "TraderSeven"
#property link      "TraderSeven@gmx.net"

#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 Red
#property indicator_color2 Orange
#property indicator_color3 Blue
#property indicator_color4 MediumSeaGreen
#property indicator_color5 Red
#property indicator_color6 White
//---- indicator parameters
extern int MA_Period=10;


extern double Percent=2;

double UpperBand;
double LowerBand;


//---- indicator buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
//----
int ExtCountedBars=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   int    draw_begin;
   string short_name;
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
   if(MA_Period<2) MA_Period=13;
   draw_begin=MA_Period-1;

   IndicatorShortName(short_name+MA_Period+")");
   SetIndexDrawBegin(0,draw_begin);
//---- indicator buffers mapping
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexBuffer(3,ExtMapBuffer4);
   SetIndexBuffer(4,ExtMapBuffer5);
   SetIndexBuffer(5,ExtMapBuffer6);
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
UpperBand=(1+Percent/100);
LowerBand=1-Percent/100;

   if(Bars<=MA_Period) return(0);
   ExtCountedBars=IndicatorCounted();
//---- check for possible errors
   if (ExtCountedBars<0) return(-1);
//---- last counted bar will be recounted
   if (ExtCountedBars>0) ExtCountedBars--;
//+------------------------------------------------------------------+
//| Simple Moving Average                                            |
//+------------------------------------------------------------------+
  {
   double sum=0;
   int    i,pos=Bars-ExtCountedBars-1;
//---- initial accumulation
   if(pos<MA_Period) pos=MA_Period;
   for(i=1;i<MA_Period;i++,pos--)
      sum+=Open[pos];
//---- main calculation loop
   while(pos>=0)
     {
      sum+=Open[pos];
      ExtMapBuffer1[pos]=(sum/MA_Period)*UpperBand;
      //ExtMapBuffer2[pos]=(((sum/MA_Period)*1.02)-(Open[pos]*0.0025));      
      ExtMapBuffer3[pos]=(sum/MA_Period)*LowerBand;
      //ExtMapBuffer4[pos]=((sum/MA_Period)*0.98)+(Open[pos]*0.0025);  
	   sum-=Open[pos+MA_Period-1];
 	   pos--;
     }
//---- zero initial bars
   if(ExtCountedBars<1)
      for(i=1;i<MA_Period;i++) ExtMapBuffer1[Bars-i]=0;
  }
//+------------------------------------------------------------------+
}





Comments