finding the highest close on 1m chart from any timeframe based on the date and time using iBarShift and Close[iHighest]

 

hello everyone , I hope that you're having a great day ,

I was trying to use CHARTEVENT_CLICK to select the bar I want to draw Fibonacci On any timeframe the the indicator will draw 2 Fibonacci level , one on the current frame highest ,and the second on the highest close on 1m timeframe ..

the problem is using the close price of the highest candle "Close[iHighest]"  is only looking back from the candle I select and I want it to look forward , I tried to code it with a negative value but it won't work . and the 1m level is working only on 1m frame

I want to be able to select any candle on any timeframe and the indicator draw one level on the frame I use and search forward stating from the time of the candle i selected maybe using the iBarShift  But, in 1 Min timeframe 

I really need some  guidance and thank you all .

"

there is another indicator for the level 0 and it complete this indicator 

"

//+------------------------------------------------------------------+
//|                                                  FIBO_High_1.mq4 |
//|                        Copyright 2023, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
 
#property description"  DoubleClick to select the highest price ==> Level 100 <=="
#property description   "just press Single Click for the Lowest Price ==> Level 0 <=="
//---

color fiboColor = Red;
double fiboWidth = 0;
double fiboStyle = 0;
color fiboColor1 = Black;
double fiboWidth1 = 0;
double fiboStyle1 = 0;

 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{

//--- return value of prev_calculated for next call
   return(rates_total);
}
//+------------------------------------------------------------------+
//| On chart event                                                   |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,         // Event identifier
                  const long& lparam,   // Event parameter of long type
                  const double& dparam, // Event parameter of double type
                  const string& sparam) // Event parameter of string type
{
   long chart_ID = ChartFirst();
   chart_ID = 0;

   {
      static ulong clickTimeMemory;
////                                                   
      if(id == CHARTEVENT_CLICK) {
         ulong clickTime = GetTickCount();
         if(clickTime < clickTimeMemory + 300) {
            ChartClean();
            int window = 0;
            datetime time1 = 0;
            double price1 = 0;

            if(ChartXYToTimePrice(ChartID(),int(lparam),int(dparam),window,time1,price1))

            {

               int bar1 = iBarShift(Symbol(),Period(),time1);//fibo draw Bar in the current bar
               int bar2 = iBarShift(Symbol(),PERIOD_M1,time1);//fibo draw Bar in the 1m bar
               datetime StartTime1 = iTime(Symbol(),Period(),bar1);//fibo draw start time for the current bar
               datetime StartTimemin = iTime(Symbol(),PERIOD_M1,bar1);//fibo draw start time for the current bar
               double price=High[bar1];
               double low_1price = Low[bar1];
               double price_c=Close[bar1];
               
               double theLowest  = Close[iLowest(NULL,PERIOD_M1,MODE_CLOSE,20,bar1)];
               double theHighest = Close[iHighest(NULL,PERIOD_M1,MODE_CLOSE,20,bar1)]; // <= close of the bar found


               double mid_price= (price + low_1price) /2 ; //to switch between drawing on the high or low




               if(price1 > mid_price) {

                  ObjectCreate(0,"Fibonacci", OBJ_FIBO, 0,StartTime1,price);
                  ObjectSetInteger(0, "Fibonacci", OBJPROP_RAY, true);
                  ObjectSetInteger(0, "Fibonacci", OBJPROP_RAY_RIGHT, true);
                  ObjectSet("Fibonacci", OBJPROP_LEVELCOLOR, fiboColor);
                  ObjectSet("Fibonacci", OBJPROP_LEVELSTYLE, fiboStyle);
                  ObjectSet("Fibonacci", OBJPROP_LEVELWIDTH, fiboWidth);
                  ObjectSet("Fibonacci", OBJPROP_FIBOLEVELS,7);
                  ObjectSet("Fibonacci", OBJPROP_FIRSTLEVEL + 1, 0.00);
                  ObjectSetFiboDescription("Fibonacci", 1, "0.00- %$");
                  ObjectSet("Fibonacci", OBJPROP_FIRSTLEVEL + 2, 0.236);
                  ObjectSetFiboDescription("Fibonacci", 2, "23.6- %$");
                  ObjectSet("Fibonacci", OBJPROP_FIRSTLEVEL + 3, 0.382);
                  ObjectSetFiboDescription("Fibonacci", 3, "38.2- %$");
                  ObjectSet("Fibonacci", OBJPROP_FIRSTLEVEL + 4, 0.50);
                  ObjectSetFiboDescription("Fibonacci", 4, "50.0- %$");
                  ObjectSet("Fibonacci", OBJPROP_FIRSTLEVEL + 5, 0.618);
                  ObjectSetFiboDescription("Fibonacci", 5, "61.8 %$");
                  ObjectSet("Fibonacci", OBJPROP_FIRSTLEVEL + 6, 0.786);
                  ObjectSetFiboDescription("Fibonacci", 6, "78.6- %$");
                  ObjectSet("Fibonacci", OBJPROP_FIRSTLEVEL + 0, 1.00);
                  ObjectSetFiboDescription("Fibonacci", 0, "100- %$");
                  //+------------------------------------------------------------------+
                  //| For the 1 MIN bar                                                |
                  //+------------------------------------------------------------------+

                  ObjectCreate(0,"Fibonacci_1M", OBJ_FIBO, 0,StartTimemin,theHighest);
                  ObjectSetInteger(0,"Fibonacci_1M",OBJPROP_TIMEFRAMES,OBJ_PERIOD_M1|OBJ_PERIOD_M1|OBJ_PERIOD_M15|OBJ_PERIOD_M30|OBJ_PERIOD_H1|OBJ_PERIOD_H4|OBJ_PERIOD_D1|OBJ_PERIOD_W1|OBJ_PERIOD_MN1);
                  ObjectSetInteger(0, "Fibonacci_1M", OBJPROP_RAY, true);
                  ObjectSetInteger(0, "Fibonacci_1M", OBJPROP_RAY_RIGHT, true);
                  ObjectSet("Fibonacci_1M", OBJPROP_LEVELCOLOR, fiboColor1);
                  ObjectSet("Fibonacci_1M", OBJPROP_LEVELSTYLE, fiboStyle1);
                  ObjectSet("Fibonacci_1M", OBJPROP_LEVELWIDTH, fiboWidth1);
                  ObjectSet("Fibonacci_1M", OBJPROP_FIBOLEVELS,7);
                  ObjectSet("Fibonacci_1M", OBJPROP_FIRSTLEVEL + 1, 0.00);
                  ObjectSetFiboDescription("Fibonacci_1M", 1, "0.00- %$");
                  ObjectSet("Fibonacci_1M", OBJPROP_FIRSTLEVEL + 2, 0.236);
                  ObjectSetFiboDescription("Fibonacci_1M", 2, "23.6- %$");
                  ObjectSet("Fibonacci_1M", OBJPROP_FIRSTLEVEL + 3, 0.382);
                  ObjectSetFiboDescription("Fibonacci_1M", 3, "38.2- %$");
                  ObjectSet("Fibonacci_1M", OBJPROP_FIRSTLEVEL + 4, 0.50);
                  ObjectSetFiboDescription("Fibonacci_1M", 4, "50.0- %$");
                  ObjectSet("Fibonacci_1M", OBJPROP_FIRSTLEVEL + 5, 0.618);
                  ObjectSetFiboDescription("Fibonacci_1M", 5, "61.8 %$");
                  ObjectSet("Fibonacci_1M", OBJPROP_FIRSTLEVEL + 6, 0.786);
                  ObjectSetFiboDescription("Fibonacci_1M", 6, "78.6- %$");
                  ObjectSet("Fibonacci_1M", OBJPROP_FIRSTLEVEL + 0, 1.00);
                  ObjectSetFiboDescription("Fibonacci_1M", 0, "100- %$");



               }

               else {

                  ObjectCreate(0,"Fibonacci", OBJ_FIBO, 0,StartTime1,low_1price);
                  ObjectSetInteger(0, "Fibonacci", OBJPROP_RAY, true);
                  ObjectSetInteger(0, "Fibonacci", OBJPROP_RAY_RIGHT, true);
                  ObjectSet("Fibonacci", OBJPROP_LEVELCOLOR, fiboColor);
                  ObjectSet("Fibonacci", OBJPROP_LEVELSTYLE, fiboStyle);
                  ObjectSet("Fibonacci", OBJPROP_LEVELWIDTH, fiboWidth);
                  ObjectSet("Fibonacci", OBJPROP_FIBOLEVELS,7);
                  ObjectSet("Fibonacci", OBJPROP_FIRSTLEVEL + 1, 0.00);
                  ObjectSetFiboDescription("Fibonacci", 1, "0.00- %$");
                  ObjectSet("Fibonacci", OBJPROP_FIRSTLEVEL + 2, 0.236);
                  ObjectSetFiboDescription("Fibonacci", 2, "23.6- %$");
                  ObjectSet("Fibonacci", OBJPROP_FIRSTLEVEL + 3, 0.382);
                  ObjectSetFiboDescription("Fibonacci", 3, "38.2- %$");
                  ObjectSet("Fibonacci", OBJPROP_FIRSTLEVEL + 4, 0.50);
                  ObjectSetFiboDescription("Fibonacci", 4, "50.0- %$");
                  ObjectSet("Fibonacci", OBJPROP_FIRSTLEVEL + 5, 0.618);
                  ObjectSetFiboDescription("Fibonacci", 5, "61.8 %$");
                  ObjectSet("Fibonacci", OBJPROP_FIRSTLEVEL + 6, 0.786);
                  ObjectSetFiboDescription("Fibonacci", 6, "78.6- %$");
                  ObjectSet("Fibonacci", OBJPROP_FIRSTLEVEL + 0, 1.00);
                  ObjectSetFiboDescription("Fibonacci", 0, "100- %$");
                  //+------------------------------------------------------------------+
                  //| For the 1 MIN bar                                                |
                  //+------------------------------------------------------------------+
                  ObjectCreate(0,"Fibonacci_1M", OBJ_FIBO, 0,StartTimemin,theLowest);
                  ObjectSetInteger(0,"Fibonacci_1M",OBJPROP_TIMEFRAMES,OBJ_PERIOD_M1|OBJ_PERIOD_M1|OBJ_PERIOD_M15|OBJ_PERIOD_M30|OBJ_PERIOD_H1|OBJ_PERIOD_H4|OBJ_PERIOD_D1|OBJ_PERIOD_W1|OBJ_PERIOD_MN1);

                  ObjectSetInteger(0, "Fibonacci_1M", OBJPROP_RAY, true);
                  ObjectSetInteger(0, "Fibonacci_1M", OBJPROP_RAY_RIGHT, true);
                  ObjectSet("Fibonacci_1M", OBJPROP_LEVELCOLOR, fiboColor1);
                  ObjectSet("Fibonacci_1M", OBJPROP_LEVELSTYLE, fiboStyle1);
                  ObjectSet("Fibonacci_1M", OBJPROP_LEVELWIDTH, fiboWidth1);
                  ObjectSet("Fibonacci_1M", OBJPROP_FIBOLEVELS,7);
                  ObjectSet("Fibonacci_1M", OBJPROP_FIRSTLEVEL + 1, 0.00);
                  ObjectSetFiboDescription("Fibonacci_1M", 1, "0.00- %$");
                  ObjectSet("Fibonacci_1M", OBJPROP_FIRSTLEVEL + 2, 0.236);
                  ObjectSetFiboDescription("Fibonacci_1M", 2, "23.6- %$");
                  ObjectSet("Fibonacci_1M", OBJPROP_FIRSTLEVEL + 3, 0.382);
                  ObjectSetFiboDescription("Fibonacci_1M", 3, "38.2- %$");
                  ObjectSet("Fibonacci_1M", OBJPROP_FIRSTLEVEL + 4, 0.50);
                  ObjectSetFiboDescription("Fibonacci_1M", 4, "50.0- %$");
                  ObjectSet("Fibonacci_1M", OBJPROP_FIRSTLEVEL + 5, 0.618);
                  ObjectSetFiboDescription("Fibonacci_1M", 5, "61.8 %$");
                  ObjectSet("Fibonacci_1M", OBJPROP_FIRSTLEVEL + 6, 0.786);
                  ObjectSetFiboDescription("Fibonacci_1M", 6, "78.6- %$");
                  ObjectSet("Fibonacci_1M", OBJPROP_FIRSTLEVEL + 0, 1.00);
                  ObjectSetFiboDescription("Fibonacci_1M", 0, "100- %$");



               }



               //+------------------------------------------------------------------+
               //|For The current Bar                                               |
               //+------------------------------------------------------------------+








            }
            clickTimeMemory = 0;
         } else
            clickTimeMemory = clickTime;
      }


   }

}
//+------------------------------------------------------------------+
//| Chart clean                                                      |
//+------------------------------------------------------------------+
void ChartClean()
{
   ObjectDelete("Fibonacci");
   ObjectDelete("Fibonacci_1M");

   Comment("");
}
//+------------------------------------------------------------------+
 
               double theLowest  = Close[iLowest(NULL,PERIOD_M1,MODE_CLOSE,20,bar1)];
               double theHighest = Close[iHighest(NULL,PERIOD_M1,MODE_CLOSE,20,bar1)]; // <= close of the bar found

You are mixing apples and oranges.

 
William Roeder #:

You are mixing apples and oranges.

thank you for mention it , you mean Idon't need to use 

Close[iLowest(NULL,PERIOD_M1,MODE_CLOSE,20,bar1)];

 because I have already set the

MODE_CLOSE

so 

iLowest(NULL,PERIOD_M1,MODE_CLOSE,20,bar1);

is the best way to code it ,, 

do you think it will look forward ? if the number of bars was in negative value like -20 ??

or just backward 

and thank you again , I'll try it

 
MUTASIM MASALMH #: thank you for mention it , you mean Idon't need to use 

Close[iLowest(NULL,PERIOD_M1,MODE_CLOSE,20,bar1)];

Read the links again. You can not use that, unless your chart is the M1.

 
William Roeder #:

Read the links again. You can not use that, unless your chart is the M1.

when I saw your replay the first time I  didn't pay attention to the links attached to " apples and oranges. " , sorry for that .

I will read it carefully .

thank you for being patient.

TimeScale problem
TimeScale problem
  • 2013.03.25
  • www.mql5.com
Hello! I need help...