#A simplified version would work perfectly too
#TF 1MN
#Long: price closes above HULL 88 and Di+ crosses above Di-
#R/R 1:1.5
#Short: price closes below hull 88 and Di- crosses above Di+
input length = 88;
input avgtype = AverageType.HULL;
def ATR_ = reference ATR();
def "DI+" = reference DIPlus();
def "DI-" = reference DIMinus();
plot ma = MovingAverage(avgtype, close, length);
ma.AssignValueColor(if ma >= ma[1] then Color.GREEN else Color.RED);
#Conditions
plot Long = if close > ma and "DI+" crosses above "DI-" then close else Double.NaN;
Long.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
def Longtarget = Long + ATR_ * 1.5;
def LongStop = Long - ATR_;
plot Short = close < ma and "DI-" crosses above "DI+";
Short.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
def Shorttarget = Short - ATR_ * 1.5;
def ShortStop = Short + ATR_;
#Orders
AddOrder(type = OrderType.BUY_TO_OPEN, condition = Long, tickColor = Color.GREEN, arrowColor = Color.GREEN);
AddOrder(type = OrderType.SELL_TO_CLOSE, condition = Longtarget or LongStop or Short, tickColor = Color.WHITE, arrowColor = Color.WHITE);
AddOrder(type = OrderType.SELL_TO_OPEN, condition = Short, tickColor = Color.RED, arrowColor = Color.RED);
AddOrder(type = OrderType.BUY_TO_CLOSE, condition = Shorttarget or ShortStop or Long, tickColor = Color.YELLOW, arrowColor = Color.YELLOW);
#Test
input test = no;
AddChartBubble(test and Long, low, "T " + Longtarget + "\nE " + Long + "\nS " + LongStop, Color.GREEN, no);
AddChartBubble(test and Short, high, "S " + ShortStop + "\nE " + Short + "\nT " + Shorttarget, Color.RED, yes);
;