Download MetaTrader 5

Coding Question - Bar Movement

To add comments, please log in or register


I'm just learning MQL4 and working on a some exercises and had a few very basic questions.  In the following lines of code, what are the 0's referencing. 

 if(iOpen(NULL,0,1)<iClose(NULL,0,1)) int BarOneUp=1;
 if(iOpen(NULL,0,2)>iClose(NULL,0,2)) int BarOneDown=1;

What code would I use, to send a market buy order when the price of bar 3 moves above the high of bar 2?  All the code that I have seen so far only references buying at the close of a bar.  What I trying to accomplish is to build a simple EA that would issue a market buy order if bar 1 is higher than bar 2 and to then take a trade when bar 3 moves above the high of bar two. 

if(BarOneUp==1&&BarTwoDown==1 ??????????

Thank you for the help!!!


Biantoro Kunarto
Biantoro Kunarto  

0 means the chart Time Frame, if you want to use 15 minutes chart, you can change the 0 with PERIOD_M15.

For using the high value, you can use this :


For using the low value, you can use this :


You can use NULL in place of _Symbol only in those calls that the documentation specially says you can. iHigh does, MarketInfo does not. Don't use NULL (except for pointers where you explicitly check for it.)

Zero is the same as PERIOD_CURRENT which means _Period.

No need for a function call with NULL,0 just use the predefined array High[]

To add comments, please log in or register