IHighest / ILowest Not Working

 

Hi All,

I am having trouble IHighest / ILowest to get the Correct High and Low Prices: 

Part of the problem is that I am working with a 1 MIN Chart and I need the Highest high and Lowest low in the last 31 Days.

My code works on a Daily Chart but not on a Minute chart.

Here is the daily code that works on a daily chart for the Lowest Low.

double LTFL;
// LOW Time Frame LTFL
   int LTFL_index=iLowest(NULL,PERIOD_D1,MODE_LOW,31,1);
   if(LTFL_index!=-1) LTFL=Low[LTFL_index];
   else PrintFormat("Error in call iLowest. Error code=%d",GetLastError());


Here is the Minute code that doesn't work on a Minute chart for the Lowest Low.

1440 * 31 Days = 44,640

double LTFL;
// LOW Time Frame LTFL
   int LTFL_index=iLowest(NULL,PERIOD_M1,MODE_LOW,44640,1);
   if(LTFL_index!=-1) LTFL=Low[LTFL_index];
   else PrintFormat("Error in call iLowest. Error code=%d",GetLastError());


My question(s) (I am an experienced developer but not with MQ4 (or C+))

1.  Why is the Minute not working?

2.  What is the most CPU efficient way to get the correct highest highs and lowest when my EA is running on a 1 minute chart? (Currently I am running this on every tick but I really only need it once (say on Load))

     I don't care about the current candle.

3.  How could I get the Highest High and Lowest Low dynamically (on any chart) (for the last 31 Days)?


Many Thanks in advance


rcrill

 
rcrill: I am having trouble IHighest / ILowest to get the Correct High and Low Prices: 

Part of the problem is that I am working with a 1 MIN Chart and I need the Highest high and Lowest low in the last 31 Days.

My code works on a Daily Chart but not on a Minute chart.

Here is the daily code that works on a daily chart for the Lowest Low.

double LTFL;
// LOW Time Frame LTFL
   int LTFL_index=iLowest(NULL,PERIOD_D1,MODE_LOW,31,1);
   if(LTFL_index!=-1) LTFL=Low[LTFL_index];
   else PrintFormat("Error in call iLowest. Error code=%d",GetLastError());
Here is the Minute code that doesn't work on a Minute chart for the Lowest Low.

1440 * 31 Days = 44,640

double LTFL;
// LOW Time Frame LTFL
   int LTFL_index=iLowest(NULL,PERIOD_M1,MODE_LOW,44640,1);
   if(LTFL_index!=-1) LTFL=Low[LTFL_index];
   else PrintFormat("Error in call iLowest. Error code=%d",GetLastError());

My question(s) (I am an experienced developer but not with MQ4 (or C+))

1.  Why is the Minute not working?

2.  What is the most CPU efficient way to get the correct highest highs and lowest when my EA is running on a 1 minute chart? (Currently I am running this on every tick but I really only need it once (say on Load))

     I don't care about the current candle.

3.  How could I get the Highest High and Lowest Low dynamically (on any chart) (for the last 31 Days)?

  1. Please use the SRC button to include source code in your posts. Don't just paste plain text. Use the SRC button for proper formatting (as I have done above).
  2. Even though you posted your query in the MT5/MQL5 section, it seems that you are using MT4/MQL4!
  3. On what Chart Time-frame is this Indicator, Expert Advisor or Script running on?
  4. When using Mult-Timeframe (and not the default time-frame of the chart), then you have to do error checking, especially for errors 4066 and 4073 due to delays in the downloading of bar data for the time-frames being used.
  5. You also always have to check the number of available bars (iBars(), Bars(), Bars[]) because they might not exist at the position or count you want, nor should you ever just hard-code the Bar Index or Bar Count.
 
Fernando Carreiro:
  1. Please use the SRC button to include source code in your posts. Don't just paste plain text. Use the SRC button for proper formatting (as I have done above).
  2. Even though you posted your query in the MT5/MQL5 section, it seems that you are using MT4/MQL4!
  3. On what Chart Time-frame is this Indicator, Expert Advisor or Script running on?
  4. When using Mult-Timeframe (and not the default time-frame of the chart), then you have to do error checking, especially for errors 4066 and 4073 due to delays in the downloading of bar data for the time-frames being used.
  5. You also always have to check the number of available bars (iBars(), Bars(), Bars[]) because they might not exist at the position or count you want, nor should you ever just hard-code the Bar Index or Bar Count.

Fernando,

That is correct, I am on MT4.

Is this Forum, only MT5?

Is there an MT4 Forum and Tab.  I was looking for it and didn't see it.

I am developing / trying to develop an EA and need the High and Low for the last 30 days to use in code that runs "On_Tick".

The Focus on the whole EA is mostly, the current candle[0] formation so I don't need much history.

I used I-bars (as per your suggestion) against the chart and it says / 986 bars.  THAT is why I can't get it to work (get the correct value).

Only 986 and I need 44640 candles to go back 31 days.

This should not be that hard!  How can I work with a M1 chart and have access to the correct HIGH and Low for 31 Days back.

Thank you in advance for any other suggestions.





Thank you .

 

Dear mister rcrill

Correct me if im wrong but the lowest value of 31 days on M1 should be the same value as the lowest 31 day value on D1....

So why do you do the 44640 candles when 31 is sufficient ?

 
rcrill:

Fernando,

That is correct, I am on MT4.

Is this Forum, only MT5?

Is there an MT4 Forum and Tab.  I was looking for it and didn't see it.

I am developing / trying to develop an EA and need the High and Low for the last 30 days to use in code that runs "On_Tick".

The Focus on the whole EA is mostly, the current candle[0] formation so I don't need much history.

I used I-bars (as per your suggestion) against the chart and it says / 986 bars.  THAT is why I can't get it to work (get the correct value).

Only 986 and I need 44640 candles to go back 31 days.

This should not be that hard!  How can I work with a M1 chart and have access to the correct HIGH and Low for 31 Days back.

Thank you in advance for any other suggestions.

The Forum is divided into several categories:

If you need more bars then maybe your broker is not supplying sufficient data or you have set your Chart settings for Max Bars, to a very low value. So check your Options (Ctrl-O).

Also, please remember that in the Strategy Tester at the beginning of the test, it will only get approximately 1000 bars and no more. Is that the case? Is the 986 bars in the Strategy Tester or is it on a live/demo usage?

 

You can press F2 to open history center to see if you can download more bars.

 
  1. MT5 doesn't have a iHighest function. Why did you post your MT4 question in the Root / MT5 General section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum

  2.        int LTFL_index=iLowest(NULL,PERIOD_D1,MODE_LOW,31,1);
    
           int LTFL_index=iLowest(NULL,PERIOD_M1,MODE_LOW,44640,1);
    Unless the current chart is the specific pair/TF referenced, you must handle 4066/4073 errors.
              Download history in MQL4 EA - MQL4 and MetaTrader 4 - MQL4 programming forum
  3. Brokers usually only have 32-64K bars of a particular TF.
Reason: