TUE ADX Crossover Signals V1.0
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// Written by TradersUltimateEdge
// Code provided open source, feel free to use it for any purpose except resale

//@version=5
indicator("TUE ADX Crossover Signals V1.0", overlay=true)

showsignals = input(true, title="Show BUY/SELL Signals")
length = input(14, title="ADX Length")
smoothing = input(10, title="ADX Smoothing")
colorup = input(color.green, title="Up Candle Color")
colordown = input(color.red, title="Down Candle Color")


/////////////////////////////////////////////////////////////////////////////////////////////// ADX CALC
[diplus, diminus, adx] = ta.dmi(length, smoothing)

//////////////////////////////////////////////////////////////////////////////////////////////TRADE CALC

int trade = 0

//Open from nothing

if trade == 0 and diplus > diminus
    trade := 1

else if trade == 0 and diminus > diplus
    trade := -1
    
//Reversal

else if trade == 1 and diminus > diplus
    trade := -1
    
else if trade == -1 and diplus > diminus
    trade := 1
    
//Keep status quo until crossover

else
    trade := trade[1]

//////////////////////////////////////////////////////////////////////////////////////////////PLOT 

colors = diplus > diminus ? colorup : colordown

plotcandle(open, high, low, close, color=colors)

plotshape(trade[1] != 1 and trade == 1 and showsignals, style=shape.labelup, text='BUY', textcolor=color.white, color=color.green, size=size.small, location=location.belowbar)
plotshape(trade[1] != -1 and trade == -1 and showsignals, style=shape.labeldown, text='SELL', textcolor=color.white, color=color.red, size=size.small, location=location.abovebar)

///////////////////////////////////////////////////////////////////////////////////////////// ALERTS

alertcondition(trade[1] != 1 and trade == 1, "ADX CROSSOVER LONG")
alertcondition(trade[1] != -1 and trade == -1, "ADX CROSSOVER SHORT")