Good day.for years now I have always had a question.
Say you make an indicator with 4 buffers and 4 plots.
All are set to array series true
And wen you compile without assigning any values to the buffers, they will be ploted
- Assign indicator buffer for all bars to an array (The indicator has bars limit)
- Error 4029 Invalid array
- Limit for Buffers is 512 but why cant my Indicator plot 10 Buffers?
A plot has to be plotted unless it is of DRAW_NONE type.
https://www.mql5.com/en/docs/customind/setindexbuffer
It says SetIndexBuffer has INDICATOR _DATA as default value..
//+------------------------------------------------------------------+ //| Default Bug.mq5 | //| Jefferson Metha | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Jefferson Metha" #property link "https://www.mql5.com" #property version "1.00" #property indicator_chart_window #property indicator_buffers 3 #property indicator_plots 3 //--- plot Label1 #property indicator_label1 "Label1" #property indicator_type1 DRAW_LINE #property indicator_color1 clrRed #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- plot Label2 #property indicator_label2 "Label2" #property indicator_type2 DRAW_HISTOGRAM #property indicator_color2 clrRed #property indicator_style2 STYLE_SOLID #property indicator_width2 1 //--- plot Label3 #property indicator_label3 "Label3" #property indicator_type3 DRAW_ARROW #property indicator_color3 clrRed #property indicator_style3 STYLE_SOLID #property indicator_width3 1 //--- input parameters input int Input1; //--- indicator buffers double Label1Buffer[]; double Label2Buffer[]; double Label3Buffer[]; //--- int handle1=INVALID_HANDLE; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,Label1Buffer,INDICATOR_DATA); SetIndexBuffer(1,Label2Buffer,INDICATOR_DATA); SetIndexBuffer(2,Label3Buffer,INDICATOR_DATA); //--- setting a code from the Wingdings charset as the property of PLOT_ARROW PlotIndexSetInteger(2,PLOT_ARROW,159); //--- ArraySetAsSeries(Label1Buffer,true); ArraySetAsSeries(Label2Buffer,true); ArraySetAsSeries(Label3Buffer,true); //--- handle1=iMA(NULL,PERIOD_CURRENT,12,0,MODE_EMA,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[]) { //--- CopyBuffer(handle1,0,0,rates_total,Label1Buffer); //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //| Timer function | //+------------------------------------------------------------------+ void OnTimer() { //--- } //+------------------------------------------------------------------+ //| ChartEvent function | //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { //--- } //+------------------------------------------------------------------+
The Above Code has a bug, as the unassigned Buffers have values to Them.
for some drawing styles you may need to initialize buffers to an empty value as part of the initialization
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0); PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0); PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,0.0);
they have it in the example code:
https://www.mql5.com/en/docs/constants/indicatorconstants/customindicatorproperties
but it's not really explained
Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Custom Indicator Properties
- www.mql5.com
Custom Indicator Properties - Indicator Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
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