Ben
Ben

Reputation: 1

Array evaluation

Newbie to C#, programming in ninjatrader and i need to develop a simple function that performs the following:

  1. I need to check to see if a stocks high price is higher than the price before, generally this would be done with indexing. Such as High[0] > High[1] (as the zero being the current price).
  2. If the current price is higher than that needs to be set to a indexed variable (array i am guessing) as if High[0] > High[1] then variable = High[0].
  3. The next evaluation and where i am stuck is how do i evaluate if the current high price is greater than each element in the array. Meaning the price is increasing.
  4. Once the price is no longer increasing the output of the function would need to be the Highest of the high prices in the array.

  5. Thanks to anyone that can help!

Ben

Upvotes: 0

Views: 637

Answers (3)

rsenna
rsenna

Reputation: 11972

3)

if (High.All(x => currentHighPrice > x)) { ... }

4)

var highest = High.Max();

But both options use LINQ. If that's not an option, just use a for/foreach loop.

Upvotes: 2

Linora
Linora

Reputation: 10998

Do a foreach loop and check if each item's value is lower than your current value

Upvotes: 0

Henk Holterman
Henk Holterman

Reputation: 273691

I think your description is incomplete or incorrect, but currently you're just asking for the Higest (Max) value in an array.

A simple solution :

using System.Linq;


 var data = new decimal[10];

 decimal m = data.Max();

Upvotes: 1

Related Questions