xmd79

Click Signal Indicator

Mar 19th, 2023
890
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.41 KB | None | 0 0
  1. //@version=5
  2. //#region PREAMBLE
  3. // ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  4. // Copyright © 2022-2023 Iason Nikolas | jason5480
  5. // The "Click Signal Indicator" script may be freely distributed under the MIT license.
  6. //
  7. // Permission is hereby granted, free of charge,
  8. // to any person obtaining a copy of this software and associated documentation files (the "Software"),
  9. // to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge,
  10. // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
  11. // is furnished to do so, subject to the following conditions:
  12. //
  13. // The above copyright notice and this permission notice shall be included in ALL COPIES or substantial portions of
  14. // the Software.
  15. //
  16. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  17. // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  18. // OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
  19. // OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. //
  21. // Description
  22. // -----------------------------------------------------------------------------------------------------------------
  23. // This Signal Indicator emits signals based on mouse clicks when the indicator is added to the chart, or later
  24. // on in the "Settings/Inputs" tab by changing/selecting the open time of the desired bar of each one of the signals.
  25. // It is designed to be used as an External Input for "Template Trailing Strategy" to verify the correctness of the
  26. // features the aforementioned script offers, and to provide an easy way to play around with this framework.
  27. // Last but not least this script offers a way to debug and report problems when this is necessary. Moreover, this\
  28. // script is a simple example you can copy-paste and create your own custom signal indicator that can be "plugged into"
  29. // the "Template Trailing Strategy" taking advantage of all the fancy stuff the TTS framework can provide!
  30. // More spesifically this indicator will signal start long on the selected bar.
  31. // This indicator will signal start short on the selected bar
  32. // This indicator will signal end long on the selected bar.
  33. // This indicator will signal end short on the selected bar.
  34. // This indicator will signal cancel start long on the selected bar.
  35. // This indicator will signal cancel start short on the selected bar.
  36. // This indicator will signal cancel end long on the selected bar.
  37. // This indicator will signal cancel end short on the selected bar.
  38. //
  39. // -----------------------------------------------------------------------------------------------------------------
  40. // Disclaimer:
  41. // 1. I am not licensed financial advisors or broker-dealer. I do not tell you when or what to buy or sell.
  42. // I developed this software which enables you execute manual or automated trades using TradingView.
  43. // The software allows you to set the criteria you want for entering and exiting trades.
  44. // 2. Do not trade with money you cannot afford to lose.
  45. // 3. I do not guarantee consistent profits or that anyone can make money with no effort.
  46. // And I am not selling the holy grail.
  47. // 4. Every system can have winning and losing streaks.
  48. // 5. Money management plays a large role in the results of your trading. For example: lot size, account size,
  49. // broker leverage, and broker margin call rules all affect on results. Also, your Take Profit and Stop Loss
  50. // settings for individual pair trades and for overall account equity have a major impact on results.
  51. // If you are new to trading and do not understand these items, then I recommend you seek educational materials
  52. // to further your knowledge.
  53. //
  54. // YOU NEED TO FIND AND USE THE TRADING SYSTEM THAT WORKS BEST FOR YOU AND YOUR TRADING TOLERANCE.
  55. // I HAVE PROVIDED NOTHING MORE THAN A TOOL WITH OPTIONS FOR YOU TO TRADE WITH THIS PROGRAM ON TRADINGVIEW.
  56. //
  57. // I accept suggestions to improve the script.
  58. // If you encounter any problems I will be happy to share with me.
  59. // -----------------------------------------------------------------------------------------------------------------
  60. //#endregion ========================================================================================================
  61. //#region SETUP
  62. // ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  63. indicator(title = 'Click Signal Indicator',
  64. shorttitle = 'CSI',
  65. overlay = true)
  66.  
  67. //#endregion ========================================================================================================
  68. //#region ⏱ Time
  69. // ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  70.  
  71. // INPUT ============================================================================================================
  72. startLongTime = input.time(defval = timestamp('01 Jan 2023 00:00'), title = 'Start Long Bar', tooltip = 'Select the bar when the "start long" signal was emitted.', group = '⏱ Time', confirm = true)
  73. cnlStartLongTime = input.time(defval = timestamp('01 Jan 2023 04:00'), title = 'Cancel Start Long Bar', tooltip = 'Select the bar when the "cancel start long" signal was emitted.', group = '⏱ Time', confirm = true)
  74. endLongTime = input.time(defval = timestamp('02 Jan 2023 00:00'), title = 'End Long Bar', tooltip = 'Select the bar when the "end long" signal was emitted.', group = '⏱ Time', confirm = true)
  75. cnlEndLongTime = input.time(defval = timestamp('02 Jan 2023 04:00'), title = 'Cancel End Long Bar', tooltip = 'Select the bar when the "cancel end long" signal was emitted.', group = '⏱ Time', confirm = true)
  76. startShortTime = input.time(defval = timestamp('03 Jan 2023 00:00'), title = 'Start Short Bar', tooltip = 'Select the bar when the "start short" signal was emitted.', group = '⏱ Time', confirm = true)
  77. cnlStartShortTime = input.time(defval = timestamp('03 Jan 2023 04:00'), title = 'Cancel Start Short Bar', tooltip = 'Select the bar when the "cancel start short" signal was emitted.', group = '⏱ Time', confirm = true)
  78. endShortTime = input.time(defval = timestamp('04 Jan 2023 00:00'), title = 'End Short Bar', tooltip = 'Select the bar when the "end short" signal was emitted.', group = '⏱ Time', confirm = true)
  79. cnlEndShortTime = input.time(defval = timestamp('04 Jan 2023 04:00'), title = 'Cancel End Short Bar', tooltip = 'Select the bar when the "cancel end short" signal was emitted.', group = '⏱ Time', confirm = true)
  80.  
  81. //#endregion ========================================================================================================
  82. //#region 📈 Filters
  83. // ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  84.  
  85. // INPUT ============================================================================================================
  86. longDealsEnabled = input.bool(defval = true, title = 'Long Deals', inline = 'Long/Short Deals', group = '📈 Filters')
  87. shortDealsEnabled = input.bool(defval = true, title = 'Short Deals', tooltip = 'Enable long/short start/end/cancel deals. An open signal will be emited when the long/short start deal conditions are met. If this option is un-checked you will not enter into long/short positions.', inline = 'Long/Short Deals', group = '📈 Filters')
  88. endDealsEnabled = input.bool(defval = true, title = 'End Deals', tooltip = 'Enable end deals. A close signal will be emited when the end deal conditions are met. If this option is un-checked you will not exit your existing position based on the strategy logic. You will exit only when the stop loss or the take profit targets are reached.', group = '📈 Filters')
  89. cnlStartDealsEnabled = input.bool(defval = true, title = 'Cancel Start Deals', inline = 'Start/End Deals', group = '📈 Filters')
  90. cnlEndDealsEnabled = input.bool(defval = true, title = 'Cancel End Deals', tooltip = 'Enable cancel start/end deals. A cancel start/close signal will be emited when the cancel start/end deal conditions are met. If this option is un-checked you will not cancel your entry/exit order based on the strategy logic when trailing.', inline = 'Start/End Deals', group = '📈 Filters')
  91.  
  92. //#endregion ========================================================================================================
  93. //#region 🔌 Signal
  94. // ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  95.  
  96. import jason5480/external_input_utils/5 as exiu
  97.  
  98. // LOGIC ============================================================================================================
  99. // Start deals should happen when the main logic applies and the filters for that direction are approved
  100. bool startLongDeal = longDealsEnabled ? startLongTime == time : false
  101. bool startShortDeal = shortDealsEnabled ? startShortTime == time : false
  102. // End deals should happen when the main logic applies
  103. bool endLongDeal = endDealsEnabled and longDealsEnabled ? endLongTime == time : false
  104. bool endShortDeal = endDealsEnabled and shortDealsEnabled ? endShortTime == time : false
  105. // If you trailing for the entry and not entered yet you may want to cancel if the conditions are not still favorable to the initial direction
  106. bool cnlStartLongDeal = cnlStartDealsEnabled and longDealsEnabled ? cnlStartLongTime == time : false
  107. bool cnlStartShortDeal = cnlStartDealsEnabled and shortDealsEnabled ? cnlStartShortTime == time : false
  108. // If you are trailing for exit and not exited yet you may want to cancel if the conditions turned favorable again to the initial direction
  109. bool cnlEndLongDeal = cnlEndDealsEnabled and endDealsEnabled and longDealsEnabled ? cnlEndLongTime == time : false
  110. bool cnlEndShortDeal = cnlEndDealsEnabled and endDealsEnabled and shortDealsEnabled ? cnlEndShortTime == time : false
  111.  
  112. // Compose the signal that will be passed to the "Template Trailing Strategy" following the "two channel mod div" convention
  113. float longChannelComp = 10.0 * (startLongDeal ? 2.0 : endLongDeal ? 1.0 : cnlStartLongDeal ? 4.0 : cnlEndLongDeal ? 3.0 : 0.0)
  114. float shortChannelComp = startShortDeal ? 2.0 : endShortDeal ? 1.0 : cnlStartShortDeal ? 4.0 : cnlEndShortDeal ? 3.0 : 0.0
  115. // This is the ONLY value that will be passed to the "Template Trailing Strategy" script as External Input
  116. float signal = longChannelComp + shortChannelComp
  117.  
  118. // Decompose the produced signal using the same "two channel mod div" convention verify the correctness of the results
  119. // WARNING! At this point we assume that the "Template Trailiing Strategy" uses the same convention in order to interpret and
  120. // decode the given signal the same way this indicator does. You might want to check TTS "Settings/Input" tab Startegy - External
  121. // section. The default strategy settings should match the logic described below.
  122. bool startLongDealDec = exiu.eval_cond(signal, '/10==', 2.0)
  123. bool endLongDealDec = exiu.eval_cond(signal, '/10==', 1.0)
  124. bool cnlStartLongDealDec = exiu.eval_cond(signal, '/10==', 4.0)
  125. bool cnlEndLongDealDec = exiu.eval_cond(signal, '/10==', 3.0)
  126. bool startShortDealDec = exiu.eval_cond(signal, 'mod10==', 2.0)
  127. bool endShortDealDec = exiu.eval_cond(signal, 'mod10==', 1.0)
  128. bool cnlStartShortDealDec = exiu.eval_cond(signal, 'mod10==', 4.0)
  129. bool cnlEndShortDealDec = exiu.eval_cond(signal, 'mod10==', 3.0)
  130.  
  131. // PLOT =============================================================================================================
  132. var longOpenColor = color.new(#2962FF, 70)
  133. var longCnlOpenColor = color.new(#3179F5, 70)
  134. var shortOpenColor = color.new(#FF1744, 70)
  135. var shortCnlOpenColor = color.new(#F7525F, 70)
  136. var closeColor = color.new(#D500F9, 70)
  137. var cnlCloseColor = color.new(#AB47BC, 70)
  138. plotshape(series = startLongDealDec, title = 'Start Long', style = shape.triangleup, location = location.belowbar, color = longOpenColor, size = size.small, display = display.pane + display.data_window)
  139. plotshape(series = endLongDealDec, title = 'End Long', style = shape.square, location = location.abovebar, color = closeColor, size = size.tiny, display = display.pane + display.data_window)
  140. plotshape(series = cnlStartLongDealDec, title = 'Cancel Start Long', style = shape.xcross, location = location.abovebar, color = longCnlOpenColor, size = size.tiny, display = display.pane + display.data_window)
  141. plotshape(series = cnlEndLongDealDec, title = 'Cancel End Long', style = shape.xcross, location = location.belowbar, color = cnlCloseColor, size = size.tiny, display = display.pane + display.data_window)
  142. plotshape(series = startShortDealDec, title = 'Start Short', style = shape.triangledown, location = location.abovebar, color = shortOpenColor, size = size.small, display = display.pane + display.data_window)
  143. plotshape(series = endShortDealDec, title = 'End Short', style = shape.square, location = location.belowbar, color = closeColor, size = size.tiny, display = display.pane + display.data_window)
  144. plotshape(series = cnlStartShortDealDec, title = 'Cancel Start Short', style = shape.xcross, location = location.belowbar, color = shortCnlOpenColor, size = size.tiny, display = display.pane + display.data_window)
  145. plotshape(series = cnlEndShortDealDec, title = 'Cancel End Short', style = shape.xcross, location = location.abovebar, color = cnlCloseColor, size = size.tiny, display = display.pane + display.data_window)
  146.  
  147. // Use this indicator as an external input in scripts like "Template Trailing Strategy" that can utilize the signal value.
  148. // Emit the current signal value (21, 20, 10, 0, 01, 02, 12, 40, 30, 04, 03).
  149. plot(series = signal, title = '🔌Signal', color = color.olive, display = display.data_window + display.status_line)
  150.  
  151. //#endregion ========================================================================================================
  152. //#region 🔔 ALERT MESSAGES
  153. // ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  154.  
  155. // LOGIC ============================================================================================================
  156. if (startLongDealDec and barstate.isconfirmed)
  157. alert(message = 'Start Long')
  158.  
  159. if (endLongDealDec and barstate.isconfirmed)
  160. alert(message = 'End Long')
  161.  
  162. if (cnlStartLongDealDec and barstate.isconfirmed)
  163. alert(message = 'Cancel Start Long')
  164.  
  165. if (cnlEndLongDealDec and barstate.isconfirmed)
  166. alert(message = 'Cancel End Long')
  167.  
  168. if (startShortDealDec and barstate.isconfirmed)
  169. alert(message = 'Start Short')
  170.  
  171. if (endShortDealDec and barstate.isconfirmed)
  172. alert(message = 'End Short')
  173.  
  174. if (cnlStartShortDealDec and barstate.isconfirmed)
  175. alert(message = 'Cancel Start Short')
  176.  
  177. if (cnlEndShortDealDec and barstate.isconfirmed)
  178. alert(message = 'Cancel End Short')
  179.  
  180. //#endregion ========================================================================================================
Advertisement
Comments
Add Comment
Please, Sign In to add comment