//@version=5
strategy(title='Saurabh' , overlay = true, max_labels_count = 500, max_lines_count
= 500)
import TradingView/ta/7
r = input.int(14, minval=1 , group = "DTI" )
s = input.int(10, minval=1 , group = "DTI" )
u = input.int(5, minval=1 , group = "DTI" )
OB = input.int(25, minval=1 , group = "DTI" )
OS = input.int(-25, maxval=-1 , group = "DTI" )
hline(0, color=color.green, linestyle=hline.style_solid)
xHMU = high - high[1] > 0 ? high - high[1] : 0
xLMD = low - low[1] < 0 ? -(low - low[1]) : 0
xPrice = xHMU - xLMD
xPriceAbs = math.abs(xPrice)
xuXA = ta.ema(ta.ema(ta.ema(xPrice, r), s), u)
xuXAAbs = ta.ema(ta.ema(ta.ema(xPriceAbs, r), s), u)
Val1 = 100 * xuXA
Val2 = xuXAAbs
DTI = Val2 != 0 ? Val1 / Val2 : 0
// plot(DTI, color=color.new(color.maroon, 0), title='DTI')
// plot(OB, color=color.new(color.blue, 0), title='OB')
// plot(OS, color=color.new(color.red, 0), title='OS')
buy_arrow_dti = DTI > DTI[1] and DTI[1] > DTI[2] and DTI[2] < DTI[3]
sell_arrow_dti = DTI < DTI[1] and DTI[1] < DTI[2] and DTI[2] > DTI[3]
plotshape( buy_arrow_dti , style = shape.triangleup , color = color.green ,
location = location.belowbar , size = size.normal, offset = 0)
plotshape( sell_arrow_dti , style = shape.triangledown , color = color.red ,
location = location.abovebar , size = size.normal , offset = 0)
//
===================================================================================
// SUPERTREND
//
===================================================================================
factor = input.int(3, "Factor", group = "Supertrend")
atrPeriod = input.int(10, "ATR period", group = "Supertrend")
stBullishLine = input.color(color.green, "Bullish Line", group = "Supertrend")
stBearishLine = input.color(color.red, "Bearish Line", group = "Supertrend")
[supertrend, direction] = ta.supertrend(factor, atrPeriod)
stBullishCondition = direction < 0
stBearishCondition = direction > 0
plot(stBullishCondition? supertrend : na, "Up direction", color = stBullishLine,
style=plot.style_linebr)
plot( stBearishCondition? supertrend : na, "Down direction", color = stBearishLine,
style=plot.style_linebr)
//
===================================================================================
// EXECUTION ENGIENE
//
===================================================================================
stopLossInput = input.int(2, "Stop Loss Percent", group = "Stop Loss")
stopLossPercent = math.round(stopLossInput/100, 2)
var float shortStopLoss = na
var float longStopLoss = na
if stBearishCondition and buy_arrow_dti
longStopLoss := (low[1] - low[1] * stopLossPercent)
strategy.entry('Long',strategy.long)
line.new(bar_index, longStopLoss, bar_index + 5, longStopLoss)
// label.new(bar_index, low, "Buy", color = color.teal, style =
label.style_label_up, textcolor = color.white)
if stBullishCondition and sell_arrow_dti
shortStopLoss := (high[1] + high[1] * stopLossPercent)
strategy.entry('Short',strategy.short)
line.new(bar_index, shortStopLoss, bar_index + 5, shortStopLoss)
// label.new(bar_index, high, "Sell", color = color.red, style =
label.style_label_down, textcolor = color.white)
// --------------------- PROFIT TARGET ------------------------
longProfitTarget = supertrend[1]
if (high > supertrend[1]) and (close[1] < supertrend[1])
strategy.close('Long','Long Profit')
shortProfitTarget = supertrend[1]
if (low < supertrend[1]) and (close[1] > supertrend[1])
strategy.close('Short','Short Profit')
// --------------------- STOP LOSS------------------------
if low < longStopLoss
strategy.close('Long','Long Stop')
if high > shortStopLoss
strategy.close('Short','Short Stop')