Hello
I'm trying to code a function, that will return the highest candle range from the last 9 candles.
than, I would like to plot it as an indicator.
Here's where I got so far -
Function:
double Last9 (int x)
{
int count, highest;
double range[9];
for (count=(x+1) ; count<(x+10) ; count++) { //bar range assigmant
range[count]=(High[count]-Low[count]);
range[count]=MathAbs(range[count]); //verifying positive
}
highest=ArrayMaximum(range,9,(x+1));
return(range[highest]);
}
here's the indicator I coded for this. If you'll use it on a charts, you will see that from a certain point it plot 0 for some reason.
Help very much appreciated!!!
Cheers,
Nati
The entire indicator:
//+------------------------------------------------------------------+
//| NatiTest.mq4 |
//| Copyright 2008, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2008, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Lime
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------+
//|Highest in last 9 function |
//+------------------------------------+
double Last9 (int x)
{
int count, highest;
double range[9];
for (count=(x+1) ; count<(x+10) ; count++) { //bar range assigmant
range[count]=(High[count]-Low[count]);
range[count]=MathAbs(range[count]); //verifying positive
}
highest=ArrayMaximum(range,9,(x+1));
return(range[highest]);
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,ExtMapBuffer2);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
//------------------------------+
//Calling Last9 function |
//------------------------------+
int j;
for (j=0 ; j<Bars ; j++)
ExtMapBuffer1[j]=Last9(j);
return(0);
}
//+------------------------------------------------------------------+
I'm trying to code a function, that will return the highest candle range from the last 9 candles.
than, I would like to plot it as an indicator.
Here's where I got so far -
Function:
double Last9 (int x)
{
int count, highest;
double range[9];
for (count=(x+1) ; count<(x+10) ; count++) { //bar range assigmant
range[count]=(High[count]-Low[count]);
range[count]=MathAbs(range[count]); //verifying positive
}
highest=ArrayMaximum(range,9,(x+1));
return(range[highest]);
}
here's the indicator I coded for this. If you'll use it on a charts, you will see that from a certain point it plot 0 for some reason.
Help very much appreciated!!!
Cheers,
Nati
The entire indicator:
//+------------------------------------------------------------------+
//| NatiTest.mq4 |
//| Copyright 2008, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2008, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Lime
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------+
//|Highest in last 9 function |
//+------------------------------------+
double Last9 (int x)
{
int count, highest;
double range[9];
for (count=(x+1) ; count<(x+10) ; count++) { //bar range assigmant
range[count]=(High[count]-Low[count]);
range[count]=MathAbs(range[count]); //verifying positive
}
highest=ArrayMaximum(range,9,(x+1));
return(range[highest]);
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,ExtMapBuffer2);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
//------------------------------+
//Calling Last9 function |
//------------------------------+
int j;
for (j=0 ; j<Bars ; j++)
ExtMapBuffer1[j]=Last9(j);
return(0);
}
//+------------------------------------------------------------------+