Write a complete custom indicator for MetaTrader 5 in MQL5 (not MQL4). Name it
"RX Trend Signal". It draws in the chart window and must work on any symbol
and timeframe. No DLLs, no file access, no network access.

Inputs, with these names, in this order:
  EmaPeriod = 50, SlopeBars = 5, MinDistancePoints = 20, RsiPeriod = 14,
  RsiLongLevel = 55.0, RsiShortLevel = 45.0, ArrowOffsetPoints = 50,
  EnableAlerts = false

Rules. Every condition is evaluated on one closed bar, using that bar's values.

1. EMA: exponential moving average of the close, period EmaPeriod.
   RSI: relative strength index of the close, period RsiPeriod.
   Use the built-in iMA and iRSI handles. Create them in OnInit and release
   them in OnDeinit.
2. Up-trend on a bar: the close is at least MinDistancePoints points above the
   EMA, and the EMA is higher than it was SlopeBars bars earlier.
   Down-trend on a bar: the close is at least MinDistancePoints points below
   the EMA, and the EMA is lower than it was SlopeBars bars earlier.
3. Buy trigger on a bar: the RSI is above RsiLongLevel and was at or below
   RsiLongLevel on the bar before.
   Sell trigger on a bar: the RSI is below RsiShortLevel and was at or above
   RsiShortLevel on the bar before.
4. Buy signal: up-trend and buy trigger on the same bar.
   Sell signal: down-trend and sell trigger on the same bar.
5. Signals alternate. After a buy signal, further buy signals are suppressed
   until a sell signal has occurred, and the other way round.
6. No repainting. Never show a signal on the unfinished bar. Once a bar is
   closed, its values never change.
7. Buffers, in this order:
   buffer 0: buy arrow, at the bar's low minus ArrowOffsetPoints points,
             EMPTY_VALUE on bars without a buy signal;
   buffer 1: sell arrow, at the bar's high plus ArrowOffsetPoints points,
             EMPTY_VALUE on bars without a sell signal;
   buffer 2: the EMA as a line.
   Buy arrow: code 233, clrDodgerBlue. Sell arrow: code 234, clrOrangeRed.
   EMA line: clrSlateGray.
8. Alerts: when EnableAlerts is true, raise one Alert for each signal on a
   bar that closes while the indicator is running. No alerts for bars that
   were already in the history when the indicator was loaded, and never more
   than one alert for the same bar.
9. Calculate the whole history on the first call. On later calls calculate
   only what is new, using prev_calculated.

First restate the rules in your own words and list everything that is
ambiguous, with the assumption you chose. Then give the complete source in
one file. Do not claim that you compiled or tested the code.
