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/
- // © NKactive
- //@version=5
- strategy(title='[SHK] Schaff Trend Cycle (STC)', shorttitle='STC', overlay=false, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, initial_capital=1000, pyramiding=0, slippage=1)
- //Library
- import EliCobra/CobraMetrics/4 as cobra
- //// PConstruct Cobra Table
- 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("Full", "Table Type", options = ["Full", "Simple", "None"], group = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
- plot(cobra.curve(disp_ind))
- cobra.cobraTable(type_table, pos_table)
- EEEEEE = input(12, 'Length')
- BBBB = input(26, 'FastLength')
- BBBBB = input(50, 'SlowLength')
- // NK inputs for smoothing
- // boundary limits
- limitOn = input.bool(defval = false, title = 'Limit Smooth On?', group = 'Smoothing')
- lowLimit = input.int(defval = 25, title = 'Smoothing Low Limit', group = 'Smoothing')
- highLimit = input.int(defval = 75, title = 'Smoothing High Limit', group = 'Smoothing')
- // ema Smooth
- emaSmoothOn = input.bool(defval = false, title = 'ema Smooth On?', group = 'Smoothing')
- emaSmoothLen = input.int(defval = 12, title = 'Smoothing EMA', group = 'Smoothing')
- // wma Smooth
- wmaSmoothOn = input.bool(defval = false, title = 'wma Smooth On?', group = 'Smoothing')
- wmaSmoothLen = input.int(defval = 18, title = 'Smoothing WMA', group = 'Smoothing')
- //Functions
- AAAA(BBB, BBBB, BBBBB) =>
- fastMA = ta.ema(BBB, BBBB)
- slowMA = ta.ema(BBB, BBBBB)
- AAAA = fastMA - slowMA
- AAAA
- AAAAA(EEEEEE, BBBB, BBBBB) =>
- AAA = input.float(defval = 0.5, title = 'AAA', group = 'function', step = 0.1 )
- var CCCCC = 0.0
- var DDD = 0.0
- var DDDDDD = 0.0
- var EEEEE = 0.0
- BBBBBB = AAAA(close, BBBB, BBBBB)
- CCC = ta.lowest(BBBBBB, EEEEEE)
- CCCC = ta.highest(BBBBBB, EEEEEE) - CCC
- CCCCC := CCCC > 0 ? (BBBBBB - CCC) / CCCC * 100 : nz(CCCCC[1])
- DDD := na(DDD[1]) ? CCCCC : DDD[1] + AAA * (CCCCC - DDD[1])
- DDDD = ta.lowest(DDD, EEEEEE)
- DDDDD = ta.highest(DDD, EEEEEE) - DDDD
- DDDDDD := DDDDD > 0 ? (DDD - DDDD) / DDDDD * 100 : nz(DDDDDD[1])
- EEEEE := na(EEEEE[1]) ? DDDDDD : EEEEE[1] + AAA * (DDDDDD - EEEEE[1])
- EEEEE
- // Maths
- mAAAAA = AAAAA(EEEEEE, BBBB, BBBBB)
- mColor = mAAAAA > mAAAAA[1] ? color.new(color.green, 20) : color.new(color.red, 20)
- //ema and wma smoothing
- emaSmooth = ta.ema(mAAAAA, emaSmoothLen)
- plot(emaSmoothOn ? emaSmooth : na, color = color.white)
- wmaSmooth = ta.wma(mAAAAA, wmaSmoothLen)
- plot(wmaSmoothOn ? wmaSmooth : na, color = color.gray)
- // limit lines
- ll = plot(limitOn ? lowLimit : na, color=color.new(color.gray, 70), title = "LowerLimit")
- ul = plot(limitOn ? highLimit : na, color=color.new(color.gray, 70), title = 'UpperLimit')
- // fill(ul, ll, color=color.new(color.gray, 90)) // need to figure out how to use ? : to do the fill
- // logic NK.active for buy and sell
- BuySignal = mAAAAA >= mAAAAA[1] and (((mAAAAA[1] < lowLimit) and limitOn) or not limitOn) and (((mAAAAA <= wmaSmooth) and wmaSmoothOn) or not wmaSmoothOn) and (((mAAAAA <= emaSmooth) and emaSmoothOn) or not emaSmoothOn)
- SellSignal = mAAAAA < mAAAAA[1] and (((mAAAAA[1] > highLimit) and limitOn) or not limitOn) and (((mAAAAA >= wmaSmooth) and wmaSmoothOn) or not wmaSmoothOn) and (((mAAAAA >= emaSmooth) and emaSmoothOn) or not emaSmoothOn)
- // Kept for original logic incase needed
- //if mAAAAA[3] <= mAAAAA[2] and mAAAAA[2] > mAAAAA[1] and mAAAAA > 75
- // alert("Red", alert.freq_once_per_bar)
- //if mAAAAA[3] >= mAAAAA[2] and mAAAAA[2] < mAAAAA[1] and mAAAAA < 25
- // alert("Green", alert.freq_once_per_bar)
- // plot the STC line
- plot(mAAAAA, color=mColor, title='STC', linewidth=2)
- //
- // Define the start and end dates for the restricted range
- //
- //startDate = timestamp("2018-01-01T00:00")
- startDate = timestamp("2017-12-29T00:00")
- endDate = time
- // Check if the current timestamp is within the restricted range
- inRestrictedRange = time >= startDate and time <= endDate
- if BuySignal and inRestrictedRange
- strategy.entry("My Long Entry Id", strategy.long, qty = 100)
- if SellSignal and inRestrictedRange
- strategy.entry("My Short Entry Id", strategy.short, qty = 100)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement