Hey guys,
My eyes are bleeding
Can anyone see what wrong with my code, have been trying for hours now.
Error when attached to the chart: array out of range - in this line : double current_high = High[current_bar_index];
My eyes are bleeding
Can anyone see what wrong with my code, have been trying for hours now.
Error when attached to the chart: array out of range - in this line : double current_high = High[current_bar_index];
Inserted Code
int ThisBarTrade = 0; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping //Each time the indi is reloaded (ie. switch between TFs, new apply, etc ...), //the current bar isn't checked for conditions. ThisBarTrade = Time[0]; //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custor indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { return(0); } //+------------------------------------------------------------------+ //| 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[]) { //--- string pairs[]; int length = getAvailableCurrencyPairs(pairs); if (Bars != ThisBarTrade ) { ThisBarTrade = Bars; // ensure only one trade opportunity per bar //Loop through symbols for(int i=0; i < length; i++) { //Alert("Pair #", i+1, ": ", pairs[i]); // Get index int current_bar_index = iHighest(pairs[i], PERIOD_M5, MODE_HIGH, 1, 0); int previous_bar_index = iHighest(pairs[i], PERIOD_M5, MODE_HIGH, 1, 1); int current_bar_index_low = iLowest(pairs[i], PERIOD_M5, MODE_LOW, 1, 0); int previous_bar_index_low = iLowest(pairs[i], PERIOD_M5, MODE_LOW, 1, 1); //Get prices double current_high = High[current_bar_index]; double previous_high = High[previous_bar_index]; double current_low = Low[current_bar_index_low]; double previous_low = Low[previous_bar_index_low]; // Logic - Start if (( previous_low + 1.0 * Point ) > current_low || ( previous_high - 1.0 * Point ) < current_high ) { Alert("Pair #", i+1, ": ", pairs[i] , "has a higher high or lower low"); } // Logic - End } // for length } // if Bars //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ int getAvailableCurrencyPairs(string& availableCurrencyPairs[]) { //--- bool selected = false; const int symbolsCount = SymbolsTotal(selected); int currencypairsCount; ArrayResize(availableCurrencyPairs, symbolsCount); int idxCurrencyPair = 0; for(int idxSymbol = 0; idxSymbol < symbolsCount; idxSymbol++) { string symbol = SymbolName(idxSymbol, selected); string firstChar = StringSubstr(symbol, 0, 1); if(firstChar != "#" && StringLen(symbol) == 6) { availableCurrencyPairs[idxCurrencyPair++] = symbol; } } currencypairsCount = idxCurrencyPair; ArrayResize(availableCurrencyPairs, currencypairsCount); return currencypairsCount; } //+------------------------------------------------------------------+ class CFix { } ExtFix; // Force expressions evaluation while debugging
Blindly following others will make you blind!