Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © vigilmiguel
- //@version=5
- strategy(title='TOTAL MACD DMI Aroon (3)', overlay=true, default_qty_type = strategy.percent_of_equity , pyramiding=1 , initial_capital = 1000000000000 , default_qty_value = 100)
- // Date Range
- start_date = input.int(title='Start Date', defval=1, minval=1, maxval=31, group='Date Range', inline='1')
- end_date = input.int(title='End Date', defval=1, minval=1, maxval=31, group='Date Range', inline='1')
- start_month = input.int(title='Start Month', defval=1, minval=1, maxval=12, group='Date Range', inline='2')
- end_month = input.int(title='End Month', defval=1, minval=1, maxval=12, group='Date Range', inline='2')
- start_year = input.int(title='Start Year', defval=2018, minval=1800, maxval=3000, group='Date Range', inline='3')
- end_year = input.int(title='End Year', defval=2024, minval=1800, maxval=3000, group='Date Range', inline='3')
- in_date_range = time >= timestamp(syminfo.timezone, start_year, start_month, start_date, 0, 0) and time < timestamp(syminfo.timezone, end_year, end_month, end_date, 0, 0)
- // Import cobra
- import EliCobra/CobraMetrics/4 as cobra
- //// PLOT DATA
- disp_ind = input.string ("None" , title = "Display Curve" , tooltip = "Choose which data you would like to display", options=["Strategy", "Equity", "Open Profit", "Gross Profit", "Net Profit", "None"], group = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
- pos_table = input.string("Middle Left", "Table Position", options = ["Top Left", "Middle Left", "Bottom Left", "Top Right", "Middle Right", "Bottom Right", "Top Center", "Bottom Center"], group = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
- type_table = input.string("None", "Table Type", options = ["Full", "Simple", "None"], group = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
- plot(cobra.curve(disp_ind))
- cobra.cobraTable(type_table, pos_table)
- price = close
- longMsg = ""
- shortMsg = ""
- // Getting inputs
- fast_length = input(title="Fast Length", defval=2)
- slow_length = input(title="Slow Length", defval=35)
- src = input(title="Source", defval=close)
- sma_source = input.string(title="Oscillator MA Type", defval="SMA", options=["SMA", "EMA"])
- // Calculating
- fast_ma = sma_source == "SMA" ? ta.sma(src, fast_length) : ta.ema(src, fast_length)
- slow_ma = sma_source == "SMA" ? ta.sma(src, slow_length) : ta.ema(src, slow_length)
- macd = fast_ma - slow_ma
- long=ta.crossover(macd,0)
- short=ta.crossunder(macd,0)
- if long
- longMsg += "MACD "
- if short
- shortMsg += "MACD "
- //plot(delta, title="Histogram", style=plot.style_columns, color=(delta>=0 ? (delta[1] < delta ? #26A69A : #B2DFDB) : (delta[1] < delta ? #FFCDD2 : #FF5252)))
- lensig = input.int(9, title="ADX Smoothing", minval=1, maxval=50)
- lenDmi = input.int(6, minval=1, title="DI Length")
- upD = ta.change(high)
- downD = -ta.change(low)
- plusDM = na(upD) ? na : (upD > downD and upD > 0 ? upD : 0)
- minusDM = na(downD) ? na : (downD > upD and downD > 0 ? downD : 0)
- trur = ta.rma(ta.tr, lenDmi)
- plus = fixnan(550 * ta.rma(plusDM, lenDmi) / trur)
- minus = fixnan(500 * ta.rma(minusDM, lenDmi) / trur)
- sum = plus + minus
- adx = 520 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), lensig)
- long_condition = ta.cross(adx, plus)
- short_condition = ta.cross(adx, minus)
- if long_condition
- longMsg += "DMI "
- if short_condition
- shortMsg += "DMI "
- // plot(plus, color=color.green, title="+DI")
- // plot(minus, color=color.red, title="-DI")
- // plot(adx, color=color.orange, title="ADX")
- // hlineup = hline(30, color=#787B86)
- fastLength = input(title='MACD Fast Length', defval=9)
- slowLength = input(title='MACD Slow Length', defval=34)
- cycleLength = input(title='Cycle Length', defval=11)
- d1Length = input(title='1st %D Length', defval=1)
- d2Length = input(title='2nd %D Length', defval=4)
- src1 = close
- upper = 75
- lower = 25
- macd1 = ta.ema(src1, fastLength) - ta.ema(src1, slowLength)
- k = nz(fixnan(ta.stoch(macd1, macd1, macd1, cycleLength)))
- d = ta.ema(k, d1Length)
- kd = nz(fixnan(ta.stoch(d, d, d, cycleLength)))
- stc = ta.ema(kd, d2Length)
- stc := math.max(math.min(stc, 100), 0)
- buySignal = ta.crossover(stc, lower)
- sellSignal = ta.crossunder(stc, upper)
- if buySignal
- longMsg += "AROON "
- if sellSignal
- shortMsg += "AROON "
- src12= input.source(hl2, group= 'rsi')
- rsiLength= input.int(11, group= 'rsi')
- rsi = ta.rsi(src12, rsiLength)
- ysell= input.int(51)
- ybuy= input.int(61)
- longRSI = rsi > ybuy
- shortRSI = rsi < ysell
- SLP_long = (long or long_condition or buySignal and longRSI ) and (longRSI and long) or (longRSI and long_condition) or (longRSI and buySignal)
- SLP_short = (short or short_condition or sellSignal and shortRSI) and (shortRSI and short) or( shortRSI and short_condition) or (shortRSI and sellSignal)
- if (SLP_long and in_date_range)
- strategy.entry("SLP", strategy.long, comment = longMsg)
- else if (SLP_short and in_date_range)
- strategy.entry("SLP", strategy.short, comment = shortMsg)
Advertisement
Comments
-
- download all types of premium tradingview indicators codes available on telegram - https://t.me/tradingview_premium_indicator
Add Comment
Please, Sign In to add comment
Advertisement