Supertrend Alert with Arrows and Time Filter

Overview
This script is designed to generate trading signals based on the Supertrend indicator, a popular technical analysis tool. The Supertrend indicator is used to identify the direction of the market trend and potential reversal points.

Supertrend Settings
The script uses two sets of Supertrend settings:

Small Supertrend
  • Factor: 3.0
  • ATR Period: 10

Big Supertrend
  • Factor: 10.0
  • ATR Period: 30

These settings are fixed and should not be altered to maintain the integrity of the signal generation process.

Configurable Parameters
  • startHour: The hour at which signal generation begins.
  • endHour: The hour at which signal generation ends.
These parameters allow users to focus on specific trading hours, optimizing the signal relevance to their trading strategy.

Signal Types
The script generates two types of signals:

Type 1: Reversal Signal
  • Long Signal: Triggered when the big Supertrend is in an uptrend, and the small Supertrend transitions from a downtrend to an uptrend.
  • Short Signal: Triggered when the big Supertrend is in a downtrend, and the small Supertrend transitions from an uptrend to a downtrend.

Type 2: Trend Change Signal
  • Long Signal: Triggered when the big Supertrend changes from a downtrend to an uptrend.
  • Short Signal: Triggered when the big Supertrend changes from an uptrend to a downtrend.

How the Script Works
  • Initialization: The script initializes with predefined Supertrend settings.
  • Data Input: Market data (e.g., price data) is fed into the script.
  • Supertrend Calculation: The script calculates the Supertrend values using the predefined factors and ATR periods.
  • Signal Detection: The script monitors the Supertrend values and detects the defined signals based on the conditions mentioned above.
  • Time Filtering: Signals are filtered based on the specified startHour and endHour, ensuring only relevant signals are displayed within the desired timeframe.

    Usage
  • Set Parameters: Define startHour and endHour according to your trading schedule.
  • Run Script: Execute the script with market data input.
  • Interpret Signals: Monitor the generated signals and use them to inform your trading decisions.

    Originality
  • Dual Supertrend Usage: The use of both a small and a big Supertrend to generate signals adds a layer of complexity and reliability to the signals.
  • Time-Based Filtering: Allows traders to focus on specific trading hours, enhancing the relevance and accuracy of signals.
  • Two Signal Types: The combination of reversal signals and trend change signals provides comprehensive market insights.

Conclusion
This Supertrend Signal Generator is a robust tool for traders seeking to leverage the Supertrend indicator for more informed trading decisions. By combining dual Supertrend settings and configurable trading hours, the script offers unique and flexible signal generation capabilities.

3VEv9jf.png



Can Supertrend Alert with Arrows and Time Filter be converted?
https://www.tradingview.com/v/2HRVpCyp/

mod note:
script converted. find the ToS code below
 
Last edited by a moderator:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Can Supertrend Alert with Arrows and Time Filter be converted?
https://www.tradingview.com/v/2HRVpCyp/

Overview
This script is designed to generate trading signals based on the Supertrend indicator, a popular technical analysis tool. The Supertrend indicator is used to identify the direction of the market trend and potential reversal points.

Supertrend Settings
The script uses two sets of Supertrend settings:

Small Supertrend
  • Factor: 3.0
  • ATR Period: 10

Big Supertrend
  • Factor: 10.0
  • ATR Period: 30

These settings are fixed and should not be altered to maintain the integrity of the signal generation process.

Configurable Parameters
  • startHour: The hour at which signal generation begins.
  • endHour: The hour at which signal generation ends.
These parameters allow users to focus on specific trading hours, optimizing the signal relevance to their trading strategy.

Signal Types
The script generates two types of signals:

Type 1: Reversal Signal
  • Long Signal: Triggered when the big Supertrend is in an uptrend, and the small Supertrend transitions from a downtrend to an uptrend.
  • Short Signal: Triggered when the big Supertrend is in a downtrend, and the small Supertrend transitions from an uptrend to a downtrend.

