Firebird_v2
Download scriptThis custom technical indicator is designed to provide traders with a visual representation of price trends by calculating and plotting specific data points on a trading chart. Rather than simply showing a single average price, it creates a dynamic range based on the "Moving Average" of an asset's opening prices.
Core Logic and Functionality
The tool operates by analyzing a set number of previous price periods (defined by the user) to determine a central moving average. It then applies a percentage-based adjustment to this average to create two distinct boundary lines. Here is how the logic flows:
1. Data Collection The script focuses on the "Open" price of candles. By looking at a specific timeframe (the period), it calculates the sum of these opening prices to establish a baseline of where the market has been moving recently.
2. Dynamic Band Calculation Once the average is established, the script applies a mathematical offset based on a user-defined percentage.
- Upper Boundary: The script takes the calculated average and increases it by the specified percentage.
- Lower Boundary: The script takes the same average and decreases it by that same percentage.
3. Visual Output The indicator produces multiple visual elements on the chart:
- It identifies the upper and lower "bands" or limits.
- These bands help traders visualize the "normal" trading range. When the price moves significantly toward or outside of these calculated boundaries, it can serve as a signal for potential overbought or oversold conditions, or indicate a shift in market momentum.
Summary for the Trader
Essentially, this script acts as a volatility and trend filter. By providing both an upper and lower boundary based on a moving average, it allows you to see the "corridor" in which the price is currently fluctuating. It simplifies complex historical data into a clear visual range, helping you identify whether current price action is staying within expected parameters or breaking out into new territory.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| 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