💭 Overview
+ Title: Template Trailing Strategy (Backtester)
+ Author: Iason Nikolas (jason5480)
+ License: CC BY-NC-SA 4.0
💢 What is the "Template Trailing Strategy (Backtester)"❓
The "Template Trailing Strategy (Backtester)" (TTS) is a back-tester orchestration framework. It supercharges the implementation-test-evaluation lifecycle of new trading strategies, by making it possible to plug in your own trading idea.
While TTS offers a vast number of configuration settings, it primarily allows the trader to:
All of the above makes TTS a practical toolkit: once you learn it, many repetitive tasks that strategy authors usually re-implement are eliminated. Using TradingView’s built-in backtesting engine makes testing and comparing ideas straightforward.
By utilizing the TTS one can easily swap "trading logic" by testing, evaluating, and comparing each trading idea and/or individual component of a strategy.
Finally, TTS, through its per-event alert management (and debugging) system, provides an automated solution that supports live trading with brokers via webhooks.
NOTE: The "Template Trailing Strategy (Backtester)" does not dictate how you can combine different indicator types. Thus, it should not be confused as a "Trading System", because it gives its user full flexibility on that end (for better or worse).
💢 What is a "Signal Indicator"❓
"Signal Indicator" (SI) is an indicator that can output a "signal" that follows a specific convention so that the "Template Trailing Strategy (Backtester)" can "understand" and execute the orders accordingly. The SI realizes the core trading logic signaling to the TTS when to enter, exit, or cancel an order. A SI instructs the TTS "when" to enter or exit, and the TTS determines "how" to enter and exit the position once the Signal Indicator generates a signal.
A very simple example of a Signal Indicator might be a 200-day Simple Moving Average Signal. When the price of the security closes above the 200-day SMA, a SI would provide TTS with a "long entry signal". Once TTS receives the "long entry signal", the TTS will open a long position and send an alert or automated trade message via webhook to a broker, based on the Entry settings defined in TTS. If the TTS Entry settings specify a "Market" order type, then the open long position will be executed by TTS immediately. But if the TTS Entry settings specify a "Stop" order type with a 1% Stop Distance, then when the price of the security rises by 1% after the "long entry signal" occurs, the TTS will open a long position and the Long Entry alert or webhook to the broker will be sent.
🤔 How to Guide
💢 How to connect a "signal" from a "Signal Indicator"❓
The "Template Trailing Strategy (Backtester)" was designed to receive external signals from a "Signal Indicator". In this way, a "new trading idea" can be developed, configured, and evaluated separately from the TTS. Similarly, the SI can be held constant, and the trading mechanics can change in the TTS settings and back-tested to answer questions such as, "Am I better with a different stop loss placement method, what if I used a limit order instead of a stop order to enter, what if I used 25% margin instead of trading spot market?"
To make that possible by connecting an external signal indicator to TTS, you should:
Verbose troubleshooting & tips
💢 How to create a custom trading logic❓
The "Template Trailing Strategy (Backtester)" provides two ways to plug in your custom trading logic. Both of them have their advantages and disadvantages.
✍️ Develop your own Customized "Signal Indicator"💥
The first approach is meant to be used for relatively more complex trading logic. The advantages of this approach are the full control and customization you have over the trading logic and the relatively simple configuration setup by having two scripts only. The downsides are that you have to have some experience with pinescript or you are willing to learn and experiment. You should also know the exact formula for every indicator you will use since you have to write it by yourself. Copy-pasting from existing open-source indicators will get you started quite fast though.
The idea here is either to create a new indicator script from scratch or to copy an existing non-signal indicator and make it a "Signal Indicator". To create a new script, press the "Pine Editor" button below the chart to open the "Pine Editor" and then press the "Open" button to open the drop-down menu with the templates. Select the "New Indicator" option. Add it to your chart to copy an existing indicator and press the source code {} button. Its source code will be shown in the "Pine Editor" with a warning on top stating that this is a read-only script. Press the "create a working copy". Now you can give a descriptive title and a short title to your script, and you can work on (or copy-paste) the (other) indicators of your interest. Once you have the information needed to decide, define a DealConditions object and plot it like this:
Pine Script®
You should import the latest version of the tts_convention library and write your deal conditions appropriately based on your trading logic and put them in the code section shown above by replacing the "…" part after "=". You can omit the conditions that are not relevant to your logic. For example, if you use only market orders for entering and exiting your positions the cnlStartLongDeal, cnlStartShortDeal, cnlEndLongDeal, and cnlEndShortDeal are irrelevant to your case and can be safely omitted from the DealConditions object. After successfully compiling your new custom SI script add it to the same chart with the TTS by pressing the "Add to chart" button. If all goes well, you will be able to connect your "signal" to the TTS as described in the "How to connect a "signal" from a "Signal Indicator"?" guide.
🧩 Adapt and Combine existing non-signal indicators💥
The second approach is meant to be used for relatively simple trading logic. The advantages of this approach are the lack of pine script and coding experience needed and the fact that it can be used with closed-source indicators as long as the decision-making part is displayed as a line in the chart. The drawback is that you have to have a subscription that supports the "indicator on indicator" feature so you can connect the output of one indicator as an input to another indicator. Please check if your plan supports that feature here
To plug in your own logic that way you have to add your indicator(s) of preference in the chart and then add the "Signal Adapter" script in the same chart as well. This script is a "Signal Indicator" that can be used as a proxy to define your custom logic in the CONDITIONS group of the "Settings/Inputs" tab after defining your inputs from your preferred indicators in the VARIABLES group. Then a "signal" will be produced, if your logic is simple enough it can be directly connected to the TTS that is also added to the same chart for execution. Check the "How to connect a "signal" from a "Signal Indicator"?" in the "🤔 How to Guide" for more information.
If your logic is slightly more complicated, you can add a second "Signal Adapter" in your chart. Then you should add the "Signal Composer" in the same chart, go to the SIGNALS group of the "Settings/Inputs" tab, and connect the "signals" from the "Signal Adapters". "Signal Composer" is also a SI so its composed "signal" can be connected to the TTS the same way it is described in the "How to connect a "signal" from a "Signal Indicator"?" guide.
At this point, due to the composability of the framework, you can add an arbitrary number (bounded by your subscription of course) of "Signal Adapters" and "Signal Composers" before connecting the final "signal" to the TTS.
💢 How to set up ⏰Alerts❓
The "Template Trailing Strategy (Backtester)" provides a fully customizable per-event alert mechanism. This means that you may have an entirely different message for entering and exiting into a position, hitting a stop-loss or a take-profit target, changing trailing targets, etc. There are no restrictions, and this gives you great flexibility.
First enable the events you want under the "🔔 ALERT MESSAGES" module. Each enabled event exposes a text area where you can craft the message using placeholders that TTS replaces with actual values when the event occurs.
The placeholder categories (exact names used by the script) are:
Chart & instrument:
Entry / exit / stop / TP prices & offsets:
Quantities, percents & derived quantities:
❗ Important: the per-event alert text is injected into the Create Alert dialog using TradingView's strategy placeholder:
During the creation of a strategy alert, make sure the placeholder {{strategy.order.alert_message}} exists in the "Message" box. TradingView will substitute the per-event text you configured and enabled in TTS Settings/Inputs before sending it via webhook/notification.
Tip: For webhook/broker execution, set the proper "Condition" in the Create Alert dialog (for changing-entry/exit/SL notifications use "Order fills and alert() function calls" or "alert() function calls only" as appropriate).
💢 How to execute my orders in a broker❓
To execute your orders in a broker that supports webhook integration, you should enable the appropriate alerts in the "Template Trailing Strategy (Backtester)" first (see the "How to set up Alerts?" guide above). Then you should go to the "Create Alert/Notifications" tab check the "Webhook URL" and paste the URL provided by your broker. You have to read the documentation of your broker for more information on what messages are expected.
Keep in mind that some brokers have deep integration with TradingView so a per-event alert approach might be overkill.
📑 Definitions
This section tries to give some definitions in terms that appear in the "Settings/Inputs" tab of the "Template Trailing Strategy (Backtester)"
💢 What is Trailing❓
Trailing is a technique where a price target follows another "barrier" price (usually high or low) by trying to keep a maximum distance from the "barrier" when it moves in only one direction (up or down). When the "barrier" moves in the other direction the price target will not change. There are as many types of trailing as price targets, which means that there are entry trailing, exit trailing, stop-loss trailing, and take-profit trailing techniques.
💢 What is a Moonbag❓
A Moonbag in a trade is the quantity of the position that is reserved and will not be exited even if all take-profit targets defined in the strategy are hit, the quantity will be exited only if the stop-loss is hit or a close signal is received. This makes the stop-loss trailing technique in a trend-following strategy a good candidate to take advantage of a Moonbag.
💢 What is Distance❓
Distance is the difference between two prices.
💢 What is Bias❓
Bias is a psychological phenomenon where you make decisions based on market sentiment. For example, when you want to enter a long position you have a long bias, and when you want to exit from the long position you have a short bias. It is the other way around for the short position.
💢 What is the Bias Distance of a price target❓
The Bias Distance of a price target is the distance that the target will deviate from its initial price. The direction of this deviation depends on the bias of the market. For example, suppose you are in a long position, and you set a take-profit target to the local highest high. In that case, adding a bias distance of five ticks will place your take-profit target 5 ticks below this local highest high because you have a short bias when exiting a long position. When the bias is long the bias distance will be added resulting in a higher target price and when you have a short bias the bias distance will be subtracted.
⚙️ Settings
In the "Settings/Inputs" tab of the "Template Trailing Strategy (Backtester)", you can find all the customizable settings that are provided by the framework. The variety of those settings is vast; hence we will only scratch the surface here. However, for every setting, there is an information icon 🛈 where you can learn more if you mouse over it. The "Settings/Inputs" tab is divided into ten main groups. Each one of them is responsible for one module of the framework. Every setting is part of a group that is named after the module it represents. So, to spot the module of a setting find the title that appears above it comes with an emoji and uppercase letters. Some settings might have the same name but belong to different modules e.g. "Tgt Dist Mtd" (Target Distance Method). Some settings are indented, which means that they are closely related to the non-indented setting above. Usually, indented settings provide further configuration for one or more options of the non-indented setting above. The groups that correspond to each module of the framework are the following:
🗺️ Quick Module Cross-Reference (use emojis to jump to setting groups)
😲 Caveats
💢 Does "Template Trailing Strategy (Backtester)" have repainting behavior?❓
The answer is that the "Template Trailing Strategy (Backtester)" does not repaint as long as the "Signal Indicator" that is connected also does not repaint. If you developed your own SI make sure that you understand and know how to prevent this behavior. The publication by PineCoders here will give you a good idea on how to avoid most of the repainting cases.
⚠️ There is an exception though, when the "Enable Trail⚠️💹" checkbox is checked, the Take Profit trailing feature is enabled, and a tick-based approach is used, meaning that after a while, when the TradingView discards all the real-time data, assumptions will be made by the backtesting engine that will cause a form of repainting. To avoid making false assumptions please disable this feature in the early stages and evaluate its usefulness in your strategy later on, after first confirming the success of the logic without this feature. In this case, consider turning on the bar magnifier feature. This way you will get more accurate backtest results when the Take Profit trailing feature is enabled.
💢 Can "Template Trailing Strategy (Backtester)" satisfy all my trading strategies❓
While this framework can satisfy quite a large number of trading strategies there are cases where it cannot do so. For example, if you have a custom logic for your stop-loss or take-profit placement, or if you want to dollar cost average, then it might be better to start a new strategy script from scratch.
⚠️ It is not recommended to copy the official TTS code and start developing unless you are a Pine wizard! Even in that case, there is a stiff learning curve that might not be worth your time. Last, you must consider that I do not offer support for customized versions of the TTS script and if something goes wrong in the process you are all alone.
💝 Support & Feedback
For feedback, bug reports, or feature requests, contact me via TradingView PM or use the script comments.
Note: The author's personal links and contact are available on the TradingView profile.
🤗 Thanks
Special thanks to the welcoming community members, who regularly gave feedback all those years and helped me to shape the framework as it is today! Thanks everyone who contributed by either filing a "defect report" or asking questions that helped me to understand what improvements were necessary to help traders.
Enjoy!
Jason
+ Title: Template Trailing Strategy (Backtester)
+ Author: Iason Nikolas (jason5480)
+ License: CC BY-NC-SA 4.0
💢 What is the "Template Trailing Strategy (Backtester)"❓
The "Template Trailing Strategy (Backtester)" (TTS) is a back-tester orchestration framework. It supercharges the implementation-test-evaluation lifecycle of new trading strategies, by making it possible to plug in your own trading idea.
While TTS offers a vast number of configuration settings, it primarily allows the trader to:
- Test and evaluate your own trading logic that is described in terms of entry, exit, and cancellation conditions.
- Define the entry and exit order types as well as their target prices when the limit, stop, or stop-limit order types are used.
- Utilize a variety of options regarding the placement of the stop-loss and take-profit target(s) prices and support for well-known techniques like moving to breakeven and trailing.
- Provide well-known quantity calculation methods to properly handle risk management and easily evaluate trading strategies and compare them.
- Alert on each trading event or any related change through a robust and fully customizable messaging system.
All of the above makes TTS a practical toolkit: once you learn it, many repetitive tasks that strategy authors usually re-implement are eliminated. Using TradingView’s built-in backtesting engine makes testing and comparing ideas straightforward.
By utilizing the TTS one can easily swap "trading logic" by testing, evaluating, and comparing each trading idea and/or individual component of a strategy.
Finally, TTS, through its per-event alert management (and debugging) system, provides an automated solution that supports live trading with brokers via webhooks.
NOTE: The "Template Trailing Strategy (Backtester)" does not dictate how you can combine different indicator types. Thus, it should not be confused as a "Trading System", because it gives its user full flexibility on that end (for better or worse).
💢 What is a "Signal Indicator"❓
"Signal Indicator" (SI) is an indicator that can output a "signal" that follows a specific convention so that the "Template Trailing Strategy (Backtester)" can "understand" and execute the orders accordingly. The SI realizes the core trading logic signaling to the TTS when to enter, exit, or cancel an order. A SI instructs the TTS "when" to enter or exit, and the TTS determines "how" to enter and exit the position once the Signal Indicator generates a signal.
A very simple example of a Signal Indicator might be a 200-day Simple Moving Average Signal. When the price of the security closes above the 200-day SMA, a SI would provide TTS with a "long entry signal". Once TTS receives the "long entry signal", the TTS will open a long position and send an alert or automated trade message via webhook to a broker, based on the Entry settings defined in TTS. If the TTS Entry settings specify a "Market" order type, then the open long position will be executed by TTS immediately. But if the TTS Entry settings specify a "Stop" order type with a 1% Stop Distance, then when the price of the security rises by 1% after the "long entry signal" occurs, the TTS will open a long position and the Long Entry alert or webhook to the broker will be sent.
🤔 How to Guide
💢 How to connect a "signal" from a "Signal Indicator"❓
The "Template Trailing Strategy (Backtester)" was designed to receive external signals from a "Signal Indicator". In this way, a "new trading idea" can be developed, configured, and evaluated separately from the TTS. Similarly, the SI can be held constant, and the trading mechanics can change in the TTS settings and back-tested to answer questions such as, "Am I better with a different stop loss placement method, what if I used a limit order instead of a stop order to enter, what if I used 25% margin instead of trading spot market?"
To make that possible by connecting an external signal indicator to TTS, you should:
- Add both your SI (e.g. "Two MA Signal Indicator", "Click Signal Indicator", "Signal Adapter", "Signal Composer") and the TTS script to the same chart.
- Open the script's Settings / Inputs dialog for the TTS.
- In the 🛠️ STRATEGY group set 𝐃𝐞𝐚𝐥 𝐂𝐨𝐧𝐝𝐢𝐨𝐧𝐬 𝐌𝐨𝐝𝐞 to 🔨External (this makes TTS listen to an external signal source).
- Still inside 🛠️ STRATEGY locate the 🔌𝐒𝐢𝐠𝐧𝐚𝐥 🛈 input and choose the plotted output of your SI. The option should look like: "<SI short title>:🔌Signal to TTS".
Verbose troubleshooting & tips
- If the SI does not appear in the 🔌Signal 🛈 selector, confirm both scripts are added to the same chart and the SI exposes a plotted series (title often "🔌Signal to TTS").
- When using multiple SIs, pick the SI instance that actually outputs the "🔌Signal to TTS" plotted series.
- Validate on the chart: when your SI changes state, the plotted "🔌Signal" series in the TTS (visible in the data window) should change accordingly.
- The TTS accepts only signals that follow the tts_convention DealConditions structure. Do not attempt to feed arbitrary scalar series without using conv.getDealConditions / conv.DealConditions.
- Make sure your SI composes a DealConditions value following the TTS convention (startLong, endLong, startShort, endShort — optional cancel fields). See the template below.
- If the plot is present but TTS does not react, ensure the SI plot is non-repainting (or accept realtime/backtest limitations). Test on historical bars first.
- Create alerts on the strategy (see the Alerts section). Use the {{strategy.order.alert_message}} placeholder in the Create Alert dialog to forward TTS messages.
💢 How to create a custom trading logic❓
The "Template Trailing Strategy (Backtester)" provides two ways to plug in your custom trading logic. Both of them have their advantages and disadvantages.
✍️ Develop your own Customized "Signal Indicator"💥
The first approach is meant to be used for relatively more complex trading logic. The advantages of this approach are the full control and customization you have over the trading logic and the relatively simple configuration setup by having two scripts only. The downsides are that you have to have some experience with pinescript or you are willing to learn and experiment. You should also know the exact formula for every indicator you will use since you have to write it by yourself. Copy-pasting from existing open-source indicators will get you started quite fast though.
The idea here is either to create a new indicator script from scratch or to copy an existing non-signal indicator and make it a "Signal Indicator". To create a new script, press the "Pine Editor" button below the chart to open the "Pine Editor" and then press the "Open" button to open the drop-down menu with the templates. Select the "New Indicator" option. Add it to your chart to copy an existing indicator and press the source code {} button. Its source code will be shown in the "Pine Editor" with a warning on top stating that this is a read-only script. Press the "create a working copy". Now you can give a descriptive title and a short title to your script, and you can work on (or copy-paste) the (other) indicators of your interest. Once you have the information needed to decide, define a DealConditions object and plot it like this:
import jason5480/tts_convention/[version] as conv
// Calculate the start, end, cancel start, cancel end conditions
dealConditions = conv.DealConditions.new(
startLongDeal = [...],
startShortDeal = [...],
endLongDeal = [...],
endShortDeal = [...],
cnlStartLongDeal = [...],
cnlStartShortDeal = [...],
cnlEndLongDeal = [...],
cnlEndShortDeal = [...])
// Use this signal in scripts like "Template Trailing Strategy (Backtester)" and "Signal Composer" that can utilize its value
// Emit the current signal value according to the TTS framework convention
plot(series = conv.getSignal(dealConditions), title = '🔌Signal to TTS', color = #808000, editable = false, display = display.data_window + display.status_line, precision = 0)
You should import the latest version of the tts_convention library and write your deal conditions appropriately based on your trading logic and put them in the code section shown above by replacing the "…" part after "=". You can omit the conditions that are not relevant to your logic. For example, if you use only market orders for entering and exiting your positions the cnlStartLongDeal, cnlStartShortDeal, cnlEndLongDeal, and cnlEndShortDeal are irrelevant to your case and can be safely omitted from the DealConditions object. After successfully compiling your new custom SI script add it to the same chart with the TTS by pressing the "Add to chart" button. If all goes well, you will be able to connect your "signal" to the TTS as described in the "How to connect a "signal" from a "Signal Indicator"?" guide.
🧩 Adapt and Combine existing non-signal indicators💥
The second approach is meant to be used for relatively simple trading logic. The advantages of this approach are the lack of pine script and coding experience needed and the fact that it can be used with closed-source indicators as long as the decision-making part is displayed as a line in the chart. The drawback is that you have to have a subscription that supports the "indicator on indicator" feature so you can connect the output of one indicator as an input to another indicator. Please check if your plan supports that feature here
To plug in your own logic that way you have to add your indicator(s) of preference in the chart and then add the "Signal Adapter" script in the same chart as well. This script is a "Signal Indicator" that can be used as a proxy to define your custom logic in the CONDITIONS group of the "Settings/Inputs" tab after defining your inputs from your preferred indicators in the VARIABLES group. Then a "signal" will be produced, if your logic is simple enough it can be directly connected to the TTS that is also added to the same chart for execution. Check the "How to connect a "signal" from a "Signal Indicator"?" in the "🤔 How to Guide" for more information.
If your logic is slightly more complicated, you can add a second "Signal Adapter" in your chart. Then you should add the "Signal Composer" in the same chart, go to the SIGNALS group of the "Settings/Inputs" tab, and connect the "signals" from the "Signal Adapters". "Signal Composer" is also a SI so its composed "signal" can be connected to the TTS the same way it is described in the "How to connect a "signal" from a "Signal Indicator"?" guide.
At this point, due to the composability of the framework, you can add an arbitrary number (bounded by your subscription of course) of "Signal Adapters" and "Signal Composers" before connecting the final "signal" to the TTS.
💢 How to set up ⏰Alerts❓
The "Template Trailing Strategy (Backtester)" provides a fully customizable per-event alert mechanism. This means that you may have an entirely different message for entering and exiting into a position, hitting a stop-loss or a take-profit target, changing trailing targets, etc. There are no restrictions, and this gives you great flexibility.
First enable the events you want under the "🔔 ALERT MESSAGES" module. Each enabled event exposes a text area where you can craft the message using placeholders that TTS replaces with actual values when the event occurs.
The placeholder categories (exact names used by the script) are:
Chart & instrument:
- {{ticker}}
- {{base_currency}}
- {{quote_currency}}
Entry / exit / stop / TP prices & offsets:
- {{entry_price}}
- {{exit_price}}
- {{stop_loss_price}}
- {{take_profit_price_1}} ... {{take_profit_price_5}}
- {{entry+_price}}, {{entry-_price}}, {{exit+_price}}, {{exit-_price}} — Optional offset helpers (computed using "Offset Ticks")
Quantities, percents & derived quantities:
- {{entry_base_quantity}} — base units at entry (e.g. BTC)
- {{entry_quote_quantity}} — quote amount at entry (e.g. USD)
- {{risk_perc}} — % of capital risked for that entry (multiplied by 100 when "Percentage Range [0,100]" is enabled)
- {{remaining_quantity_perc}} — % of the initial position remaining at close/SL
- {{remaining_base_quantity}} — remaining base units at close/SL
- {{take_profit_quantity_perc_1}} ... {{take_profit_quantity_perc_5}} — % sold/bought at each TP
- {{take_profit_base_quantity_1}} ... {{take_profit_base_quantity_5}} — base units closed at each TP
❗ Important: the per-event alert text is injected into the Create Alert dialog using TradingView's strategy placeholder:
- {{strategy.order.alert_message}}
During the creation of a strategy alert, make sure the placeholder {{strategy.order.alert_message}} exists in the "Message" box. TradingView will substitute the per-event text you configured and enabled in TTS Settings/Inputs before sending it via webhook/notification.
Tip: For webhook/broker execution, set the proper "Condition" in the Create Alert dialog (for changing-entry/exit/SL notifications use "Order fills and alert() function calls" or "alert() function calls only" as appropriate).
💢 How to execute my orders in a broker❓
To execute your orders in a broker that supports webhook integration, you should enable the appropriate alerts in the "Template Trailing Strategy (Backtester)" first (see the "How to set up Alerts?" guide above). Then you should go to the "Create Alert/Notifications" tab check the "Webhook URL" and paste the URL provided by your broker. You have to read the documentation of your broker for more information on what messages are expected.
Keep in mind that some brokers have deep integration with TradingView so a per-event alert approach might be overkill.
📑 Definitions
This section tries to give some definitions in terms that appear in the "Settings/Inputs" tab of the "Template Trailing Strategy (Backtester)"
💢 What is Trailing❓
Trailing is a technique where a price target follows another "barrier" price (usually high or low) by trying to keep a maximum distance from the "barrier" when it moves in only one direction (up or down). When the "barrier" moves in the other direction the price target will not change. There are as many types of trailing as price targets, which means that there are entry trailing, exit trailing, stop-loss trailing, and take-profit trailing techniques.
💢 What is a Moonbag❓
A Moonbag in a trade is the quantity of the position that is reserved and will not be exited even if all take-profit targets defined in the strategy are hit, the quantity will be exited only if the stop-loss is hit or a close signal is received. This makes the stop-loss trailing technique in a trend-following strategy a good candidate to take advantage of a Moonbag.
💢 What is Distance❓
Distance is the difference between two prices.
💢 What is Bias❓
Bias is a psychological phenomenon where you make decisions based on market sentiment. For example, when you want to enter a long position you have a long bias, and when you want to exit from the long position you have a short bias. It is the other way around for the short position.
💢 What is the Bias Distance of a price target❓
The Bias Distance of a price target is the distance that the target will deviate from its initial price. The direction of this deviation depends on the bias of the market. For example, suppose you are in a long position, and you set a take-profit target to the local highest high. In that case, adding a bias distance of five ticks will place your take-profit target 5 ticks below this local highest high because you have a short bias when exiting a long position. When the bias is long the bias distance will be added resulting in a higher target price and when you have a short bias the bias distance will be subtracted.
⚙️ Settings
In the "Settings/Inputs" tab of the "Template Trailing Strategy (Backtester)", you can find all the customizable settings that are provided by the framework. The variety of those settings is vast; hence we will only scratch the surface here. However, for every setting, there is an information icon 🛈 where you can learn more if you mouse over it. The "Settings/Inputs" tab is divided into ten main groups. Each one of them is responsible for one module of the framework. Every setting is part of a group that is named after the module it represents. So, to spot the module of a setting find the title that appears above it comes with an emoji and uppercase letters. Some settings might have the same name but belong to different modules e.g. "Tgt Dist Mtd" (Target Distance Method). Some settings are indented, which means that they are closely related to the non-indented setting above. Usually, indented settings provide further configuration for one or more options of the non-indented setting above. The groups that correspond to each module of the framework are the following:
🗺️ Quick Module Cross-Reference (use emojis to jump to setting groups)
- 📆 FILTERS — session, date & weekday filters
- 🛠️ STRATEGY — internal vs external deal-conditions; pick the signal source
- 🔧 STRATEGY – INTERNAL — built-in Two MA logic for demonstration purposes
- 🎢 VOLATILITY — ATR / StDev update modes
- 🔷 ENTRY — entry order types & trailing
- 🎯 TAKE PROFIT — multi-step TP and trailing rules
- 🛑 STOP LOSS — stop placement, move-to-breakeven, trailing
- 🟪 EXIT — exit order types & cancel logic
- 💰 QUANTITY/RISK MANAGEMENT — position sizing, moonbag, limits
- 📊 ANALYTICS — stats, streaks, seasonal tables
- 🔔 ALERT MESSAGES — per-event alert templates & placeholders
😲 Caveats
💢 Does "Template Trailing Strategy (Backtester)" have repainting behavior?❓
The answer is that the "Template Trailing Strategy (Backtester)" does not repaint as long as the "Signal Indicator" that is connected also does not repaint. If you developed your own SI make sure that you understand and know how to prevent this behavior. The publication by PineCoders here will give you a good idea on how to avoid most of the repainting cases.
⚠️ There is an exception though, when the "Enable Trail⚠️💹" checkbox is checked, the Take Profit trailing feature is enabled, and a tick-based approach is used, meaning that after a while, when the TradingView discards all the real-time data, assumptions will be made by the backtesting engine that will cause a form of repainting. To avoid making false assumptions please disable this feature in the early stages and evaluate its usefulness in your strategy later on, after first confirming the success of the logic without this feature. In this case, consider turning on the bar magnifier feature. This way you will get more accurate backtest results when the Take Profit trailing feature is enabled.
💢 Can "Template Trailing Strategy (Backtester)" satisfy all my trading strategies❓
While this framework can satisfy quite a large number of trading strategies there are cases where it cannot do so. For example, if you have a custom logic for your stop-loss or take-profit placement, or if you want to dollar cost average, then it might be better to start a new strategy script from scratch.
⚠️ It is not recommended to copy the official TTS code and start developing unless you are a Pine wizard! Even in that case, there is a stiff learning curve that might not be worth your time. Last, you must consider that I do not offer support for customized versions of the TTS script and if something goes wrong in the process you are all alone.
💝 Support & Feedback
For feedback, bug reports, or feature requests, contact me via TradingView PM or use the script comments.
Note: The author's personal links and contact are available on the TradingView profile.
🤗 Thanks
Special thanks to the welcoming community members, who regularly gave feedback all those years and helped me to shape the framework as it is today! Thanks everyone who contributed by either filing a "defect report" or asking questions that helped me to understand what improvements were necessary to help traders.
Enjoy!
Jason
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
📧 Contact info
Telegram: @jason5480
🔗 Addresses
₿ - bc1qxh3jeld7ke70fx3r5q243d96jsx0etth6x8fa7
* Please contact me before any donation ☕
Telegram: @jason5480
🔗 Addresses
₿ - bc1qxh3jeld7ke70fx3r5q243d96jsx0etth6x8fa7
* Please contact me before any donation ☕
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
📧 Contact info
Telegram: @jason5480
🔗 Addresses
₿ - bc1qxh3jeld7ke70fx3r5q243d96jsx0etth6x8fa7
* Please contact me before any donation ☕
Telegram: @jason5480
🔗 Addresses
₿ - bc1qxh3jeld7ke70fx3r5q243d96jsx0etth6x8fa7
* Please contact me before any donation ☕
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。