How do you find the highest value in an array of numbers?
Author: rmandel00
Creation Date: 5/17/2011 7:07 PM
profile picture

rmandel00

#1
I am using several external sector funds and looking for the one that has the highest rate of change. I have introduced each fund with
CODE:
Please log in to see this code.


I would then like to find the one with the highest value and then screen for stocks that are in that sector by saving the sector name of the ETF and requiring that each stock scanned have the same sector name. I have created an array of these ETF ROCS as follows:
CODE:
Please log in to see this code.

This array is apparently correct as the program compiles in WLP but I don't know how to use it.

I don't know how to pick out the one with the highest (or lowest) or second highest and save it as a variable to test in a later part of the strategy.
Thanks for your help.
Rich Man
profile picture

Eugene

#2
Add this to your strategy class (hint: paste before protected override void Execute(), for example)
CODE:
Please log in to see this code.

Then, assuming that your array is created in the main loop and "bar5" is the indexer, this is how to return the highest value:
CODE:
Please log in to see this code.

A method for returning the lowest value can be designed in a similar fashion.

To return the 2nd highest/lowest you could use this approach:

CODE:
Please log in to see this code.
profile picture

rmandel00

#3
Thanks Eugene.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).