FRAMA_Bands

Download script
Author: Copyright � 2007, Forex-TSD.com
FRAMA_Bands

This indicator is designed to provide traders with a visual tool for identifying market trends and potential price extremes by combining two advanced mathematical concepts: the Fractal Adaptive Moving Average (FRAMA) and Bollinger-style Band dynamics.

How the Logic Works

The script processes market data in two distinct stages to create a comprehensive visual layout on your chart.

1. The Core: Fractal Adaptive Movement

Instead of using a standard moving average that reacts slowly to new information or creates "noise" during sideways markets, this tool uses a Fractal Adaptive approach.

  • Volatility Sensing: The logic looks at recent price highs and lows over specific windows of time to calculate the "fractal dimension" of the market. This essentially measures how "jagged" or "smooth" the current price action is.
  • Dynamic Adaptation: Based on that measurement, the script calculates an adaptation factor (Alpha). When the market is moving strongly in one direction (trending), the indicator reacts quickly to follow that trend. When the market becomes choppy or consolidates, the indicator automatically slows down to smooth out the data.
  • Customizable Inputs: You can choose which price data to base this on—whether it be the standard closing price, the high/low range, or even a weighted average of all three.

2. The Outer Layer: Dynamic Bands

Once the script establishes the core adaptive line (the FRAMA), it builds a "channel" around it.

  • Upper and Lower Bands: Similar to standard volatility bands, these lines expand and contract based on the price's deviation from the adaptive core.
  • Trend Visualization: The upper band represents an area of potential over-extension, while the lower band represents a baseline for upward momentum.

Summary of User Experience

For a trader, this means the indicator doesn't just give you a static line; it provides a "living" channel that adjusts its sensitivity automatically. It is designed to stay glued to the trend during strong moves while widening or tightening based on market volatility, helping users identify where the price is deviating from its normal adaptive path.

Miscellaneous
Implements a curve of type %1
9 Views
0 Downloads
0 Favorites
FRAMA_Bands
//+------------------------------------------------------------------+
//|                                                  FRAMA Bands.mq4 |
//|                                                             Rosh |
//|                    http://www.alpari-idc.ru/ru/experts/articles/ |
//|                                              Written by Linuxser |   
//|                                       http://www.linuxser.com.ar | 
//+------------------------------------------------------------------+
#property copyright "Rosh"
#property link      "http://www.alpari-idc.ru/ru/experts/articles/"
#property copyright "Copyright © 2007, Forex-TSD.com "
#property link      "http://www.forex-tsd.com/"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 C'183,71,243'
#property indicator_color2 C'183,71,243'
#property indicator_color3 CLR_NONE
//---- input parameters
extern string abc="-----------Bands Options------------------------";
extern int BandsLength = 20;
extern double BandsDeviation = 2;
extern double BandsShift = 0;
extern string bac="-----------FRAMA Options------------------------";
extern int       PeriodFRAMA=10;
extern int       PriceType=0;
//PRICE_CLOSE 0 Öåíà çàêðûòèÿ 
//PRICE_OPEN 1 Öåíà îòêðûòèÿ 
//PRICE_HIGH 2 Ìàêñèìàëüíàÿ öåíà 
//PRICE_LOW 3 Ìèíèìàëüíàÿ öåíà 
//PRICE_MEDIAN 4 Ñðåäíÿÿ öåíà, (high+low)/2 
//PRICE_TYPICAL 5 Òèïè÷íàÿ öåíà, (high+low+close)/3 
//PRICE_WEIGHTED 6 Âçâåøåííàÿ öåíà çàêðûòèÿ, (high+low+close+close)/4 

//---- buffers
double bup[];
double blow[];
double ExtMapBuffer1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,bup);
   
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,blow);

   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,ExtMapBuffer1);
   SetIndexEmptyValue(2,0.0);
   
   SetIndexLabel(0,"Upper TEMA Band");
   SetIndexLabel(1,"Lower TEMA Band");
   
   IndicatorShortName("FRAMA Bands("+PeriodFRAMA+","+BandsLength+")");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| âîçâðàùàåò öåíó                                                  |
//+------------------------------------------------------------------+
double Price(int shift)
  {
//----
   double res;
//----
   switch (PriceType)
      {
      case PRICE_OPEN: res=Open[shift]; break;
      case PRICE_HIGH: res=High[shift]; break;
      case PRICE_LOW: res=Low[shift]; break;
      case PRICE_MEDIAN: res=(High[shift]+Low[shift])/2.0; break;
      case PRICE_TYPICAL: res=(High[shift]+Low[shift]+Close[shift])/3.0; break;
      case PRICE_WEIGHTED: res=(High[shift]+Low[shift]+2*Close[shift])/4.0; break;
      default: res=Close[shift];break;
      }
   return(res);
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   double Hi1,Lo1,Hi2,Lo2,Hi3,Lo3;   
   double N1,N2,N3,D;
   double ALFA;
   int limit;
   
   
   int    counted_bars=IndicatorCounted();
   if (counted_bars==0) limit=Bars-2*PeriodFRAMA;
   if (counted_bars>0) limit=Bars-counted_bars;
   limit--;
      
//----
   for (int i=limit;i>=0;i--)
      {
      Hi1=High[iHighest(Symbol(),0,MODE_HIGH,PeriodFRAMA,i)];
      Lo1=Low[iLowest(Symbol(),0,MODE_LOW,PeriodFRAMA,i)];
      Hi2=High[iHighest(Symbol(),0,MODE_HIGH,PeriodFRAMA,i+PeriodFRAMA)];
      Lo2=Low[iLowest(Symbol(),0,MODE_LOW,PeriodFRAMA,i+PeriodFRAMA)];
      Hi3=High[iHighest(Symbol(),0,MODE_HIGH,2*PeriodFRAMA,i)];
      Lo3=Low[iLowest(Symbol(),0,MODE_LOW,2*PeriodFRAMA,i)];
      N1=(Hi1-Lo1)/PeriodFRAMA;
      N2=(Hi2-Lo2)/PeriodFRAMA;
      N3=(Hi3-Lo3)/(2.0*PeriodFRAMA);
      D=(MathLog(N1+N2)-MathLog(N3))/MathLog(2.0);
      ALFA=MathExp(-4.6*(D-1.0));
      ExtMapBuffer1[i]=ALFA*Price(i)+(1-ALFA)*ExtMapBuffer1[i+1];      
      }
      
      for (i=limit;i>=0;i--) bup[i]=iBandsOnArray(ExtMapBuffer1,Bars,BandsLength,BandsDeviation,BandsShift,MODE_UPPER,i);
      for (i=limit;i>=0;i--) blow[i]=iBandsOnArray(ExtMapBuffer1,Bars,BandsLength,BandsDeviation,BandsShift,MODE_LOWER,i);
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments