Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- //#region PREAMBLE
- // ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- // Copyright © 2022-2023 Iason Nikolas | jason5480
- // The "Click Signal Indicator" script may be freely distributed under the MIT license.
- //
- // Permission is hereby granted, free of charge,
- // to any person obtaining a copy of this software and associated documentation files (the "Software"),
- // to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge,
- // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
- // is furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in ALL COPIES or substantial portions of
- // the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
- // OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
- // OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- // Description
- // -----------------------------------------------------------------------------------------------------------------
- // This Signal Indicator emits signals based on mouse clicks when the indicator is added to the chart, or later
- // on in the "Settings/Inputs" tab by changing/selecting the open time of the desired bar of each one of the signals.
- // It is designed to be used as an External Input for "Template Trailing Strategy" to verify the correctness of the
- // features the aforementioned script offers, and to provide an easy way to play around with this framework.
- // Last but not least this script offers a way to debug and report problems when this is necessary. Moreover, this\
- // script is a simple example you can copy-paste and create your own custom signal indicator that can be "plugged into"
- // the "Template Trailing Strategy" taking advantage of all the fancy stuff the TTS framework can provide!
- // More spesifically this indicator will signal start long on the selected bar.
- // This indicator will signal start short on the selected bar
- // This indicator will signal end long on the selected bar.
- // This indicator will signal end short on the selected bar.
- // This indicator will signal cancel start long on the selected bar.
- // This indicator will signal cancel start short on the selected bar.
- // This indicator will signal cancel end long on the selected bar.
- // This indicator will signal cancel end short on the selected bar.
- //
- // -----------------------------------------------------------------------------------------------------------------
- // Disclaimer:
- // 1. I am not licensed financial advisors or broker-dealer. I do not tell you when or what to buy or sell.
- // I developed this software which enables you execute manual or automated trades using TradingView.
- // The software allows you to set the criteria you want for entering and exiting trades.
- // 2. Do not trade with money you cannot afford to lose.
- // 3. I do not guarantee consistent profits or that anyone can make money with no effort.
- // And I am not selling the holy grail.
- // 4. Every system can have winning and losing streaks.
- // 5. Money management plays a large role in the results of your trading. For example: lot size, account size,
- // broker leverage, and broker margin call rules all affect on results. Also, your Take Profit and Stop Loss
- // settings for individual pair trades and for overall account equity have a major impact on results.
- // If you are new to trading and do not understand these items, then I recommend you seek educational materials
- // to further your knowledge.
- //
- // YOU NEED TO FIND AND USE THE TRADING SYSTEM THAT WORKS BEST FOR YOU AND YOUR TRADING TOLERANCE.
- // I HAVE PROVIDED NOTHING MORE THAN A TOOL WITH OPTIONS FOR YOU TO TRADE WITH THIS PROGRAM ON TRADINGVIEW.
- //
- // I accept suggestions to improve the script.
- // If you encounter any problems I will be happy to share with me.
- // -----------------------------------------------------------------------------------------------------------------
- //#endregion ========================================================================================================
- //#region SETUP
- // ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- indicator(title = 'Click Signal Indicator',
- shorttitle = 'CSI',
- overlay = true)
- //#endregion ========================================================================================================
- //#region ⏱ Time
- // ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- // INPUT ============================================================================================================
- 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)
- 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)
- 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)
- 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)
- 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)
- 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)
- 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)
- 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)
- //#endregion ========================================================================================================
- //#region 📈 Filters
- // ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- // INPUT ============================================================================================================
- longDealsEnabled = input.bool(defval = true, title = 'Long Deals', inline = 'Long/Short Deals', group = '📈 Filters')
- 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')
- 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')
- cnlStartDealsEnabled = input.bool(defval = true, title = 'Cancel Start Deals', inline = 'Start/End Deals', group = '📈 Filters')
- 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')
- //#endregion ========================================================================================================
- //#region 🔌 Signal
- // ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- import jason5480/external_input_utils/5 as exiu
- // LOGIC ============================================================================================================
- // Start deals should happen when the main logic applies and the filters for that direction are approved
- bool startLongDeal = longDealsEnabled ? startLongTime == time : false
- bool startShortDeal = shortDealsEnabled ? startShortTime == time : false
- // End deals should happen when the main logic applies
- bool endLongDeal = endDealsEnabled and longDealsEnabled ? endLongTime == time : false
- bool endShortDeal = endDealsEnabled and shortDealsEnabled ? endShortTime == time : false
- // 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
- bool cnlStartLongDeal = cnlStartDealsEnabled and longDealsEnabled ? cnlStartLongTime == time : false
- bool cnlStartShortDeal = cnlStartDealsEnabled and shortDealsEnabled ? cnlStartShortTime == time : false
- // 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
- bool cnlEndLongDeal = cnlEndDealsEnabled and endDealsEnabled and longDealsEnabled ? cnlEndLongTime == time : false
- bool cnlEndShortDeal = cnlEndDealsEnabled and endDealsEnabled and shortDealsEnabled ? cnlEndShortTime == time : false
- // Compose the signal that will be passed to the "Template Trailing Strategy" following the "two channel mod div" convention
- float longChannelComp = 10.0 * (startLongDeal ? 2.0 : endLongDeal ? 1.0 : cnlStartLongDeal ? 4.0 : cnlEndLongDeal ? 3.0 : 0.0)
- float shortChannelComp = startShortDeal ? 2.0 : endShortDeal ? 1.0 : cnlStartShortDeal ? 4.0 : cnlEndShortDeal ? 3.0 : 0.0
- // This is the ONLY value that will be passed to the "Template Trailing Strategy" script as External Input
- float signal = longChannelComp + shortChannelComp
- // Decompose the produced signal using the same "two channel mod div" convention verify the correctness of the results
- // WARNING! At this point we assume that the "Template Trailiing Strategy" uses the same convention in order to interpret and
- // decode the given signal the same way this indicator does. You might want to check TTS "Settings/Input" tab Startegy - External
- // section. The default strategy settings should match the logic described below.
- bool startLongDealDec = exiu.eval_cond(signal, '/10==', 2.0)
- bool endLongDealDec = exiu.eval_cond(signal, '/10==', 1.0)
- bool cnlStartLongDealDec = exiu.eval_cond(signal, '/10==', 4.0)
- bool cnlEndLongDealDec = exiu.eval_cond(signal, '/10==', 3.0)
- bool startShortDealDec = exiu.eval_cond(signal, 'mod10==', 2.0)
- bool endShortDealDec = exiu.eval_cond(signal, 'mod10==', 1.0)
- bool cnlStartShortDealDec = exiu.eval_cond(signal, 'mod10==', 4.0)
- bool cnlEndShortDealDec = exiu.eval_cond(signal, 'mod10==', 3.0)
- // PLOT =============================================================================================================
- var longOpenColor = color.new(#2962FF, 70)
- var longCnlOpenColor = color.new(#3179F5, 70)
- var shortOpenColor = color.new(#FF1744, 70)
- var shortCnlOpenColor = color.new(#F7525F, 70)
- var closeColor = color.new(#D500F9, 70)
- var cnlCloseColor = color.new(#AB47BC, 70)
- plotshape(series = startLongDealDec, title = 'Start Long', style = shape.triangleup, location = location.belowbar, color = longOpenColor, size = size.small, display = display.pane + display.data_window)
- plotshape(series = endLongDealDec, title = 'End Long', style = shape.square, location = location.abovebar, color = closeColor, size = size.tiny, display = display.pane + display.data_window)
- plotshape(series = cnlStartLongDealDec, title = 'Cancel Start Long', style = shape.xcross, location = location.abovebar, color = longCnlOpenColor, size = size.tiny, display = display.pane + display.data_window)
- plotshape(series = cnlEndLongDealDec, title = 'Cancel End Long', style = shape.xcross, location = location.belowbar, color = cnlCloseColor, size = size.tiny, display = display.pane + display.data_window)
- plotshape(series = startShortDealDec, title = 'Start Short', style = shape.triangledown, location = location.abovebar, color = shortOpenColor, size = size.small, display = display.pane + display.data_window)
- plotshape(series = endShortDealDec, title = 'End Short', style = shape.square, location = location.belowbar, color = closeColor, size = size.tiny, display = display.pane + display.data_window)
- plotshape(series = cnlStartShortDealDec, title = 'Cancel Start Short', style = shape.xcross, location = location.belowbar, color = shortCnlOpenColor, size = size.tiny, display = display.pane + display.data_window)
- plotshape(series = cnlEndShortDealDec, title = 'Cancel End Short', style = shape.xcross, location = location.abovebar, color = cnlCloseColor, size = size.tiny, display = display.pane + display.data_window)
- // Use this indicator as an external input in scripts like "Template Trailing Strategy" that can utilize the signal value.
- // Emit the current signal value (21, 20, 10, 0, 01, 02, 12, 40, 30, 04, 03).
- plot(series = signal, title = '🔌Signal', color = color.olive, display = display.data_window + display.status_line)
- //#endregion ========================================================================================================
- //#region 🔔 ALERT MESSAGES
- // ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- // LOGIC ============================================================================================================
- if (startLongDealDec and barstate.isconfirmed)
- alert(message = 'Start Long')
- if (endLongDealDec and barstate.isconfirmed)
- alert(message = 'End Long')
- if (cnlStartLongDealDec and barstate.isconfirmed)
- alert(message = 'Cancel Start Long')
- if (cnlEndLongDealDec and barstate.isconfirmed)
- alert(message = 'Cancel End Long')
- if (startShortDealDec and barstate.isconfirmed)
- alert(message = 'Start Short')
- if (endShortDealDec and barstate.isconfirmed)
- alert(message = 'End Short')
- if (cnlStartShortDealDec and barstate.isconfirmed)
- alert(message = 'Cancel Start Short')
- if (cnlEndShortDealDec and barstate.isconfirmed)
- alert(message = 'Cancel End Short')
- //#endregion ========================================================================================================
Advertisement