This Expert Advisor identifies the Highest High and the Lowest Low of the recent TRADING_PERIOD candles to place LONG and SHORT breakout trades respectively. When the price breaks out of its recent trading bandit implies a new market direction is in force, and therefore the Expert Advisor places a trade in the direction of the trade.
When the Expert Advisor is started, it calculates the Highest High and the Lowest Low of the recent TRADING_PERIOD candles for the previous candle. When the price crosses above this Highest High value, a BUY (LONG) trade is opened if a BUY trade does not already exist. If a SELL trade exists when a BUY signal is received, the Expert Advisor keeps the SELL trade open and opens a new BUY trade.
On the contrary if the price crosses below the Lowest Low value, a SELL (SHORT) trade is opened if a SELL trade does not already exists. If a BUY trade already exists when a SELL signal is received, the Expert Advisor keeps the BUY trade open and opens a new SELL trade.
The lot-size is based upon the MONEY_MANAGEMENT setting. If MONEY_MANAGEMNT is set to false, the lot-size is set to the fixed LOT_SIZE value. However, if the setting is true, the lot-size is calculated based on the RISK_PERCENT and the initial stop-loss.
This Expert Advisor employs two levels of stop-loss – an initial stop-loss that is based on the Highest High and Lowest Low of the recent STOP_PERIOD candles, and a dynamic stop-loss based on the Average True Range (ATR).
The initial stop-loss is the Lowest Low of the recent STOP_PERIOD for BUY trades, and the Highest High of the recent STOP_PERIOD for SELL trades. These levels also act as trailing stop.
If SL_ENABLED is set to true, the Expert Advisor employs a trailing stop using the Average True. The trailing stop trails the current price by Average True Range multiplied by the ATR_MULTIPLIER value.