Type 2: Trend Change Signal
  • Long Signal: Triggered when the big Supertrend changes from a downtrend to an uptrend.
  • Short Signal: Triggered when the big Supertrend changes from an uptrend to a downtrend.

How the Script Works
  • Initialization: The script initializes with predefined Supertrend settings.
  • Data Input: Market data (e.g., price data) is fed into the script.
  • Supertrend Calculation: The script calculates the Supertrend values using the predefined factors and ATR periods.
  • Signal Detection: The script monitors the Supertrend values and detects the defined signals based on the conditions mentioned above.
  • Time Filtering: Signals are filtered based on the specified startHour and endHour, ensuring only relevant signals are displayed within the desired timeframe.

    Usage
  • Set Parameters: Define startHour and endHour according to your trading schedule.
  • Run Script: Execute the script with market data input.
  • Interpret Signals: Monitor the generated signals and use them to inform your trading decisions.

    Originality
  • Dual Supertrend Usage: The use of both a small and a big Supertrend to generate signals adds a layer of complexity and reliability to the signals.
  • Time-Based Filtering: Allows traders to focus on specific trading hours, enhancing the relevance and accuracy of signals.
  • Two Signal Types: The combination of reversal signals and trend change signals provides comprehensive market insights.

Conclusion
This Supertrend Signal Generator is a robust tool for traders seeking to leverage the Supertrend indicator for more informed trading decisions. By combining dual Supertrend settings and configurable trading hours, the script offers unique and flexible signal generation capabilities.
check the below:

CSS:
# Indicator for TOS
# https://www.tradingview.com/v/2HRVpCyp/
#//@risk_alpha
#indicator("Supertrend Alert with Arrows and Time Filter", overlay=true)
# Converted by Sam4Cok@Samer800    - 07/2024

input colorBars  = yes;
input signalStyle = {Default "Bubbles", "Arrows", "Don't Show"};
input signalSession = {Default "Regular Trading Hours", "All Sessions", "Custom Hours"};
input CustomStartTime = 0830; # "Start hour"
input CustomEndTime   = 1230; # "End hour"
input st1_factor = 3.0;
input st1_atrPeriod = 10;
input st2_factor = 10.0;
input st2_atrPeriod = 30;

def na = Double.NaN;
def bubble = signalStyle==signalStyle."Bubbles";
def arrow = signalStyle==signalStyle."Arrows";
#/ The same on Pine Script®
script supertrend {
    input factor = 3;
    input atrPeriod = 10;
    def src = hl2;
    def atr = ATR(Length = atrPeriod);
    def up = src + factor * atr;
    def lo = src - factor * atr;
    def lowerBand = CompoundValue(1, if !lowerBand[1] then lo else
                    if lo > lowerBand[1] or close[1] < lowerBand[1] then lo else lowerBand[1], lo);
    def upperBand = CompoundValue(1, if !upperBand[1] then up else
                    if up < upperBand[1] or close[1] > upperBand[1] then up else upperBand[1], up);
    def _direction;
    def superTrend;
    def prevUpperBand = CompoundValue(1, upperBand[1], up);
    def prevSuperTrend = CompoundValue(1, superTrend[1], 0);
    if IsNaN(atr[1]) {
        _direction = 1;
    } else if prevSuperTrend == prevUpperBand {
        _direction = if close > upperBand then -1 else 1;
    } else {
        _direction = if close < lowerBand then 1 else -1;
    }
    def trend = CompoundValue(1, if !_direction then 1 else _direction, 1);
    superTrend = if trend == -1 then lowerBand else upperBand;
    plot st = superTrend;
    plot dir = trend;
}
#f_insession(_session) =>
script in_Range {
    input _sessionStart = 0930;
    input _sessionEnd  = 1030;
    def insession = if SecondsTillTime(_sessionEnd) > 0 and SecondsFromTime(_sessionStart) >= 0
                    then 1 else 0;
    plot return = insession;
}
def time = GetTime();
def RTH = time >= RegularTradingStart(GetYYYYMMDD()) and time <= RegularTradingEND(GetYYYYMMDD());
def custom = in_Range(CustomStartTime, CustomEndTime);
def in_time_range;

