Advertisement
NKactive

NK Trend Trigger Factor

Nov 17th, 2023
177
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.93 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © NKactive
  3. //@version=5
  4.  
  5. strategy("NK Trend Trigger Factor", overlay=false, initial_capital=1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, pyramiding=0, slippage=1)
  6. import EliCobra/CobraMetrics/4 as cobra
  7. //// PLOT DATA
  8. 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 = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
  9. 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 = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
  10. type_table = input.string("None", "Table Type", options = ["Full", "Simple", "None"], group = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
  11. plot(cobra.curve(disp_ind))
  12. cobra.cobraTable(type_table, pos_table)
  13. //
  14. // ****************************************************************************************************************************************************************
  15. //
  16.  
  17. // Inputs
  18. timeframeTTF=input.timeframe(defval ='1D', group = "Trend Trigger", tooltip = "Select a different timeframe for this series") // Use Alternative timeframe
  19. length=input(30, group="Trend Trigger")
  20. bt = input( 100, title="Buy Trigger", group="Trend Trigger")
  21. st = input( -100, title="Sell Trigger", group="Trend Trigger")
  22. markCrossovers = input.bool(false, title="Mark Cross Overs", group="Trend Trigger", tooltip = "Just to make crossovers pretty")
  23.  
  24. // Functions
  25. prev(s,i) =>
  26. y=math.abs(math.round(i))
  27. s[y]
  28.  
  29. calc_ttf( periods ) =>
  30. bp = request.security(syminfo.tickerid,timeframeTTF, ta.highest(high, periods)) - prev( request.security(syminfo.tickerid,timeframeTTF, ta.lowest(low, periods)), - periods)
  31. sp = prev(request.security(syminfo.tickerid,timeframeTTF,ta.highest( high, periods )), - periods ) - request.security(syminfo.tickerid,timeframeTTF,ta.lowest(low, periods))
  32. 100 * (bp - sp) / ( 0.5*( bp + sp) )
  33.  
  34. //Calculation
  35. ttf = calc_ttf( length )
  36.  
  37. // Plot gray chart boundaries bt and bs
  38. plot(0, color=color.gray)
  39. btl=plot(bt, color=color.gray, linewidth = 3)
  40. stl=plot(st, color=color.gray, linewidth = 3)
  41.  
  42. long_f = request.security(syminfo.tickerid,timeframeTTF,ta.cross( ttf, st )) and request.security(syminfo.tickerid,timeframeTTF,ta.rising(ttf, 1))
  43. short_f = request.security(syminfo.tickerid,timeframeTTF,ta.cross(ttf, bt )) and request.security(syminfo.tickerid,timeframeTTF,ta.falling(ttf, 1))
  44.  
  45. bs = (ttf > bt) ? bt : ttf
  46. us = (ttf < st) ? st : ttf
  47. bl=plot(bs, color=color.white)
  48. ul=plot(us, color=color.white)
  49. tl=plot(ttf, title="TTF", color=markCrossovers ? (long_f ? color.green : short_f ? color.red : color.blue) : color.maroon, linewidth=2)
  50. fill(bl, tl, color.new(color.green, 75))
  51. fill(ul, tl, color.new(color.red, 75))
  52.  
  53. // ****************************************************************************************************************************************************************
  54. // Call combine signals and execute buy/sell positions within timeframe
  55. //.****************************************************************************************************************************************************************
  56. // Date Range To Include
  57. startDate = timestamp("2018-01-01T00:00")
  58. endDate = time
  59. // Check if the current timestamp is within the restricted range
  60. inRestrictedRange = time >= startDate and time <= endDate
  61. //
  62. // Buy Signals on overbought and oversold
  63. //
  64. if inRestrictedRange and long_f // ADD OTHER BUY SIGNAL BOOLS
  65. strategy.entry("My Long Entry Id", strategy.long, 100)
  66. if inRestrictedRange and short_f // ADD OTHER BUY SIGNAL BOOLS
  67. strategy.entry("My Short Entry Id", strategy.short, 100)
  68.  
  69.  
  70.  
Advertisement
Comments
  • # text 0.12 KB | 0 0
    1. 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