Goldmine Wealth Builder - DKK/SKK
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Deepak-Patil

//@version=5
//SuperTrend+3EMA Crosses for Goldmine Wealth Builder - DKK/SKK/SKK2 system with Alrt and Signals for Buying on Bottom when Reversal in ETF's/Stocks

indicator('Goldmine Wealth Builder', overlay=true)

// Super Trend Settings
Periods = 10  // default ATR Period
Multiplier = 3  //default ATR Multiplier
changeATR = true  // Default setting for changing ATR Calculation Method
src = hl2  // Default setting for source 
atr2 = ta.sma(ta.tr, Periods)
atr = changeATR ? ta.atr(Periods) : atr2
up = src - Multiplier * atr
up1 = nz(up[1], up)
up := close[1] > up1 ? math.max(up, up1) : up
dn = src + Multiplier * atr
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? math.min(dn, dn1) : dn
trend = 1
trend := nz(trend[1], trend)
trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend
// Input for EMA lengths
ema1_length = input.int(20, title='EMA 1 Length', group='EMA Settings')
ema2_length = input.int(50, title='EMA 2 Length', group='EMA Settings')
ema3_length = input.int(200, title='EMA 3 Length', group='EMA Settings')
// Show Signals/EMA's/SuperTrend On/Off
show_EMA = input(title='Show EMA\'s', defval=true)
show_Crossover = input(title='Show EMA Cross', defval=false)
show_SuperTrend = input(title='Show SuperTrend', defval=true)
show_AlertSignal = input(title='Show DKK/SKK Alert Signals', defval=true)
show_SKK = input(title='Show SKK Signals for ETFs/Funds', defval=false)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Calculate EMAs
ema1 = ta.ema(close, ema1_length)
ema2 = ta.ema(close, ema2_length)
ema3 = ta.ema(close, ema3_length)
// Calculate RSI
rsi = ta.rsi(close, 14)
// Check if the instrument is a Stock/ETF/Funds
isSelectedStock = (ticker.standard(syminfo.tickerid) == "NSE:INDIGRID") or (ticker.standard(syminfo.tickerid) == "NSE:PGINVIT") or (ticker.standard(syminfo.tickerid) == "NSE:IRBINVIT") // Define the selected stock symbol
isStock = syminfo.type == 'stock' and not isSelectedStock
isFund = syminfo.type == 'fund' or isSelectedStock
isStockOrFund = isStock or isFund
// SKK for ETF/Funds condition
if show_SKK
    isStockOrFund := isStock or isFund
else
    isStockOrFund := isStock
// Define only Daily timeframe
isDaily = timeframe.isdaily
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// SuperTrend plot Settings
transparency = 90  // Define transparency using color.new()
plotSuperTrend = show_SuperTrend ? true : na
mPlot = plot(plotSuperTrend ? close : na, title='Plot', style=plot.style_linebr, linewidth=1, display=display.none, editable = false)
upPlot = plot(plotSuperTrend ? trend == 1 ? up : na : na, title='Up Trend', style=plot.style_linebr, linewidth=1, color=color.new(color.green, 0))
dnPlot = plot(plotSuperTrend ? trend == 1 ? na : dn : na, title='Down Trend', style=plot.style_linebr, linewidth=1, color=color.new(color.red, 0))
fill(mPlot, upPlot, color=color.new(color.green, transparency), fillgaps=false)
fill(mPlot, dnPlot, color=color.new(color.red, transparency), fillgaps=false)
changeCond = trend != trend[1]
// Plot EMAs on the chart
plot(show_EMA ? ema1 : na, title='EMA 1', color=color.new(color.blue, 0), linewidth=1)
plot(show_EMA ? ema2 : na, title='EMA 2', color=color.new(color.purple, 0), linewidth=2)
plot(show_EMA ? ema3 : na, title='EMA 3', color=color.new(#f23645, 0), linewidth=3)
// Plot EMA crossover 
crossUpCondition = show_Crossover ? isDaily ? isStock ? ta.crossover(ema1, ema2) ? ema1 : na : na : na : na
crossDownCondition = show_Crossover ? isDaily ? isStock ? ta.crossunder(ema1, ema2) ? ema1 : na : na : na : na
plot(crossUpCondition, title='Cross_Up 1', style=plot.style_cross, color=color.new(color.orange, 0), linewidth=3, display = display.all - display.status_line)
plot(crossDownCondition, title='Cross_Down 1', style=plot.style_cross, color=color.new(color.red, 0), linewidth=3, display = display.all - display.status_line)
var tbl = table.new(position.bottom_right, 1, 2) 
if time > timestamp(2023, 12, 12)
    table.cell(tbl, 0, 0, "@ Deepak Patil", text_color = color.new(#5d606b, 50))
    table.cell(tbl, 0, 1, "", text_color = color.new(#5d606b, 50), text_size = size.small)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// DKK System for accumulating ETF's for long-terms //
// Condition for a red candle closing below the 200EMA and RSI less than 40
redCandleAlert = isFund and isDaily and close < ema3 and close < open and rsi < 40
// Marking Trigger Candle for DKK
plotshape(series=show_AlertSignal and redCandleAlert, title='DKK Buy Signal', location=location.belowbar, color=color.new(color.red, 0), style=shape.triangleup, size=size.small, display = display.all - display.status_line)
//DKK end
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// SKK System for accumulating Stocks for long-terms conservative investment//
// Detecting SuperTrend Zone Transition
superTrendRedToGreen = trend == 1 and trend[1] == -1
superTrendGreen = trend == 1
superTrendRed = trend == -1
// SKK system Active condition
var bool SKK_activeSignal = true
var bool SKK_activeSignal2 = false
var bool SKK_activeSignal3 = false
SKK_active = SKK_activeSignal and close < open and close < ema3 and superTrendRed
if SKK_active
    SKK_activeSignal := false
    SKK_activeSignal2 := true
// SuperTrend Crossover Rod to green
triggerCondition = SKK_activeSignal2 and superTrendRedToGreen
if triggerCondition
    SKK_activeSignal3 := true
// Detecting Trigger Candle
triggerCandle = SKK_activeSignal3 and isStockOrFund and isDaily and close > open and superTrendGreen
// Mark high of Trigger Candle
var float triggerHigh = na
if triggerCandle
    triggerHigh := high
    SKK_activeSignal3 := false
// Marking Trigger Candle for SKK
plotshape(series=show_AlertSignal and triggerCandle, title='SKK Alert Signal', location=location.belowbar, color=color.new(color.orange, 0), style=shape.triangleup, size=size.small, display = display.all - display.status_line)
// Buy Signal Condition
buySignal = close > triggerHigh and close > open
// SKK Final Buy Signal
// Mark high of Trigger Candle to na after Buy Signal true and Mark close of Buy Candle for Entry
var float buyClose = na
var float buyHigh = na
if buySignal
    triggerHigh := na
    buyClose := close
    buyHigh := high
// Convert buyClose value   
closeToHigh = high > buyClose and open <= buyClose and close < buyClose
// Calculate the crossover condition
crossoverCondition = ta.crossover(close, buyClose) or open > buyClose
// Calculate buySignal as per High instead of close
closeToHighCondition = high > buyHigh
// Check both condition
finalBuySignal = if closeToHigh
    closeToHighCondition
else
    crossoverCondition
if finalBuySignal
    buyClose := na
    buyHigh := na
    SKK_activeSignal := true
    SKK_activeSignal2 := false
// Plot Buy Signal
plotshape(series=show_AlertSignal and buySignal, title='SKK Buy Signal', location=location.belowbar, color=color.new(color.green, 0), style=shape.triangleup, size=size.small, display = display.all - display.status_line)
// SKK end
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// SKK2 System for accumulating Stocks for long-terms aggressive investment//
var bool triggerActive = true  // Mark Trigger Active
var bool SKK2Alert = false  // Mark Alert Active
// Define trigger candle condition for SKK2
triggerCandleCondition = triggerActive and isStock and isDaily and close < ema2 and rsi < 40 and close < open and close > ema3
SKK2Deactive = close < ema3
if triggerCandleCondition
    triggerActive := false
    SKK2Alert := true
// Define buy signal condition
buySignalCondition = SKK2Alert and rsi > 40 and close > open
// Mark high of Buy Signal Candle
var float buySignalHigh = na
if buySignalCondition
    buySignalHigh := high
// Mark Alert Re-ctive after Buy Signal Complete
if buySignalCondition or SKK2Deactive
    SKK2Alert := false
// SKK2 Final Buy Signal
SKK2finalBuySignal = high > buySignalHigh
if SKK2finalBuySignal or SKK2Deactive
    buySignalHigh := na
    triggerActive := true
// Plot shapes for the trigger candle condition
plotshape(series=show_AlertSignal and triggerCandleCondition, title='SKK2 Alert Signal', location=location.abovebar, color=color.new(color.red, 0), style=shape.triangledown, size=size.small, display = display.all - display.status_line)
// Plot shapes for the buy signal condition
plotshape(series=show_AlertSignal and buySignalCondition, title='SKK2 Buy Signal', location=location.belowbar, color=color.new(color.purple, 0), style=shape.triangleup, size=size.small, display = display.all - display.status_line)
//SKK2 end
