Finding inside bars

 

Hello,


First post LFG!

I'm pretty new to MT4. I coded a lot in python so MT4 will take some getting used to.

1) What resources do you recommend as I can't find decent ones online

2) I'm trying to make an EA that checks if the last bar printed is inside the previous one


Like say we're at time, T. Is the bar T-1 inside of T-2? If so, print some signal

Again its on the 1m timeframe


Thx

 
Abbas2022: First post LFG! I'm pretty new to MT4. I coded a lot in python so MT4 will take some getting used to.

1) What resources do you recommend as I can't find decent ones online

2) I'm trying to make an EA that checks if the last bar printed is inside the previous one

Like say we're at time, T. Is the bar T-1 inside of T-2? If so, print some signal

Again its on the 1m timeframe

If you are just starting, them I recommend you skip MQL4 and instead invest in learning MQL5 and using MetaTrader 5.
 
Fernando Carreiro #:
If you are just starting, them I recommend you skip MQL4 and instead invest in learning MQL5 and using MetaTrader 5.
Ah I can't. I'm building a few strategies with friends and they agree on using MT4. Not sure why tbh
 
Abbas2022 #:
Ah I can't. I'm building a few strategies with friends and they agree on using MT4. Not sure why tbh

In MQL, prices are indexed in an array in what's called a "Timeseries."

This means that High[0] refers to the currently open candle, while High[Bars-1] (or High[rates_total-1] refers to the candle at the very beginning of the chart to the left.

In your case, you want to be checking for indices 2 and 1.

From there on, there are quite a few ways to get the high and low of the candles you're interested in. The most popular ones are High[] and Low[]. However, these only refer to the timeframe on the chart that the program is running on.

If you want to check on another timeframe and/or symbol, the equivalent is iHigh() and iLow(). However, there's one caveat to using these functions and it's that the history data may not be up-to-date if you don't have a chart open with the symbol + timeframe that you specified when making those calls. In which case, you should check the value on the time of the candles to confirm that they are up-to-date, and also check for any error codes.

More on this can be found here: https://www.mql5.com/en/forum/376376#comment_24289884