@sandun, to put this script in MT4, you need to program on MQL4, which is similar C/C++ languages but with some advantages of the platform for trading! I did that long time ago but I forgot how to do it!