How to find Index of a bar in the price array...

 

Update NOTE: this thread I have SOLVED out by using a for..loop and if..loop to filter out NON Zero Values and got the Index of Bar(s) with price data.

Need guidance how I can use Structured Array for index and price data, and create a new thread for it.

Dear Members

I have a double SwingHigh[] with values say {0,0,0,0,1.20000,0,0,0,0}

How can I find the Index for value containing 1.20000 as price ?

I have tried looking in the forum thread but could not find something to work this out.

Your guidance to achieve this, will be highly appreciated.



 
Anil Varma -: How can I find the Index for value containing 1.20000 as price ?

Go through the list and find it. What's the problem? Show us your attempt (using the CODE button) and state the nature of your problem.
          No free help 2017.04.21

 
Anil Varma -: I have a double SwingHigh[] with values say {0,0,0,0,1.20000,0,0,0,0} How can I find the Index for value containing 1.20000 as price ?

I have tried looking in the forum thread but could not find something to work this out. Your guidance to achieve this, will be highly appreciated.

To find the array index of the maximum (or minimum) value, you can use the function ArrayMaximum (or ArrayMinimum).

Please note that these functions are different in MQL5 and MQL4!

 
Fernando Carreiro:

To find the array index of the maximum (or minimum) value, you can use the function ArrayMaximum (or ArrayMinimum).

Please note that these functions are different in MQL5 and MQL4!

Thanks Fernando

yes I know about ArrayMax / ArrayMin functions. but my SwighMajorHigh[], SwingMajorLow[], etc already contained high and low values given certain no of bars. It is basically result of ZigZag Indicator.

I have just got an idea to select array values into another array where values are not equal to ZERO, this should help me catch the BarIndex and the Prices together.

Will give it a try and update the post here, if I succeed.

Thanks again for your reply.

 
William Roeder:

Go through the list and find it. What's the problem? Show us your attempt (using the CODE button) and state the nature of your problem.
          No free help 2017.04.21

Thanks William for your reply, however my problem was that I was unable to think of any idea how to do that. That's why there no attempt shown.

In case you have time to review my previous posts, you will notice that wherever possible I do share all the necessary information and my attempts.

 
Thanks for help with this problem. I also have the same question.
 
Anil Varma - #:

Thanks William for your reply, however my problem was that I was unable to think of any idea how to do that. That's why there no attempt shown.

In case you have time to review my previous posts, you will notice that wherever possible I do share all the necessary information and my attempts.

No idea? Just go through the list and find it (or not).
Not compiled, not tested, just typed.
template<typename T>
int linear_search(const T& arr[], T value){
   for(int i=ArraySize(arr) - 1; i >= 0; --i) if(arr[i] == value) return i;
   return EMPTY;
}
///////////////////////////////
double SwingHigh[]={0,0,0,0,1.20000,0,0,0,0};
Print( linear_search(SwingHigh, 1.2) ); // 4
Not compiled, not tested, just typed.
Reason: