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/
- // © Jackoooomate
- //@version=5
- strategy("BTC STRAT 2", overlay=true, pyramiding = 0, slippage = 1, initial_capital = 100, default_qty_type = strategy.percent_of_equity, default_qty_value = 100)
- // Plot Cobra Metrics Table
- import EliCobra/CobraMetrics/4 as cobra
- disp_ind = input.string ("Equity" , 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("Bottom Right", "Table Position", options = ["Top Left", "Middle Left", "Bottom Left", "Top Right", "Middle Right", "Bottom Right", "Top Center", "Bottom Center"], group = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
- type_table = input.string("Full", "Table Type", options = ["Full", "Simple", "None"], group = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
- plot(cobra.curve(disp_ind))
- cobra.cobraTable(type_table, pos_table)
- // Time Range
- startTime = input.time(defval = timestamp("01 January 2018"), title = "Start Date")
- isInTimeRange = time >= startTime
- //////////////////////////////////////////////////////////////////////////Main indicators////////////////////////////////////////////////////////////////////////
- // ****************************************************************************************************************************************************************
- // FranDMI
- // ****************************************************************************************************************************************************************
- lensig = input.int(8, title="ADX Smoothing", minval=1, maxval=50)
- lenDmi = input.int(5, 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)
- buyFranDMI = ta.cross(adx, plus)
- sellFranDMI = ta.cross(adx, minus)
- plot(adx, color=color.red)
- plot(plus, color=color.gray)
- plot(minus, color=color.gray)
- // ****************************************************************************************************************************************************************
- // Call combine signals and execute buy/sell positions within timeframe
- //.****************************************************************************************************************************************************************
- // Set Buy/Sell Condition
- goLong = buyFranDMI
- goShort = sellFranDMI
- // ****************************************************************************************************************************************************************
- //MACD
- // ****************************************************************************************************************************************************************
- // Inputs
- FastLength = input(title="MACD Fast Length", group="MACD", defval=47)
- Slowlength = input(title="MACD Slow Length", group="MACD", defval=79)
- MACDLength = input(title="MACD Signal Length", group="MACD", defval=29)
- thresholdMACD = input.int(title="MACD Threshold", group="MACD", defval=0)
- timeframe=input.timeframe(defval ='1D', group = "MACD", tooltip = "Select a different timeframe for this series") // Use Alternative timeframe
- MACD = request.security(syminfo.tickerid,timeframe , ta.ema(close, FastLength)) - request.security(syminfo.tickerid,timeframe , ta.ema(close, Slowlength))
- aMACD = request.security(syminfo.tickerid,timeframe , ta.ema(MACD, MACDLength))
- delta = MACD - aMACD
- // Testing plots
- //plot(MACD, color = color.blue)
- //plot(aMACD, color = color.red)
- plot(thresholdMACD, color = color.gray)
- plot(delta, color = color.green)
- // Calculate Buy/Sell orders intermittently
- LongMACD = ta.crossover(delta, thresholdMACD)
- ShortMACD = ta.crossunder(delta, thresholdMACD)
- // Calculate Buy/Sell orders intermittently
- //LongMACD = delta > thresholdMACD ? true : false
- //ShortMACD = delta < thresholdMACD ? true : false
- //////////////////////////////////////////////////////////////////
- // ****************************************************************************************************************************************************************
- // EverPSAR
- // ****************************************************************************************************************************************************************
- start = input.float(title='Start', step=0.001, defval=0.02)
- increment = input.float(title='Increment', step=0.001, defval=0.02)
- maximum = input.float(title='Maximum', step=0.01, defval=0.2)
- width = input.int(title='Point Width', minval=1, defval=2)
- highlightStartPoints = input(title='Highlight Start Points ?', defval=true)
- showLabels = input(title='Show Buy/Sell Labels ?', defval=true)
- highlightState = input(title='Highlight State ?', defval=true)
- psar = ta.sar(start, increment, maximum)
- dir = psar < close ? 1 : -1
- buyPSAR = dir == 1 and dir[1] == -1
- sellPSAR = dir == -1 and dir[1] == 1
- //Plots
- psarColor = dir == 1 ? #3388bb : #fdcc02
- psarPlot = plot(psar, title='PSAR', style=plot.style_circles, linewidth=width, color=color.new(psarColor, 0))
- var color longColor = color.green
- var color shortColor = color.red
- // Buy Plots
- plotshape(buyPSAR and highlightStartPoints ? psar : na, title='Long Start', location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(longColor, 50))
- plotshape(buyPSAR and showLabels ? psar : na, title='Buy Label', text='Buy', location=location.absolute, style=shape.labelup, size=size.tiny, color=color.new(longColor, 50), textcolor=color.new(color.white, 0))
- // Sell Plots
- plotshape(sellPSAR and highlightStartPoints ? psar : na, title='Short Start', location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(shortColor, 50))
- plotshape(sellPSAR and showLabels ? psar : na, title='Sell Label', text='Sell', location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(shortColor, 50), textcolor=color.new(color.white, 0))
- midPricePlot = plot(ohlc4, title='', display=display.none)
- fillColor = highlightState ? dir == 1 ? longColor : shortColor : na
- fill(midPricePlot, psarPlot, title='Trade State Filling', color=color.new(fillColor, 75))
- ////////////////////////////////////////////////////////
- src12= input.source(hlcc4, group= 'rsi')
- rsiLength= input.int(11, group= 'rsi')
- rsi = ta.rsi(src12, rsiLength)
- ysell= input.int(61)
- ybuy= input.int(54)
- longRSI = rsi > ybuy
- shortRSI = rsi < ysell
- // Date Range To Include
- startDate = timestamp("2018-01-01T00:00")
- endDate = time
- // Check if the current timestamp is within the restricted range
- inRestrictedRange = time >= startDate and time <= endDate
- //
- // Buy Signals on overbought and oversold
- //
- if inRestrictedRange and (buyPSAR and LongMACD or buyFranDMI ) and (buyFranDMI or LongMACD and longRSI)
- strategy.entry("LONG MATE ", strategy.long)
- if inRestrictedRange and (sellFranDMI and ShortMACD or (sellPSAR and shortRSI) )
- strategy.entry("SHORT MATE", strategy.short)
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