Skip to main content


Common MQL4 Functions Library

Recent posts

Mutual Exclusion (Mutex) Implementation in MQL4

Introduction In computer science, mutual exclusion is a property of concurrency control, which is instituted for the purpose of preventing race conditions; it is the requirement that one thread of execution never enters its critical section at the same time that another concurrent thread of execution enters its own critical section.

In Algotrading, you may encounter this situation while:
Running several expert advisers using a shared object which may worked on only once and not in parallel.Trading only in certain conditions, for example allowing only one expert adviser to open a position while the other ones are blocked. In my case, I am running several expert advisers on the same account trading different currencies. But, I wanted to have only one product open at a given moment while the others are blocked. So, if for example both EURUSD & EURJPY have the right conditions to open an order, only one order will be open. I wanted to avoid to be double exposed to products which are c…

MetaTrader 4 Indicator to show Currency trend in Different Timeframes

Usage When trading, you probably have several windows open next to each other, different products, different time frames. Or, you have the same product but in different timeframes to see how it performs.
I wrote this indicator so I can see for a given product, how it behaves in the different timeframes available by MetaTradre 4. It has three different lines to express the following information: The trend for a given timeframe, blue arrow means bullish, red arrow means bearish.The pips change for a given timeframe, blue text means bullish, red text means bearish.The standard deviation for a given timeframe, red text means that the timeframe movement is higher thatn the volatility, otherwise black. Once attached, a panel will be drawn in the lower left corner as in the following screenshot for EURUSD:

You may see, that the daily trend for example is bullish. And that the hourly movement in pips is higher than the volatility, thus the STD value for hourly timeframe is painted in red.

To …

Looking back at 2018 and forward to 2019


Every year brings with it 365 opportunities to make a difference, so did 2018 and so will 2019. The last was very exciting and challenging. Since going live with my algorithmic strategies to the public, it a was a roller coaster. As soon as you expose your ideas and start getting an inflow of investors it's a whole new and different experience.

The challenge we face as FX traders, specifically as retail ones is that we don't have enough equity to make a living out of the trading, which drives us to take more risky positions with insane leverage hoping this will make us overnight rich. Of course, in reality the market has its own rules and most of the traders gets punished for acting foolish, seeing their account gets blown. This is one of the reasons that 80% of retails traders lose money on average, a figure which can be seen on many FX brokers sites:


Lessons Learned

In 2018 I learned the hard way how risk management is critical. I got burnt with GBPUSD crash in …

Implementing Trailing Stop Loss in MQL4

Cut your losses early, and let your winners runs.
Trading circles Introduction This is the most common quote you'll probably hear in trading circles. Which basically means, that as soon as you open a position, you need to monitor it and make a decision against it or for it. When you move into the algotrading regime, I would modify this quote into the following one:
Cut your losses early, and let your winners run... to your trailing stop loss.
Roy Meshulam That's because you don't want to spend your time in front your PC monitoring the order. The contrary, you want to have a fully automated expert adviser that does it for you, opening and closing order according to the logic you built.

Trailing stop loss a strong utility to have. It is basically the logic to update the stop loss value and move it together with the price. So, if the price is in your favour, you move the stop loss, thus, capturing more profit. If it is against, you keep the stop loss with the same value. Hence…

How to Communicate Between MetaTrader Terminals using Files


Do you need different MetaTrader terminals to be able to communicate between themselves?

Some reasons to implement this logic could be:

Trading with different accounts which need to know on each other status.
Trading with different brokers which needs to have the same orders open.
Using one terminal to notify another terminal upon a certain trading condition.

The use case which enforced me to communicate between different terminals, was a strategy running on one account that had to notify another terminal to open orders once certain conditions were met. The second strategy was a derivative of the first one, so it had a dependency on its behavior. But I didn’t want to run both strategies in the same terminal as I wanted the order book to be clean and not a mixture of these two strategies.

Important: this solution will only work if the terminals are running on the same PC, otherwise, you need to consider using other methods like reading remote URL or using FTP.


Using Common…

How I make Money trading Forex

Did you know that on average 80% of retail traders lose money when trading Forex?

But, if you've been following my blog, you realized by now that I make my income from trading Forex, and to be specific from trading EURUSD only. This is the only product I trade and live from, which is quite counter intuitive, how is it possible to trade only one product with all it's ups and downs and live from it? In this post, I will explain exactly how I make a living from trading Forex and which traps to avoid.

Still, even that it worked for me and the setup is quite simple, there's no guarantee it will work for you the reader. We are all in a different situations in life, with more or less to risk, knowledge and so on. But still, I suggest to read this post to understand which traps are out there and which path you can follow to avoid losing your money.

The Traps

But first, let's start with the typical pitfalls out there, unfortunately, in some of them I fell myself and lost money: