Download MetaTrader 5

iLowest

To add comments, please log in or register
PieroNetto
296
PieroNetto  

Hi Everyone!

Please point me in the right direction!

Trying to get either Lowest_Open or Lowest_Close in Comment, show only the lower of a candle body.

The same to the up side Highest_Open or Highest_Close.

//+------------------------------------------------------------------+
//|                                                            Piero |
//+------------------------------------------------------------------+
#property copyright "Piero"



extern int       BarsFromMidnight = 8;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
      string   tl   = TimeToStr(TimeCurrent(),TIME_SECONDS);
      datetime now  = Time[0],
               bod  = now - now % 86400; // Beginning of the day
      int      iBod = iBarShift(NULL,0, bod),
               nH4  = BarsFromMidnight * 60 / Period(), // Number of bars for 8 hours
               iH4  = iBod - nH4 + 1;
               
      if (iH4 <= 0) return(0);
      
      double HH = High [iHighest(NULL,0, MODE_HIGH ,nH4,iH4)];
      double LL = Low  [iLowest (NULL,0, MODE_LOW  ,nH4,iH4)];
      double HC = Close[iHighest(NULL,0, MODE_CLOSE,nH4,iH4)];
      double HO = Close[iHighest(NULL,0, MODE_OPEN ,nH4,iH4)];
      double LC = Close[iLowest (NULL,0, MODE_CLOSE,nH4,iH4)];
      double LO = Open [iLowest (NULL,0, MODE_OPEN ,nH4,iH4)];
      

     {
      Comment("Local Time     =",tl,"\n",
              "High           =",(DoubleToStr(HH,5)),"\n",   //needed for future calculation
              "Low            =",(DoubleToStr(LL,5)),"\n",   //needed for future calculation
              "Highest Close  =",(DoubleToStr(HC,5)),"\n",   //just show for functionality
              "Highest Open   =",(DoubleToStr(HO,5)),"\n",   //just show for functionality
              "Lowest  Close  =",(DoubleToStr(LC,5)),"\n",   //just show for functionality
              "Lowest  Open   =",(DoubleToStr(LO,5)),"\n",   //just show for functionality
              "Highest CLose or Open ="             ,"\n",   //needed show only the higher of HC or HO
              "Lowest  CLose or Open ="             ,"\n");  //needed show only the lower  of LC or LO
     }
   return(0);
  }
//+----

whroeder1
16058
whroeder1  
PieroNetto: Trying to get either Lowest_Open or Lowest_Close in Comment, show only the lower of a candle body.
  1.  int iBod = iBarShift(NULL,0, bod),
     nH4 = BarsFromMidnight * 60 / Period(), // Number of bars for 8 hours
     iH4 = iBod - nH4 + 1;
     if (iH4 <= 0) return(0);
    This assumes every bar every exists. What if there are no ticks during a specific candle period? There can be minutes between ticks during the Asian session, think M1 chart. There can be days between ticks, think weekend, market holiday. Don't assume
     int iBod = iBarShift(NULL,0, bod),
     iH4 = iBarShift(NULL,0, bod + BarsFromMidnight * 3600 -1); // Number of bars for 8 hours exclusive
     nH4 = iH4 - iBod + 1;
    Exclusive, you want hour bars [0..7] for a total of eight.
  2.  double HH = High [iHighest(NULL,0, MODE_HIGH ,nH4,iH4)];
     double LL = Low  [iLowest (NULL,0, MODE_LOW  ,nH4,iH4)];
     double HC = Close[iHighest(NULL,0, MODE_CLOSE,nH4,iH4)];
     double HO = Close[iHighest(NULL,0, MODE_OPEN ,nH4,iH4)];
     double LC = Close[iLowest (NULL,0, MODE_CLOSE,nH4,iH4)];
     double LO = Open [iLowest (NULL,0, MODE_OPEN ,nH4,iH4)];
    Look closer
PieroNetto
296
PieroNetto  
whroeder1:
  1. This assumes every bar every exists. What if there are no ticks during a specific candle period? There can be minutes between ticks during the Asian session, think M1 chart. There can be days between ticks, think weekend, market holiday. Don't assume
  2. Look closer

Thanks for your quick response. I corrected the one thing you pointed out. Thanks. I do understand the problem with the no ticks on the weekend and holidays. Coming to this later.

Still can find out how to calculate that it shows me witch one is lower the LC or LO, in the up side the HC or HO.

This code is for learning purpose only

      double HH = High [iHighest(NULL,0, MODE_HIGH ,nH4,iH4)];
      double LL = Low  [iLowest (NULL,0, MODE_LOW  ,nH4,iH4)];
      double HC = Close[iHighest(NULL,0, MODE_CLOSE,nH4,iH4)];
      double HO = Open [iHighest(NULL,0, MODE_OPEN ,nH4,iH4)];
      double LC = Close[iLowest (NULL,0, MODE_CLOSE,nH4,iH4)];
      double LO = Open [iLowest (NULL,0, MODE_OPEN ,nH4,iH4)];

