input price = close;
input length = 20;
input averageType = AverageType.HULL;
plot Avg = MovingAverage(averageType, price, length);
Avg.AssignValueColor(if Avg > Avg[1] then Color.GREEN else Color.RED);
def crossAbove = Avg crosses above Avg[1];
def crossBelow = Avg crosses below Avg[1];
#===These AUTO settings take the place of BUY_TO_OPEN or CLOSE and are intended to produce an order to enter the trade in the opposite direction after exiting the current position.
AddOrder(OrderType.BUY_AUTO, crossAbove, tickcolor = GetColor(9), arrowcolor = GetColor(9), name = "LE");
AddOrder(OrderType.SELL_AUTO, crossBelow, tickcolor = GetColor(9), arrowcolor = GetColor(9), name = "SE");