
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!
I'm really new to MQL5, so sorry for the question. I'm writing the code below, just to get started, but the indicators are returning zero (when they should return 10 and 25). What am I doingo wrong, please?
//+------------------------------------------------------------------+
//| BHM.mq5 |
//| Copyright 2020, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots 2
//--- plot MaxV
#property indicator_label1 "MaxV"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- plot AvgMaxV
#property indicator_label2 "AvgMaxV"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrBlue
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//--- input parameters
input int nMaxV=10;
input int nAvgMaxV=25;
//--- indicator buffers
double MaxVBuffer[];
double AvgMaxVBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,MaxVBuffer,INDICATOR_DATA);
SetIndexBuffer(1,AvgMaxVBuffer,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[])
{
//---
MaxVBuffer[i]=nMaxV;
AvgMaxVBuffer[i]=nAvgMaxV;
//--- return value of prev_calculated for next call
return(rates_total);
}