I previously posted an alternative to TD sequential here. However, it was an imperfect first attempt at resembling TD. In the interest of avoiding trademark issues, I will call it The 913 signal or “913SIG”, and implement the code a bit differently. Here is the new and improved v2.0 with the following fixes:
- The code is overall more concise, elegant and easier to understand.
- Fixed bug where the bonus phase was triggering too many times in a row. Now ensures the bonus phase resets the entire indicator properly if interrupted or completed.
- Added 10 plot to show continuous transition from setup phase to bonus phase. Previously only plotted two warning plots before the 13(just 11 12 13, now it’s 10, 11, 12, 13.)
It’s okay to run this on tradingview privately (do not publish publicly or you may run into issues with new Tradingview policy). Enjoy:
//@version=5
indicator('913SIGv2', shorttitle='913SIGv2', overlay=true)
// Define the lookback periods using input options for user customization
lookbackSetup = input.int(4, "Lookback Setup", minval=1)
lookbackBonusSetup = input.int(2, "Lookback Bonus Setup", minval=1)
// Initialize counters
var int setupCountF = na
var int setupCountR = na
var int bonusCountF = na
var int bonusCountR = na
// Define the setup and bonus phases
setupPhaseF = close < close[lookbackSetup]
setupPhaseR = close > close[lookbackSetup]
bonusPhaseF = close < close[lookbackBonusSetup]
bonusPhaseR = close > close[lookbackBonusSetup]
// Increment counters or reset based on conditions
if setupPhaseF
setupCountF := na(setupCountF) ? 1 : setupCountF + 1
else
setupCountF := na
if setupPhaseR
setupCountR := na(setupCountR) ? 1 : setupCountR + 1
else
setupCountR := na
if setupCountF > 9 and bonusPhaseF
bonusCountF := na(bonusCountF) ? 1 : bonusCountF + 1
else
bonusCountF := na
if setupCountF > 9 and not bonusPhaseF
setupCountF := na
setupCountR := na
if setupCountR > 9 and bonusPhaseR
bonusCountR := na(bonusCountR) ? 1 : bonusCountR + 1
else
bonusCountR := na
if setupCountR > 9 and not bonusPhaseR
setupCountR := na
setupCountF := na
// Function to plot labels for easier code maintenance
plotLabel(condition, priceLevel, labelText, color, style, size) =>
if condition
label.new(x=bar_index, y=priceLevel, text=labelText, color=color, style=style, size=size)
// Plot labels for setups and bonuses
plotLabel(not na(setupCountF) and setupCountF >= 7 and setupCountF <= 9, low - syminfo.mintick * 2, str.tostring(setupCountF), color.rgb(33, 149, 243, 57 - 8 * (setupCountF - 7)), label.style_label_up, size.tiny)
plotLabel(not na(bonusCountF) and bonusCountF >= 1 and bonusCountF <= 4, low - syminfo.mintick * 2, str.tostring(bonusCountF + 9), color.rgb(33, 243, 243, 70 - 16 * (bonusCountF - 2)), label.style_label_up, size.tiny)
plotLabel(not na(setupCountR) and setupCountR >= 7 and setupCountR <= 9, high + syminfo.mintick * 2, str.tostring(setupCountR), color.rgb(238, 255, 0, 73 - 8 * (setupCountR - 7)), label.style_label_down, size.tiny)
plotLabel(not na(bonusCountR) and bonusCountR >= 1 and bonusCountR <= 4, high + syminfo.mintick * 2, str.tostring(bonusCountR + 9), color.rgb(33, 243, 243, 70 - 16 * (bonusCountR - 2)), label.style_label_down, size.tiny)
Leave a Reply