Switch (signalSession) {     # 'Trading Session'
Case "All Sessions" :
    in_time_range = yes;
Case "Custom Hours" :
    in_time_range = custom;
Default :
    in_time_range = RTH;
}
#// Supertrend (10, 3)
def st1_line = supertrend(st1_factor, st1_atrPeriod).st;
def st1_dir  = supertrend(st1_factor, st1_atrPeriod).dir;

#// Supertrend (30, 10)
def st2_line = supertrend(st2_factor, st2_atrPeriod).st;
def st2_dir  = supertrend(st2_factor, st2_atrPeriod).dir;

#// Determine the trend direction
def st1_trend_up = st1_dir > 0;
def st1_trend_down = st1_dir < 0;

def st2_trend_up = st2_dir > 0;
def st2_trend_down = st2_dir < 0;

#// Trend change detection
def st1_trend_change_up = st1_dir[2] < 0 and st1_dir[1] > 0;
def st1_trend_change_down = st1_dir[2] > 0 and st1_dir[1] < 0;
def st2_trend_change_up = st2_dir[2] < 0 and st2_dir[1] > 0;
def st2_trend_change_down = st2_dir[2] > 0 and st2_dir[1] < 0;

#// Alert conditions
def short_condition = if in_time_range then
                      (st1_trend_change_up and st2_trend_up) or st2_trend_change_up else na;
def long_condition  = if in_time_range then
                      (st1_trend_change_down and st2_trend_down) or st2_trend_change_down else na;

#// Plot Supertrend (10, 3)
plot st1 = if st1_line then st1_line else na;
plot st2 = if st2_line then st2_line else na;
st1.AssignValueColor(if st1_trend_up then Color.RED else Color.GREEN);
st2.AssignValueColor(if st2_trend_up then Color.DOWNTICK else Color.LIGHT_GREEN);

#// Plot arrows for signals
plot long = if arrow and long_condition[-1] then low else na; #"Long Signal",
plot short = if arrow and short_condition[-1] then high else na; #, title="Short Signal", colordown=c
long.SetLineWeight(2);
short.SetLineWeight(2);
long.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
short.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
long.SetDefaultColor(Color.CYAN);
short.SetDefaultColor(Color.MAGENTA);
AddChartBubble(bubble and long_condition[-1], low, "BUY", Color.GREEN, no);
AddChartBubble(bubble and short_condition[-1], high, "SELL", Color.RED);

#-- bar color
def extDn  = st1_dir > 0 and st2_dir > 0;
def weakDn = st1_dir < 0 and st2_dir > 0;
def extUp  = st1_dir < 0 and st2_dir < 0;
def weakUp = st1_dir > 0 and st2_dir < 0;


AssignPriceColor( if !colorBars then Color.CURRENT else
                  if extUp  then Color.GREEN else
                  if weakUp then Color.DARK_GREEN else
                  if extDn  then Color.RED else
                  if weakDn then Color.DARK_RED else Color.GRAY);


#-- END of CODE
 
I am having difficulty with this particular SuperTrend.
After playing with the lengths, I still couldn't get it to align with other basic indicators such as moving averages and oscillators for any consistent confirmation.

That said, I do find that the two-length approach to SuperTrend is superior.
For example, here is @samer800 2-length SuperTrend interpretation which provides excellent definition of trend and aligns better with day trader's traditional charts:
https://usethinkscript.com/threads/trendrange-for-thinkorswim.14439/

Put both of these 2-length Supertrend studies on your chart.
Which works best for you?
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
517 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top