This is the first indicator I am trying to program, day 1 of teaching myself from the MQL book...
All it is supposed to do is draw two lines with the maximum and minimum prices from the last 20 bars. It correctly draws the lines for the current high and low prices but it only draws a horizontal line, it doesn't change for the historic prices. In a live chart it draws the lines correctly for the future bars.
I'm a bit confused with the "Bars" and "IndicatorCounted" functions, this is probably the problem.
I will appreciate if anyone can have a quick look at the code:
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Red
// ------------------------------------------------|
// Variables changable by user |
// ------------------------------------------------|
extern int Max_Bars = 20;
extern int Min_Bars = 20;
// ------------------------------------------------|
// Declare arrays for indicator buffers |
// ------------------------------------------------|
double Buf_0[],
Buf_1[];
// ------------------------------------------------|
// Assign arrays to buffers and set line styles |
// ------------------------------------------------|
int init()
{
SetIndexBuffer(0,Buf_0);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
SetIndexBuffer(1,Buf_1);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);
}
// ------------------------------------------------|
// Main program |
// ------------------------------------------------|
int start()
{
// Assign variable names
double MAX20,
MIN20;
int i,
j,
Counted_bars;
// Program
Counted_bars = IndicatorCounted();
i = Bars - Counted_bars - 1;
while (i>=0)
{
j=1; // Determine highest value
MAX20 = High[j];
while(j <= Max_Bars)
{
if (High[j] > MAX20)
MAX20 = High[j];
j++;
}
j=1; // Determine lowest value
MIN20 = Low[j];
while(j <= Min_Bars)
{
if (Low[j] < MIN20)
MIN20 = Low[j];
j++;
}
Buf_0[i]=MAX20; //Fill buffers with max and min values
Buf_1[i]=MIN20;
i--;
}
return;
}
All it is supposed to do is draw two lines with the maximum and minimum prices from the last 20 bars. It correctly draws the lines for the current high and low prices but it only draws a horizontal line, it doesn't change for the historic prices. In a live chart it draws the lines correctly for the future bars.
I'm a bit confused with the "Bars" and "IndicatorCounted" functions, this is probably the problem.
I will appreciate if anyone can have a quick look at the code:
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Red
// ------------------------------------------------|
// Variables changable by user |
// ------------------------------------------------|
extern int Max_Bars = 20;
extern int Min_Bars = 20;
// ------------------------------------------------|
// Declare arrays for indicator buffers |
// ------------------------------------------------|
double Buf_0[],
Buf_1[];
// ------------------------------------------------|
// Assign arrays to buffers and set line styles |
// ------------------------------------------------|
int init()
{
SetIndexBuffer(0,Buf_0);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
SetIndexBuffer(1,Buf_1);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);
}
// ------------------------------------------------|
// Main program |
// ------------------------------------------------|
int start()
{
// Assign variable names
double MAX20,
MIN20;
int i,
j,
Counted_bars;
// Program
Counted_bars = IndicatorCounted();
i = Bars - Counted_bars - 1;
while (i>=0)
{
j=1; // Determine highest value
MAX20 = High[j];
while(j <= Max_Bars)
{
if (High[j] > MAX20)
MAX20 = High[j];
j++;
}
j=1; // Determine lowest value
MIN20 = Low[j];
while(j <= Min_Bars)
{
if (Low[j] < MIN20)
MIN20 = Low[j];
j++;
}
Buf_0[i]=MAX20; //Fill buffers with max and min values
Buf_1[i]=MIN20;
i--;
}
return;
}