Search for an element with the maximal value |
|
Search for an element with the minimal value |
Try CArrayDouble
#include <Arrays/ArrayDouble.mqh> //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnStart() { CArrayDouble arr; arr.Add(1.0); arr.Add(4.0); arr.Add(3.0); arr.Add(5.0); arr.Add(2.0); double max_value=arr.At(arr.Maximum(0,WHOLE_ARRAY)); Alert("max=",max_value); }
Array Functions
Search for an element with the maximal value |
|
Search for an element with the minimal value |
I followed the same thing, but once the array values are saved in array, it is not being over written in the next candle. how to calculate ArrayMaximum for new candle in EA? Resize array to 0 and again back to 10?
Try CArrayDouble
I never try this, will read and try it. will this Carraydouble overwrite values into array whenever the EA reads values from indicator?
why did you give arr.Add(1.0);
I need a one dimension array, so can I give arr.Add(1)=SI(0,1) and it will be overwritten whenever the EA runs? SI value is taken from indicator every candle as below.
SI(int buff,int shift){ return(iCustom(NULL,PERIOD_H4,"tales",buff,shift));}
I followed the same thing, but once the array values are saved in array, it is not being over written in the next candle. how to calculate ArrayMaximum for new candle in EA? Resize array to 0 and again back to 10?
You can use a rotating index.
static int idx=0; arr[idx]=current_value; idx=(idx+1) % 10;
The index will increase by 1 for each iteration and reset to 0 if it reaches 10. So that new values always overwrite the eldest entry.
I followed the same thing, but once the array values are saved in array, it is not being over written in the next candle. how to calculate ArrayMaximum for new candle in EA? Resize array to 0 and again back to 10?
Read Array Functions
Can you give example of a code to use zeromemory and ArrayResize for 10 indexes to reset and write values to it on each cycle/candle?
Can you give example of a code to use zeromemory and ArrayResize for 10 indexes to reset and write values to it on each cycle/candle?
Something like this...
double test[], test_max, test_min; bool Test(void) { ZeroMemory(test); for(int i=0; i<10; i++) { if( ArrayResize(test, i+1) != i+1 ) return false; test[i] = (iOpen(_Symbol, PERIOD_CURRENT, i) + iClose(_Symbol, PERIOD_CURRENT, i))/2; } test_max = test[ArrayMaximum(test,0)]; test_min = test[ArrayMinimum(test,0)]; return true; }
Can someone add array function to this EA to check for highest value in last n candles for tales indicator I used?
I am using variables to store the value of each shift candle and calculating mathmax etc.
double SI(int buff,int shift){ return(iCustom(NULL,PERIOD_H4,"tales",buff,shift));} //indicator
double TalesU1=NormalizeDouble(SI(0,1),4);
double TalesU2=NormalizeDouble(SI(0,2),4);
double TalesU3=NormalizeDouble(SI(0,3),4);
double TalesU4=NormalizeDouble(SI(0,4),4);
double TalesU5=NormalizeDouble(SI(0,5),4);
double TalesU6=NormalizeDouble(SI(0,6),4);
double MaxU=NormalizeDouble((MathMax(TalesU2,TalesU3)),4);
double MaxU1=NormalizeDouble((MathMax(MaxU,TalesU4)),4);
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I am saving values of a indicator in variable 10 times or more based on shift. Now I want to calculate the maximum and minimum value of those values. Whats the best way?
MathMax(v3,MathMax(v1,v2))..........?
Using arrays? I create array[] and resize and insert value from indicator? This option leaves only 1 time use of array and does not rewrite value into array.
Please help.