The idea behind the Expert Advisor is to trade in the direction of the breakout, with a predefined stop-loss to protect the trade in case of adversity.
When opposite signals are received, the trade is protected using break-even stop-loss and by opening hedged trade in the opposite direction.
If the sum of the current Close and Open of 2P bars ago is greater than twice the Open price of P bars ago, a BUY signal is generated, otherwise a SELL
signal is generated. If the RANDOM input variable is set to FALSE then the signals are reversed – and BUY signal is reversed to SELL and SELL
signal is reversed to BUY.
So, its BUY if currant Close price Plus Open price at 2P bars ago is greater than Doubble of Close price at P bars ago
SELL if, currant Close Price Plus Open price at 2P bars ago is less than Doubble of Close price at P bars ago
The market signals are evaluated on close of each candle. If a new signal is encountered, the trade is placed accordingly. After placing new trades (if
any) as per the signal criteria, it evaluates open positions for updating the stop-loss, targets and hedging mechanism.