Simple & Quick Programming Help need

 
Hi All,

I need code for the following function:

I need to search back over any given number of bars and return the bar index # and the value of the bar with the greatest range from High to Low.

i.e. something like:
for(int i=1;i<50;i++)
{
double range=high[i]-low[i];
}



Then I need to find which index had the "greatest" range and return that index and also return the actual range value.

Any help would be appreciated,
Thanks,
SaxMan

 
Hi all,

I answered my own question. Here's the code:

double range[5];
  for(int i=1;i<5;i++)
   {
  range[i]={High[i]-Low[i]};
  int Max=ArrayMaximum(range);
  double MaxRange=(High[Max]-Low[Max])/Point;
  }
  
  Print("Max Range: ",MaxRange," found at index: ",Max);



This could be used to get the highest/lowest(using ArrayMinimum(range)) of the array to compare any variables.

Hope this helps,
SaxMan

 
int maxRange(int i)
{
    double r, v;
    int b;

    r = 0.;
    for (; i >= 0; i--)
    {
        v = High[i] - Low[i];
        if (r < v)
        {
            r = v;
            b = i;
        }
    }
    return (b);
}

int start()
{
    int n;
    double range;

    n = maxRange(50);
    range = High[n] - Low[n];
}
 
Same code with added:
* Minimum
* Vertical lines for graphic highlight of the minimum and maximum bars
double range[2000];
  for(int i=1;i<2000;i++)
   {
   range[i]={High[i]-Low[i]};
   int Max=ArrayMaximum(range,WHOLE_ARRAY,1);
   int Min=ArrayMinimum(range,WHOLE_ARRAY,1);
   double MaxRange=(High[Max]-Low[Max])/Point;
   double MinRange=(High[Min]-Low[Min])/Point;
   }
  
  Print("Max Range: ",MaxRange," pips    found at index: ",Max);
  Print("Min Range: ",MinRange," pips    found at index: ",Min);
  
  int time1=Time[Max];
  int time2=Time[Min];
  
  ObjectCreate("stats1",OBJ_VLINE,0,0,0);
  ObjectSet("stats1", OBJPROP_TIME1, time1);
  ObjectSet("stats1", OBJPROP_COLOR, Red);
  ObjectSet("stats1", OBJPROP_WIDTH, 1);
  
  ObjectCreate("stats2",OBJ_VLINE,0,0,0);
  ObjectSet("stats2", OBJPROP_TIME1, time2);
  ObjectSet("stats2", OBJPROP_COLOR, Blue);
  ObjectSet("stats2", OBJPROP_WIDTH, 1);