HELP - Indicator High, Low, Highest High, Lower Low on current time frame / chart

 

Hi, can anybody help me with my costum indicator?
I'm new here, new in MQL4. I've been searching it on this forum and googling it since 2 weeks ago, but still no luck with my experiment.

Help me, please ...

Thanks in advance

// I'm expecting the highest high and lowest low from last candle to 00.00 on current time frame

int start()
  {
   int Counted_Bars     = IndicatorCounted();
//   datetime Now       = Time[0] - Time[0] % 86400;
   int      ShiftTo     = iBarShift(NULL,0,0);
   int      ShiftFrom   = Counted_Bars - 1;
   double HH            = High [iHighest(NULL,0,MODE_HIGH,ShiftFrom,ShiftTo)];
   double LL            = Low [iLowest (NULL,0,MODE_LOW,ShiftFrom,ShiftTo)]; 
   

//+------------------------------------------------------------------+
//| How to solve code below and make it more simple? Please...       |
//+------------------------------------------------------------------+

   for ( int i = Counted_Bars; i>-1; i--)
   {
      if (Close[i+1] < Open[i+1])                                 // If previous candle is bearish
      {
         if (Close[i+2] > Open[i+2] && Close[i+3] > Open[i+3])    // ... the second and third candles earlier is bullish
         {
            Result = (High[i+1] + Low[i+1]) / (HH + LL);          // get value
         }
      }
      
      if (Close[i+1] > Open[i+1])                                 // If previous candle is bullish
      {
         if (Close[i+2] < Open[i+2] && Close[i+3] < Open[i+3])    // ... the second and third candles earlier is bearish
         {
            Result = (High[i+1] + Low[i+1]) / (HH + LL);          // get value
         }
      }

//    If the second and third candle earlier is bullish then previous candle is bearish, get value. If value >= 1 draw arrow on current candle
      if (Result >= 1)
      {

            SelArrow[i] = High[i] + (Point * Offset);

      }
//    If the second and third candle earlier is bearish then previous candle is bullish, get value. If value < 1 , draw arrow on current candle
      if (Result < 1)
      {

            BuyArrow[i] = Low[i] - (Point * Offset);
      }
      
      
           
   }
   
  return(0);  
  }
  
//+------------------------------------------------------------------+
 
Yahdi_Irsam:

Hi, can anybody help me with my costum indicator?
I'm new here, new in MQL4. I've been searching it on this forum and googling it since 2 weeks ago, but still no luck with my experiment.

// I'm expecting the highest high and lowest low from last candle to 00.00 on current time frame


   int      ShiftTo     = iBarShift(NULL,0,0);
   int      ShiftFrom   = Counted_Bars - 1;   //  why this ?
By 00:00 I assume you mean the last midnight ? so why is coiunted_bars - 1 midnight ?
 
Yahdi_Irsam:
   int Counted_Bars     = IndicatorCounted();
//   datetime Now       = Time[0] - Time[0] % 86400;
   int      ShiftTo     = iBarShift(NULL,0,0);
   int      ShiftFrom   = Counted_Bars - 1;
   double HH            = High [iHighest(NULL,0,MODE_HIGH,ShiftFrom,ShiftTo)];
   double LL            = Low [iLowest (NULL,0,MODE_LOW,ShiftFrom,ShiftTo)]; 
   for ( int i = Counted_Bars; i>-1; i--){     
     if (Close[i+1] < Open[i+1])
  1. The first time the indicator runs Counted_Bars is zero and your loop runs just bar zero. After that it's Bars - 1, so your loop recalculates all bars, every tick. Do it like all the others in the codebase.
       int Counted_Bars     = IndicatorCounted();
       if(Counted_Bars < LOOKBACK) Counted_Bars = LOOKBACK;
       for ( int i = Bars - 1 - Counted_Bars; i>=0; i--)
    

  2. iBarShift with time=0 gets the index of the earliest bar on the chart. ShiftTo = Bars - 1.
  3. ShiftFrom is -1 the first time and Bars -2 after that. Bogus
  4. RTFM What is the 4th argument to iHighest it's not a index. It's a count. What is the 5th argument? It's the newest bar index. If you like to think in indexes (like C/C++ programmers) do it like
    int      iGetHighest(int iEnd, int iBeg=0, int p=0){                    // Excluding iEnd.
       return( iHighest(NULL,p, MODE_HIGH, iEnd - iBeg, iBeg) ); }
    int      iGetLowest( int iEnd, int iBeg=0, int p=0){
       return(  iLowest(NULL,p, MODE_LOW,  iEnd - iBeg, iBeg) ); }
    :
     double HH = iGetHighest( i+LOOKBACK, i);

  5. All that code should be inside the loop because they should be changing each time
  6. Why are you looking at the C[i+1] < O[i+1]? Your loop is calculating bar i so you should be looking a C[i] < O[i]
 
RaptorUK:
By 00:00 I assume you mean the last midnight ? so why is coiunted_bars - 1 midnight ?


Sorry, I am not fluent in English. I hope you understand what I mean

I expect to get a total of candles ranging from market opening up to the last candle formed for the current time frame.

For example: in current time frame h1

Sample H1

Current time H4:

Sample H4

 
WHRoeder:
  1. The first time the indicator runs Counted_Bars is zero and your loop runs just bar zero. After that it's Bars - 1, so your loop recalculates all bars, every tick. Do it like all the others in the codebase.
  2. iBarShift with time=0 gets the index of the earliest bar on the chart. ShiftTo = Bars - 1.
  3. ShiftFrom is -1 the first time and Bars -2 after that. Bogus
  4. RTFM What is the 4th argument to iHighest it's not a index. It's a count. What is the 5th argument? It's the newest bar index. If you like to think in indexes (like C/C++ programmers) do it like
  5. All that code should be inside the loop because they should be changing each time
  6. Why are you looking at the C[i+1] < O[i+1]? Your loop is calculating bar i so you should be looking a C[i] < O[i]


As I said earlier, I'm new in MQL4. I only collect references that I got from this forum and tried to combine them in order to fit with what I expected.

If only there MQL4 reference books in Indonesian, perhaps the code I wrote is not like this. Unfortunately there is no book like it here. My last hope is on this forum. hoping someone would help solve my problem