// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © traderschatroom88 // © udaysquest //@version=5 indicator(title='DTC - v1.36', shorttitle='DTC v1.36', overlay=true, max_labels_count=500, max_lines_count=500) // ===================================== // USER INPUTS // ===================================== // EMA Settings group_ema = "EMA Settings" len1 = input.int(30, minval=1, title='EMA 1', group=group_ema) len2 = input.int(35, minval=1, title='EMA 2', group=group_ema) len3 = input.int(40, minval=1, title='EMA 3', group=group_ema) len4 = input.int(45, minval=1, title='EMA 4', group=group_ema) len5 = input.int(50, minval=1, title='EMA 5', group=group_ema) len6 = input.int(60, minval=1, title='EMA 6', group=group_ema) // Multi-Timeframe Settings group_mtf = "Multi-Timeframe Settings" tf1 = input.timeframe("15", title="15M", group=group_mtf) tf2 = input.timeframe("30", title="30M", group=group_mtf) tf3 = input.timeframe("60", title="1H", group=group_mtf) tf4 = input.timeframe("240", title="4H", group=group_mtf) tf5 = input.timeframe("1D", title="Daily", group=group_mtf) // Risk Management group_trade = "Risk Management" sl_lookback = input.string("Mid", title="Stop-Loss Lookback", options=["Tiny", "Small", "Mid", "Large"], group=group_trade) stopLossVal = input.float(0.25, title="Stop Loss %", minval=0, group=group_trade) tp1Multiplier = input.float(1.0, "TP1 Multiplier", minval=0, step=0.1, group=group_trade) tp2Multiplier = input.float(2.0, "TP2 Multiplier", minval=0, step=0.1, group=group_trade) tp3Multiplier = input.float(3.0, "TP3 Multiplier", minval=0, step=0.1, group=group_trade) tp4Multiplier = input.float(4.0, "TP4 Multiplier", minval=0, step=0.1, group=group_trade) // Display Settings group_display = "Display" lineLength = input.int(1, "Line Length (bars)", minval=1, maxval=50, group=group_display) showNumbers = input.bool(true, "Show Price Numbers", group=group_display) showLabels = input.bool(true, "Show Signal Labels", group=group_display) // ATR Filter group_filter = "ATR Filter" useATR = input.bool(true, "Enable ATR Filter?", group=group_filter) atrPeriod = input.int(14, "ATR Period", minval=1, group=group_filter) atrMin = input.float(0.5, "Min ATR Value", minval=0, step=0.1, group=group_filter) // Dashboard Settings group_dashboard = "Dashboard" show_dashboard = input.bool(true, title="Show Multi-Timeframe Dashboard", group=group_dashboard) dashboard_size = input.string("normal", title="Dashboard Size", options=["small", "normal", "large"], group=group_dashboard) // ===================================== // HELPER FUNCTIONS // ===================================== // Get table text size based on dashboard size setting get_table_size() => switch dashboard_size "small" => size.tiny "normal" => size.small "large" => size.normal => size.small // ===================================== // STOP-LOSS LOOKBACK VALUES // ===================================== sl_length = switch sl_lookback "Tiny" => 3 "Small" => 5 "Mid" => 8 "Large" => 12 => 8 // ===================================== // EMA CALCULATIONS // ===================================== src = close ema1 = ta.ema(src, len1) ema2 = ta.ema(src, len2) ema3 = ta.ema(src, len3) ema4 = ta.ema(src, len4) ema5 = ta.ema(src, len5) ema6 = ta.ema(src, len6) // Trend Detection Logic bullish_trend = ema1 > ema2 and ema2 > ema3 and ema3 > ema4 and ema4 > ema5 and ema5 > ema6 bearish_trend = ema1 < ema2 and ema2 < ema3 and ema3 < ema4 and ema4 < ema5 and ema5 < ema6 // EMA Color Based on Trend ema_color = bullish_trend ? color.lime : bearish_trend ? color.red : color.gray // Plot EMAs plot(ema1, title='EMA 30', linewidth=3, color=ema_color) plot(ema2, title='EMA 35', linewidth=2, color=ema_color) plot(ema3, title='EMA 40', linewidth=2, color=ema_color) plot(ema4, title='EMA 45', linewidth=1, color=ema_color) plot(ema5, title='EMA 50', linewidth=1, color=ema_color) plot(ema6, title='EMA 60', linewidth=1, color=ema_color) // ===================================== // MULTI-TIMEFRAME ANALYSIS // ===================================== htf1_ema_fast = request.security(syminfo.tickerid, tf1, ta.ema(close, 20), lookahead=barmerge.lookahead_off) htf1_ema_slow = request.security(syminfo.tickerid, tf1, ta.ema(close, 50), lookahead=barmerge.lookahead_off) htf2_ema_fast = request.security(syminfo.tickerid, tf2, ta.ema(close, 20), lookahead=barmerge.lookahead_off) htf2_ema_slow = request.security(syminfo.tickerid, tf2, ta.ema(close, 50), lookahead=barmerge.lookahead_off) htf3_ema_fast = request.security(syminfo.tickerid, tf3, ta.ema(close, 20), lookahead=barmerge.lookahead_off) htf3_ema_slow = request.security(syminfo.tickerid, tf3, ta.ema(close, 50), lookahead=barmerge.lookahead_off) htf4_ema_fast = request.security(syminfo.tickerid, tf4, ta.ema(close, 20), lookahead=barmerge.lookahead_off) htf4_ema_slow = request.security(syminfo.tickerid, tf4, ta.ema(close, 50), lookahead=barmerge.lookahead_off) htf5_ema_fast = request.security(syminfo.tickerid, tf5, ta.ema(close, 20), lookahead=barmerge.lookahead_off) htf5_ema_slow = request.security(syminfo.tickerid, tf5, ta.ema(close, 50), lookahead=barmerge.lookahead_off) htf1_trend = htf1_ema_fast > htf1_ema_slow htf2_trend = htf2_ema_fast > htf2_ema_slow htf3_trend = htf3_ema_fast > htf3_ema_slow htf4_trend = htf4_ema_fast > htf4_ema_slow htf5_trend = htf5_ema_fast > htf5_ema_slow // ===================================== // SIGNAL GENERATION (+ no-repeat + ATR filter) // ===================================== var int signal_state = 0 // 1=long, -1=short, 0=none long_signal_raw = not bullish_trend[1] and bullish_trend and barstate.isconfirmed short_signal_raw = not bearish_trend[1] and bearish_trend and barstate.isconfirmed atr_value = ta.atr(atrPeriod) atr_ok = not useATR or (atr_value > atrMin) long_signal = long_signal_raw and signal_state != 1 and atr_ok short_signal = short_signal_raw and signal_state != -1 and atr_ok // ===================================== // CALCULATE FUNCTIONS ON EVERY BAR // ===================================== lowest_low = ta.lowest(low, sl_length) highest_high = ta.highest(high, sl_length) // ===================================== // POSITION TRACKING - LINES, LABELS, FILLS // ===================================== var float entry = na var float sl = na var float tp1 = na var float tp2 = na var float tp3 = na var float tp4 = na var line entryLine = na var line slLine = na var line tp1Line = na var line tp2Line = na var line tp3Line = na var line tp4Line = na var label entryLabel = na var label slLabel = na var label tp1Label = na var label tp2Label = na var label tp3Label = na var label tp4Label = na var linefill slFill = na var linefill tpFill = na // Update state & levels if long_signal signal_state := 1 entry := close sl := entry * (1 - stopLossVal/100) tp1 := entry * (1 + stopLossVal * tp1Multiplier/100) tp2 := entry * (1 + stopLossVal * tp2Multiplier/100) tp3 := entry * (1 + stopLossVal * tp3Multiplier/100) tp4 := entry * (1 + stopLossVal * tp4Multiplier/100) else if short_signal signal_state := -1 entry := close sl := entry * (1 + stopLossVal/100) tp1 := entry * (1 - stopLossVal * tp1Multiplier/100) tp2 := entry * (1 - stopLossVal * tp2Multiplier/100) tp3 := entry * (1 - stopLossVal * tp3Multiplier/100) tp4 := entry * (1 - stopLossVal * tp4Multiplier/100) // ===================================== // CLEAN REMOVAL OF PREVIOUS ELEMENTS // ===================================== if long_signal or short_signal if not na(entryLine) line.delete(entryLine) if not na(slLine) line.delete(slLine) if not na(tp1Line) line.delete(tp1Line) if not na(tp2Line) line.delete(tp2Line) if not na(tp3Line) line.delete(tp3Line) if not na(tp4Line) line.delete(tp4Line) if not na(entryLabel) label.delete(entryLabel) if not na(slLabel) label.delete(slLabel) if not na(tp1Label) label.delete(tp1Label) if not na(tp2Label) label.delete(tp2Label) if not na(tp3Label) label.delete(tp3Label) if not na(tp4Label) label.delete(tp4Label) if not na(slFill) linefill.delete(slFill) if not na(tpFill) linefill.delete(tpFill) // NEW lines with width=1 entryLine := line.new(bar_index, entry, bar_index + lineLength, entry, color=color.blue, width=1) slLine := line.new(bar_index, sl, bar_index + lineLength, sl, color=color.red, width=1) tp1Line := line.new(bar_index, tp1, bar_index + lineLength, tp1, color=color.green, width=1) tp2Line := line.new(bar_index, tp2, bar_index + lineLength, tp2, color=color.green, width=1) tp3Line := line.new(bar_index, tp3, bar_index + lineLength, tp3, color=color.green, width=1) tp4Line := line.new(bar_index, tp4, bar_index + lineLength, tp4, color=color.green, width=1) // Transparent background using linefill if signal_state == 1 slFill := linefill.new(slLine, entryLine, color.new(color.red, 85)) tpFill := linefill.new(entryLine, tp4Line, color.new(color.green, 85)) else if signal_state == -1 slFill := linefill.new(entryLine, slLine, color.new(color.red, 85)) tpFill := linefill.new(tp4Line, entryLine, color.new(color.green, 85)) // NEW labels if showNumbers posOffset = lineLength entryLabel := label.new(bar_index + posOffset, entry, "ENTRY\n" + str.tostring(entry, format.mintick), color=color.blue, textcolor=color.white, style=label.style_label_left, yloc=yloc.price, size=size.small) slLabel := label.new(bar_index + posOffset, sl, "SL\n" + str.tostring(sl, format.mintick), color=color.red, textcolor=color.white, style=label.style_label_left, yloc=yloc.price, size=size.small) tp1Label := label.new(bar_index + posOffset, tp1, "TP1\n" + str.tostring(tp1, format.mintick), color=color.green, textcolor=color.white, style=label.style_label_left, yloc=yloc.price, size=size.small) tp2Label := label.new(bar_index + posOffset, tp2, "TP2\n" + str.tostring(tp2, format.mintick), color=color.green, textcolor=color.white, style=label.style_label_left, yloc=yloc.price, size=size.small) tp3Label := label.new(bar_index + posOffset, tp3, "TP3\n" + str.tostring(tp3, format.mintick), color=color.green, textcolor=color.white, style=label.style_label_left, yloc=yloc.price, size=size.small) tp4Label := label.new(bar_index + posOffset, tp4, "TP4\n" + str.tostring(tp4, format.mintick), color=color.green, textcolor=color.white, style=label.style_label_left, yloc=yloc.price, size=size.small) // ===================================== // EXTEND ACTIVE SIGNAL LINES AND LABELS // ===================================== if signal_state != 0 if not na(entryLine) line.set_x2(entryLine, bar_index + lineLength) if not na(slLine) line.set_x2(slLine, bar_index + lineLength) if not na(tp1Line) line.set_x2(tp1Line, bar_index + lineLength) if not na(tp2Line) line.set_x2(tp2Line, bar_index + lineLength) if not na(tp3Line) line.set_x2(tp3Line, bar_index + lineLength) if not na(tp4Line) line.set_x2(tp4Line, bar_index + lineLength) if showNumbers if not na(entryLabel) label.set_x(entryLabel, bar_index + lineLength) if not na(slLabel) label.set_x(slLabel, bar_index + lineLength) if not na(tp1Label) label.set_x(tp1Label, bar_index + lineLength) if not na(tp2Label) label.set_x(tp2Label, bar_index + lineLength) if not na(tp3Label) label.set_x(tp3Label, bar_index + lineLength) if not na(tp4Label) label.set_x(tp4Label, bar_index + lineLength) // ===================================== // SIMPLE BUY/SELL SIGNAL LABELS // ===================================== if showLabels and long_signal label.new(bar_index, low - atr_value * 0.5, 'BUY', style=label.style_label_up, color=color.green, textcolor=color.white, size=size.normal) if showLabels and short_signal label.new(bar_index, high + atr_value * 0.5, 'SELL', style=label.style_label_down, color=color.red, textcolor=color.white, size=size.normal) // ===================================== // MULTI-TIMEFRAME DASHBOARD // ===================================== if show_dashboard var table dashboard = table.new(position.top_right, 2, 6, bgcolor=color.black, border_width=1) if barstate.islast table_text_size = get_table_size() table.cell(dashboard, 0, 0, "DTC V - 1.36", text_color=color.white, text_size=table_text_size, bgcolor=color.black, text_halign=text.align_center) table.cell(dashboard, 1, 0, "", text_color=color.white, text_size=table_text_size, bgcolor=color.black) tf_15_color = htf1_trend ? color.lime : color.red tf_15_text = htf1_trend ? "Bullish" : "Bearish" table.cell(dashboard, 0, 1, "15", text_color=color.white, text_size=table_text_size, bgcolor=color.black) table.cell(dashboard, 1, 1, tf_15_text, text_color=color.black, text_size=table_text_size, bgcolor=tf_15_color) tf_30_color = htf2_trend ? color.lime : color.red tf_30_text = htf2_trend ? "Bullish" : "Bearish" table.cell(dashboard, 0, 2, "30", text_color=color.white, text_size=table_text_size, bgcolor=color.black) table.cell(dashboard, 1, 2, tf_30_text, text_color=color.black, text_size=table_text_size, bgcolor=tf_30_color) tf_60_color = htf3_trend ? color.lime : color.red tf_60_text = htf3_trend ? "Bullish" : "Bearish" table.cell(dashboard, 0, 3, "60", text_color=color.white, text_size=table_text_size, bgcolor=color.black) table.cell(dashboard, 1, 3, tf_60_text, text_color=color.black, text_size=table_text_size, bgcolor=tf_60_color) tf_240_color = htf4_trend ? color.lime : color.red tf_240_text = htf4_trend ? "Bullish" : "Bearish" table.cell(dashboard, 0, 4, "240", text_color=color.white, text_size=table_text_size, bgcolor=color.black) table.cell(dashboard, 1, 4, tf_240_text, text_color=color.black, text_size=table_text_size, bgcolor=tf_240_color) tf_d_color = htf5_trend ? color.lime : color.red tf_d_text = htf5_trend ? "Bullish" : "Bearish" table.cell(dashboard, 0, 5, "D", text_color=color.white, text_size=table_text_size, bgcolor=color.black) table.cell(dashboard, 1, 5, tf_d_text, text_color=color.black, text_size=table_text_size, bgcolor=tf_d_color) // ===================================== // ALERTS // ===================================== alertcondition(long_signal, title='Long Signal', message='DTC Long Signal: {{ticker}} at {{close}}') alertcondition(short_signal, title='Short Signal', message='DTC Short Signal: {{ticker}} at {{close}}')