I just trying your code?????

 int iBod = iBarShift(NULL,0, bod),
     iH4  = iBarShift(NULL,0, bod + BarsFromMidnight * 3600 -1); // Number of bars for 8 hours exclusive
     nH4  = iH4 - iBod + 1;

Would you please explane whats the different to my code. Thanks

      int      iBod = iBarShift(NULL,0, bod),
               nH4  = BarsFromMidnight * 60 / Period(), // Number of Bars From Midnight
               iH4  = iBod - nH4 + 1;

Your code testing, not showing LL,LC,LO correct from midnight

PieroNetto
296
PieroNetto  

Any one can help?

PieroNetto
296
PieroNetto  

That,s what i have so far, i know im totally wrong here . Not getting it to work. not really understanding the else function, was reading it in documentation.

Please help!

Don,t lough to hard about it.

      double LLD(double LO,double LC);
      
      if(LO>LC)
      {
      LC=LLD;
      return LLD;
      }
      else
      
      if(LO<LC)
      {
      LO=LLD;
      return LLD;
      }
PieroNetto
296
PieroNetto  

So it toke me a few day to solved my problem. 

Don't know how to get rid of the warnings, any hint would be nice.

Thanks Piero.

This is a sample for learning purpose only.

double c;


int start()
      {
  

      Comment("C0=",(DoubleToStr(c,5)));
      
      c = Add(a, b);
      }
      
      
      double a = 1.99999;
      double b = 1.88888;
  
      double Add(double a,double b)
      {
      if(a > b) {c = a;}
        
      else 

      if(a < b) {c = b;}

      return(c);
      
      }
whroeder1
16058
whroeder1  
PieroNetto: Don't know how to get rid of the warnings, any hint would be nice.
double c;
int start(){
  Comment("C0=",(DoubleToStr(c,5)));
  c = Add(a, b);
}
  1. Functions can be declared anywhere (outside of other functions.) So Add can be declared below start; no problem.
  2. c is a global variable, so no problem there.
  3. a, and b are undefined variable. That is not a warning, that is an error.
PieroNetto
296
PieroNetto  

Thanks for your help, hope getting it right this time.

double c;
      double Add(double a,double b)
      {
      if(a > b) {c = a;}
      else 
      if(a < b) {c = b;}
      else
      if(a == b){c = b;}
      return(c);
      }
int start()
{
      {
      double a = 1.99999;
      double b = 1.88888;
      Comment("C0=",(DoubleToStr(c,5)));
      c = Add(a, b);
      }
return(0);
} 
PieroNetto
296
PieroNetto  

And there is the code i have so far. pls comment.

And i was wondering if is possibly to right Comment Function different so it looks more organized on the chart.

//+------------------------------------------------------------------+
//|                                                            Piero |
//+------------------------------------------------------------------+
#property copyright "Piero"



extern int       BarsFromMidnight = 8;

double LCB;
      double LowestCandelBody(double LC,double LO)
      {
      if(LC > LO) {LCB = LC;}
      else 
      if(LC < LO) {LCB = LO;}
      else
      if(LC == LO) {LCB = LO;}
      return(LCB);
      }
double HCB;
      double HighestCandelBody(double HC,double HO)
      {
      if(HO > HC) {HCB = HO;}
      else 
      if(HO < HC) {HCB = HC;}
      else
      if(HO == HC) {HCB = HC;}
      return(HCB);
      }
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{  
      {
      string   tb   = TimeToStr(TimeCurrent(),TIME_SECONDS);
      datetime now  = Time[0],
               bod  = now - now % 86400; // Beginning of the day
      int      iBod = iBarShift(NULL,0, bod),
               nH4  = BarsFromMidnight * 60 / Period(), // Number of Bars From Midnight
               iH4  = iBod - nH4 + 1;
               
      if (iH4 <= 0) return(0);
      
      double HH = High [iHighest(NULL,0, MODE_HIGH ,nH4,iH4)];
      double LL = Low  [iLowest (NULL,0, MODE_LOW  ,nH4,iH4)];
      double HC = Close[iHighest(NULL,0, MODE_CLOSE,nH4,iH4)];
      double HO = Open [iHighest(NULL,0, MODE_OPEN ,nH4,iH4)];
      double LC = Close[iLowest (NULL,0, MODE_CLOSE,nH4,iH4)];
      double LO = Open [iLowest (NULL,0, MODE_OPEN ,nH4,iH4)];
      }




      
      {
      Comment("Broker Time         =",tb,                  "\n",
              "High                =",(DoubleToStr(HH,5)), "\n",   
              "Low                 =",(DoubleToStr(LL,5)), "\n",   
              "Highest Close       =",(DoubleToStr(HC,5)), "\n",   
              "Highest Open        =",(DoubleToStr(HO,5)), "\n",   
              "Lowest  Close       =",(DoubleToStr(LC,5)), "\n",   
              "Lowest  Open        =",(DoubleToStr(LO,5)), "\n",   
              "Highest Candle Body =",(DoubleToStr(HCB,5)),"\n",  
              "Lowest  Candel Body =",(DoubleToStr(LCB,5))); 
       LCB = LowestCandelBody (LO, LC);
       HCB = HighestCandelBody(HO, HC);
       }       
return(0);
}
To add comments, please log in or register