Highest high for an indicator - page 5

 

No Idea

The right way is the one that works. I would do it another way with ifs, but I am not going to provide a code sample because I have no time to ensure the code works.

 

update... if interested

i tried a complicated and long way with if, i am not quite sure if i got better results with it anymore, but i did not get the correct results as shown in the indicator. i guess there is something wrong with the indicator values while reading out, maybe it is not made for this or someting like that.

In the meantime i forgot about that idea as i recognized it was not really necessary for my ea.

But i do something similar with another indicator, bizarrely, it works fine with a while-loop but not with a for-loop (i did not see any mistakes in the code).

Well, problem solved.

bye

 
dclarke:

Ok I have found a way to calculate the highest high or lowest low for an indicator over a specified period.

If you wanted to find the highest high or lowest low for an indicator like the simple moving average you have to declare an array and fill a "for" loop with the calculated values for each bar of the period you are testing.

Then you have to use ArrayMaximum and ArrayMinimum to find the position of the high or low in the array and then find the value of that position using iHigh() and iLow().

//calculate the highest high of the moving average

int malookback=5; //4+1 - the number of bars to calc the value of the ma

int madailyPERIOD = 30; //moving average period

double madaily[5];//declare an array

double dhhv,dllv;

for(int i = 0; i < malookback; i++)

{

madaily=iMA(NULL,PERIOD_D1,madailyPERIOD,0,MODE_SMA,PRICE_CLOSE,i);

dhhv=iHigh("EURUSD", PERIOD_D1,(ArrayMaximum(madaily,4, 1))) ;

//calculate the lowest low of the moving average

dllv=iLow("EURUSD", PERIOD_D1,(ArrayMinimum(madaily,4, 1))) ;

}


Hi DCLARKE,


I tried this but it didnt work for me. I keep getting an error - invalid array access.

int h = TimeHour(TimeCurrent());
   int bars = h*4;
   int malookback=bars; //4+1 - the number of bars to calc the value of the ma

   int madailyPERIOD = 50; //moving average period
   
   double madaily[97];//declare an array
   
   double dhhv,dllv;
   
   for(int i = 0; i < malookback; i++)
   
   {
   
   madaily=iMA(NULL,PERIOD_D1,madailyPERIOD,0,MODE_SMA,PRICE_CLOSE,i);
      
   dllv=iLow("EURUSD", PERIOD_D1,(ArrayMinimum(madaily,4, 1))) ;
 
pipsographer:


Hi DCLARKE,


I tried this but it didnt work for me. I keep getting an error - invalid array access.

Try

madaily[i]=iMA(NULL,PERIOD_D1,madailyPERIOD,0,MODE_SMA,PRICE_CLOSE,i);
 
And move your ArrayMinimum code outside of your loop.
Reason: