Stage Analysis
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © EquityCraze

//@version=5
indicator(title='Stage Analysis', overlay=true)

period = timeframe.period
valid_periods = period == 'D' or period == 'W'

// function to convert daily period to weekly period
get_sma_period(sma_input) =>
    if period == 'D'
        int(sma_input)
    else
        int(sma_input / 5)


dma50_days = get_sma_period(50)
dma150_days = get_sma_period(150)
dma200_days = get_sma_period(200)

dma50_days_visible = input(title='dma50_days', defval=false)
dma150_days_visible = input(title='dma150_days', defval=false)
dma200_days_visible = input(title='dma200_days', defval=false)

show_50_pointer = input(title='50X150', defval=true)
show_150_pointer = input(title='150X200', defval=true)
show_200_pointer = input(title='50X200', defval=true)

DMA50 = ta.sma(close, dma50_days)
DMA150 = ta.sma(close, dma150_days)
DMA200 = ta.sma(close, dma200_days)


if show_50_pointer and show_150_pointer and ta.crossunder(DMA50, DMA150) and valid_periods
    stage3_starting = label.new(bar_index, na, yloc=yloc.price, color=color.yellow, style=label.style_label_down, size=size.tiny)
    label.set_y(stage3_starting, DMA50)
    label.set_tooltip(stage3_starting, str.tostring(dma150_days) + ' x ' + str.tostring(dma50_days))
if show_50_pointer and show_150_pointer and ta.crossover(DMA50, DMA150) and valid_periods
    stage2_starting = label.new(bar_index, na, yloc=yloc.price, color=color.green, style=label.style_label_up, size=size.tiny)
    label.set_y(stage2_starting, DMA50)
    label.set_tooltip(stage2_starting, str.tostring(dma50_days) + ' x ' + str.tostring(dma150_days))
if show_50_pointer and show_200_pointer and ta.crossunder(DMA50, DMA200) and valid_periods
    stage4 = label.new(bar_index, na, yloc=yloc.price, color=color.red, style=label.style_label_down, size=size.tiny)
    label.set_y(stage4, DMA50)
    label.set_tooltip(stage4, str.tostring(dma200_days) + ' x ' + str.tostring(dma50_days))
if show_50_pointer and show_200_pointer and ta.crossover(DMA50, DMA200) and valid_periods
    stage2_accumulation = label.new(bar_index, na, yloc=yloc.price, color=color.green, style=label.style_label_up, size=size.tiny)
    label.set_y(stage2_accumulation, DMA50)
    label.set_tooltip(stage2_accumulation, str.tostring(dma50_days) + ' x ' + str.tostring(dma200_days))
if show_150_pointer and show_200_pointer and ta.crossunder(DMA150, DMA200) and valid_periods
    stage3_starting = label.new(bar_index, na, yloc=yloc.price, color=color.yellow, style=label.style_label_down, size=size.tiny)
    label.set_y(stage3_starting, DMA150)
    label.set_tooltip(stage3_starting, str.tostring(dma200_days) + ' x ' + str.tostring(dma150_days))
if show_150_pointer and show_200_pointer and ta.crossover(DMA150, DMA200) and valid_periods
    stage2_confirmed = label.new(bar_index, na, yloc=yloc.price, color=color.yellow, style=label.style_label_up, size=size.tiny)
    label.set_y(stage2_confirmed, DMA150)
    label.set_tooltip(stage2_confirmed, str.tostring(dma150_days) + ' x ' + str.tostring(dma200_days))


plot(dma50_days_visible and valid_periods ? DMA50 : na, color=color.new(color.green, 10), linewidth=1)
plot(dma150_days_visible and valid_periods ? DMA150 : na, color=color.new(color.yellow, 20), linewidth=2)
plot(dma200_days_visible and valid_periods ? DMA200 : na, color=color.new(color.red, 30), linewidth=3)

