Download MetaTrader 5

First indicator

To add comments, please log in or register
Deposit to your account via PayPal
iharter
21
iharter 2013.10.15 17:31 

Hi

I am inciting and would like to create a basic indicator. to draw a line in average prices ((open-close / 2) + open)
grateful

Documentation on MQL5: Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants
Documentation on MQL5: Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants
  • www.mql5.com
Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants - Documentation on MQL5
Alain Verleyen
Moderator
30702
Alain Verleyen 2013.10.15 17:40  
iharter:

Hi

I am inciting and would like to create a basic indicator. to draw a line in average prices ((open-close / 2) + open)
grateful

Ok, what have you tried ?
Pasi Hakamaki
4676
Pasi Hakamaki 2013.10.15 17:46  

Hi,

Maybe this code can get you up and running?

//+------------------------------------------------------------------+
//|                                               average prices.mq5 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrRed
#property indicator_width1 1

double indicator_buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,indicator_buffer,INDICATOR_DATA);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   if(rates_total<1)
      return 0;

   int limit;

   if(prev_calculated==0)
     {
      limit=0;
      ArrayInitialize(indicator_buffer,EMPTY_VALUE);
     }
   else
      limit=rates_total-1;

   for(int i=limit;i<rates_total;i++)
      indicator_buffer[i]=(open[i]-close[i])/2+open[i];
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
To add comments, please log in or register