Maximum value from last x bars

 

Hello, 

this code is the sum of the differences, I need the maximum value found there...

Example: if Bars = 5
(In brackets is the sum)

Bar[5] +0.00010 

Bar[4] +0.00004 (+0.00014)  

Bar[3] +0.00010 (+0.00024)

Bar[2] -0.00010 (+0.00014)

Bar[1] -0.00010 (+0.00004)

Bar[0] -0.00010 (-0.00006)

I need value from Bar[3], so the maximum value from all sums...


Thank you very much for help and I wish nice day 



#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
int start()
  {
//-------------------------------------------------------------------------------------
   int CountedBars=101; 
   int k; 

   if(Bars<CountedBars) return(0); 
//-------------------------------------------------------------------------------------
  
   double diff=0;
   
   // This returned sumary points from last 100 bars
   for(k=0; k<CountedBars; k++)
      {
      diff += (iClose(Symbol(), NULL, k) - iOpen(Symbol(), NULL, k))  ;   
      }
      
   // I need to get the maximum value out of it
   
      

   Comment("diff " + diff + "\n" );
//-------------------------------------------------------------------------------------   
   
   
   
  

   return(0);
  }
//+------------------------------------------------------------------+
 
microhydI need value from Bar[3], so the maximum value from all sums... Thank you very much for help
Help you with what? You haven't stated a problem. Show us your attempt (using SRC) and state the nature of your problem.
          No free help
          urgent help.
 
whroeder1:
Help you with what? You haven't stated a problem. Show us your attempt (using SRC) and state the nature of your problem.
          No free help
          urgent help.

Hello whroeder1, 

Thank for reply, my question is here :

my src code is functional, but we need to get the maximum value from it too ...

my code returns a sum, and for this I also need the highest value of these totals...

Please check screen 

Example: if Bars = 5
(In brackets is the sum)

Bar[5] +0.00010 

Bar[4] +0.00004 (+0.00014)  

Bar[3] +0.00010 (+0.00024)

Bar[2] -0.00010 (+0.00014)

Bar[1] -0.00010 (+0.00004)

Bar[0] -0.00010 (-0.00006)

I need value from Bar[3], so the maximum value from all sums...

Screen


my posted SRC code works fine, but only returns the current sum to bar[0]...

And i need maximum value from this code (from 5bars).

 
microhyd: Thank for reply, my question is here .. my code returns a sum, and for this I also need the highest value of these totals..

You said that in your original post, why say it again? What part of "You haven't stated a problem. Show us your attempt (using SRC) and state the nature of your problem" was unclear?

 
microhyd:

Hello whroeder1, 

Thank for reply, my question is here :

my src code is functional, but we need to get the maximum value from it too ...

my code returns a sum, and for this I also need the highest value of these totals...

Please check screen 

Example: if Bars = 5
(In brackets is the sum)

Bar[5] +0.00010 

Bar[4] +0.00004 (+0.00014)  

Bar[3] +0.00010 (+0.00024)

Bar[2] -0.00010 (+0.00014)

Bar[1] -0.00010 (+0.00004)

Bar[0] -0.00010 (-0.00006)

I need value from Bar[3], so the maximum value from all sums...



#property strict
void OnStart()
{
   double body[5];
   for(int i=0;i<5;i++)
      body[i] = fabs(Open[i] - Close[i]);
   printf("The maximum body size in the past 5 bars is %f",body[ArrayMaximum(body)]);
}
 
whroeder1:

You said that in your original post, why say it again? What part of "You haven't stated a problem. Show us your attempt (using SRC) and state the nature of your problem" was unclear?


No, I do not understand.

I put the question and added the src code, I do not know what to say.


Thank you so, I've already found a solution.


We take the bar price [5], then I will find the maximum price, and I will determine the difference.

 
nicholishen:


Hello nicholishen !

Yes! this is the answer for me! Thank you som much! :)

Reason: