Problem with for loop

 
double highestrange, rangecalc;
double range[6];

   for (int bcount = 1; bcount > 7; bcount++)     //scan the last 7 prevbars
   
            {
                 rangecalc = (High[bcount]-Low[bcount]);     //store the range of that candle in the appropriate part of array
                 range[bcount-1] = rangecalc;   // bcount -1 because arrays start at 0
            }

highestrange = ArrayMaximum(range,WHOLE_ARRAY,0);  //give me the range of the largest candle in the last 7 bars

I want this bit of code to scan the last 7 bars, and tell me the highest range.


But all I get is 0's lol. Where did I screw up? P.s Iam still an amateur coder

 

Hi,

First your for loop: You should change bcount > 7 to bcount <= 7, then it actually checks last 7 bars.

Remember that ArrayMaximum returns position of max value in array, for example if largest bar was the fifth,it will return 5.

So in your case you can read your max value with for example range[highestrange], but first change highestrange into integer as it is array index now.

int highestrange;
double rangecalc;
double range[6];
double array_maximum_value;

   for (int bcount = 1; bcount <= 7; bcount++)     //scan the last 7 prevbars
   
            {
                 rangecalc = (High[bcount]-Low[bcount]);     //store the range of that candle in the appropriate part of array
                 range[bcount-1] = rangecalc;   // bcount -1 because arrays start at 0
            }

highestrange = ArrayMaximum(range,WHOLE_ARRAY,0);  //position of largest bar
array_maximum_value = range[highestrange]; //give me the range of the largest candle in the last 7 bars
 

jacekkrawiec thankyou very much your prompt reply as I said I am no expert



I will go ahead and make the changes and you probably haven't heard the last from me :P

 

Доброго времени суток уважаемые форумчане!

Меня зовут Герман, мне 23 года, я являюсь трейдером компании "Инстафорекс"

Помогите в поиске нужного скрипта! Скрипт нужен для сетки отложенных ордеров.