Author: Copyright � 2010, Alexey Sergeev
Price Data Components
Series array that contains close prices for each barSeries array that contains open prices of each barSeries array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
sProperMA
//+------------------------------------------------------------------+
//|                                                     				 +MA |
//|     programming & support - Alexey Sergeev (profy.mql@gmail.com) |
//|	 1.04                                                            |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, Alexey Sergeev"
#property link      "profy.mql@gmail.com"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 LimeGreen

extern int TF=240; // òàéìôðåéì 
extern int PeriodMA=14; // ïåðèîä ÌÀ
extern int MethodMA=0; // ìåòîä ÌÀ
extern int PriceMA=0; // öåíà ÌÀ
extern bool ShowSimple=false; // 

double MA[],PR[];
datetime last=0;
//------------------------------------------------------------------	init
void init()
  {
   SetIndexBuffer(0,MA); SetIndexStyle(0,DRAW_LINE); SetIndexLabel(0,"MA");
   IndicatorShortName("MA("+PeriodMA+")");
   ArrayResize(PR,PeriodMA+1); ArraySetAsSeries(PR,true);
   if(TF<Period()) TF=Period();
  }
//------------------------------------------------------------------	start
void start()
  {
   string smb=Symbol();
   if(Bars<=PeriodMA) return(0);

   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
   if(counted_bars==0) limit-=1+PeriodMA;

   if(counted_bars<=0) for(int i=1; i<=PeriodMA; i++) MA[limit-i]=EMPTY_VALUE;

   for(i=limit-1; i>=0; i--)
     {
      int b=iBarShift(smb,TF,Time[i]); // áàð òåêóùåãî âðåìåíè ìëàäøåãî íà ñòàðøåì ÒÔ
      if(last!=iTime(smb,TF,b)) // åñëè ýòî íîâûé áàð
        {
         last=iTime(smb,TF,b);
         for(int j=PeriodMA-1; j>=0; j--) PR[j]=GetPrice(smb,TF,b+j,PriceMA); // ñìåñòèëè áàðû íà íîâûå
        }
      if(!ShowSimple) PR[0]=GetPrice(smb,Period(),i,PriceMA); // îáíîâèëè òåêóùèé áàð
      MA[i]=iMAOnArray(PR,0,PeriodMA,0,MethodMA,0); // ðàñ÷èòàëè ÌÀ
     }
  }
//------------------------------------------------------------------
double GetPrice(string smb,int tf,int i,int price)
  {
   if(price==PRICE_CLOSE) return(iClose(smb,tf,i));
   if(price==PRICE_OPEN) return(iOpen(smb, tf, i));
   if(price==PRICE_HIGH) return(iHigh(smb, tf, i));
   if(price==PRICE_LOW) return(iLow(smb,tf,i));
   if(price==PRICE_MEDIAN) return((iHigh(smb,tf,i)+iLow(smb,tf,i))/2);
   if(price==PRICE_TYPICAL) return((iHigh(smb,tf,i)+iLow(smb,tf,i)+iClose(smb,tf,i))/3);
   if(price==PRICE_WEIGHTED) return((iHigh(smb,tf,i)+iLow(smb,tf,i)+iClose(smb,tf,i)+iClose(smb,tf,i))/4);
  }
//+------------------------------------------------------------------+

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 ---