HighestHigh & Open working but LowestLow & open not working.

 

Hi,

I am unable to understand whats wrong with the code.
HighestHigh & HighestOpen working , But lowestLow & LowestOpen for current day not working.



int HighestHigh = iHighest(_Symbol,_Period,MODE_HIGH,Day(),0);
int HighestOpen = iHighest(_Symbol,_Period,MODE_OPEN,Day(),0);

int LowestLow = iLowest(_Symbol,_Period,MODE_LOW,Day(),0);
int LowestOpen = iLowest(_Symbol,_Period,MODE_OPEN,Day(),0);


 
Junead Qureshi: I am unable to understand whats wrong with the code. HighestHigh & HighestOpen working , But lowestLow & LowestOpen for current day not working.

Maybe the error is not in those code lines you have shown us but somewhere else in your code. Maybe it is where you use those variables that may be the problem. So, show more of your code and where you use those variables.

Or maybe, it is even the Day() function that is returning the wrong bar count. You may need to show much more of your code and a more detailed explanation of what you are trying to do!

 
Fernando Carreiro:

Maybe the error is not in those code lines you have shown us but somewhere else in your code. Maybe it is where you use those variables that may be the problem. So, show more of your code and where you use those variables.

Or maybe, it is even the Day() function that is returning the wrong bar count. You may need to show much more of your code and a more detailed explanation of what you are trying to do!


#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

enum ENUM_TESTER_SPEED
{
   SUPER_FAST=0,
   FAST50=50,
   FAST100=100,
   FAST250=250,
   MEDIUM500=500,
   SLOW750=750,
   SUPER_SLOW=1000,
   SUPER_DUPER_SLOW=2000
};

extern ENUM_TESTER_SPEED speed = FAST100;


int HighestHigh,HighestOpen,LowestLow,LowestOpen;


void OnTick()
  {
//---

   for(int i = speed;i>0;i--)
   {
      Comment(TimeCurrent());
   }
   
   
HighestHigh = iHighest(_Symbol,_Period,MODE_HIGH,Day(),0);
HighestOpen = iHighest(_Symbol,_Period,MODE_OPEN,Day(),0);

LowestLow = iLowest(_Symbol,_Period,MODE_LOW,Day(),0);
LowestOpen = iLowest(_Symbol,_Period,MODE_OPEN,Day(),0);


ObjectDelete("line1");
ObjectDelete("line2");
ObjectDelete("line3");
ObjectDelete("line4");


   ObjectCreate("line1",OBJ_HLINE,0,Time[0], High[HighestHigh]);
   Print("High High of the Day is =   ", High[HighestHigh]); 

   ObjectCreate("line2",OBJ_HLINE,0,Time[0], Low[LowestLow]);
   Print("Lowest Low of the Day is =   ", Low[LowestLow]); 
     
 
   ObjectCreate("line3",OBJ_HLINE,0,Time[0], Open[HighestOpen]);
   ObjectSet("line3",OBJPROP_STYLE,STYLE_DOT);
   ObjectSet("line3",OBJPROP_COLOR,Blue);
   Print("Highest Open of the Day is =   ",Open[HighestOpen]);      
  
  
   ObjectCreate("line4",OBJ_HLINE,0,Time[0], Open[LowestOpen]);
   ObjectSet("line4",OBJPROP_STYLE,STYLE_DOT);
   ObjectSet("line4",OBJPROP_COLOR,Green);
   Print("Lowest Open of the Day is =   ", Open[LowestOpen]); 
   
   
return;

  }

LowestLow & Lowest Open are sometime 8,9,10 hrs behind the current bars, on using  H1 Chart.

Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
 
Junead Qureshi: LowestLow & Lowest Open are sometime 8,9,10 hrs behind the current bars, on using  H1 Chart.

Why are you using the built in function "Day()" for a count of bars to scan? That returns the current day of the month! What does that have to do with the number of bars?

However, taking into account the use of the current day of the month as the number of bars, then the code is working correctly.

What is not working correctly is the logic of it all as I am sure you are trying to achieve something else!

Also your code is running on every single tick, deleting and creating objects on every single tick. That is a waste of resources and makes it very slow!

Please explain your logic and what you are trying to achieve because the code is just not making any sense!

 
Fernando Carreiro:

Why are you using the built in function "Day()" for a count of bars to scan? That returns the current day of the month! What does that have to do with the number of bars?

However, taking into account the use of the current day of the month as the number of bars, then the code is working correctly.

What is not working correctly is the logic of it all as I am sure you are trying to achieve something else!

Also your code is running on every single tick, deleting and creating objects on every single tick. That is a waste of resources and makes it very slow!

Please explain your logic and what you are trying to achieve because the code is just not making any sense!

I just need 4 values , HighestHigh , HighestOpen.LowestLow , LowestOpen,  Of current day starting from 00Hrs  in  H1

So what should I add in the place of Day() ?

Also Why its working for HH & HO and not for LL & LO?
 
Junead Qureshi: I just need 4 values , HighestHigh , HighestOpen.LowestLow , LowestOpen,  Of current day starting from 00Hrs  in  H1. So what should I add in the place of Day() ? Also Why its working for HH & HO and not for LL & LO?

You have to first use iBarShift() to find out what is the index of the first bar of the day, then use that information in iHighest() and iLowest().

It is working correctly for HH, HO, LL and LO. What is NOT correct is using "Day()". You are basing your observation on the wrong assumption. That is why you "think" it is wrong.

iBarShift - Timeseries and Indicators Access - MQL4 Reference
iBarShift - Timeseries and Indicators Access - MQL4 Reference
  • docs.mql4.com
iBarShift - Timeseries and Indicators Access - MQL4 Reference
 
I am not able to understand how to use iBarShift() , So used the following code and it's working perfectly.
datetime starttimetoday=iTime(NULL,PERIOD_D1,0);

int numberofbarstoday=Bars(_Symbol,_Period,starttimetoday,Time[0]); //starttimetoday is 00:00 hrs of the day , Time[0] current hours of candle

int LowestLow = iLowest(_Symbol,_Period,MODE_LOW,numberofbarstoday,0);
int LowestOpen = iLowest(_Symbol,_Period,MODE_OPEN,numberofbarstoday,0);


 
Junead Qureshi:
I am not able to understand how to use iBarShift() , So used the following code and it's working perfectly.


the drawing could now be limited to new bar, that will free up resources, as Fernando alluded to.

Reason: