I'm pretty new to mql5 and are trying to create an indicator, what i want is simple, but i seem to be missing something from it.
I want to compare the close price of the 2 bars by the minute, if it is more than a certain value, it adds 1 to a indicator (Array?)
So Say
Bar A-1 closes at 1.555
Bar A closes at 1.455
each 0.01 it shall add 1 to the bar indicator, hence there should be a bar with a value of 10.
#property copyright "Copyright 2011, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_plots 1
//--- plot Bars
#property indicator_label1 "Bars"
#property indicator_type1 DRAW_BARS
#property indicator_color1 clrGreen
#property indicator_style1 STYLE_SOLID
#property indicator_width1 5
#property indicator_maximum 5
#property indicator_minimum 0.000
//--- input parameter
input int pip=100; // Number of pip
//--- An indicator buffer for the plot
double LineBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- Binding an array and an indicator buffer
SetIndexBuffer(1,LineBuffer,INDICATOR_DATA);
//--- Initializing the generator of pseudo-random numbers
//---
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[])
{
//--- Block for calculating indicator values
for(int i=0;i<rates_total;i++)
{
if(i>= 1 && (close[i] - close[i-1] >= pip*_Point))
{
LineBuffer[i]=1;
}
}
//--- return value of prev_calculated for next call
return(rates_total);
}
yet when i tested it, it seem that close[i] is called every tick instead of every bar, and i can't seem to get the LineBuffer indicator to show the difference of close[i] and close[i-1] (hence i stuck it with 1 to get an indicator it has a difference more than the value called pip)