arickett:
Hi all,
I'm relatively new to metatradted. I'm trying to create an indicator in MQL5 with 5 multicolored plots but only one is showing up when I run it. Can anyone show me how to do this or share an indicator that has multiple multi-colored plots? Thanks!
There is a bug in MT5/mql5. (and in your code too but that's an other matter ;-))
Replace your SetIndexBuffer/PlotIndexSetInteger by :
// CurrentEMA
PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_COLOR_ARROW);
SetIndexBuffer(0,CurrentEMA_Buffer,INDICATOR_DATA);
SetIndexBuffer(1,CurrentEMA_Colors,INDICATOR_COLOR_INDEX);
// H1EMA
PlotIndexSetInteger(1,PLOT_DRAW_TYPE,DRAW_COLOR_ARROW);
SetIndexBuffer(2,H1EMA_Buffer,INDICATOR_DATA);
SetIndexBuffer(3,H1EMA_Colors,INDICATOR_COLOR_INDEX);
// H2EMA
PlotIndexSetInteger(2,PLOT_DRAW_TYPE,DRAW_COLOR_ARROW);
SetIndexBuffer(4,H2EMA_Buffer,INDICATOR_DATA);
SetIndexBuffer(5,H2EMA_Colors,INDICATOR_COLOR_INDEX);
// H3EMA
PlotIndexSetInteger(3,PLOT_DRAW_TYPE,DRAW_COLOR_ARROW);
SetIndexBuffer(6,H3EMA_Buffer,INDICATOR_DATA);
SetIndexBuffer(7,H3EMA_Colors,INDICATOR_COLOR_INDEX);
// H4EMA
PlotIndexSetInteger(4,PLOT_DRAW_TYPE,DRAW_COLOR_ARROW);
SetIndexBuffer(8,H4EMA_Buffer,INDICATOR_DATA);
SetIndexBuffer(9,H4EMA_Colors,INDICATOR_COLOR_INDEX);
PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_COLOR_ARROW);
SetIndexBuffer(0,CurrentEMA_Buffer,INDICATOR_DATA);
SetIndexBuffer(1,CurrentEMA_Colors,INDICATOR_COLOR_INDEX);
// H1EMA
PlotIndexSetInteger(1,PLOT_DRAW_TYPE,DRAW_COLOR_ARROW);
SetIndexBuffer(2,H1EMA_Buffer,INDICATOR_DATA);
SetIndexBuffer(3,H1EMA_Colors,INDICATOR_COLOR_INDEX);
// H2EMA
PlotIndexSetInteger(2,PLOT_DRAW_TYPE,DRAW_COLOR_ARROW);
SetIndexBuffer(4,H2EMA_Buffer,INDICATOR_DATA);
SetIndexBuffer(5,H2EMA_Colors,INDICATOR_COLOR_INDEX);
// H3EMA
PlotIndexSetInteger(3,PLOT_DRAW_TYPE,DRAW_COLOR_ARROW);
SetIndexBuffer(6,H3EMA_Buffer,INDICATOR_DATA);
SetIndexBuffer(7,H3EMA_Colors,INDICATOR_COLOR_INDEX);
// H4EMA
PlotIndexSetInteger(4,PLOT_DRAW_TYPE,DRAW_COLOR_ARROW);
SetIndexBuffer(8,H4EMA_Buffer,INDICATOR_DATA);
SetIndexBuffer(9,H4EMA_Colors,INDICATOR_COLOR_INDEX);
I was wrong in my previous post, this is not a MT5/mql5 bug, I should not work in such things in the night
The problem is in this line :
#property indicator_type12 DRAW_COLOR_ARROW
must be
#property indicator_type2 DRAW_COLOR_ARROW
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi all,
I'm relatively new to metatradted. I'm trying to create an indicator in MQL5 with 5 multicolored plots but only one is showing up when I run it. Can anyone show me how to do this or share an indicator that has multiple multi-colored plots? Thanks!
//| EMA_Dots.mq5 |
//| |
//| |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""
#property version "1.01"
#property indicator_separate_window
#property indicator_buffers 10
#property indicator_plots 5
//--- plot Current
#property indicator_label1 "Current"
#property indicator_type1 DRAW_COLOR_ARROW
#property indicator_color1 clrRed,clrLimeGreen
#property indicator_style1 STYLE_SOLID
#property indicator_width1 3
#property indicator_label2 "H1"
#property indicator_type12 DRAW_COLOR_ARROW
#property indicator_color2 clrRed,clrLimeGreen
#property indicator_style2 STYLE_SOLID
#property indicator_width2 3
#property indicator_label3 "H2"
#property indicator_type3 DRAW_COLOR_ARROW
#property indicator_color3 clrRed,clrLimeGreen
#property indicator_style3 STYLE_SOLID
#property indicator_width3 3
#property indicator_label4 "H3"
#property indicator_type4 DRAW_COLOR_ARROW
#property indicator_color4 clrRed,clrLimeGreen
#property indicator_style4 STYLE_SOLID
#property indicator_width4 3
#property indicator_label5 "H4"
#property indicator_type5 DRAW_COLOR_ARROW
#property indicator_color5 clrRed,clrLimeGreen
#property indicator_style5 STYLE_SOLID
#property indicator_width5 3
sinput int InpAlignEMAPeriod = 14;
//sinput ENUM_APPLIED_PRICE InpOpen = PRICE_OPEN;
//+------------------------------------------------------------------+
//| Global variables |
//+------------------------------------------------------------------+
ENUM_TIMEFRAMES TF[5];
int BarConv[5];
//--- indicator buffers
// EMA
double CurrentEMA_Buffer[]; //Data buffer for plot
double CurrentEMA_Colors[]; //Color buffer for plot
double CurrentEMA_Temp[]; // Temporary buffer for EMA copying
int handle_CurrentEMA = 0; // Handle for Current EMA indicator
double H1EMA_Buffer[]; //Data buffer for plot
double H1EMA_Colors[]; //Color buffer for plot
double H1EMA_Temp[]; // Temporary buffer for EMA copying
int handle_H1EMA = 0; // Handle for Current EMA indicator
double H2EMA_Buffer[]; //Data buffer for plot
double H2EMA_Colors[]; //Color buffer for plot
double H2EMA_Temp[]; // Temporary buffer for EMA copying
int handle_H2EMA = 0; // Handle for Current EMA indicator
double H3EMA_Buffer[]; //Data buffer for plot
double H3EMA_Colors[]; //Color buffer for plot
double H3EMA_Temp[]; // Temporary buffer for EMA copying
int handle_H3EMA = 0; // Handle for Current EMA indicator
double H4EMA_Buffer[]; //Data buffer for plot
double H4EMA_Colors[]; //Color buffer for plot
double H4EMA_Temp[]; // Temporary buffer for EMA copying
int handle_H4EMA = 0; // Handle for Current EMA indicator
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//logger.SetSetting("MTF Indicators","EMA_Dots","Errors",60);
//logger.init();
//ENUM_TIMEFRAMES period = Period();
//ENUM_TIMEFRAMES test = PERIOD_M10;
// Set TimeFrames
switch(Period())
{
case PERIOD_M10:
TF[0] = PERIOD_M10;
TF[1] = PERIOD_H1;
TF[2] = PERIOD_H4;
TF[3] = PERIOD_D1;
TF[4] = PERIOD_W1;
BarConv[0] = 1;
BarConv[1] = 6;
BarConv[2] = 24;
BarConv[3] = 144;
BarConv[4] = 720;
break;
case PERIOD_M15:
TF[0] = PERIOD_M15;
TF[1] = PERIOD_H1;
TF[2] = PERIOD_H4;
TF[3] = PERIOD_D1;
TF[4] = PERIOD_W1;
BarConv[0] = 1;
BarConv[1] = 4;
BarConv[2] = 16;
BarConv[3] = 96;
BarConv[4] = 480;
break;
case PERIOD_M30:
TF[0] = PERIOD_M30;
TF[1] = PERIOD_H2;
TF[2] = PERIOD_H8;
TF[3] = PERIOD_D1;
TF[4] = PERIOD_W1;
BarConv[0] = 1;
BarConv[1] = 4;
BarConv[2] = 16;
BarConv[3] = 48;
BarConv[4] = 240;
break;
case PERIOD_H1:
TF[0] = PERIOD_H1;
TF[1] = PERIOD_H4;
TF[2] = PERIOD_D1;
TF[3] = PERIOD_W1;
TF[4] = PERIOD_MN1;
BarConv[0] = 1;
BarConv[1] = 4;
BarConv[2] = 24;
BarConv[3] = 120;
BarConv[4] = 528;
break;
case PERIOD_H4:
TF[0] = PERIOD_H4;
TF[1] = PERIOD_D1;
TF[2] = PERIOD_W1;
TF[3] = PERIOD_MN1;
TF[4] = PERIOD_MN1;
BarConv[0] = 1;
BarConv[1] = 6;
BarConv[2] = 30;
BarConv[3] = 132;
BarConv[4] = 132;
break;
case PERIOD_D1:
TF[0] = PERIOD_D1;
TF[1] = PERIOD_W1;
TF[2] = PERIOD_MN1;
TF[3] = PERIOD_MN1;
TF[4] = PERIOD_MN1;
BarConv[0] = 1;
BarConv[1] = 5;
BarConv[2] = 22;
BarConv[3] = 22;
BarConv[4] = 22;
break;
default:
TF[0] = PERIOD_D1;
TF[1] = PERIOD_W1;
TF[2] = PERIOD_MN1;
TF[3] = PERIOD_MN1;
TF[4] = PERIOD_MN1;
BarConv[0] = 1;
BarConv[1] = 5;
BarConv[2] = 22;
BarConv[3] = 22;
BarConv[4] = 22;
break;
}
// CurrentEMA
SetIndexBuffer(0,CurrentEMA_Buffer,INDICATOR_DATA);
SetIndexBuffer(1,CurrentEMA_Colors,INDICATOR_COLOR_INDEX);
PlotIndexSetInteger(0, PLOT_COLOR_INDEXES, 2);
PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,LimeGreen);
PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,Red);
// H1EMA
SetIndexBuffer(2,H1EMA_Buffer,INDICATOR_DATA);
SetIndexBuffer(3,H1EMA_Colors,INDICATOR_COLOR_INDEX);
PlotIndexSetInteger(2, PLOT_COLOR_INDEXES, 2);
PlotIndexSetInteger(2,PLOT_LINE_COLOR,0,LimeGreen);
PlotIndexSetInteger(2,PLOT_LINE_COLOR,1,Red);
// H2EMA
SetIndexBuffer(4,H2EMA_Buffer,INDICATOR_DATA);
SetIndexBuffer(5,H2EMA_Colors,INDICATOR_COLOR_INDEX);
PlotIndexSetInteger(4, PLOT_COLOR_INDEXES, 2);
PlotIndexSetInteger(4,PLOT_LINE_COLOR,0,LimeGreen);
PlotIndexSetInteger(4,PLOT_LINE_COLOR,1,Red);
// H3EMA
SetIndexBuffer(6,H3EMA_Buffer,INDICATOR_DATA);
SetIndexBuffer(7,H3EMA_Colors,INDICATOR_COLOR_INDEX);
PlotIndexSetInteger(6, PLOT_COLOR_INDEXES, 2);
PlotIndexSetInteger(6,PLOT_LINE_COLOR,0,LimeGreen);
PlotIndexSetInteger(6,PLOT_LINE_COLOR,1,Red);
// H4EMA
SetIndexBuffer(8,H4EMA_Buffer,INDICATOR_DATA);
SetIndexBuffer(9,H4EMA_Colors,INDICATOR_COLOR_INDEX);
PlotIndexSetInteger(8, PLOT_COLOR_INDEXES, 2);
PlotIndexSetInteger(8,PLOT_LINE_COLOR,0,LimeGreen);
PlotIndexSetInteger(8,PLOT_LINE_COLOR,1,Red);
//Handles
handle_CurrentEMA = iMA(_Symbol,TF[0], InpAlignEMAPeriod * BarConv[0],0,MODE_EMA,PRICE_CLOSE);
handle_H1EMA = iMA(_Symbol,TF[0], InpAlignEMAPeriod * BarConv[1],0,MODE_EMA,PRICE_OPEN);
handle_H2EMA = iMA(_Symbol,TF[0], InpAlignEMAPeriod * BarConv[2],0,MODE_EMA,PRICE_OPEN);
handle_H3EMA = iMA(_Symbol,TF[0], InpAlignEMAPeriod * BarConv[3],0,MODE_EMA,PRICE_OPEN);
handle_H4EMA = iMA(_Symbol,TF[0], InpAlignEMAPeriod * BarConv[4],0,MODE_EMA,PRICE_OPEN);
//---
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[])
{
for(int i=prev_calculated;i<=rates_total-1;i++)
{ //CurrentEMA
CurrentEMA_Buffer[i] = 5;
CopyBuffer(handle_CurrentEMA,0,BarsCalculated(handle_CurrentEMA)-i-1,1,CurrentEMA_Temp);
double currentEMAVal = CurrentEMA_Temp[0];
if(open[i]>currentEMAVal)
{ CurrentEMA_Colors[i] = 0; }
else
{ CurrentEMA_Colors[i] = 1;}
H1EMA_Buffer[i] = 10;
CopyBuffer(handle_H1EMA,2,BarsCalculated(handle_H1EMA)-i-1,1,H1EMA_Temp);
double H1EMAVal = H1EMA_Temp[0];
if(open[i]>H1EMAVal)
{ H1EMA_Colors[i] = 0; }
else
{ H1EMA_Colors[i] = 1;}
H2EMA_Buffer[i] = 15;
CopyBuffer(handle_H2EMA,4,BarsCalculated(handle_H2EMA)-i-1,1,H2EMA_Temp);
double H2EMAVal = H2EMA_Temp[0];
if(open[i]>H2EMAVal)
{ H2EMA_Colors[i] = 0; }
else
{ H2EMA_Colors[i] = 1;}
H3EMA_Buffer[i] = 20;
CopyBuffer(handle_H3EMA,6,BarsCalculated(handle_H3EMA)-i-1,1,H3EMA_Temp);
double H3EMAVal = H3EMA_Temp[0];
if(open[i]>H3EMAVal)
{ H3EMA_Colors[i] = 0; }
else
{ H3EMA_Colors[i] = 1;}
H4EMA_Buffer[i] = 25;
CopyBuffer(handle_H4EMA,8,BarsCalculated(handle_H4EMA)-i-1,1,H4EMA_Temp);
double H4EMAVal = H4EMA_Temp[0];
if(open[i]>H4EMAVal)
{ H4EMA_Colors[i] = 0; }
else
{ H4EMA_Colors[i] = 1;}
}
//---
//--- return value of prev_calculated for next call
return(rates_total-1);
}
//+------------------------------------------------------------------+