How to get the highest/lowest/difference(Highest-lowest) in values in an iMAOnArray?

 

I am trying to store the MA values using iMAOnArray.

For example, I want to store the current bar 0 to prev 4 valules of an MA in the array MA_Buffer[5];

Once I have them, I want to calcuate the highest value and lowest value and want to know the difference between them.

For example. 0=1.4320

1=1.4315

2=1.4314

3=1.4313

4=1.4312

Based on the above setup, the price is moving higher from 4th buffer(4th from 0th bar/candle) to the current (0th). How do I check the highest and lowest of the stored values in the array and calculate the difference in pips. In this example it is 8 pips.

Thanks for your time/replies in advance.

 
Kent wrote >>

I am trying to store the MA values using iMAOnArray.

For example, I want to store the current bar 0 to prev 4 valules of an MA in the array MA_Buffer[5];

Once I have them, I want to calcuate the highest value and lowest value and want to know the difference between them.

For example. 0=1.4320

1=1.4315

2=1.4314

3=1.4313

4=1.4312

Based on the above setup, the price is moving higher from 4th buffer(4th from 0th bar/candle) to the current (0th). How do I check the highest and lowest of the stored values in the array and calculate the difference in pips. In this example it is 8 pips.

Thanks for your time/replies in advance.

I did do a search on this, but couldnot find any specific reference to find highest or lowest or to calculate the differences? Any help is greatly appreciated.

Thanks

 
Kent:

How do I check the highest and lowest of the stored values in the array and calculate the difference in pips

I'm not sure, but it sounds as though what you're after can be achieved either just by looping through the array looking for the highest and lowest values, or even more simply by using ArraySort(). If the original array needs to be left untouched/undamaged, then either take a copy of it using ArrayCopy(), or just loop through the entries instead.


   // Example data, in any order...
   double MA_Buffer[5] = {1.4320, 1.4315, 1.4314, 1.4313, 1.4312};

   // Sort the array (into ascending order), and get the highest and lowest values.
   // The first line needs amendment if not all the slots in the array are being used.
   int SizeOfArray = ArraySize(MA_Buffer);
   ArraySort(MA_Buffer, SizeOfArray, 0, MODE_ASCEND);
   double vLowest = MA_Buffer[0];
   double vHighest = MA_Buffer[SizeOfArray - 1];
   
   // Get the range from highest to lowest and convert into a number of pips.
   // The range really _ought_ to be an integer number of pips...
   double Range = vHighest - vLowest;
   int PipsInRange = NormalizeDouble(Range / MarketInfo(Symbol(), MODE_TICKSIZE), 0);
   
   Print("Range is from " + vLowest + " to " + vHighest);
   Print("Range in pips is " + PipsInRange);
 
jjc wrote >>

I'm not sure, but it sounds as though what you're after can be achieved either just by looping through the array looking for the highest and lowest values, or even more simply by using ArraySort(). If the original array needs to be left untouched/undamaged, then either take a copy of it using ArrayCopy(), or just loop through the entries instead.

Thanks a lot for your effort/time to answer. Let me explain what I am trying to do. It might help.

Assuming the MA goes from low to high in those 5 candles, I want to store the Current (0) to 4th (5th value from current candle) and by knowing the difference between the highest/lowest, I can see whether the MA is moving up with a considerable difference between high/low. Suppose my logic is to deduct that the difference is > 20 pips then I see the trend is reversing (i.e. the prev down trend is reversing and upside is forming) and if it it is < 20, I can ignore that trend/direction.

Reason: