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/
- // © Specalist333
- //@version=5
- strategy("BTC Specalist V1", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, pyramiding=0, slippage=1)
- // Date Range (and limits start date for level 1 submission)
- 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)
- // Inport 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)
- //EMAs
- // - EMA1 superfast
- // - EMA2 slow
- // - EMA1 very slow
- EMA_Length_1 = input.int(title="EMA 1 Length", group="EMA", defval=5)
- EMA_Length_2 = input.int(title="EMA 2 Length", group="EMA", defval=50)
- EMA_Length_3 = input.int(title="EMA 3 Length", group="EMA", defval=98)
- EMA1 = ta.ema(close, EMA_Length_1)
- EMA2 = ta.ema(close, EMA_Length_2)
- EMA3 = ta.ema(close, EMA_Length_3)
- // Use these plots to visualise what the code is doing
- //plot(EMA1, color=color.red, title = "EMA1", linewidth=10) // NK Debug
- //plot(EMA2, color=color.white, title = "EMA2", linewidth=5)// NK Debug
- //plot(EMA3, color=color.blue, title = "EMA3", linewidth=2) // NK Debug
- // Price Volatility
- // Calcualtes the price volatility giving extrream +ve value for upwards trends and -ve for downward trends
- // volatilityLower and volatilityHigher used later to filter
- volatilityLower = input.float(title = "Lower Range", defval= -39, group = "VRG")
- volatilityHigher = input.float(title = "Higher Range", defval= 9)
- volatilityLength = 58
- volatilityRange = ta.sma(close - open, volatilityLength)
- // Use this plot to visualise what the code is doing
- // plot(volatilityRange, color=color.fuchsia, title = "sma")// NK Debug
- //MACD
- FastLength = input(title="MACD Fast Length", group="MACD", defval=56)
- Slowlength = input(title="MACD Slow Length", group="MACD", defval=73)
- MACDLength = input(title="MACD Signal Length", group="MACD", defval=26)
- MACD = ta.ema(close, FastLength) - ta.ema(close, Slowlength)
- aMACD = ta.ema(MACD, MACDLength)
- delta = MACD - aMACD
- // Use these plots to visualise what the code is doing
- //plot(MACD, color=color.red, title = "MACD", linewidth=10) // NK Debug
- //plot(aMACD, color=color.white, title = "aMACD", linewidth=5) // NK Debug
- //plot(delta, color=color.blue, title = "delta", linewidth=10) // NK Debug
- //STRATEGY PARAMETERS
- start= timestamp(2012,1,1,0,0)
- timeCond = time > start
- // Picking up ANY possible buy/sell signal using all EMAs
- LongEMA = ta.crossover(EMA1, EMA2) or ta.crossover(EMA1, EMA3) or ta.crossover(EMA2, EMA3)
- ShortEMA = ta.crossunder(EMA1, EMA2) or ta.crossunder(EMA1, EMA3) or ta.crossunder(EMA2, EMA3)
- // Using the differnce between the MACDs to find buy/sell signals
- LongMACD = ta.crossover(delta, 0)
- ShortMACD = ta.crossunder(delta, 0)
- // Checks Market Direction
- VRL = volatilityRange > volatilityLower
- VRS = volatilityRange < volatilityHigher
- // Builds bool for buy/sell based on individual indictor calculations
- Long = (LongMACD and LongEMA) or (LongMACD and VRL) or (LongEMA and VRL)
- Short = (ShortMACD and ShortEMA) or (ShortMACD and VRS) or (ShortEMA and VRS)
- strategy.entry("Open Long", strategy.long, when=Long and in_date_range)
- strategy.entry("Open Short", strategy.short, when=Short and in_date_range)
- //these strategy.entry commands are fine but will be phased out in future iterations
- // I have added 100% of euqity to the entry to avoid margin calls
- //if Long and in_date_range
- // strategy.entry("Open Long", strategy.long, 100)
- //if Short and in_date_range
- // strategy.entry("Open Short", strategy.short, 100)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement