Array evaluation
Newbie to C#, programming in ninjatrader and i need to develop a simple function that performs the following:
- 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).
- 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].
- 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.
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.
Thanks to anyone that can help!
Ben
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.
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();
Do a foreach loop and check if each item's value is lower than your current value
精彩评论