FRAMA_Bands

Author: Copyright � 2007, Forex-TSD.com
FRAMA_Bands
Miscellaneous
Implements a curve of type %1
0 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

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---