Advertisement
NKactive

Untitled

Aug 5th, 2023
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 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.  
  4. //@version=5
  5. strategy("Logic Test NK.active") // , margin_long=100, margin_short=100)
  6.  
  7. // Simple Moving Average TPI Input
  8. // ************************************************************************************************************************************
  9. // Produce a 1 or long
  10. // produce a -1 for short
  11. longConditionSMACross = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))
  12. shortConditionSMACross = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))
  13. float SMACrossInputTPI = 0.00
  14. if longConditionSMACross
  15. SMACrossInputTPI := 1
  16. if shortConditionSMACross
  17. SMACrossInputTPI := -1
  18. // RSI TPI Input
  19. // ************************************************************************************************************************************
  20. // Produce a 1 or long
  21. // produce a -1 for short
  22. rsiValue = ta.rsi(close, 7)
  23. longConditionRSI = rsiValue < 25
  24. shortConditionRSI = rsiValue > 75
  25. float RSIInputTPI = 0.00
  26. if longConditionRSI or longConditionRSI[1] or longConditionRSI[2] or longConditionRSI[3] or longConditionRSI[4] or longConditionRSI[5]
  27. RSIInputTPI := 1
  28. if shortConditionRSI or shortConditionRSI[1] or shortConditionRSI[2] or shortConditionRSI[3] or shortConditionRSI[4] or shortConditionRSI[5]
  29. RSIInputTPI := -1
  30. // RVOL TPI Input
  31. // ************************************************************************************************************************************
  32. // Produce a 1 or long
  33. // produce a -1 for short
  34. //
  35. // Get volume data
  36. averageVol = ta.sma(volume, 100)
  37. ratioVol = volume / averageVol
  38. // Generate RVOL signal
  39. longConditionRVOL = ratioVol >= 2.5
  40. shortConditionRVOL = ratioVol <= 1
  41.  
  42. float RVOLInputTPI = 0.00
  43. if longConditionRVOL
  44. RVOLInputTPI := 1
  45. if shortConditionRVOL
  46. RVOLInputTPI := -1
  47. //
  48. // ************************************************************************************************************************************
  49. //
  50. // Logic to determine buy or sell signal
  51. //
  52. // Initialise variables
  53. triggerPositionBuy = false
  54. triggerPositionSell = false
  55. float triggerTPIvalue = 0.00
  56. //
  57. // Find the absolute triggerTPIvalue used to decide buy and sell signals
  58. triggerTPIvalue := math.avg(SMACrossInputTPI, RSIInputTPI, RVOLInputTPI)
  59. // Debugging code for triggerTPIvalue
  60. // plot(SMACrossInputTPI, color = color.blue, title = "SMACrossInputTPI") // this is the TPI input from the SMA Crossover
  61. // plot(RSIInputTPI, color = color.fuchsia, title = "RSIInputTPI") // this is the TPI input from the SMA Crossover
  62. // plot(RVOLInputTPI, color = color.green, title = "RVOLInputTPI") // this is the TPI input from the SMA Crossover
  63. //plot(triggerTPIvalue, color = color.white, linewidth = 2, title = "triggerTPIvalue") // this is the TPI input value calculated from the average of all the inputs
  64. //
  65. // Find the RoC of the TPI (percentage)
  66. //
  67. TPItriggerRoC = ta.roc(triggerTPIvalue, 1)
  68. //
  69. // Find trend bool for RoC Trend
  70. //
  71. TPIpositiveRoCtrend = false
  72. TPInegativeRoCtrend = false
  73. TPIpositiveRoCtrend := ta.rising(triggerTPIvalue, 1)
  74. TPInegativeRoCtrend := ta.falling(triggerTPIvalue, 1)
  75. // highest_bar_offset = ta.highest(triggerTPIvalue, 2)
  76. //TPItriggerRoC := highest_bar_offset - triggerTPIvalue
  77.  
  78.  
  79. plot(TPIpositiveRoCtrend ? 10 : na, title= "TPIpositiveRoCtrend", color = color.orange)
  80. plot(TPInegativeRoCtrend ? -10 : na, title= "TPInegativeRoCtrend", color = color.fuchsia)
  81. plot(triggerTPIvalue, title = "triggerTPIvalue", color = color.lime)
  82. plot(TPItriggerRoC, title= "TPItriggerRoC", color = color.gray)
  83. //
  84. // Combines the TPI value, RoC percent and RoC Trend
  85. //
  86. // triggerTPIvalue float
  87. // TPItriggerRoC float
  88. // TPIpositiveRoCtrend bool
  89. //
  90. if triggerTPIvalue >= 0.3 and (TPItriggerRoC >= 50 or TPIpositiveRoCtrend)
  91. triggerPositionBuy := true
  92. if triggerTPIvalue <= 0.3 and (TPItriggerRoC <= 50 or TPInegativeRoCtrend)
  93. triggerPositionSell := true
  94. //
  95. // Execute buy/sell positions based on the logic above
  96. // *************************************
  97. //
  98. if triggerPositionBuy
  99. strategy.entry("My Long Entry Id", strategy.long)
  100. if triggerPositionSell
  101. strategy.entry("My Short Entry Id", strategy.short)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement