As promised, I outsourced code creation. I have attached the MQL5 file. If anyone wishes to improve on it, please post updated files.