MQL4 and MQL 2

 

I wrote a custom indicator in MQL4 and need to write this in MQL2. Why, you might ask... I am using mtapi.dll from C# and I want to see this indicator on the MetaTrader 3 platform (FXDD account).

I want to be able to get the last day's close, low and high. On the surface you can do this using Close[1], Low[1], High[1]. But when you change the time frame to say 5 minutes, the Close[1] returns (as expected), the close of the previous 5 minute interval.

IN MQL4 you can do:

double prevLow = iLow(NULL, PERIOD_D1, 1);

double prevHigh = iHigh(NULL, PERIOD_D1, 1) ;

double open = iOpen(NULL, PERIOD_D1, 0);

Does anyone know how to do this in MQL2. This type of functionality seems to be missing where you can lock in a timeframe for getting Low[1], etc.

Thanks for all your help. I am new to this forum but quite impressed with the previous posts on this forum.

 

You can use High[] and Highest() to emulate the iHigh() function. And Low[] and Lowest() to emulate iLow().

Syntax: Highest(type,beginbar,periods)

Description: Returns the shift of the maximum value over a specific number of periods depending on type.

Says, you want to emulate iHigh(NULL, PERIOD_D1, 1) on 1H chart at 23 o'clock. You can use High[Highest(MODE_HIGH,47,24)]. Be sure to calculate the beginbar correctly.

For iOpen() and iClose(), you can use Open[] and Close[] to do the job. Simply you just calculate the correct bar. E.g. Open[47] on 1H chart at 23 o'clock simply gets the Open Price of yesterday.

Hope this helps

 

And...

Congratulations! You are the 1000th member! You are a milestone, Karan!

You must be an elite programmer from India, right?

 
scorpion:
And... Congratulations! You are the 1000th member! You are a milestone, Karan! You must be an elite programmer from India, right?

What a coincidence... 1000th member!

I was born in India. But I have settled in the USA for many years.

And thanks for all your help.

Reason: