The concept behind the X Trail 2 script is that the combination of a fast Moving Average and a slow Moving Average identifies trending markets, especially fast breakouts. It scans for trading opportunities every Run_Interval seconds, and alerts the user when a BUY or a SELL criteria is met.
The fast Moving Average responds to price quicker than the slow Moving Average. When the market transitions from a sideways movement to a breakout (either bullish or bearish), the fast Moving Average crosses in the slow Moving Average in the direction of the breakout. If this cross is sustained on the next bar, a Bullish or Bearish criteria is confirmed and the script generates a BUY or SELL alert respectively.
A BUY alert is generated when the fast Moving Average of the current candle is above its slow Moving Average, AND, the fast Moving Average of the previous candle is also above its slow Moving Average, AND, the fast Moving Average two candles ago is below its slow Moving Average of two candles ago.
In other words, the fast Moving Average has crossed above the slow Moving Average on the previous candle and is continuing its uptrend. This implies that the price has exhibited a bullish breakout recently, and is a potential for BUY trade.
A SELL alert is generated when the fast Moving Average of the current candle is below its slow Moving Average, AND, the fast Moving Average of the previous candle is also belwo its slow Moving Average, AND, the fast Moving Average two candles ago is above its slow Moving Average of two candles ago.
In other words, the fast Moving Average has crossed below the slow Moving Average on the previous candle and is continuing its downtrend. This implies that the price has exhibited a bearish breakout recently, and is a potential for SELL trade.