68 lines
2.5 KiB
MQL5
68 lines
2.5 KiB
MQL5
|
//+------------------------------------------------------------------+
|
||
|
//| ColourMA.mq5 |
|
||
|
//| Copyright 2018, Benjamin Pillet |
|
||
|
//| |
|
||
|
//+------------------------------------------------------------------+
|
||
|
#property copyright "Copyright 2018, Benjamin Pillet"
|
||
|
#property link ""
|
||
|
#property version "1.00"
|
||
|
#property indicator_chart_window
|
||
|
#property indicator_buffers 1
|
||
|
#property indicator_plots 1
|
||
|
//--- plot MA
|
||
|
#property indicator_label1 "MA"
|
||
|
#property indicator_type1 DRAW_LINE
|
||
|
#property indicator_color1 clrRed
|
||
|
#property indicator_style1 STYLE_SOLID
|
||
|
#property indicator_width1 1
|
||
|
//--- input parameters
|
||
|
input ENUM_TIMEFRAMES TF;
|
||
|
input int period;
|
||
|
input ENUM_MA_METHOD Method;
|
||
|
input color Colour;
|
||
|
//--- indicator handle and buffer
|
||
|
int MAHandle;
|
||
|
double MABuffer[];
|
||
|
//+------------------------------------------------------------------+
|
||
|
//| Custom indicator initialization function |
|
||
|
//+------------------------------------------------------------------+
|
||
|
int OnInit()
|
||
|
{
|
||
|
//--- indicator buffers mapping
|
||
|
SetIndexBuffer(0,MABuffer,INDICATOR_DATA);
|
||
|
PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,Colour);
|
||
|
MAHandle = iMA(_Symbol,TF,period,0,Method,PRICE_CLOSE);
|
||
|
|
||
|
//---
|
||
|
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[])
|
||
|
{
|
||
|
//--- copy MA buffer
|
||
|
int toCopy;
|
||
|
if(prev_calculated>rates_total || prev_calculated<=0) toCopy=rates_total;
|
||
|
else
|
||
|
{
|
||
|
toCopy=rates_total-prev_calculated;
|
||
|
//--- last value is always copied
|
||
|
toCopy++;
|
||
|
}
|
||
|
CopyBuffer(MAHandle,0,0,toCopy,MABuffer);
|
||
|
|
||
|
//--- return value of prev_calculated for next call
|
||
|
return(rates_total);
|
||
|
}
|
||
|
//+------------------------------------------------------------------+
|