TradingLegend RangeLevels
Indicator Description:
I am incredibly proud and excited to share my first indicator with the TradingView community! This tool has been instrumental in helping me optimize my positioning and maximize my trades.
Tradinglegend RangeLevels— is a technical indicator that is used to determine the levels at which price may face support or resistance. This indicator consists number of levels which will show several support (S) and resistance (R) levels.
Calculation
Resistance and support values are calculated in different ways, depending on the type of the indicator, specified by the Type field in indicator inputs. To calculate TL range support/resistance levels, the values OPENcurr, OPENprev, HIGHprev, LOWprev, CLOSEprev of hour,day,weekly candles with avarage buying and selling volumes. which are the values of the current open and previous open, high, low and close, respectively, on the indicator resolution. The indicator resolution is set by the input of the different standard Timeframe.
users can change the cofficient of facor which calculated on basis of previous day high to low distance and number of 5min candles existing in a day,they can customisze it in setting for accurate results
for intraday resolutions up to and including 15 min, DAY (1D) is used
for intraday resolutions more than 15 min, WEEK (1W) is used
for daily resolutions MONTH is used (1M)
for weekly and monthly resolutions, 12-MONTH (12M) is used
Types
Leves are designed as pivot standard levels but calculation is different.When you will use it,definitely u gonna love it
Educational
Turtle Soup ICT Strategy [TradingFinder] FVG + CHoCH/CSD🔵 Introduction
The ICT Turtle Soup trading setup, designed in the ICT style, operates by hunting or sweeping liquidity zones to exploit false breakouts and failed breakouts in key liquidity Zones, such as recent highs, lows, or major support and resistance levels.
This setup identifies moments when the price breaches these liquidity zones, triggering stop orders placed (Stop Hunt) by other traders, and then quickly reverses direction. These movements are often associated with liquidity sweeps that create temporary market imbalances.
The reversal is typically confirmed by one of three structural shifts : a Market Structure Shift (MSS), a Change of Character (CHoCH), or a break of the Change in State of Delivery (CISD). Each of these structural shifts provides a reliable signal to interpret market intent and align trading decisions with the expected price movement. After the structural shift, the price frequently pullback to a Fair Value Gap (FVG), offering a precise entry point for trades.
By integrating key concepts such as liquidity, liquidity sweeps, stop order activation, structural shifts (MSS, CHoCH, CISD), and price imbalances, the ICT Turtle Soup setup enables traders to identify reversal points and key entry zones with high accuracy.
This strategy is highly versatile, making it applicable across markets such as forex, stocks, cryptocurrencies, and futures. It offers traders a robust and systematic approach to understanding price movements and optimizing their trading strategies
🟣 Bullish and Bearish Setups
Bullish Setup : The price first sweeps below a Sell-Side Liquidity (SSL) zone, then reverses upward after forming an MSS or CHoCH, and finally pulls back to an FVG, creating a buying opportunity.
Bearish Setup : The price first sweeps above a Buy-Side Liquidity (BSL) zone, then reverses downward after forming an MSS or CHoCH, and finally pulls back to an FVG, creating a selling opportunity.
🔵 How to Use
To effectively utilize the ICT Turtle Soup trading setup, begin by identifying key liquidity zones, such as recent highs, lows, or support and resistance levels, in higher timeframes.
Then, monitor lower timeframes for a Liquidity Sweep and confirmation of a Market Structure Shift (MSS) or Change of Character (CHoCH).
After the structural shift, the price typically pulls back to an FVG, offering an optimal trade entry point. Below, the bullish and bearish setups are explained in detail.
🟣 Bullish Turtle Soup Setup
Identify Sell-Side Liquidity (SSL) : In a higher timeframe (e.g., 1-hour or 4-hour), identify recent price lows or support levels that serve as SSL zones, typically the location of stop-loss orders for traders.
Observe a Liquidity Sweep : On a lower timeframe (e.g., 15-minute or 30-minute), the price must move below one of these liquidity zones and then reverse. This movement indicates a liquidity sweep.
Confirm Market Structure Shift : After the price reversal, look for a structural shift (MSS or CHoCH) indicated by the formation of a Higher Low (HL) and Higher High (HH).
Enter the Trade : Once the structural shift is confirmed, the price typically pulls back to an FVG. Enter a buy trade in this zone, set a stop-loss slightly below the recent low, and target Buy-Side Liquidity (BSL) in the higher timeframe for profit.
🟣 Bearish Turtle Soup Setup
Identify Buy-Side Liquidity (BSL) : In a higher timeframe, identify recent price highs or resistance levels that serve as BSL zones, typically the location of stop-loss orders for traders.
Observe a Liquidity Sweep : On a lower timeframe, the price must move above one of these liquidity zones and then reverse. This movement indicates a liquidity sweep.
Confirm Market Structure Shift : After the price reversal, look for a structural shift (MSS or CHoCH) indicated by the formation of a Lower High (LH) and Lower Low (LL).
Enter the Trade : Once the structural shift is confirmed, the price typically pulls back to an FVG. Enter a sell trade in this zone, set a stop-loss slightly above the recent high, and target Sell-Side Liquidity (SSL) in the higher timeframe for profit.
🔵 Settings
Higher TimeFrame Levels : This setting allows you to specify the higher timeframe (e.g., 1-hour, 4-hour, or daily) for identifying key liquidity zones.
Swing period : You can set the swing detection period.
Max Swing Back Method : It is in two modes "All" and "Custom". If it is in "All" mode, it will check all swings, and if it is in "Custom" mode, it will check the swings to the extent you determine.
Max Swing Back : You can set the number of swings that will go back for checking.
FVG Length : Default is 120 Bar.
MSS Length : Default is 80 Bar.
FVG Filter : This refines the number of identified FVG areas based on a specified algorithm to focus on higher quality signals and reduce noise.
Types of FVG filter s:
Very Aggressive Filter: Adds a condition where, for an upward FVG, the last candle's highest price must exceed the middle candle's highest price, and for a downward FVG, the last candle's lowest price must be lower than the middle candle's lowest price. This minimally filters out FVGs.
Aggressive Filter: Builds on the Very Aggressive mode by ensuring the middle candle is not too small, filtering out more FVGs.
Defensive Filter: Adds criteria regarding the size and structure of the middle candle, requiring it to have a substantial body and specific polarity conditions, filtering out a significant number of FVGs.
Very Defensive Filter: Further refines filtering by ensuring the first and third candles are not small-bodied doji candles, retaining only the highest quality signals.
In the indicator settings, you can customize the visibility of various elements, including MSS, FVG, and HTF Levels. Additionally, the color of each element can be adjusted to match your preferences. This feature allows traders to tailor the chart display to their specific needs, enhancing focus on the key data relevant to their strategy.
🔵 Conclusion
The ICT Turtle Soup trading setup is a powerful tool in the ICT style, enabling traders to exploit false breakouts in key liquidity zones. By combining concepts of liquidity, liquidity sweeps, market structure shifts (MSS and CHoCH), and pullbacks to FVG, this setup helps traders identify precise reversal points and execute trades with reduced risk and increased accuracy.
With applications across various markets, including forex, stocks, crypto, and futures, and its customizable indicator settings, the ICT Turtle Soup setup is ideal for both beginner and advanced traders. By accurately identifying liquidity zones in higher timeframes and confirming structure shifts in lower timeframes, this setup provides a reliable strategy for navigating volatile market conditions.
Ultimately, success with this setup requires consistent practice, precise market analysis, and proper risk management, empowering traders to make smarter decisions and achieve their trading goals.
Heikin Ashi_NormanHeikin Ashi para la estrategia de Norman
as;lasd;jmdsalkvlfsamlfdslnfsamnslfsaa;'fA
AVFSAPAP;M;LAM;CMV
FDSAVMAMAM;A;ABSA;
Christmas RSI with Jingle Bell [TrendX_]Jingle Bell 🔔, Jingle Bell 🔔, Jingle all the chart 📈 Merry Christmas Tradingview Community !!!
Introducing the Jingle Bell Indicator, a festive Pine Script creation designed to spread joy and luck to your trading endeavors. The Bow will change colors based on the reaction of RSI with the 50 level. Add a Jingle Bell drawing to your charts and celebrate the most wonderful time of the year. Turn on alert for today to get my Merry Christmas wish.
This indicator is my gift to the Tradingview community, designed to bring a touch of luck to your trades. Hope this Jingle Bell will bring some joy and festive vibes to your trading experience.
Merry Christmas Tree🎄 Merry Christmas 2024 🎅
May your holidays sparkle with joy and laughter, and may the year ahead be full of blessings and success. Wishing you and your loved ones peace, love, and happiness this Christmas and always! 🌟🎁
Heikin Ashi Candles - [Better Overlay]Heikin Ashi Candles - Better Overlay
Heikin Ashi candles are a unique charting technique designed to smooth price data, making it easier to identify trends and potential reversals. The "Heikin Ashi Candles - Better Overlay" indicator takes this concept further by introducing enhancements like a moving average based on the Heikin Ashi values and an overlay of actual price dynamics. This blog explores the functionality and features of this indicator.
Key Features
1. Heikin Ashi Candle Plotting
The indicator calculates Heikin Ashi values (open, high, low, and close) to plot candles directly on the chart. These candles provide a clearer view of market trends by reducing noise commonly seen in standard candlesticks.
- Heikin Ashi Close: The average of open, high, low, and close prices.
- Heikin Ashi Open: A smoothed value derived from the previous Heikin Ashi open and close values.
- Heikin Ashi High/Low: The highest and lowest prices between the Heikin Ashi open, close, and the actual high/low of the period.
The candle colors are intuitive:
- Green: Indicates bullish movement.
- Red: Indicates bearish movement.
The indicator uses semi-transparent candle bodies to ensure better visibility of the actual price chart underneath.
2. Heikin Ashi Moving Average
The indicator includes an optional moving average calculated from the Heikin Ashi values. This moving average helps traders identify the overall trend direction and its strength.
- The length of the moving average is adjustable via input settings.
- The color of the moving average line reflects its trend:
- Green: Uptrend.
- Red: Downtrend.
3. Dynamic Actual Price Line
To maintain a connection with real-time price data, the indicator overlays a dashed line representing the actual closing price of the asset. This feature provides valuable context when analyzing Heikin Ashi data, ensuring traders do not lose sight of the actual price levels.
Customization Options
The indicator offers several customization settings for better usability:
- Heikin Ashi Moving Average:
- Toggle to show or hide the moving average.
- Adjustable length for the moving average, ranging from 1 to 500 periods.
- Candle Styling:
- The colors and transparency levels of the candles are predefined to maintain chart clarity.
- Users can visually distinguish Heikin Ashi data from the actual price chart.
Practical Use Cases
1. Trend Identification
Heikin Ashi candles smooth out noise, making it easier to identify trends. Bullish and bearish candle coloring provides a quick visual cue for market sentiment.
2. Trend Strength and Reversals
The Heikin Ashi moving average serves as a reliable indicator of trend strength. A change in the color of the moving average can indicate a potential trend reversal.
3. Real-Time Price Reference
The dynamic price line ensures traders have a clear reference to the actual closing price, which is crucial for making informed decisions in real-time markets.
Conclusion
The "Heikin Ashi Candles - Better Overlay" indicator is a versatile tool for traders looking to combine the smoothing benefits of Heikin Ashi candles with the precision of real-time price data. Its additional features, like the Heikin Ashi moving average and dynamic price line, make it a comprehensive solution for both trend-following and real-time trading strategies.
This indicator is a great addition to any trader's toolkit, offering clarity and actionable insights without overcomplicating the chart. Give it a try to explore its potential in your trading journey.
21 EMA Crossover Strategy with 80% accuracy21 EMA Crossover Strategy with 80% accuracy. Once high of the buy signal is broken take a long trade and once low of sell signal is broken then take a short trade. Put stoploss as high or low of prev candle based on the trade
Market Sessions
//@version=5
indicator('Market Sessions', 'Sessions', overlay=true, max_lines_count=200, max_boxes_count=200, max_labels_count=200, max_bars_back=500, explicit_plot_zorder=true)
import boitoki/AwesomeColor/9 as ac
import boitoki/Utilities/3 as util
///////////////
// Groups
///////////////
g0 = '// GENERAL //'
g1_01 = '// ♯1 SESSION //'
g1_02 = '// ♯2 SESSION //'
g1_03 = '// ♯3 SESSION //'
g1_04 = '// ♯4 SESSION //'
g1_05 = '// ♯5 SESSION //'
g4 = '// BOX //'
g6 = '// LABELS //'
g5 = '// OPENING RANGE //'
g7 = '// FIBONACCI LEVELS //'
g8 = '// OPTIONS //'
g11 = '// CANDLE //'
g10 = '// ALERTS VISUALISED //'
g12 = '// INFORMATION //'
///////////////
// Defined
///////////////
MAX_BARS = 500
option_yes = 'Yes'
option_no = '× No'
option_extend1 = 'Yes'
option_hide = '× Hide'
option_border_style1 = '────'
option_border_style2 = '- - - - - -'
option_border_style3 = '•••••••••'
option_chart_x = '× No'
option_chart_1 = 'Bar color'
option_chart_2 = 'Candles'
option_opr_label1 = 'High・Low'
option_opr_label2 = 'Buy・Sell'
option_opr_label_none = 'None'
option_candle_color1 = 'Session color'
option_candle_color2 = 'Red • Green'
fmt_price = '{0,number,#.#####}'
fmt_pips = '{0,number,#.#}'
icon_separator = ' • '
color_text = color.new(color.white, 0)
TRANSPARENT = color.new(color.black, 100)
///////////////
// Methods
///////////////
method clear (array id, int _min = 0) =>
if array.size(id) > _min
array.pop(id)
method clear (array id, int _min = 0) =>
if array.size(id) > _min
array.pop(id)
///////////////
// Types
///////////////
// OHLC
type OHLC
float open
float high
float low
float close
float hl
// Dot
type Dot
int x
float y
string t = ''
color c
method create(Dot this) =>
label.new(this.x, this.y, this.t, style=label.style_label_center, color=TRANSPARENT, textcolor=this.c, size=size.small)
// Candle
type Candle
box body
line wick
method create(Candle this) =>
this.body := array.new()
this.wick := array.new()
this
type State
string extend_style
bool show_fibs
bool show_op
method is_extended (State this) =>
this.extend_style != option_no
// OpeningRange
type OpeningRange
float top
float btm
float avg
float R1
float R2
float S1
float S2
int total_count = 0
int reached_count = 0
int reached_R1_count = 0
int reached_R2_count = 0
int reached_S1_count = 0
int reached_S2_count = 0
// Data
type Session
string sess
string tz
string name
color colour
float price_ranges
float price_range_avg
box boxes
line lines
label labels
line oclines
box ocboxes
label oc_labels
box opr_boxes
line opr_lines
linefill opr_linefills
label opr_labels
line fib
int session
bool is_extended
bool in_session
Candle candle
OHLC ohlc
State state
OpeningRange op
method create (Session this, string _extend, bool _show_fib, bool _show_op) =>
this.boxes := array.new()
this.lines := array.new()
this.labels := array.new()
this.oclines := array.new()
this.ocboxes := array.new()
this.oc_labels := array.new()
this.opr_boxes := array.new()
this.opr_lines := array.new()
this.opr_linefills := array.new()
this.opr_labels := array.new()
this.fib := array.new()
this.price_ranges := array.new()
this.state := State.new(_extend, _show_fib, _show_op)
this.candle := Candle.new().create()
this.ohlc := OHLC.new()
this.op := OpeningRange.new()
this.is_extended := this.state.is_extended()
this
method session (Session this) =>
time(timeframe.period, this.sess, this.tz)
method add (Session this, range_price, length = 50) =>
this.price_ranges.unshift(range_price)
this.price_ranges.clear(length)
this.price_range_avg := array.avg(this.price_ranges)
///////////////
// Functions
///////////////
f_get_time_by_bar (bar_count) => timeframe.multiplier * bar_count * 60 * 1000
f_border_style (_style) =>
switch _style
option_border_style1 => line.style_solid
option_border_style2 => line.style_dashed
option_border_style3 => line.style_dotted
=> _style
f_get_period (_session, _start, _lookback) =>
result = math.max(_start, 1)
for i = result to _lookback
if na(_session ) and _session
result := i+1
break
result
f_get_label_position (_y, _side) =>
switch _y
'top' => _side == 'outside' ? label.style_label_lower_left : label.style_label_upper_left
'bottom' => _side == 'outside' ? label.style_label_upper_left : label.style_label_lower_left
f_get_started (_session) => na(_session ) and _session
f_get_ended (_session) => na(_session) and _session
f_message_limit_bars (_v) => '⚠️ This box\'s right position exceeds 500 bars(' + str.tostring(_v) + '). This box is not displayed correctly.'
f_set_line_x1 (_line, _x) =>
if (line.get_x1(_line) != _x)
line.set_x1(_line, _x)
f_set_line_x2 (_line, _x) =>
if (line.get_x2(_line) != _x)
line.set_x2(_line, _x)
f_set_box_right (_box, _x) =>
if box.get_right(_box) != _x
box.set_right(_box, _x)
///////////////
// Inputs
///////////////
// Timezone
i_tz = input.string('GMT+0', title='Timezone', options= , group=g0)
i_history_period = input.int(10, 'History', minval=0, group=g0)
i_show = i_history_period > 0
i_lookback = 12 * 60
// Sessions
i_show_sess1 = input.bool(true, 'Session 1 ', group=g1_01, inline='session1_1') and i_show
i_sess1_label = input.string('London', '', group=g1_01, inline='session1_1')
i_sess1_color = input.color(#66D9EF, '', group=g1_01, inline='session1_1')
i_sess1_barcolor1 = input.color(#66D9EF, '•', group=g1_01, inline='session1_1')
i_sess1_barcolor2 = input.color(#66D9EF, '', group=g1_01, inline='session1_1')
i_sess1 = input.session('0800-1700', 'Time', group=g1_01)
i_sess1_extend = input.string(option_no, 'Extend', options= , group=g1_01)
i_sess1_op = input.string(option_no, 'Opening range', group=g1_01, options= ) != option_no and i_show
i_sess1_fib = input.string(option_no, 'Fibonacci levels', group=g1_01, options= ) != option_no
i_sess1_chart = input.string(option_chart_x, 'Bar', options= , group=g1_01)
i_sess1_barcolor = i_sess1_chart == option_chart_1
i_sess1_plotcandle = i_sess1_chart == option_chart_2
i_show_sess2 = input.bool(true, 'Session 2 ', group=g1_02, inline='session2_1') and i_show
i_sess2_label = input.string('New York', '', group=g1_02, inline='session2_1')
i_sess2_color = input.color(#FD971F, '', group=g1_02, inline='session2_1')
i_sess2_barcolor1 = input.color(#FD971F, '•', group=g1_02, inline='session2_1')
i_sess2_barcolor2 = input.color(#FD971F, '', group=g1_02, inline='session2_1')
i_sess2 = input.session('1300-2200', 'Time', group=g1_02)
i_sess2_extend = input.string(option_no, 'Extend', options= , group=g1_02)
i_sess2_op = input.string(option_no, 'Opening range', group=g1_02, options= ) != option_no and i_show
i_sess2_fib = input.string(option_no, 'Fibonacci levels', group=g1_02, options= ) != option_no
i_sess2_chart = input.string(option_chart_x, 'Bar', options= , group=g1_02)
i_sess2_barcolor = i_sess2_chart == option_chart_1
i_sess2_plotcandle = i_sess2_chart == option_chart_2
i_show_sess3 = input.bool(true, 'Session 3 ', group=g1_03, inline='session3_1') and i_show
i_sess3_label = input.string('Tokyo', '', group=g1_03, inline='session3_1')
i_sess3_color = input.color(#AE81FF, '', group=g1_03, inline='session3_1')
i_sess3_barcolor1 = input.color(#AE81FF, '•', group=g1_03, inline='session3_1')
i_sess3_barcolor2 = input.color(#AE81FF, '', group=g1_03, inline='session3_1')
i_sess3 = input.session('0000-0900', 'Time', group=g1_03)
i_sess3_extend = input.string(option_no, 'Extend', options= , group=g1_03)
i_sess3_op = input.string(option_no, 'Opening range', group=g1_03, options= ) != option_no and i_show
i_sess3_fib = input.string(option_no, 'Fibonacci levels', group=g1_03, options= ) != option_no
i_sess3_chart = input.string(option_chart_x, 'Bar', options= , group=g1_03)
i_sess3_barcolor = i_sess3_chart == option_chart_1
i_sess3_plotcandle = i_sess3_chart == option_chart_2
i_show_sess4 = input.bool(false, 'Session 4 ', group=g1_04, inline='session4_1') and i_show
i_sess4_label = input.string('Sydney', '', group=g1_04, inline='session4_1')
i_sess4_color = input.color(#FB71A3, '', group=g1_04, inline='session4_1')
i_sess4_barcolor1 = input.color(#FB71A3, '•', group=g1_04, inline='session4_1')
i_sess4_barcolor2 = input.color(#FB71A3, '', group=g1_04, inline='session4_1')
i_sess4 = input.session('2000-0500', 'Time', group=g1_04)
i_sess4_extend = input.string(option_no, 'Extend', options= , group=g1_04)
i_sess4_op = input.string(option_no, 'Opening range', group=g1_04, options= ) != option_no and i_show
i_sess4_fib = input.string(option_no, 'Fibonacci levels', group=g1_04, options= ) != option_no
i_sess4_chart = input.string(option_chart_x, 'Bar', options= , group=g1_04)
i_sess4_barcolor = i_sess4_chart == option_chart_1
i_sess4_plotcandle = i_sess4_chart == option_chart_2
i_show_sess5 = input.bool(false, 'Session 5 ', group=g1_05, inline='session5_1') and i_show
i_sess5_label = input.string('Sydney', '', group=g1_05, inline='session5_1')
i_sess5_color = input.color(#FB71A3, '', group=g1_05, inline='session5_1')
i_sess5_barcolor1 = input.color(#FB71A3, '•', group=g1_05, inline='session5_1')
i_sess5_barcolor2 = input.color(#FB71A3, '', group=g1_05, inline='session5_1')
i_sess5 = input.session('2000-0500', 'Time', group=g1_05)
i_sess5_extend = input.string(option_no, 'Extend', options= , group=g1_05)
i_sess5_op = input.string(option_no, 'Opening range', group=g1_05, options= ) != option_no and i_show
i_sess5_fib = input.string(option_no, 'Fibonacci levels', group=g1_05, options= ) != option_no
i_sess5_chart = input.string(option_chart_x, 'Bar', options= , group=g1_05)
i_sess5_barcolor = i_sess5_chart == option_chart_1
i_sess5_plotcandle = i_sess5_chart == option_chart_2
// Show & Styles
i_sess_box_style = input.string('Box', '', options= , group=g4, inline='box_style')
i_sess_border_style = f_border_style(input.string(option_border_style2, '', options= , group=g4, inline='box_style'))
i_sess_border_width = input.int(1, '', minval=0, group=g4, inline='box_style')
i_sess_box_background = input.bool(true, 'BG color', group=g4, inline='box_style_options')
i_sess_box_dots = input.bool(true, 'Dots', group=g4, inline='box_style_options')
i_sess_end_offset = input.bool(true, 'Include the latest bar in the Session end', group=g4)
i_sess_bgopacity = i_sess_box_background ? 94 : 100
i_sess_bgopacity2 = math.min(i_sess_bgopacity - 4, 100)
i_sess_border_width := i_sess_box_style == 'Background' ? 0 : i_sess_border_width
session_end_offset = i_sess_end_offset ? 0 : 1
// Labels
i_label_show = input.bool(true, '', inline='label_show', group=g6) and i_show
i_label_size = str.lower(input.string('Small', '', options= , inline='label_show', group=g6))
i_label_position_y = str.lower(input.string('Top', '', options= , inline='label_show', group=g6))
i_label_position_s = str.lower(input.string('Outside', '', options= , inline='label_show', group=g6))
i_label_position = f_get_label_position(i_label_position_y, i_label_position_s)
i_label_format_name = input.bool(true, 'Name', inline='label_format', group=g6)
i_label_format_day = input.bool(false, 'Day', inline='label_format', group=g6)
i_label_format_price = input.bool(false, 'Price', inline='label_format', group=g6)
i_label_format_pips = input.bool(false, 'Pips', inline='label_format', group=g6)
// Opening range
i_o_minutes = input.int(15, title='Periods mins', minval=1, step=1, group=g5)
i_o_minutes := math.max(i_o_minutes, timeframe.multiplier + 1)
i_o_transp = 65
i_o_size = input.string(size.small, 'Label size', options= , group=g5)
i_o_color = input.string(option_candle_color1, 'Label color', options= , group=g5)
i_o_label_1 = input.string('High', 'Label text ', group=g5, inline='op_label', tooltip="Type \"price\" to display the price")
i_o_label_2 = input.string('Low', '', group=g5, inline='op_label')
i_o_nowonly = input.bool(false, 'Now only', group=g5, inline='op_options')
i_o_breakout_icon = input.bool(false, 'Breakout flag', group=g5, inline='op_options')
i_o_target = input.bool(false, 'Target lines', group=g5, inline='op_options')
// Candle
option_candle_body = 'OC'
option_candle_wick = 'OHLC'
i_show_candle = input.bool(false, '', group=g11, inline='candle_display') //and (i_candle_border_width > 0)
i_candle = input.string(option_candle_wick, '', options= , group=g11, inline='candle_display')
i_candle_border_width = input.int(1, '', minval=1, group=g11, inline='candle_display')
i_candle_color = input.string(option_candle_color1, '', options= , group=g11, inline='candle_display')
i_candle_color_g = input.color(#A6E22E, '', group=g11, inline='candle_display')
i_candle_color_r = input.color(#F92672, '', group=g11, inline='candle_display')
i_candle := i_show_candle ? i_candle : option_hide
i_show_candle_wick = i_candle == option_candle_wick
i_sess_bgopacity2 := i_show_candle ? 100 : i_sess_bgopacity2
// Fibonacci levels
i_f_show = input.bool(true, '', group=g7, inline='fib_display')
i_f_linestyle = f_border_style(input.string(option_border_style1, '', options= , group=g7, inline='fib_display'))
i_f_linewidth = input.int(1, '', minval=1, group=g7, inline='fib_display')
i_sess1_fib := i_f_show ? i_sess1_fib : false
i_sess2_fib := i_f_show ? i_sess2_fib : false
i_sess3_fib := i_f_show ? i_sess3_fib : false
i_sess4_fib := i_f_show ? i_sess4_fib : false
// Information table
i_show_info = input.bool(true, '', group=g12, inline='info_display')
i_info_size = input.string(size.normal, '', options= , group=g12, inline='info_display')
i_info_value_type = input.string('Pips', '', options= , group=g12, inline='info_display')
i_info_period = input.int(50, '', group=g12, inline='info_display')
// Alerts
i_alert1_show = input.bool(false, 'Alerts - Sessions stard/end', group=g10)
i_alert2_show = input.bool(false, 'Alerts - Opening range breakouts', group=g10)
i_alert3_show = input.bool(false, 'Alerts - Price crossed session\'s High/Low after session closed', group=g10)
// ------------------------
// Drawing labels
// ------------------------
f_render_label (_show, Session data, _is_started, _color, _top, _bottom) =>
var label my_label = na
var int start_time = na
session = data.session()
v_position_y = (i_label_position_y == 'top') ? _top : _bottom
v_label = array.new_string()
v_chg = _top - _bottom
if _is_started
start_time := time
if i_label_format_name and not na(data.name)
array.push(v_label, data.name)
if i_label_format_day
array.push(v_label, util.get_day(dayofweek(start_time, i_tz)))
if i_label_format_price
array.push(v_label, str.format(fmt_price, v_chg))
if i_label_format_pips
array.push(v_label, str.format(fmt_pips, util.toPips(v_chg)))
if _show
if _is_started
my_label := label.new(bar_index, v_position_y, array.join(v_label, icon_separator), textcolor=_color, color=TRANSPARENT, size=i_label_size, style=i_label_position, tooltip='Pips')
array.push(data.labels, my_label)
util.clear_labels(data.labels, data.is_extended ? 1 : i_history_period)
else if session
label.set_y(my_label, v_position_y)
label.set_text(my_label, array.join(v_label, icon_separator))
data
// ------------------------
// Drawing Fibonacci levels
// ------------------------
f_render_fibonacci (_show, data, _is_started, _is_ended, _x1, _x2, _color, _top, _bottom, _level, _width, _style) =>
var line my_line = na
session = data.session()
if _show
y = (_top - _bottom) * _level + _bottom
if _is_started
my_line := line.new(_x1, y, _x2, y, width=_width, color=color.new(_color, 30), style=_style)
array.push(data.fib, my_line)
if data.is_extended
line.set_extend(my_line, extend.right)
else if session
line.set_y1(my_line, y)
line.set_y2(my_line, y)
f_set_line_x2(my_line, _x2)
else if _is_ended
f_set_line_x2(my_line, _x2-session_end_offset)
data
// ------------------------
// Drawing Opening range
// ------------------------
f_render_oprange (_show, Session data, _is_started, _is_ended, _x1, _x2, _color, _max) =>
var int start_time = na
var box my_box = na
var line my_line1 = na
var line my_line2 = na
var label my_label1 = na
var label my_label2 = na
var bool is_opened = false
var float R1 = na, var float R2 = na
var float S1 = na, var float S2 = na
var is_reached_R1 = false
var is_reached_R2 = false
var is_reached_S1 = false
var is_reached_S2 = false
var color_gray = ac.tradingview('gray')
var color_orange = ac.tradingview('orange')
var target_line_width = 2
session = data.session()
top = ta.highest(high, _max)
btm = ta.lowest(low, _max)
is_crossover = ta.crossover(close, box.get_top(my_box))
is_crossunder = ta.crossunder(close, box.get_bottom(my_box))
var float saved_top = na
if _show
if _is_started
util.clear_boxes(data.opr_boxes, math.max(0, i_history_period - 1))
util.clear_lines(data.opr_lines, math.max(0, (i_history_period - 1) * 6))
util.clear_labels(data.opr_labels, math.max(0, (i_history_period - 1) * 2))
start_time := time
my_box := na
is_opened := true
else if session
time_op = start_time + (i_o_minutes * 60 * 1000)
time_op_delay = time_op - f_get_time_by_bar(1)
if time <= time_op and time > time_op_delay
top_color = i_o_color == option_candle_color2 ? ac.tradingview('blue') : _color
btm_color = i_o_color == option_candle_color2 ? ac.tradingview('red') : _color
top_text_color = color.from_gradient(85, 0, 100, top_color, ac.panda('white'))
bot_text_color = color.from_gradient(85, 0, 100, btm_color, ac.panda('white'))
mdl = math.avg(top, btm)
avg1 = (data.price_range_avg * 0.786) * 0.5
avg2 = (data.price_range_avg * 1.272) * 0.5
saved_top := top
R1 := math.avg(btm, mdl) + avg1
R2 := math.avg(btm, mdl) + avg2
S1 := math.avg(top, mdl) - avg1
S2 := math.avg(top, mdl) - avg2
array.push(data.opr_boxes, box.new (_x1, top, bar_index, btm, border_width=0, bgcolor=color.new(_color, i_o_transp)))
array.push(data.opr_lines, line.new(_x1, top, _x2, top, style=line.style_dashed, color=top_color))
array.push(data.opr_lines, line.new(_x1, btm, _x2, btm, style=line.style_dashed, color=btm_color))
array.push(data.opr_lines, line.new(_x1, R2 , _x2, R2 , style=line.style_solid, color=i_o_target ? color.new(top_color, 40) : TRANSPARENT, width=target_line_width))
array.push(data.opr_lines, line.new(_x1, S2 , _x2, S2 , style=line.style_solid, color=i_o_target ? color.new(btm_color, 40) : TRANSPARENT, width=target_line_width))
array.push(data.opr_lines, line.new(_x1, R1 , _x2, R1 , style=line.style_solid, color=i_o_target ? color.new(top_color, 40) : TRANSPARENT, width=target_line_width))
array.push(data.opr_lines, line.new(_x1, S1 , _x2, S1 , style=line.style_solid, color=i_o_target ? color.new(btm_color, 40) : TRANSPARENT, width=target_line_width))
if i_o_target
array.unshift(data.opr_linefills, linefill.new(array.get(data.opr_lines, array.size(data.opr_lines)-1), array.get(data.opr_lines, array.size(data.opr_lines)-3), color.new(btm_color, 96))) // S
array.unshift(data.opr_linefills, linefill.new(array.get(data.opr_lines, array.size(data.opr_lines)-2), array.get(data.opr_lines, array.size(data.opr_lines)-4), color.new(top_color, 96))) // R
t1 = i_o_label_1 == 'price' ? str.tostring(top, format.mintick) : i_o_label_1
t2 = i_o_label_2 == 'price' ? str.tostring(btm, format.mintick) : i_o_label_2
my_label1 := label.new(_x1-1, top, t1, yloc=yloc.price, style=label.style_label_right, color=top_color, textcolor=top_text_color, size=i_o_size, tooltip=str.tostring(top, format.mintick))
my_label2 := label.new(_x1-1, btm, t2, yloc=yloc.price, style=label.style_label_right, color=btm_color, textcolor=bot_text_color, size=i_o_size, tooltip=str.tostring(btm, format.mintick))
array.push(data.opr_labels, my_label1)
array.push(data.opr_labels, my_label2)
array.push(data.opr_boxes , my_box)
if data.is_extended
box.set_extend(my_box, extend.right)
alert('Opening range is fixed.', alert.freq_once_per_bar)
else if is_opened
if ta.crossover(high, R1) and (not is_reached_R1)
is_reached_R1 := true
if i_o_breakout_icon
label.new(bar_index, high, '×', yloc=yloc.price, style=label.style_label_center, color=TRANSPARENT, textcolor=ac.tradingview('blue'), size=size.large)
if ta.crossover(high, R2) and (not is_reached_R2)
is_reached_R2 := true
if i_o_breakout_icon
label.new(bar_index, high, '×', yloc=yloc.price, style=label.style_label_center, color=TRANSPARENT, textcolor=ac.tradingview('blue'), size=size.large)
if ta.crossunder(low, S1) and (not is_reached_S1)
is_reached_S1 := true
if i_o_breakout_icon
label.new(bar_index, low, '×', yloc=yloc.price, style=label.style_label_center, color=TRANSPARENT, textcolor=ac.tradingview('red'), size=size.large)
if ta.crossunder(low, S2) and (not is_reached_S2)
is_reached_S2 := true
if i_o_breakout_icon
label.new(bar_index, low, '×', yloc=yloc.price, style=label.style_label_center, color=TRANSPARENT, textcolor=ac.tradingview('red'), size=size.large)
true
else
if is_crossover
alert('Price crossed over the opening range', alert.freq_once_per_bar)
if i_alert2_show
label.new(bar_index, box.get_top(my_box), "×", color=color.blue, textcolor=ac.tradingview('blue'), style=label.style_none, size=size.large)
if is_crossunder
alert('Price crossed under the opening range', alert.freq_once_per_bar)
if i_alert2_show
label.new(bar_index, box.get_bottom(my_box), "×", color=color.red, textcolor=ac.tradingview('red'), style=label.style_none, size=size.large)
else if _is_ended
if i_o_nowonly
util.clear_lines(data.opr_lines, 0)
util.clear_labels(data.opr_labels, 0)
util.clear_boxes(data.opr_boxes, 0)
else if array.size(data.opr_lines) > 0
for i = 0 to 5
the_line = array.get(data.opr_lines, array.size(data.opr_lines) - (i + 1))
line.set_x2(the_line, _x2-session_end_offset)
for i = 0 to 1
the_label = array.get(data.opr_labels, array.size(data.opr_labels) - (i + 1))
label.set_text(the_label, '●')
label.set_style(the_label, label.style_label_center)
label.set_textcolor(the_label, i_o_color == option_candle_color2 ? label.get_y(the_label) >= saved_top ? ac.tradingview('blue') : ac.tradingview('red') : _color)
label.set_color(the_label, TRANSPARENT)
label.set_size(the_label, size.tiny)
label.set_x(the_label,_x1)
data.op.total_count := data.op.total_count + 1
data.op.reached_count := (is_reached_R1 or is_reached_R2 or is_reached_S1 or is_reached_S2) ? data.op.reached_count + 1 : data.op.reached_count
data.op.reached_R1_count := is_reached_R1 ? data.op.reached_R1_count + session_end_offset : data.op.reached_R1_count
data.op.reached_R2_count := is_reached_R2 ? data.op.reached_R2_count + session_end_offset : data.op.reached_R2_count
data.op.reached_S1_count := is_reached_S1 ? data.op.reached_S1_count + session_end_offset : data.op.reached_S1_count
data.op.reached_S2_count := is_reached_S2 ? data.op.reached_S2_count + session_end_offset : data.op.reached_S2_count
// Reset
R1 := na, R2 := na, S1 := na, S2 := na
is_reached_R1 := false
is_reached_R2 := false
is_reached_S1 := false
is_reached_S2 := false
is_opened := false
saved_top := na
is_opened
data
// ------------------------
// Drawing candle
// ------------------------
f_render_candle (_show, Session data, _is_started, _is_ended, _color, _top, _bottom, _open, _x1, _x2) =>
var box body = na
var line wick1 = na
var line wick2 = na
session = data.session()
border_width = i_candle_border_width
cx = math.round(math.avg(_x2, _x1)) - math.round(border_width / 2)
body_color = i_candle_color == option_candle_color2 ? close > _open ? i_candle_color_g : i_candle_color_r : _color
body_color := color.new(body_color, 30)
if _show
if _is_started
body := box.new(_x1, _top, _x2, _bottom, body_color, border_width, line.style_solid, bgcolor=color.new(color.black, 100))
wick1 := i_show_candle_wick ? line.new(cx, _top, cx, _top, color=body_color, width=border_width, style=line.style_solid) : na
wick2 := i_show_candle_wick ? line.new(cx, _bottom, cx, _bottom, color=body_color, width=border_width, style=line.style_solid) : na
array.push(data.candle.body, body)
array.push(data.candle.wick, wick1)
array.push(data.candle.wick, wick2)
util.clear_boxes(data.candle.body, i_history_period)
util.clear_lines(data.candle.wick, i_history_period * 2)
else if session
top = math.max(_open, close)
bottom = math.min(_open, close)
box.set_top(body, top)
box.set_bottom(body, bottom)
box.set_right(body, _x2)
box.set_border_color(body, body_color)
line.set_y1(wick1, _top)
line.set_y2(wick1, top)
f_set_line_x1(wick1, cx)
f_set_line_x2(wick1, cx)
line.set_color(wick1, body_color)
line.set_y1(wick2, _bottom)
line.set_y2(wick2, bottom)
f_set_line_x1(wick2, cx)
f_set_line_x2(wick2, cx)
line.set_color(wick2, body_color)
else if _is_ended
box.set_right(body, bar_index-session_end_offset)
data
// ------------------------
// Rendering limit message
// ------------------------
f_render_limitmessage (_show, Session data, _is_started, _is_ended, _x, _y, _rightbars) =>
var label my_note = na
session = data.session()
if _show
if _is_started
if _rightbars > MAX_BARS
my_note := label.new(_x, _y, f_message_limit_bars(_rightbars), style=label.style_label_upper_left, color=color.yellow, textalign=text.align_left, yloc=yloc.price)
else if session
if _rightbars > MAX_BARS
label.set_y(my_note, _y)
label.set_text(my_note, f_message_limit_bars(_rightbars))
else
label.delete(my_note)
else if _is_ended
label.delete(my_note)
data
// Rendering session
//
f_render_sessionrange (_show, Session data, _is_started, _is_ended, _color, _top, _bottom, _x1, _x2, _is_vertical = false) =>
var line above_line = na
var line below_line = na
session = data.session()
if _show
if _is_started
if _is_vertical
above_line := line.new(_x1, _top, _x1, _bottom, width=i_sess_border_width, style=i_sess_border_style, color=_color)
below_line := line.new(_x2, _top, _x2, _bottom, width=i_sess_border_width, style=i_sess_border_style, color=_color)
else
above_line := line.new(_x1, _top, _x2, _top, width=i_sess_border_width, style=i_sess_border_style, color=_color)
below_line := line.new(_x1, _bottom, _x2, _bottom, width=i_sess_border_width, style=i_sess_border_style, color=_color)
linefill.new(above_line, below_line, color.new(_color, i_sess_bgopacity))
array.push(data.lines, above_line)
array.push(data.lines, below_line)
util.clear_lines(data.lines, data.is_extended ? 2 : i_history_period * 2)
if data.is_extended
if _is_vertical
line.set_extend(above_line, extend.both)
line.set_extend(below_line, extend.both)
else
line.set_extend(above_line, extend.right)
line.set_extend(below_line, extend.right)
else if session
if _is_vertical
line.set_y1(above_line, _bottom)
line.set_y2(above_line, _top)
line.set_y1(below_line, _bottom)
line.set_y2(below_line, _top)
else
line.set_y1(above_line, _top)
line.set_y2(above_line, _top)
line.set_x2(above_line, _x2)
line.set_y1(below_line, _bottom)
line.set_y2(below_line, _bottom)
line.set_x2(below_line, _x2)
else if _is_ended
if _is_vertical
line.set_x1(below_line, _x2-session_end_offset)
line.set_x2(below_line, _x2-session_end_offset)
else
line.set_x2(above_line, _x2-session_end_offset)
line.set_x2(below_line, _x2-session_end_offset)
data.add(_top - _bottom , i_info_period)
data
// ------------------------
// Rendering session box
// ------------------------
f_render_session (_show, Session data, _is_started, _is_ended, _color, _top, _bottom, _x1, _x2) =>
var box my_box = na
session = data.session()
if _show
if _is_started
my_box := box.new(_x1, _top, _x2, _bottom, _color, i_sess_border_width, i_sess_border_style, bgcolor=color.new(_color, i_sess_bgopacity))
array.push(data.boxes, my_box)
util.clear_boxes(data.boxes, data.is_extended ? 1 : i_history_period)
if data.is_extended
box.set_extend(my_box, extend.right)
else if session
box.set_top(my_box, _top)
box.set_bottom(my_box, _bottom)
f_set_box_right(my_box, _x2)
else if _is_ended
box.set_right(my_box, bar_index-session_end_offset)
data.add(_top - _bottom , i_info_period)
data
f_render_dots (_show, Session data, _is_started, _is_ended, _color, _top, _bottom, _x1, _x2) =>
var float _open = na
var box oc_box = na
var line oc_line_u = na
var line oc_line_l = na
session = data.session()
if _show and i_sess_box_dots
if _is_started
oc_line_u := line.new(_x1, open , _x2, open , color=color.new(_color, 70), style=line.style_dotted)
oc_line_l := line.new(_x1, close, _x2, close, color=color.new(_color, 70), style=line.style_dotted)
linefill.new(oc_line_u, oc_line_l, color.new(_color, i_sess_bgopacity2))
array.push(data.oclines, oc_line_u)
array.push(data.oclines, oc_line_l)
util.clear_lines(data.oclines, data.is_extended ? 2 : i_history_period * 2)
util.clear_labels(data.oc_labels, data.is_extended ? 2 : math.max(0, (i_history_period - 1) * 2))
_open := open
else if session
line.set_x2(oc_line_u, _x2)
line.set_x2(oc_line_l, _x2)
line.set_y1(oc_line_l, close)
line.set_y2(oc_line_l, close)
else if _is_ended
array.push(data.oc_labels, Dot.new(_x1, _open, '●', _color).create())
array.push(data.oc_labels, Dot.new(_x2-session_end_offset, close , '◉', _color).create())
line.set_x2(oc_line_u, _x2-session_end_offset)
line.set_x2(oc_line_l, _x2-session_end_offset)
line.set_y1(oc_line_l, close )
line.set_y2(oc_line_l, close )
_open := na
true
// ------------------------
// Drawing market
// ------------------------
f_render_main (_show, Session data, _is_started, _is_ended, _color, _top, _bottom) =>
var x1 = 0
var x2 = 0
x2_offset = 1
session = data.session()
x0_1 = ta.valuewhen(na(session ) and session, bar_index, 1)
x0_2 = ta.valuewhen(na(session) and session , bar_index, 0)
x0_d = math.min(math.abs(x0_2 - x0_1), MAX_BARS)
rightbars = x0_d
if _show
if _is_started
x1 := bar_index
x2 := bar_index + x0_d
data.ohlc.open := open
data.ohlc.high := _top
data.ohlc.low := _bottom
data.ohlc.hl := _top -_bottom
data.in_session := true
else if session
true_x2 = x1 + x0_d
rightbars := true_x2 - bar_index
max_bars = bar_index + MAX_BARS
x2 := math.min(true_x2, max_bars)
data.ohlc.high := _top
data.ohlc.low := _bottom
data.ohlc.hl := _top - _bottom
else if _is_ended
data.in_session := false
data.ohlc.open := na
// ------------------------
// Drawing
// ------------------------
draw (_show, Session data, _extend, _show_fib, _show_op) =>
session = data.session()
max = f_get_period(session, 1, i_lookback)
top = ta.highest(high, max)
bottom = ta.lowest(low, max)
col = data.colour
is_started = f_get_started(session)
is_ended = f_get_ended(session)
= f_render_main(_show, data, is_started, is_ended, col, top, bottom)
if i_sess_box_style == 'Box' or i_sess_box_style == 'Background' or i_sess_box_style == 'Candle'
f_render_session(_show, data, is_started, is_ended, col, top, bottom, x1, x2)
f_render_dots(_show, data, is_started, is_ended, col, top, bottom, x1, x2)
else if i_sess_box_style == 'Hamburger'
f_render_sessionrange(_show, data, is_started, is_ended, col, top, bottom, x1, x2)
else if i_sess_box_style == 'Sandwich'
f_render_sessionrange(_show, data, is_started, is_ended, col, top, bottom, x1, x2, true)
if i_show_candle
f_render_candle(_show, data, is_started, is_ended, col, top, bottom, ohlc.open, x1, x2)
if i_label_show
f_render_label(_show, data, is_started, col, top, bottom)
if _show_op
f_render_oprange(_show, data, is_started, is_ended, x1, x2, col, max)
if _show_fib
f_render_fibonacci(_show, data, is_started, is_ended, x1, x2, col, top, bottom, 0.500, 2, line.style_solid)
f_render_fibonacci(_show, data, is_started, is_ended, x1, x2, col, top, bottom, 0.628, i_f_linewidth, i_f_linestyle)
f_render_fibonacci(_show, data, is_started, is_ended, x1, x2, col, top, bottom, 0.382, i_f_linewidth, i_f_linestyle)
util.clear_lines(data.fib, i_history_period * 3)
f_render_limitmessage(_show, data, is_started, is_ended, x1, bottom, _rightbars)
///////////////////
// Calculating
///////////////////
string tz = (i_tz == option_no or i_tz == '') ? na : i_tz
///////////////////
// Plotting
///////////////////
var sess1_data = Session.new(i_sess1, tz, i_sess1_label, i_sess1_color).create(i_sess1_extend, i_sess1_fib, i_sess1_op)
var sess2_data = Session.new(i_sess2, tz, i_sess2_label, i_sess2_color).create(i_sess2_extend, i_sess2_fib, i_sess2_op)
var sess3_data = Session.new(i_sess3, tz, i_sess3_label, i_sess3_color).create(i_sess3_extend, i_sess3_fib, i_sess3_op)
var sess4_data = Session.new(i_sess4, tz, i_sess4_label, i_sess4_color).create(i_sess4_extend, i_sess4_fib, i_sess4_op)
var sess5_data = Session.new(i_sess5, tz, i_sess5_label, i_sess5_color).create(i_sess5_extend, i_sess5_fib, i_sess5_op)
= draw(i_show_sess1, sess1_data, i_sess1_extend, i_sess1_fib, i_sess1_op)
= draw(i_show_sess2, sess2_data, i_sess2_extend, i_sess2_fib, i_sess2_op)
= draw(i_show_sess3, sess3_data, i_sess3_extend, i_sess3_fib, i_sess3_op)
= draw(i_show_sess4, sess4_data, i_sess4_extend, i_sess4_fib, i_sess4_op)
= draw(i_show_sess5, sess5_data, i_sess5_extend, i_sess5_fib, i_sess5_op)
is_positive_bar = close > open
color c_barcolor = na
color c_plotcandle = na
c_sess1_barcolor = (is_sess1) ? (is_positive_bar ? i_sess1_barcolor1 : i_sess1_barcolor2) : na
c_sess2_barcolor = (is_sess2) ? (is_positive_bar ? i_sess2_barcolor1 : i_sess2_barcolor2) : na
c_sess3_barcolor = (is_sess3) ? (is_positive_bar ? i_sess3_barcolor1 : i_sess3_barcolor2) : na
c_sess4_barcolor = (is_sess4) ? (is_positive_bar ? i_sess4_barcolor1 : i_sess4_barcolor2) : na
c_sess5_barcolor = (is_sess5) ? (is_positive_bar ? i_sess5_barcolor1 : i_sess5_barcolor2) : na
if (i_sess1_chart != option_chart_x) and is_sess1
c_barcolor := i_sess1_barcolor ? c_sess1_barcolor : na
c_plotcandle := i_sess1_plotcandle ? c_sess1_barcolor : na
if (i_sess2_chart != option_chart_x) and is_sess2
c_barcolor := i_sess2_barcolor ? c_sess2_barcolor : na
c_plotcandle := i_sess2_plotcandle ? c_sess2_barcolor : na
if (i_sess3_chart != option_chart_x) and is_sess3
c_barcolor := i_sess3_barcolor ? c_sess3_barcolor : na
c_plotcandle := i_sess3_plotcandle ? c_sess3_barcolor : na
if (i_sess4_chart != option_chart_x) and is_sess4
c_barcolor := i_sess4_barcolor ? c_sess4_barcolor : na
c_plotcandle := i_sess4_plotcandle ? c_sess4_barcolor : na
if (i_sess5_chart != option_chart_x) and is_sess5
c_barcolor := i_sess5_barcolor ? c_sess5_barcolor : na
c_plotcandle := i_sess5_plotcandle ? c_sess5_barcolor : na
barcolor(c_barcolor)
plotcandle(open, high, low, close, color=is_positive_bar ? TRANSPARENT : c_plotcandle, bordercolor=c_plotcandle, wickcolor=c_plotcandle)
////////////////////
// Alerts
////////////////////
// Session alerts
sess1_started = is_sess1 and not is_sess1 , sess1_ended = not is_sess1 and is_sess1
sess2_started = is_sess2 and not is_sess2 , sess2_ended = not is_sess2 and is_sess2
sess3_started = is_sess3 and not is_sess3 , sess3_ended = not is_sess3 and is_sess3
sess4_started = is_sess4 and not is_sess4 , sess4_ended = not is_sess4 and is_sess4
sess5_started = is_sess5 and not is_sess5 , sess5_ended = not is_sess5 and is_sess5
alertcondition(sess1_started, 'Session #1 started')
alertcondition(sess1_ended, 'Session #1 ended' )
alertcondition(sess2_started, 'Session #2 started')
alertcondition(sess2_ended, 'Session #2 ended' )
alertcondition(sess3_started, 'Session #3 started')
alertcondition(sess3_ended, 'Session #3 ended' )
alertcondition(sess4_started, 'Session #4 started')
alertcondition(sess4_ended, 'Session #4 ended' )
alertcondition(sess5_started, 'Session #5 started')
alertcondition(sess5_ended, 'Session #5 ended' )
alertcondition((not is_sess1) and ta.crossover (close, sess1_ohlc.high), 'Session #1 High crossed (after session closed)')
alertcondition((not is_sess1) and ta.crossunder(close, sess1_ohlc.low) , 'Session #1 Low crossed (after session closed)' )
alertcondition((not is_sess2) and ta.crossover (close, sess2_ohlc.high), 'Session #2 High crossed (after session closed)')
alertcondition((not is_sess2) and ta.crossunder(close, sess2_ohlc.low) , 'Session #2 Low crossed (after session closed)' )
alertcondition((not is_sess3) and ta.crossover (close, sess3_ohlc.high), 'Session #3 High crossed (after session closed)')
alertcondition((not is_sess3) and ta.crossunder(close, sess3_ohlc.low) , 'Session #3 Low crossed (after session closed)' )
alertcondition((not is_sess4) and ta.crossover (close, sess4_ohlc.high), 'Session #4 High crossed (after session closed)')
alertcondition((not is_sess4) and ta.crossunder(close, sess4_ohlc.low) , 'Session #4 Low crossed (after session closed)' )
alertcondition((not is_sess5) and ta.crossover (close, sess5_ohlc.high), 'Session #5 High crossed (after session closed)')
alertcondition((not is_sess5) and ta.crossunder(close, sess5_ohlc.low) , 'Session # Low crossed (after session closed)' )
// Alerts visualized
if i_alert1_show
if i_show_sess1
if sess1_started
label.new(bar_index, close, 'Start', yloc=yloc.abovebar, color=i_sess1_color, textcolor=color_text, size=size.small, style=label.style_label_down)
if sess1_ended
label.new(bar_index - session_end_offset, close, 'End' , yloc=yloc.abovebar, color=i_sess1_color, textcolor=color_text, size=size.small, style=label.style_label_down)
if i_show_sess2
if sess2_started
label.new(bar_index, close, 'Start', yloc=yloc.abovebar, color=i_sess2_color, textcolor=color_text, size=size.small, style=label.style_label_down)
if sess2_ended
label.new(bar_index - session_end_offset, close, 'End' , yloc=yloc.abovebar, color=i_sess2_color, textcolor=color_text, size=size.small, style=label.style_label_down)
if i_show_sess3
if sess3_started
label.new(bar_index, close, 'Start', yloc=yloc.abovebar, color=i_sess3_color, textcolor=color_text, size=size.small, style=label.style_label_down)
if sess3_ended
label.new(bar_index - session_end_offset, close, 'End' , yloc=yloc.abovebar, color=i_sess3_color, textcolor=color_text, size=size.small, style=label.style_label_down)
if i_show_sess4
if sess4_started
label.new(bar_index, close, 'Start', yloc=yloc.abovebar, color=i_sess4_color, textcolor=color_text, size=size.small, style=label.style_label_down)
if sess4_ended
label.new(bar_index - session_end_offset, close, 'End' , yloc=yloc.abovebar, color=i_sess4_color, textcolor=color_text, size=size.small, style=label.style_label_down)
if i_show_sess5
if sess5_started
label.new(bar_index, close, 'Start', yloc=yloc.abovebar, color=i_sess4_color, textcolor=color_text, size=size.small, style=label.style_label_down)
if sess5_ended
label.new(bar_index - session_end_offset, close, 'End' , yloc=yloc.abovebar, color=i_sess5_color, textcolor=color_text, size=size.small, style=label.style_label_down)
plot(i_alert3_show ? sess1_ohlc.high : na, 'sess1_high', style=plot.style_linebr, color=i_sess1_color)
plot(i_alert3_show ? sess1_ohlc.low : na, 'sess1_low' , style=plot.style_linebr, color=i_sess1_color, linewidth=2)
plot(i_alert3_show ? sess2_ohlc.high : na, 'sess2_high', style=plot.style_linebr, color=i_sess2_color)
plot(i_alert3_show ? sess2_ohlc.low : na, 'sess2_low' , style=plot.style_linebr, color=i_sess2_color, linewidth=2)
plot(i_alert3_show ? sess3_ohlc.high : na, 'sess3_high', style=plot.style_linebr, color=i_sess3_color)
plot(i_alert3_show ? sess3_ohlc.low : na, 'sess3_low' , style=plot.style_linebr, color=i_sess3_color, linewidth=2)
plot(i_alert3_show ? sess4_ohlc.high : na, 'sess4_high', style=plot.style_linebr, color=i_sess4_color)
plot(i_alert3_show ? sess4_ohlc.low : na, 'sess4_low' , style=plot.style_linebr, color=i_sess4_color, linewidth=2)
plot(i_alert3_show ? sess5_ohlc.high : na, 'sess5_high', style=plot.style_linebr, color=i_sess5_color)
plot(i_alert3_show ? sess5_ohlc.low : na, 'sess5_low' , style=plot.style_linebr, color=i_sess5_color, linewidth=2)
plotshape(i_alert3_show and (not is_sess1) and ta.crossover (close, sess1_ohlc.high) ? sess1_ohlc.high : na, 'cross sess1_high', color=i_sess1_color, style=shape.triangleup , location=location.absolute, size=size.tiny)
plotshape(i_alert3_show and (not is_sess1) and ta.crossunder(close, sess1_ohlc.low) ? sess1_ohlc.low : na, 'cross sess1_low' , color=i_sess1_color, style=shape.triangledown, location=location.absolute, size=size.tiny)
plotshape(i_alert3_show and (not is_sess2) and ta.crossover (close, sess2_ohlc.high) ? sess2_ohlc.high : na, 'cross sess2_high', color=i_sess2_color, style=shape.triangleup , location=location.absolute, size=size.tiny)
plotshape(i_alert3_show and (not is_sess2) and ta.crossunder(close, sess2_ohlc.low) ? sess2_ohlc.low : na, 'cross sess2_low' , color=i_sess2_color, style=shape.triangledown, location=location.absolute, size=size.tiny)
plotshape(i_alert3_show and (not is_sess3) and ta.crossover (close, sess3_ohlc.high) ? sess3_ohlc.high : na, 'cross sess3_high', color=i_sess3_color, style=shape.triangleup , location=location.absolute, size=size.tiny)
plotshape(i_alert3_show and (not is_sess3) and ta.crossunder(close, sess3_ohlc.low) ? sess3_ohlc.low : na, 'cross sess3_low' , color=i_sess3_color, style=shape.triangledown, location=location.absolute, size=size.tiny)
plotshape(i_alert3_show and (not is_sess4) and ta.crossover (close, sess4_ohlc.high) ? sess4_ohlc.high : na, 'cross sess4_high', color=i_sess4_color, style=shape.triangleup , location=location.absolute, size=size.tiny)
plotshape(i_alert3_show and (not is_sess4) and ta.crossunder(close, sess4_ohlc.low) ? sess4_ohlc.low : na, 'cross sess4_low' , color=i_sess4_color, style=shape.triangledown, location=location.absolute, size=size.tiny)
//////////////
// Analysis //
var text_color = #e1e2e4
var bgcolor = #1a1c20
var color_green = ac.monokai('green')
var color_orange = ac.monokai('orange')
var color_red = ac.monokai('red')
var color_ind_green = ac.tradingview('green')
var color_ind_gray = color.new(ac.tradingview('gray'), 30)
var color_white = #e1e2e4
i_show_op_analysis = false//input.bool(true, 'Opening range table')
i_show_analysis2 = false//input.bool(false)
if i_show_info and barstate.islast
data = array.new()
if array.size(sess1_data.price_ranges) > 0
data.push(sess1_data)
if array.size(sess2_data.price_ranges) > 0
data.push(sess2_data)
if array.size(sess3_data.price_ranges) > 0
data.push(sess3_data)
if array.size(sess4_data.price_ranges) > 0
data.push(sess4_data)
var tbl_avg = table.new(position.top_right, 5, 5, frame_width=2, bgcolor=bgcolor, frame_color=#25272c, border_width=1, border_color=#25272c)
table.cell(tbl_avg, 0, 0, 'Session', text_color=color.new(text_color, 60), text_size=i_info_size, text_halign=text.align_center)
table.cell(tbl_avg, 1, 0, '', text_color=color.new(text_color, 60), text_size=i_info_size)
table.cell(tbl_avg, 2, 0, 'Cur', text_color=color.new(text_color, 60), text_size=i_info_size)
table.cell(tbl_avg, 3, 0, 'Avg('+str.tostring(i_info_period)+')', text_color=color.new(text_color, 60), text_size=i_info_size)
table.cell(tbl_avg, 4, 0, '%', text_color=color.new(text_color, 60), text_size=i_info_size)
table.merge_cells(tbl_avg, 0, 0, 1, 0)
if array.size(data) > 0
for i = 0 to array.size(data) - 1
my_data = array.get(data, i)
in_session = my_data.in_session and session.ismarket
p = my_data.ohlc.hl / my_data.price_range_avg
col_cur = p < 0.75 ? color_green : p < 1.25 ? color_orange : color_red
v1 = i_info_value_type == 'Price' ? str.tostring(my_data.ohlc.hl, format.mintick) : str.tostring(util.toPips(my_data.ohlc.hl), '#.#')
v2 = i_info_value_type == 'Price' ? str.tostring(my_data.price_range_avg, format.mintick) : str.tostring(util.toPips(my_data.price_range_avg), '#.#')
v3 = in_session ? '◉' : '●'
color_name = in_session ? color_white : color.new(ac.monokai('gray'), 30)
color_ind = in_session ? color_ind_green : color_ind_gray
color_cur = in_session ? col_cur : color.new(col_cur, 60)
table.cell(tbl_avg, 0, i + 1, my_data.name, text_color=color_name, text_size=i_info_size, text_halign=text.align_left)
table.cell(tbl_avg, 1, i + 1, v3, text_color=color_ind , text_size=size.tiny, text_halign=text.align_center, text_valign=text.align_center)
table.cell(tbl_avg, 2, i + 1, v1, text_color=color_cur , text_size=i_info_size, text_halign=text.align_right, text_font_family=font.family_monospace)
table.cell(tbl_avg, 3, i + 1, v2, text_color=color_name, text_size=i_info_size, text_halign=text.align_right, text_font_family=font.family_monospace)
table.cell(tbl_avg, 4, i + 1, str.format('{0,number,percent}', p), text_color=color_cur, text_size=i_info_size, text_halign=text.align_right, text_font_family=font.family_monospace)
if i_show_op_analysis and (barstate.islast or barstate.isconfirmed)
data = array.new()
if sess1_data.op.reached_count > 0
array.unshift(data, sess1_data)
if sess2_data.op.reached_count > 0
array.unshift(data, sess2_data)
if sess3_data.op.reached_count > 0
array.unshift(data, sess3_data)
if sess4_data.op.reached_count > 0
array.unshift(data, sess4_data)
var tbl_op = table.new(position.bottom_right, 7, 5, frame_width=2, bgcolor=bgcolor, frame_color=#25272c, border_width=1, border_color=#25272c)
table.cell(tbl_op, 0, 0, 'Opening range' + (array.size(data) == 0 ? ' (No data)' : ''), text_size=i_info_size)
table.merge_cells(tbl_op, 0, 0, 6, 0)
if array.size(data) > 0
table.cell(tbl_op, 0, 1, 'Session', text_size=i_info_size)
table.cell(tbl_op, 1, 1, 'Sum', text_size=i_info_size)
table.cell(tbl_op, 2, 1, 'R1', text_size=i_info_size)
table.cell(tbl_op, 3, 1, 'S1', text_size=i_info_size)
table.cell(tbl_op, 4, 1, 'R2', text_size=i_info_size)
table.cell(tbl_op, 5, 1, 'S2', text_size=i_info_size)
table.cell(tbl_op, 6, 1, 'Total', text_size=i_info_size)
row_index = 2
for i = 0 to array.size(data) -1
my_data = array.get(data, i)
table.cell(tbl_op, 0, row_index + i, my_data.name, text_size=i_info_size, text_color=color_white, text_halign=text.align_left)
table.cell(tbl_op, 1, row_index + i, str.format('{0,number,percent}', my_data.op.reached_count / my_data.op.total_count), text_font_family=font.family_monospace, text_halign=text.align_right, text_color=color_white, text_size=i_info_size)
table.cell(tbl_op, 2, row_index + i, str.format('{0,number,percent}', my_data.op.reached_R1_count / my_data.op.total_count), text_font_family=font.family_monospace, text_halign=text.align_right, text_color=color_white, text_size=i_info_size)
table.cell(tbl_op, 3, row_index + i, str.format('{0,number,percent}', my_data.op.reached_S1_count / my_data.op.total_count), text_font_family=font.family_monospace, text_halign=text.align_right, text_color=color_white, text_size=i_info_size)
table.cell(tbl_op, 4, row_index + i, str.format('{0,number,percent}', my_data.op.reached_R2_count / my_data.op.total_count), text_font_family=font.family_monospace, text_halign=text.align_right, text_color=color_white, text_size=i_info_size)
table.cell(tbl_op, 5, row_index + i, str.format('{0,number,percent}', my_data.op.reached_S2_count / my_data.op.total_count), text_font_family=font.family_monospace, text_halign=text.align_right, text_color=color_white, text_size=i_info_size)
table.cell(tbl_op, 6, row_index + i, str.tostring(my_data.op.total_count), text_font_family=font.family_monospace, text_halign=text.align_right, text_color=color_white, text_size=i_info_size)
if i_show_analysis2 and barstate.islast
max = 100
g_base = ta.lowest(max)
s3_count = 0
s2_count = 0
var g_lines = array.new()
x = bar_index + 20
util.clear_lines(g_lines, 0)
array.push(g_lines, line.new(x + 0, g_base, x + 0, g_base + sess1_data.price_range_avg, color=sess1_data.colour, width=3))
array.push(g_lines, line.new(x + 2, g_base, x + 2, g_base + sess2_data.price_range_avg, color=sess2_data.colour, width=3))
array.push(g_lines, line.new(x + 4, g_base, x + 4, g_base + sess3_data.price_range_avg, color=sess3_data.colour, width=3))
array.push(g_lines, line.new(x + 6, g_base, x + 6, g_base + sess4_data.price_range_avg, color=sess4_data.colour, width=3))
if array.size(sess1_data.price_ranges) > 0 and array.size(sess3_data.price_ranges) > 0
for i = 0 to array.size(sess1_data.price_ranges) - 1
s1 = array.get(sess1_data.price_ranges, i)
s3 = array.get(sess3_data.price_ranges, i)
if s3 / s1 > 1
s3_count := s3_count + 1
tbl = table.new(position.bottom_right, 3, 3, frame_width=2, bgcolor=bgcolor, frame_color=#25272c, border_width=1, border_color=#25272c)
table.cell(tbl, 0, 0, sess3_data.name + ' > ' + sess1_data.name, text_color=#e1e2e4)
table.cell(tbl, 1, 0, str.tostring(s3_count) + ' / ' + str.tostring(array.size(sess1_data.price_ranges)), text_color=#e1e2e4)
table.cell(tbl, 2, 0, str.format('{0,number,percent}', s3_count / array.size(sess1_data.price_ranges) ), text_color=#e1e2e4)
table.cell(tbl, 0, 1, syminfo.ticker + '('+ syminfo.currency +')', text_color=#e1e2e4)
table.merge_cells(tbl, 0, 1, 2, 1)
// --- Input Definitions ---
range_start_hour = input.int(4, "Range Start Hour", group="START", inline="start", minval=0, maxval=23)
range_start_minute = input.int(0, "Minutes", group="START", inline="start", minval=0, maxval=59)
range_end_hour = input.int(12, "Range End Hour", group="END", inline="end", minval=0, maxval=23)
range_end_minute = input.int(0, "Minutes", group="END", inline="end", minval=0, maxval=59)
timezone_offset_hours = input.int(0, "Timezone UTC Offset Hours", group="Time Zone Offset", minval=-12, maxval=14)
timezone_offset_minutes = input.int(0, "Timezone UTC Offset Minutes", group="Time Zone Offset", minval=-59, maxval=59)
count = input(3, "Count")
colorTop = input(color.green, "Top Color", group="STYLING")
colorBetween = input(color.new(color.gray, 50), "Between Color", group="STYLING")
colorBottom = input(color.red, "Bottom Color", group="STYLING")
colorRange = input(color.blue, "Range Color", group="STYLING")
rangeIsDotted = input(true, "Dash Line Style For The Range", group="STYLING")
plot_mid = input(true, "Plot Mid Lines")
close_to_close = input(false, "Close To Close (instead of low to high distance)")
// --- Variable Initialization ---
var float range_high = na
var float range_low = na
var float distance = na
var int startIDX = na
// Function to calculate adjusted time based on timezone offset
getAdjustedTime(hour, minute, offset_hours, offset_minutes) =>
total_minutes = hour * 60 + minute + offset_hours * 60 + offset_minutes
// Function to normalize time to minutes from the start of the week
normalizeTimeToWeek(hour, minute) =>
(dayofweek - 1) * 24 * 60 + hour * 60 + minute
// Adjusted Time Calculations
= getAdjustedTime(range_start_hour, range_start_minute, timezone_offset_hours, timezone_offset_minutes)
= getAdjustedTime(range_end_hour, range_end_minute, timezone_offset_hours, timezone_offset_minutes)
// Normalize times to minutes from the start of the week
start_time_minutes = normalizeTimeToWeek(adjusted_start_hour, adjusted_start_minute)
end_time_minutes = normalizeTimeToWeek(adjusted_end_hour, adjusted_end_minute)
// Adjust the end time if the range spans over midnight
if adjusted_start_hour > adjusted_end_hour or (adjusted_start_hour == adjusted_end_hour and adjusted_start_minute > adjusted_end_minute)
end_time_minutes := end_time_minutes + 7 * 24 * 60 // Add 7 days worth of minutes
// Current time normalized to minutes from the start of the week
current_time_minutes = normalizeTimeToWeek(hour, minute)
// Detect if the current time is before the start of the week normalized time
if current_time_minutes < start_time_minutes
current_time_minutes := current_time_minutes + 7 * 24 * 60 // Adjust for new week
// Determine if we are in the plotting range
isInRange = current_time_minutes >= start_time_minutes and current_time_minutes <= end_time_minutes
// Main Logic
if isInRange
if na(range_high) // If this is the first bar to plot
startIDX := bar_index
range_high := close_to_close ? close : high
range_low := close_to_close ? close : low
else
range_high := math.max(range_high, close_to_close ? close : high)
range_low := math.min(range_low, close_to_close ? close : low)
distance := range_high - range_low
else if not na(range_high) // If we have completed the range
// Draw the range lines
line.new(startIDX, range_high, bar_index , range_high, xloc=xloc.bar_index, style=rangeIsDotted ? line.style_dashed : line.style_solid, color=colorRange)
line.new(startIDX, range_low, bar_index , range_low, xloc=xloc.bar_index, style=rangeIsDotted ? line.style_dashed : line.style_solid, color=colorRange)
// Draw additional lines based on the count input
for i = 1 to count
line.new(startIDX, range_high + i * distance, bar_index , range_high + i * distance, xloc=xloc.bar_index, style=line.style_solid, color=colorTop)
line.new(startIDX, range_low - i * distance, bar_index , range_low - i * distance, xloc=xloc.bar_index, style=line.style_solid, color=colorBottom)
if plot_mid
line.new(startIDX, range_high + (i - 0.5) * distance, bar_index , range_high + (i - 0.5) * distance, xloc=xloc.bar_index, style=line.style_dashed, color=colorBetween)
line.new(startIDX, range_low - (i - 0.5) * distance, bar_index , range_low - (i - 0.5) * distance, xloc=xloc.bar_index, style=line.style_dashed, color=colorBetween)
// Reset the variables after plotting
range_high := na
range_low := na
distance := na
startIDX := na
Stock Trend Catcher - VThis Pine Script trading strategy has three main components:
Entry Conditions:
Uses multiple timeframe analysis with EMA crossover, SuperTrend, RSI, and ADX
Requires volume spike confirmation
Checks both higher and current timeframe data
Long entry: EMA cross up + SuperTrend up + RSI>50 + ADX>25 + volume spike
Short entry: Opposite conditions
Exit Conditions:
Takes profit at user-defined percentage (default 2%)
Stops loss at user-defined percentage (default 1%)
[Taj_treyder] signal buy-sell + ZigZagСалом ба хама Трейдерони Точик! Ман Абдулло Ахмадов хастам.
Ман ин индикатор-ро барои истифодабарии трейдер-хо ва тредуня-хои Точик сохтам,
Аз сабабе ки ин индикатор-ро ман аз 4- авторхои дигари Тредингвью гирифтам якчоя кардам онро дар руйи хати умуми монда наметонам. Шумо метавонед ин индикатор-ро озод дар графикхои худ истифода баред (Таймфрейми аз 45М, 1Н, 2Н, 4Н, то D1).
Хусусият-хои ин индикатор: Ердам кардан дар Торговляи шумо, Осон намудани Тичорати шумо дар бозорхои чахони!
1.- Муян намудани уровен-хои Сапративления ва Подержка,
2.- Муаян намудани Линия Тренда.
3.- Муаян намудани Восходящий ё Нисходящий Тренд (Рынок боло ё поён харакат дорад).
4.- Муаян намудани Точка входа-100% (чойи аники 100% Сделкаро кушодан).
5.- Мондани-100% Стоп-Лосс (чойи аники-100% мондани басс-зарар-дидан, - 2% аз Капитал).
6.- Мондани Тейк-профит (Чойи аники-100% баландтар-ини гирифтани фойда, 1/3, 1/5).
Ман ин индикаторро барои истифода барии Трейдер-хои тамоми Точикони руи замин сохтам! истифода-барии ин ройгон (бе пул, "без платно" мебошад).
Ин Индикатор кори шуморо-95% осон мекунад, Ердами аники хисоби математикии Уровинхо, Ердами аники математикии Линия-Тренда, Ердами-100% аники кушодани сделкахои Лонг ё Шорт (100%- сигналы Buy и Sell с помощью искусственного интеллекта).
Ердами фахмиши боло ё поён равии Рынокхо (100%- определения Восходящего и Нисходящего рынока).
Supertrend + KAMA Long StrategyThis strategy combines Supertrend and Kaufman Adaptive Moving Average (KAMA) indicators to identify long positions and manage stop-loss conditions effectively.
**Supertrend**: Determines the trend direction and helps identify entry and exit points.
**KAMA**: Adapts dynamically to market volatility and confirms trend reversals.
The strategy enters a long position when the Supertrend indicates an uptrend and the price is above the KAMA. It exits when the Supertrend switches to a downtrend and the price is below the KAMA, minimizing losses or protecting profits.
Temporary Help Services Jobs - Trend Allocation StrategyThis strategy is designed to capitalize on the economic trends represented by the Temporary Help Services (TEMPHELPS) index, which is published by the Federal Reserve Economic Data (FRED). Temporary Help Services Jobs are often regarded as a leading indicator of labor market conditions, as changes in temporary employment levels frequently precede broader employment trends.
Methodology:
Data Source: The strategy uses the FRED dataset TEMPHELPS for monthly data on temporary help services.
Trend Definition:
Uptrend: When the current month's value is greater than the previous month's value.
Downtrend: When the current month's value is less than the previous month's value.
Entry Condition: A long position is opened when an uptrend is detected, provided no position is currently held.
Exit Condition: The long position is closed when a downtrend is detected.
Scientific Basis:
The TEMPHELPS index serves as a leading economic indicator, as noted in studies analyzing labor market cyclicality (e.g., Katz & Krueger, 1999). Temporary employment is often considered a proxy for broader economic conditions, particularly in predicting recessions or recoveries. Incorporating this index into trading strategies allows for aligning trades with potential macroeconomic shifts, as suggested by research on employment trends and market performance (Autor, 2001; Valetta & Bengali, 2013).
Usage:
This strategy is best suited for long-term investors or macroeconomic trend followers who wish to leverage labor market signals for equity or futures trading. It operates exclusively on end-of-month data, ensuring minimal transaction costs and noise.
Prem_0915_5mins_strategyThis is the strategy which is worked out in 5 min TF. This should be applied only on Indexes (e.g., Nifty 50, BankNifty, etc.). This should strictly NOT be used for stocks and other F&Os. This is just for an educational purpose. Do not follow the strategy as such. Analyse before using every strategy and every investment.
Step 1: The candle should breakout and close beyond the high line (or The candle should breakdown and close below to the the low line)
Step 2: Enter at the next candle after the breakout (for CE) or breakdown (for PE)
Step 3: SL should be the low of the previous candle under the highline (or above the low line) but within the range
Step 4: Apply for 1:1 RR ratio and quit for safer profit.
MTF Countdown with Direction - AynetIndicator Definition and Inputs:
pineCopyindicator('MTF Countdown with Direction - Aynet', overlay = true)
This code creates a Multiple Time Frame (MTF) countdown indicator with direction
The overlay = true parameter places the indicator on top of the price chart
Timeframe Options:
Users can choose to show/hide the following timeframes:
1 minute
5 minutes
15 minutes
30 minutes
1 hour
4 hours
Daily
Time Calculations:
pineCopyget_current_time()
Calculates the current time
Converts Unix timestamp to seconds
Calculates time since midnight
Returns time broken down into hours, minutes, and seconds
Countdown Calculation:
pineCopyget_period_countdown(period_seconds)
Calculates remaining time for each timeframe
Computes elapsed time in current period
Returns remaining time in hours, minutes, and seconds
Direction and Closing Price Calculation:
Separate functions for each timeframe (get_direction_and_close_1m(), get_direction_and_close_5m(), etc.)
Each function:
Gets current closing price
Compares with previous closing price
Determines direction (up: 1, down: -1, sideways: 0)
Returns direction and closing price
Table Creation and Updates:
Creates a table in the top right corner
Table consists of 4 columns:
Period (Timeframe)
Time Left (Remaining time)
Direction (Shown with arrows)
Close (Closing price)
Each row has a different background color
Direction arrows:
Green up arrow (▲): Price rising
Red down arrow (▼): Price falling
Gray line (―): Price sideways
Dynamic Data Structures:
pineCopyvar timeframes = array.new_int()
var timeframe_names = array.new_string()
var show_array = array.new_bool()
Uses dynamic arrays for timeframes
Adds selected timeframes to arrays on first run
Key Features:
Shows remaining time until period close
Displays price direction for each timeframe
Shows current closing prices
All information in a single, easy-to-read table
This indicator helps traders by providing a comprehensive view of:
When each timeframe will close
The direction of price movement
Current closing prices
across multiple timeframes in a single table, making it easier to track market movements across different time periods.
The color-coding and arrow system makes it visually intuitive to understand market direction at a glance, while the countdown timer helps with timing decisions.
ALMA Crossover StrategyALMA (Arnaud Legoux Moving Average) is a type of moving average that attempts to reduce the lag of traditional moving averages while still being responsive to recent price changes. It is based on a weighted average. Strategy has user defined line length and can be adjusted to suit the trader's preference.
The script is purely for educational purposes and you are advised to backtest before using for trading
Anchored GB TimeCustomizable indicator designed to track the number of hours elapsed since a user-defined starting point, such as the weekly market open. It highlights significant time intervals by checking the elapsed hour count against predefined GB Numbers and CE Numbers, offering precise insights for time-based trading strategies.
Custom Start Time:
Choose the day and hour when the counter resets, making it adaptable to different asset classes and market sessions.
Perfect for aligning with weekly opens or specific algorithmic strategies.
GB and CE Numbers:
Predefined sets of Goldbach (GB) Numbers and Critical Event (CE) Numbers.
Labels are displayed when the hour counter matches one of these significant numbers.
Customizable Appearance:
Separate settings for GB and CE labels:
Enable or disable each set.
Customize label colors, sizes, and vertical offsets.
Time Zone Support:
Select your desired time zone for accurate start time synchronization with your chart.
Consistent Label Placement:
Labels remain fixed above the candles regardless of zoom level or price range, ensuring clarity on any chart.
Useful for:
Time-Based Strategies: Identify key market intervals for entries or exits based on elapsed trading hours.
Custom Session Tracking: Monitor time progression across different market sessions or instruments.
Algorithmic Insights: Integrate time-based rules into your trading systems with precision.
How to Use:
1. Set the start day and hour using the Algo Start Day and Algo Start Hour inputs.
2. Customize the appearance of GB Time and CE Numbers labels as needed.
3. Align the chart's time zone with the indicator for accurate time tracking.
In the chart example, price is anchored to Sunday at 6pm, the opening hour for the week for futures
Option Time ValueThis TradingView script calculates and visualizes the time value of an option (Call or Put) based on its market price and intrinsic value. The time value represents the premium paid for the option above its intrinsic value, and it is a key metric for analyzing the cost of holding an option.
This script is suitable for traders analyzing options on indices or stocks, such as the NIFTY 50, and supports both Call and Put options. By dynamically extracting the strike price and option type from the input symbol, it adapts seamlessly to the selected instrument.
Key Features:
Dynamic Instrument Selection:
Users can input the underlying asset (e.g., NSE:NIFTY) and the specific option instrument (e.g., NSE:NIFTY250327C24000 for a Call or NSE:NIFTY250327P24000 for a Put).
Automatic Option Type Detection:
The script detects whether the option is a Call or a Put by parsing the input symbol for the characters "C" (Call) or "P" (Put).
Dynamic Strike Price Extraction:
The strike price is dynamically extracted from the input option symbol, eliminating the need for hardcoding and reducing user errors.
Key Metrics Plotted:
Time Value: The premium paid above the intrinsic value, plotted in blue.
Intrinsic Value: The calculated intrinsic value of the option, plotted in green.
Seamless Integration:
Designed for ease of use and integration into existing TradingView setups.
Automatically adjusts to the timeframe and pricing data of the selected instruments.
IU 4 Bar UP StrategyIU 4 Bar UP Strategy
The IU 4 Bar UP Strategy is a trend-following strategy designed to identify and execute long trades during strong bullish momentum, combined with confirmation from the SuperTrend indicator. This strategy is suitable for traders aiming to capitalize on sustained upward market movements.
Features :
1. SuperTrend Confirmation: Incorporates the SuperTrend indicator as a dynamic support/resistance line to filter trades in the direction of the trend.
2. 4 Consecutive Bullish Bars: Detects a series of 4 bullish candles as a signal for strong upward momentum, ensuring robust trade setups.
3. Dynamic Alerts: Sends alerts for trade entries and exits to keep traders informed.
4. Visual Enhancements:
- Plots the SuperTrend indicator on the chart.
- Changes the background color while a trade is active for easy visualization.
Inputs :
- SuperTrend ATR Period: The period used to calculate the Average True Range (ATR) for the SuperTrend indicator.
- SuperTrend ATR Factor: The multiplier for the ATR in the SuperTrend calculation.
Entry Conditions :
A long entry is triggered when:
1. The last 4 consecutive candles are bullish (closing prices are higher than opening prices).
2. The current price is above the SuperTrend line.
3. The strategy is not already in a position.
4. The bar is confirmed (not a partially formed bar).
When all these conditions are met, the strategy enters a long position and provides an alert:
"Long Entry triggered"
Exit Conditions :
The strategy exits the long position when:
1. The closing price drops below the SuperTrend line.
2. An alert is generated: "Close the long Trade"
Visualization :
- The SuperTrend line is plotted, dynamically colored:
- Green when the trend is bullish.
- Red when the trend is bearish.
- The background color turns semi-transparent green while a trade is active, indicating a long position.
Do use proper risk management while using this strategy.
Enhanced SMA Signal Box With TargetsEnhanced SMA Signal Box with Targets
The Enhanced SMA Signal Box with Targets is a unique trading tool designed to help traders identify potential entry and exit opportunities with clarity and precision. It combines a 20-period Simple Moving Average (SMA) with customizable target levels and filtering options, making it a versatile indicator for various trading strategies.
What Makes It Unique:
Dynamic Profit Targets: Automatically adjusts ATR-based target levels to changing market conditions.
Flexible Filters: Optional MACD, RSI, and volume filters refine signals to suit different trading styles.
Visually Distinct Signals: Highlights potential opportunities with easy-to-read markers and customizable visuals.
Adaptability: Works across multiple asset classes and timeframes.
How It Works:
Buy Signals: Generated when the price closes above the SMA, indicating potential bullish momentum.
Sell Signals: Triggered when the price closes below the SMA, signaling bearish conditions.
Profit Targets: Three adjustable ATR-based levels provide guidance for trade exits and risk management.
Customization Options:
Modify SMA length, colors, and line styles for a personalized experience.
Enable or disable filters to match your trading strategy.
Tailor target levels for precise risk-reward setups.
Important Note:
This script is a tool to assist traders in their analysis and decision-making process. It does not guarantee specific outcomes and should always be used alongside other risk management practices.
Disclaimer:
This indicator is provided for educational purposes only and does not constitute financial advice. Users should backtest thoroughly and trade responsibly. The author is not liable for any financial losses resulting from the use of this tool.
Market Sessions
//@version=5
indicator('Market Sessions', 'Sessions', overlay=true, max_lines_count=200, max_boxes_count=200, max_labels_count=200, max_bars_back=500, explicit_plot_zorder=true)
import boitoki/AwesomeColor/9 as ac
import boitoki/Utilities/3 as util
///////////////
// Groups
///////////////
g0 = '// GENERAL //'
g1_01 = '// ♯1 SESSION //'
g1_02 = '// ♯2 SESSION //'
g1_03 = '// ♯3 SESSION //'
g1_04 = '// ♯4 SESSION //'
g1_05 = '// ♯5 SESSION //'
g4 = '// BOX //'
g6 = '// LABELS //'
g5 = '// OPENING RANGE //'
g7 = '// FIBONACCI LEVELS //'
g8 = '// OPTIONS //'
g11 = '// CANDLE //'
g10 = '// ALERTS VISUALISED //'
g12 = '// INFORMATION //'
///////////////
// Defined
///////////////
MAX_BARS = 500
option_yes = 'Yes'
option_no = '× No'
option_extend1 = 'Yes'
option_hide = '× Hide'
option_border_style1 = '────'
option_border_style2 = '- - - - - -'
option_border_style3 = '•••••••••'
option_chart_x = '× No'
option_chart_1 = 'Bar color'
option_chart_2 = 'Candles'
option_opr_label1 = 'High・Low'
option_opr_label2 = 'Buy・Sell'
option_opr_label_none = 'None'
option_candle_color1 = 'Session color'
option_candle_color2 = 'Red • Green'
fmt_price = '{0,number,#.#####}'
fmt_pips = '{0,number,#.#}'
icon_separator = ' • '
color_text = color.new(color.white, 0)
TRANSPARENT = color.new(color.black, 100)
///////////////
// Methods
///////////////
method clear (array id, int _min = 0) =>
if array.size(id) > _min
array.pop(id)
method clear (array id, int _min = 0) =>
if array.size(id) > _min
array.pop(id)
///////////////
// Types
///////////////
// OHLC
type OHLC
float open
float high
float low
float close
float hl
// Dot
type Dot
int x
float y
string t = ''
color c
method create(Dot this) =>
label.new(this.x, this.y, this.t, style=label.style_label_center, color=TRANSPARENT, textcolor=this.c, size=size.small)
// Candle
type Candle
box body
line wick
method create(Candle this) =>
this.body := array.new()
this.wick := array.new()
this
type State
string extend_style
bool show_fibs
bool show_op
method is_extended (State this) =>
this.extend_style != option_no
// OpeningRange
type OpeningRange
float top
float btm
float avg
float R1
float R2
float S1
float S2
int total_count = 0
int reached_count = 0
int reached_R1_count = 0
int reached_R2_count = 0
int reached_S1_count = 0
int reached_S2_count = 0
// Data
type Session
string sess
string tz
string name
color colour
float price_ranges
float price_range_avg
box boxes
line lines
label labels
line oclines
box ocboxes
label oc_labels
box opr_boxes
line opr_lines
linefill opr_linefills
label opr_labels
line fib
int session
bool is_extended
bool in_session
Candle candle
OHLC ohlc
State state
OpeningRange op
method create (Session this, string _extend, bool _show_fib, bool _show_op) =>
this.boxes := array.new()
this.lines := array.new()
this.labels := array.new()
this.oclines := array.new()
this.ocboxes := array.new()
this.oc_labels := array.new()
this.opr_boxes := array.new()
this.opr_lines := array.new()
this.opr_linefills := array.new()
this.opr_labels := array.new()
this.fib := array.new()
this.price_ranges := array.new()
this.state := State.new(_extend, _show_fib, _show_op)
this.candle := Candle.new().create()
this.ohlc := OHLC.new()
this.op := OpeningRange.new()
this.is_extended := this.state.is_extended()
this
method session (Session this) =>
time(timeframe.period, this.sess, this.tz)
method add (Session this, range_price, length = 50) =>
this.price_ranges.unshift(range_price)
this.price_ranges.clear(length)
this.price_range_avg := array.avg(this.price_ranges)
///////////////
// Functions
///////////////
f_get_time_by_bar (bar_count) => timeframe.multiplier * bar_count * 60 * 1000
f_border_style (_style) =>
switch _style
option_border_style1 => line.style_solid
option_border_style2 => line.style_dashed
option_border_style3 => line.style_dotted
=> _style
f_get_period (_session, _start, _lookback) =>
result = math.max(_start, 1)
for i = result to _lookback
if na(_session ) and _session
result := i+1
break
result
f_get_label_position (_y, _side) =>
switch _y
'top' => _side == 'outside' ? label.style_label_lower_left : label.style_label_upper_left
'bottom' => _side == 'outside' ? label.style_label_upper_left : label.style_label_lower_left
f_get_started (_session) => na(_session ) and _session
f_get_ended (_session) => na(_session) and _session
f_message_limit_bars (_v) => '⚠️ This box\'s right position exceeds 500 bars(' + str.tostring(_v) + '). This box is not displayed correctly.'
f_set_line_x1 (_line, _x) =>
if (line.get_x1(_line) != _x)
line.set_x1(_line, _x)
f_set_line_x2 (_line, _x) =>
if (line.get_x2(_line) != _x)
line.set_x2(_line, _x)
f_set_box_right (_box, _x) =>
if box.get_right(_box) != _x
box.set_right(_box, _x)
///////////////
// Inputs
///////////////
// Timezone
i_tz = input.string('GMT+0', title='Timezone', options= , group=g0)
i_history_period = input.int(10, 'History', minval=0, group=g0)
i_show = i_history_period > 0
i_lookback = 12 * 60
// Sessions
i_show_sess1 = input.bool(true, 'Session 1 ', group=g1_01, inline='session1_1') and i_show
i_sess1_label = input.string('London', '', group=g1_01, inline='session1_1')
i_sess1_color = input.color(#66D9EF, '', group=g1_01, inline='session1_1')
i_sess1_barcolor1 = input.color(#66D9EF, '•', group=g1_01, inline='session1_1')
i_sess1_barcolor2 = input.color(#66D9EF, '', group=g1_01, inline='session1_1')
i_sess1 = input.session('0800-1700', 'Time', group=g1_01)
i_sess1_extend = input.string(option_no, 'Extend', options= , group=g1_01)
i_sess1_op = input.string(option_no, 'Opening range', group=g1_01, options= ) != option_no and i_show
i_sess1_fib = input.string(option_no, 'Fibonacci levels', group=g1_01, options= ) != option_no
i_sess1_chart = input.string(option_chart_x, 'Bar', options= , group=g1_01)
i_sess1_barcolor = i_sess1_chart == option_chart_1
i_sess1_plotcandle = i_sess1_chart == option_chart_2
i_show_sess2 = input.bool(true, 'Session 2 ', group=g1_02, inline='session2_1') and i_show
i_sess2_label = input.string('New York', '', group=g1_02, inline='session2_1')
i_sess2_color = input.color(#FD971F, '', group=g1_02, inline='session2_1')
i_sess2_barcolor1 = input.color(#FD971F, '•', group=g1_02, inline='session2_1')
i_sess2_barcolor2 = input.color(#FD971F, '', group=g1_02, inline='session2_1')
i_sess2 = input.session('1300-2200', 'Time', group=g1_02)
i_sess2_extend = input.string(option_no, 'Extend', options= , group=g1_02)
i_sess2_op = input.string(option_no, 'Opening range', group=g1_02, options= ) != option_no and i_show
i_sess2_fib = input.string(option_no, 'Fibonacci levels', group=g1_02, options= ) != option_no
i_sess2_chart = input.string(option_chart_x, 'Bar', options= , group=g1_02)
i_sess2_barcolor = i_sess2_chart == option_chart_1
i_sess2_plotcandle = i_sess2_chart == option_chart_2
i_show_sess3 = input.bool(true, 'Session 3 ', group=g1_03, inline='session3_1') and i_show
i_sess3_label = input.string('Tokyo', '', group=g1_03, inline='session3_1')
i_sess3_color = input.color(#AE81FF, '', group=g1_03, inline='session3_1')
i_sess3_barcolor1 = input.color(#AE81FF, '•', group=g1_03, inline='session3_1')
i_sess3_barcolor2 = input.color(#AE81FF, '', group=g1_03, inline='session3_1')
i_sess3 = input.session('0000-0900', 'Time', group=g1_03)
i_sess3_extend = input.string(option_no, 'Extend', options= , group=g1_03)
i_sess3_op = input.string(option_no, 'Opening range', group=g1_03, options= ) != option_no and i_show
i_sess3_fib = input.string(option_no, 'Fibonacci levels', group=g1_03, options= ) != option_no
i_sess3_chart = input.string(option_chart_x, 'Bar', options= , group=g1_03)
i_sess3_barcolor = i_sess3_chart == option_chart_1
i_sess3_plotcandle = i_sess3_chart == option_chart_2
i_show_sess4 = input.bool(false, 'Session 4 ', group=g1_04, inline='session4_1') and i_show
i_sess4_label = input.string('Sydney', '', group=g1_04, inline='session4_1')
i_sess4_color = input.color(#FB71A3, '', group=g1_04, inline='session4_1')
i_sess4_barcolor1 = input.color(#FB71A3, '•', group=g1_04, inline='session4_1')
i_sess4_barcolor2 = input.color(#FB71A3, '', group=g1_04, inline='session4_1')
i_sess4 = input.session('2000-0500', 'Time', group=g1_04)
i_sess4_extend = input.string(option_no, 'Extend', options= , group=g1_04)
i_sess4_op = input.string(option_no, 'Opening range', group=g1_04, options= ) != option_no and i_show
i_sess4_fib = input.string(option_no, 'Fibonacci levels', group=g1_04, options= ) != option_no
i_sess4_chart = input.string(option_chart_x, 'Bar', options= , group=g1_04)
i_sess4_barcolor = i_sess4_chart == option_chart_1
i_sess4_plotcandle = i_sess4_chart == option_chart_2
i_show_sess5 = input.bool(false, 'Session 5 ', group=g1_05, inline='session5_1') and i_show
i_sess5_label = input.string('Sydney', '', group=g1_05, inline='session5_1')
i_sess5_color = input.color(#FB71A3, '', group=g1_05, inline='session5_1')
i_sess5_barcolor1 = input.color(#FB71A3, '•', group=g1_05, inline='session5_1')
i_sess5_barcolor2 = input.color(#FB71A3, '', group=g1_05, inline='session5_1')
i_sess5 = input.session('2000-0500', 'Time', group=g1_05)
i_sess5_extend = input.string(option_no, 'Extend', options= , group=g1_05)
i_sess5_op = input.string(option_no, 'Opening range', group=g1_05, options= ) != option_no and i_show
i_sess5_fib = input.string(option_no, 'Fibonacci levels', group=g1_05, options= ) != option_no
i_sess5_chart = input.string(option_chart_x, 'Bar', options= , group=g1_05)
i_sess5_barcolor = i_sess5_chart == option_chart_1
i_sess5_plotcandle = i_sess5_chart == option_chart_2
// Show & Styles
i_sess_box_style = input.string('Box', '', options= , group=g4, inline='box_style')
i_sess_border_style = f_border_style(input.string(option_border_style2, '', options= , group=g4, inline='box_style'))
i_sess_border_width = input.int(1, '', minval=0, group=g4, inline='box_style')
i_sess_box_background = input.bool(true, 'BG color', group=g4, inline='box_style_options')
i_sess_box_dots = input.bool(true, 'Dots', group=g4, inline='box_style_options')
i_sess_end_offset = input.bool(true, 'Include the latest bar in the Session end', group=g4)
i_sess_bgopacity = i_sess_box_background ? 94 : 100
i_sess_bgopacity2 = math.min(i_sess_bgopacity - 4, 100)
i_sess_border_width := i_sess_box_style == 'Background' ? 0 : i_sess_border_width
session_end_offset = i_sess_end_offset ? 0 : 1
// Labels
i_label_show = input.bool(true, '', inline='label_show', group=g6) and i_show
i_label_size = str.lower(input.string('Small', '', options= , inline='label_show', group=g6))
i_label_position_y = str.lower(input.string('Top', '', options= , inline='label_show', group=g6))
i_label_position_s = str.lower(input.string('Outside', '', options= , inline='label_show', group=g6))
i_label_position = f_get_label_position(i_label_position_y, i_label_position_s)
i_label_format_name = input.bool(true, 'Name', inline='label_format', group=g6)
i_label_format_day = input.bool(false, 'Day', inline='label_format', group=g6)
i_label_format_price = input.bool(false, 'Price', inline='label_format', group=g6)
i_label_format_pips = input.bool(false, 'Pips', inline='label_format', group=g6)
// Opening range
i_o_minutes = input.int(15, title='Periods mins', minval=1, step=1, group=g5)
i_o_minutes := math.max(i_o_minutes, timeframe.multiplier + 1)
i_o_transp = 65
i_o_size = input.string(size.small, 'Label size', options= , group=g5)
i_o_color = input.string(option_candle_color1, 'Label color', options= , group=g5)
i_o_label_1 = input.string('High', 'Label text ', group=g5, inline='op_label', tooltip="Type \"price\" to display the price")
i_o_label_2 = input.string('Low', '', group=g5, inline='op_label')
i_o_nowonly = input.bool(false, 'Now only', group=g5, inline='op_options')
i_o_breakout_icon = input.bool(false, 'Breakout flag', group=g5, inline='op_options')
i_o_target = input.bool(false, 'Target lines', group=g5, inline='op_options')
// Candle
option_candle_body = 'OC'
option_candle_wick = 'OHLC'
i_show_candle = input.bool(false, '', group=g11, inline='candle_display') //and (i_candle_border_width > 0)
i_candle = input.string(option_candle_wick, '', options= , group=g11, inline='candle_display')
i_candle_border_width = input.int(1, '', minval=1, group=g11, inline='candle_display')
i_candle_color = input.string(option_candle_color1, '', options= , group=g11, inline='candle_display')
i_candle_color_g = input.color(#A6E22E, '', group=g11, inline='candle_display')
i_candle_color_r = input.color(#F92672, '', group=g11, inline='candle_display')
i_candle := i_show_candle ? i_candle : option_hide
i_show_candle_wick = i_candle == option_candle_wick
i_sess_bgopacity2 := i_show_candle ? 100 : i_sess_bgopacity2
// Fibonacci levels
i_f_show = input.bool(true, '', group=g7, inline='fib_display')
i_f_linestyle = f_border_style(input.string(option_border_style1, '', options= , group=g7, inline='fib_display'))
i_f_linewidth = input.int(1, '', minval=1, group=g7, inline='fib_display')
i_sess1_fib := i_f_show ? i_sess1_fib : false
i_sess2_fib := i_f_show ? i_sess2_fib : false
i_sess3_fib := i_f_show ? i_sess3_fib : false
i_sess4_fib := i_f_show ? i_sess4_fib : false
// Information table
i_show_info = input.bool(true, '', group=g12, inline='info_display')
i_info_size = input.string(size.normal, '', options= , group=g12, inline='info_display')
i_info_value_type = input.string('Pips', '', options= , group=g12, inline='info_display')
i_info_period = input.int(50, '', group=g12, inline='info_display')
// Alerts
i_alert1_show = input.bool(false, 'Alerts - Sessions stard/end', group=g10)
i_alert2_show = input.bool(false, 'Alerts - Opening range breakouts', group=g10)
i_alert3_show = input.bool(false, 'Alerts - Price crossed session\'s High/Low after session closed', group=g10)
// ------------------------
// Drawing labels
// ------------------------
f_render_label (_show, Session data, _is_started, _color, _top, _bottom) =>
var label my_label = na
var int start_time = na
session = data.session()
v_position_y = (i_label_position_y == 'top') ? _top : _bottom
v_label = array.new_string()
v_chg = _top - _bottom
if _is_started
start_time := time
if i_label_format_name and not na(data.name)
array.push(v_label, data.name)
if i_label_format_day
array.push(v_label, util.get_day(dayofweek(start_time, i_tz)))
if i_label_format_price
array.push(v_label, str.format(fmt_price, v_chg))
if i_label_format_pips
array.push(v_label, str.format(fmt_pips, util.toPips(v_chg)))
if _show
if _is_started
my_label := label.new(bar_index, v_position_y, array.join(v_label, icon_separator), textcolor=_color, color=TRANSPARENT, size=i_label_size, style=i_label_position, tooltip='Pips')
array.push(data.labels, my_label)
util.clear_labels(data.labels, data.is_extended ? 1 : i_history_period)
else if session
label.set_y(my_label, v_position_y)
label.set_text(my_label, array.join(v_label, icon_separator))
data
// ------------------------
// Drawing Fibonacci levels
// ------------------------
f_render_fibonacci (_show, data, _is_started, _is_ended, _x1, _x2, _color, _top, _bottom, _level, _width, _style) =>
var line my_line = na
session = data.session()
if _show
y = (_top - _bottom) * _level + _bottom
if _is_started
my_line := line.new(_x1, y, _x2, y, width=_width, color=color.new(_color, 30), style=_style)
array.push(data.fib, my_line)
if data.is_extended
line.set_extend(my_line, extend.right)
else if session
line.set_y1(my_line, y)
line.set_y2(my_line, y)
f_set_line_x2(my_line, _x2)
else if _is_ended
f_set_line_x2(my_line, _x2-session_end_offset)
data
// ------------------------
// Drawing Opening range
// ------------------------
f_render_oprange (_show, Session data, _is_started, _is_ended, _x1, _x2, _color, _max) =>
var int start_time = na
var box my_box = na
var line my_line1 = na
var line my_line2 = na
var label my_label1 = na
var label my_label2 = na
var bool is_opened = false
var float R1 = na, var float R2 = na
var float S1 = na, var float S2 = na
var is_reached_R1 = false
var is_reached_R2 = false
var is_reached_S1 = false
var is_reached_S2 = false
var color_gray = ac.tradingview('gray')
var color_orange = ac.tradingview('orange')
var target_line_width = 2
session = data.session()
top = ta.highest(high, _max)
btm = ta.lowest(low, _max)
is_crossover = ta.crossover(close, box.get_top(my_box))
is_crossunder = ta.crossunder(close, box.get_bottom(my_box))
var float saved_top = na
if _show
if _is_started
util.clear_boxes(data.opr_boxes, math.max(0, i_history_period - 1))
util.clear_lines(data.opr_lines, math.max(0, (i_history_period - 1) * 6))
util.clear_labels(data.opr_labels, math.max(0, (i_history_period - 1) * 2))
start_time := time
my_box := na
is_opened := true
else if session
time_op = start_time + (i_o_minutes * 60 * 1000)
time_op_delay = time_op - f_get_time_by_bar(1)
if time <= time_op and time > time_op_delay
top_color = i_o_color == option_candle_color2 ? ac.tradingview('blue') : _color
btm_color = i_o_color == option_candle_color2 ? ac.tradingview('red') : _color
top_text_color = color.from_gradient(85, 0, 100, top_color, ac.panda('white'))
bot_text_color = color.from_gradient(85, 0, 100, btm_color, ac.panda('white'))
mdl = math.avg(top, btm)
avg1 = (data.price_range_avg * 0.786) * 0.5
avg2 = (data.price_range_avg * 1.272) * 0.5
saved_top := top
R1 := math.avg(btm, mdl) + avg1
R2 := math.avg(btm, mdl) + avg2
S1 := math.avg(top, mdl) - avg1
S2 := math.avg(top, mdl) - avg2
array.push(data.opr_boxes, box.new (_x1, top, bar_index, btm, border_width=0, bgcolor=color.new(_color, i_o_transp)))
array.push(data.opr_lines, line.new(_x1, top, _x2, top, style=line.style_dashed, color=top_color))
array.push(data.opr_lines, line.new(_x1, btm, _x2, btm, style=line.style_dashed, color=btm_color))
array.push(data.opr_lines, line.new(_x1, R2 , _x2, R2 , style=line.style_solid, color=i_o_target ? color.new(top_color, 40) : TRANSPARENT, width=target_line_width))
array.push(data.opr_lines, line.new(_x1, S2 , _x2, S2 , style=line.style_solid, color=i_o_target ? color.new(btm_color, 40) : TRANSPARENT, width=target_line_width))
array.push(data.opr_lines, line.new(_x1, R1 , _x2, R1 , style=line.style_solid, color=i_o_target ? color.new(top_color, 40) : TRANSPARENT, width=target_line_width))
array.push(data.opr_lines, line.new(_x1, S1 , _x2, S1 , style=line.style_solid, color=i_o_target ? color.new(btm_color, 40) : TRANSPARENT, width=target_line_width))
if i_o_target
array.unshift(data.opr_linefills, linefill.new(array.get(data.opr_lines, array.size(data.opr_lines)-1), array.get(data.opr_lines, array.size(data.opr_lines)-3), color.new(btm_color, 96))) // S
array.unshift(data.opr_linefills, linefill.new(array.get(data.opr_lines, array.size(data.opr_lines)-2), array.get(data.opr_lines, array.size(data.opr_lines)-4), color.new(top_color, 96))) // R
t1 = i_o_label_1 == 'price' ? str.tostring(top, format.mintick) : i_o_label_1
t2 = i_o_label_2 == 'price' ? str.tostring(btm, format.mintick) : i_o_label_2
my_label1 := label.new(_x1-1, top, t1, yloc=yloc.price, style=label.style_label_right, color=top_color, textcolor=top_text_color, size=i_o_size, tooltip=str.tostring(top, format.mintick))
my_label2 := label.new(_x1-1, btm, t2, yloc=yloc.price, style=label.style_label_right, color=btm_color, textcolor=bot_text_color, size=i_o_size, tooltip=str.tostring(btm, format.mintick))
array.push(data.opr_labels, my_label1)
array.push(data.opr_labels, my_label2)
array.push(data.opr_boxes , my_box)
if data.is_extended
box.set_extend(my_box, extend.right)
alert('Opening range is fixed.', alert.freq_once_per_bar)
else if is_opened
if ta.crossover(high, R1) and (not is_reached_R1)
is_reached_R1 := true
if i_o_breakout_icon
label.new(bar_index, high, '×', yloc=yloc.price, style=label.style_label_center, color=TRANSPARENT, textcolor=ac.tradingview('blue'), size=size.large)
if ta.crossover(high, R2) and (not is_reached_R2)
is_reached_R2 := true
if i_o_breakout_icon
label.new(bar_index, high, '×', yloc=yloc.price, style=label.style_label_center, color=TRANSPARENT, textcolor=ac.tradingview('blue'), size=size.large)
if ta.crossunder(low, S1) and (not is_reached_S1)
is_reached_S1 := true
if i_o_breakout_icon
label.new(bar_index, low, '×', yloc=yloc.price, style=label.style_label_center, color=TRANSPARENT, textcolor=ac.tradingview('red'), size=size.large)
if ta.crossunder(low, S2) and (not is_reached_S2)
is_reached_S2 := true
if i_o_breakout_icon
label.new(bar_index, low, '×', yloc=yloc.price, style=label.style_label_center, color=TRANSPARENT, textcolor=ac.tradingview('red'), size=size.large)
true
else
if is_crossover
alert('Price crossed over the opening range', alert.freq_once_per_bar)
if i_alert2_show
label.new(bar_index, box.get_top(my_box), "×", color=color.blue, textcolor=ac.tradingview('blue'), style=label.style_none, size=size.large)
if is_crossunder
alert('Price crossed under the opening range', alert.freq_once_per_bar)
if i_alert2_show
label.new(bar_index, box.get_bottom(my_box), "×", color=color.red, textcolor=ac.tradingview('red'), style=label.style_none, size=size.large)
else if _is_ended
if i_o_nowonly
util.clear_lines(data.opr_lines, 0)
util.clear_labels(data.opr_labels, 0)
util.clear_boxes(data.opr_boxes, 0)
else if array.size(data.opr_lines) > 0
for i = 0 to 5
the_line = array.get(data.opr_lines, array.size(data.opr_lines) - (i + 1))
line.set_x2(the_line, _x2-session_end_offset)
for i = 0 to 1
the_label = array.get(data.opr_labels, array.size(data.opr_labels) - (i + 1))
label.set_text(the_label, '●')
label.set_style(the_label, label.style_label_center)
label.set_textcolor(the_label, i_o_color == option_candle_color2 ? label.get_y(the_label) >= saved_top ? ac.tradingview('blue') : ac.tradingview('red') : _color)
label.set_color(the_label, TRANSPARENT)
label.set_size(the_label, size.tiny)
label.set_x(the_label,_x1)
data.op.total_count := data.op.total_count + 1
data.op.reached_count := (is_reached_R1 or is_reached_R2 or is_reached_S1 or is_reached_S2) ? data.op.reached_count + 1 : data.op.reached_count
data.op.reached_R1_count := is_reached_R1 ? data.op.reached_R1_count + session_end_offset : data.op.reached_R1_count
data.op.reached_R2_count := is_reached_R2 ? data.op.reached_R2_count + session_end_offset : data.op.reached_R2_count
data.op.reached_S1_count := is_reached_S1 ? data.op.reached_S1_count + session_end_offset : data.op.reached_S1_count
data.op.reached_S2_count := is_reached_S2 ? data.op.reached_S2_count + session_end_offset : data.op.reached_S2_count
// Reset
R1 := na, R2 := na, S1 := na, S2 := na
is_reached_R1 := false
is_reached_R2 := false
is_reached_S1 := false
is_reached_S2 := false
is_opened := false
saved_top := na
is_opened
data
// ------------------------
// Drawing candle
// ------------------------
f_render_candle (_show, Session data, _is_started, _is_ended, _color, _top, _bottom, _open, _x1, _x2) =>
var box body = na
var line wick1 = na
var line wick2 = na
session = data.session()
border_width = i_candle_border_width
cx = math.round(math.avg(_x2, _x1)) - math.round(border_width / 2)
body_color = i_candle_color == option_candle_color2 ? close > _open ? i_candle_color_g : i_candle_color_r : _color
body_color := color.new(body_color, 30)
if _show
if _is_started
body := box.new(_x1, _top, _x2, _bottom, body_color, border_width, line.style_solid, bgcolor=color.new(color.black, 100))
wick1 := i_show_candle_wick ? line.new(cx, _top, cx, _top, color=body_color, width=border_width, style=line.style_solid) : na
wick2 := i_show_candle_wick ? line.new(cx, _bottom, cx, _bottom, color=body_color, width=border_width, style=line.style_solid) : na
array.push(data.candle.body, body)
array.push(data.candle.wick, wick1)
array.push(data.candle.wick, wick2)
util.clear_boxes(data.candle.body, i_history_period)
util.clear_lines(data.candle.wick, i_history_period * 2)
else if session
top = math.max(_open, close)
bottom = math.min(_open, close)
box.set_top(body, top)
box.set_bottom(body, bottom)
box.set_right(body, _x2)
box.set_border_color(body, body_color)
line.set_y1(wick1, _top)
line.set_y2(wick1, top)
f_set_line_x1(wick1, cx)
f_set_line_x2(wick1, cx)
line.set_color(wick1, body_color)
line.set_y1(wick2, _bottom)
line.set_y2(wick2, bottom)
f_set_line_x1(wick2, cx)
f_set_line_x2(wick2, cx)
line.set_color(wick2, body_color)
else if _is_ended
box.set_right(body, bar_index-session_end_offset)
data
// ------------------------
// Rendering limit message
// ------------------------
f_render_limitmessage (_show, Session data, _is_started, _is_ended, _x, _y, _rightbars) =>
var label my_note = na
session = data.session()
if _show
if _is_started
if _rightbars > MAX_BARS
my_note := label.new(_x, _y, f_message_limit_bars(_rightbars), style=label.style_label_upper_left, color=color.yellow, textalign=text.align_left, yloc=yloc.price)
else if session
if _rightbars > MAX_BARS
label.set_y(my_note, _y)
label.set_text(my_note, f_message_limit_bars(_rightbars))
else
label.delete(my_note)
else if _is_ended
label.delete(my_note)
data
// Rendering session
//
f_render_sessionrange (_show, Session data, _is_started, _is_ended, _color, _top, _bottom, _x1, _x2, _is_vertical = false) =>
var line above_line = na
var line below_line = na
session = data.session()
if _show
if _is_started
if _is_vertical
above_line := line.new(_x1, _top, _x1, _bottom, width=i_sess_border_width, style=i_sess_border_style, color=_color)
below_line := line.new(_x2, _top, _x2, _bottom, width=i_sess_border_width, style=i_sess_border_style, color=_color)
else
above_line := line.new(_x1, _top, _x2, _top, width=i_sess_border_width, style=i_sess_border_style, color=_color)
below_line := line.new(_x1, _bottom, _x2, _bottom, width=i_sess_border_width, style=i_sess_border_style, color=_color)
linefill.new(above_line, below_line, color.new(_color, i_sess_bgopacity))
array.push(data.lines, above_line)
array.push(data.lines, below_line)
util.clear_lines(data.lines, data.is_extended ? 2 : i_history_period * 2)
if data.is_extended
if _is_vertical
line.set_extend(above_line, extend.both)
line.set_extend(below_line, extend.both)
else
line.set_extend(above_line, extend.right)
line.set_extend(below_line, extend.right)
else if session
if _is_vertical
line.set_y1(above_line, _bottom)
line.set_y2(above_line, _top)
line.set_y1(below_line, _bottom)
line.set_y2(below_line, _top)
else
line.set_y1(above_line, _top)
line.set_y2(above_line, _top)
line.set_x2(above_line, _x2)
line.set_y1(below_line, _bottom)
line.set_y2(below_line, _bottom)
line.set_x2(below_line, _x2)
else if _is_ended
if _is_vertical
line.set_x1(below_line, _x2-session_end_offset)
line.set_x2(below_line, _x2-session_end_offset)
else
line.set_x2(above_line, _x2-session_end_offset)
line.set_x2(below_line, _x2-session_end_offset)
data.add(_top - _bottom , i_info_period)
data
// ------------------------
// Rendering session box
// ------------------------
f_render_session (_show, Session data, _is_started, _is_ended, _color, _top, _bottom, _x1, _x2) =>
var box my_box = na
session = data.session()
if _show
if _is_started
my_box := box.new(_x1, _top, _x2, _bottom, _color, i_sess_border_width, i_sess_border_style, bgcolor=color.new(_color, i_sess_bgopacity))
array.push(data.boxes, my_box)
util.clear_boxes(data.boxes, data.is_extended ? 1 : i_history_period)
if data.is_extended
box.set_extend(my_box, extend.right)
else if session
box.set_top(my_box, _top)
box.set_bottom(my_box, _bottom)
f_set_box_right(my_box, _x2)
else if _is_ended
box.set_right(my_box, bar_index-session_end_offset)
data.add(_top - _bottom , i_info_period)
data
f_render_dots (_show, Session data, _is_started, _is_ended, _color, _top, _bottom, _x1, _x2) =>
var float _open = na
var box oc_box = na
var line oc_line_u = na
var line oc_line_l = na
session = data.session()
if _show and i_sess_box_dots
if _is_started
oc_line_u := line.new(_x1, open , _x2, open , color=color.new(_color, 70), style=line.style_dotted)
oc_line_l := line.new(_x1, close, _x2, close, color=color.new(_color, 70), style=line.style_dotted)
linefill.new(oc_line_u, oc_line_l, color.new(_color, i_sess_bgopacity2))
array.push(data.oclines, oc_line_u)
array.push(data.oclines, oc_line_l)
util.clear_lines(data.oclines, data.is_extended ? 2 : i_history_period * 2)
util.clear_labels(data.oc_labels, data.is_extended ? 2 : math.max(0, (i_history_period - 1) * 2))
_open := open
else if session
line.set_x2(oc_line_u, _x2)
line.set_x2(oc_line_l, _x2)
line.set_y1(oc_line_l, close)
line.set_y2(oc_line_l, close)
else if _is_ended
array.push(data.oc_labels, Dot.new(_x1, _open, '●', _color).create())
array.push(data.oc_labels, Dot.new(_x2-session_end_offset, close , '◉', _color).create())
line.set_x2(oc_line_u, _x2-session_end_offset)
line.set_x2(oc_line_l, _x2-session_end_offset)
line.set_y1(oc_line_l, close )
line.set_y2(oc_line_l, close )
_open := na
true
// ------------------------
// Drawing market
// ------------------------
f_render_main (_show, Session data, _is_started, _is_ended, _color, _top, _bottom) =>
var x1 = 0
var x2 = 0
x2_offset = 1
session = data.session()
x0_1 = ta.valuewhen(na(session ) and session, bar_index, 1)
x0_2 = ta.valuewhen(na(session) and session , bar_index, 0)
x0_d = math.min(math.abs(x0_2 - x0_1), MAX_BARS)
rightbars = x0_d
if _show
if _is_started
x1 := bar_index
x2 := bar_index + x0_d
data.ohlc.open := open
data.ohlc.high := _top
data.ohlc.low := _bottom
data.ohlc.hl := _top -_bottom
data.in_session := true
else if session
true_x2 = x1 + x0_d
rightbars := true_x2 - bar_index
max_bars = bar_index + MAX_BARS
x2 := math.min(true_x2, max_bars)
data.ohlc.high := _top
data.ohlc.low := _bottom
data.ohlc.hl := _top - _bottom
else if _is_ended
data.in_session := false
data.ohlc.open := na
// ------------------------
// Drawing
// ------------------------
draw (_show, Session data, _extend, _show_fib, _show_op) =>
session = data.session()
max = f_get_period(session, 1, i_lookback)
top = ta.highest(high, max)
bottom = ta.lowest(low, max)
col = data.colour
is_started = f_get_started(session)
is_ended = f_get_ended(session)
= f_render_main(_show, data, is_started, is_ended, col, top, bottom)
if i_sess_box_style == 'Box' or i_sess_box_style == 'Background' or i_sess_box_style == 'Candle'
f_render_session(_show, data, is_started, is_ended, col, top, bottom, x1, x2)
f_render_dots(_show, data, is_started, is_ended, col, top, bottom, x1, x2)
else if i_sess_box_style == 'Hamburger'
f_render_sessionrange(_show, data, is_started, is_ended, col, top, bottom, x1, x2)
else if i_sess_box_style == 'Sandwich'
f_render_sessionrange(_show, data, is_started, is_ended, col, top, bottom, x1, x2, true)
if i_show_candle
f_render_candle(_show, data, is_started, is_ended, col, top, bottom, ohlc.open, x1, x2)
if i_label_show
f_render_label(_show, data, is_started, col, top, bottom)
if _show_op
f_render_oprange(_show, data, is_started, is_ended, x1, x2, col, max)
if _show_fib
f_render_fibonacci(_show, data, is_started, is_ended, x1, x2, col, top, bottom, 0.500, 2, line.style_solid)
f_render_fibonacci(_show, data, is_started, is_ended, x1, x2, col, top, bottom, 0.628, i_f_linewidth, i_f_linestyle)
f_render_fibonacci(_show, data, is_started, is_ended, x1, x2, col, top, bottom, 0.382, i_f_linewidth, i_f_linestyle)
util.clear_lines(data.fib, i_history_period * 3)
f_render_limitmessage(_show, data, is_started, is_ended, x1, bottom, _rightbars)
///////////////////
// Calculating
///////////////////
string tz = (i_tz == option_no or i_tz == '') ? na : i_tz
///////////////////
// Plotting
///////////////////
var sess1_data = Session.new(i_sess1, tz, i_sess1_label, i_sess1_color).create(i_sess1_extend, i_sess1_fib, i_sess1_op)
var sess2_data = Session.new(i_sess2, tz, i_sess2_label, i_sess2_color).create(i_sess2_extend, i_sess2_fib, i_sess2_op)
var sess3_data = Session.new(i_sess3, tz, i_sess3_label, i_sess3_color).create(i_sess3_extend, i_sess3_fib, i_sess3_op)
var sess4_data = Session.new(i_sess4, tz, i_sess4_label, i_sess4_color).create(i_sess4_extend, i_sess4_fib, i_sess4_op)
var sess5_data = Session.new(i_sess5, tz, i_sess5_label, i_sess5_color).create(i_sess5_extend, i_sess5_fib, i_sess5_op)
= draw(i_show_sess1, sess1_data, i_sess1_extend, i_sess1_fib, i_sess1_op)
= draw(i_show_sess2, sess2_data, i_sess2_extend, i_sess2_fib, i_sess2_op)
= draw(i_show_sess3, sess3_data, i_sess3_extend, i_sess3_fib, i_sess3_op)
= draw(i_show_sess4, sess4_data, i_sess4_extend, i_sess4_fib, i_sess4_op)
= draw(i_show_sess5, sess5_data, i_sess5_extend, i_sess5_fib, i_sess5_op)
is_positive_bar = close > open
color c_barcolor = na
color c_plotcandle = na
c_sess1_barcolor = (is_sess1) ? (is_positive_bar ? i_sess1_barcolor1 : i_sess1_barcolor2) : na
c_sess2_barcolor = (is_sess2) ? (is_positive_bar ? i_sess2_barcolor1 : i_sess2_barcolor2) : na
c_sess3_barcolor = (is_sess3) ? (is_positive_bar ? i_sess3_barcolor1 : i_sess3_barcolor2) : na
c_sess4_barcolor = (is_sess4) ? (is_positive_bar ? i_sess4_barcolor1 : i_sess4_barcolor2) : na
c_sess5_barcolor = (is_sess5) ? (is_positive_bar ? i_sess5_barcolor1 : i_sess5_barcolor2) : na
if (i_sess1_chart != option_chart_x) and is_sess1
c_barcolor := i_sess1_barcolor ? c_sess1_barcolor : na
c_plotcandle := i_sess1_plotcandle ? c_sess1_barcolor : na
if (i_sess2_chart != option_chart_x) and is_sess2
c_barcolor := i_sess2_barcolor ? c_sess2_barcolor : na
c_plotcandle := i_sess2_plotcandle ? c_sess2_barcolor : na
if (i_sess3_chart != option_chart_x) and is_sess3
c_barcolor := i_sess3_barcolor ? c_sess3_barcolor : na
c_plotcandle := i_sess3_plotcandle ? c_sess3_barcolor : na
if (i_sess4_chart != option_chart_x) and is_sess4
c_barcolor := i_sess4_barcolor ? c_sess4_barcolor : na
c_plotcandle := i_sess4_plotcandle ? c_sess4_barcolor : na
if (i_sess5_chart != option_chart_x) and is_sess5
c_barcolor := i_sess5_barcolor ? c_sess5_barcolor : na
c_plotcandle := i_sess5_plotcandle ? c_sess5_barcolor : na
barcolor(c_barcolor)
plotcandle(open, high, low, close, color=is_positive_bar ? TRANSPARENT : c_plotcandle, bordercolor=c_plotcandle, wickcolor=c_plotcandle)
////////////////////
// Alerts
////////////////////
// Session alerts
sess1_started = is_sess1 and not is_sess1 , sess1_ended = not is_sess1 and is_sess1
sess2_started = is_sess2 and not is_sess2 , sess2_ended = not is_sess2 and is_sess2
sess3_started = is_sess3 and not is_sess3 , sess3_ended = not is_sess3 and is_sess3
sess4_started = is_sess4 and not is_sess4 , sess4_ended = not is_sess4 and is_sess4
sess5_started = is_sess5 and not is_sess5 , sess5_ended = not is_sess5 and is_sess5
alertcondition(sess1_started, 'Session #1 started')
alertcondition(sess1_ended, 'Session #1 ended' )
alertcondition(sess2_started, 'Session #2 started')
alertcondition(sess2_ended, 'Session #2 ended' )
alertcondition(sess3_started, 'Session #3 started')
alertcondition(sess3_ended, 'Session #3 ended' )
alertcondition(sess4_started, 'Session #4 started')
alertcondition(sess4_ended, 'Session #4 ended' )
alertcondition(sess5_started, 'Session #5 started')
alertcondition(sess5_ended, 'Session #5 ended' )
alertcondition((not is_sess1) and ta.crossover (close, sess1_ohlc.high), 'Session #1 High crossed (after session closed)')
alertcondition((not is_sess1) and ta.crossunder(close, sess1_ohlc.low) , 'Session #1 Low crossed (after session closed)' )
alertcondition((not is_sess2) and ta.crossover (close, sess2_ohlc.high), 'Session #2 High crossed (after session closed)')
alertcondition((not is_sess2) and ta.crossunder(close, sess2_ohlc.low) , 'Session #2 Low crossed (after session closed)' )
alertcondition((not is_sess3) and ta.crossover (close, sess3_ohlc.high), 'Session #3 High crossed (after session closed)')
alertcondition((not is_sess3) and ta.crossunder(close, sess3_ohlc.low) , 'Session #3 Low crossed (after session closed)' )
alertcondition((not is_sess4) and ta.crossover (close, sess4_ohlc.high), 'Session #4 High crossed (after session closed)')
alertcondition((not is_sess4) and ta.crossunder(close, sess4_ohlc.low) , 'Session #4 Low crossed (after session closed)' )
alertcondition((not is_sess5) and ta.crossover (close, sess5_ohlc.high), 'Session #5 High crossed (after session closed)')
alertcondition((not is_sess5) and ta.crossunder(close, sess5_ohlc.low) , 'Session # Low crossed (after session closed)' )
// Alerts visualized
if i_alert1_show
if i_show_sess1
if sess1_started
label.new(bar_index, close, 'Start', yloc=yloc.abovebar, color=i_sess1_color, textcolor=color_text, size=size.small, style=label.style_label_down)
if sess1_ended
label.new(bar_index - session_end_offset, close, 'End' , yloc=yloc.abovebar, color=i_sess1_color, textcolor=color_text, size=size.small, style=label.style_label_down)
if i_show_sess2
if sess2_started
label.new(bar_index, close, 'Start', yloc=yloc.abovebar, color=i_sess2_color, textcolor=color_text, size=size.small, style=label.style_label_down)
if sess2_ended
label.new(bar_index - session_end_offset, close, 'End' , yloc=yloc.abovebar, color=i_sess2_color, textcolor=color_text, size=size.small, style=label.style_label_down)
if i_show_sess3
if sess3_started
label.new(bar_index, close, 'Start', yloc=yloc.abovebar, color=i_sess3_color, textcolor=color_text, size=size.small, style=label.style_label_down)
if sess3_ended
label.new(bar_index - session_end_offset, close, 'End' , yloc=yloc.abovebar, color=i_sess3_color, textcolor=color_text, size=size.small, style=label.style_label_down)
if i_show_sess4
if sess4_started
label.new(bar_index, close, 'Start', yloc=yloc.abovebar, color=i_sess4_color, textcolor=color_text, size=size.small, style=label.style_label_down)
if sess4_ended
label.new(bar_index - session_end_offset, close, 'End' , yloc=yloc.abovebar, color=i_sess4_color, textcolor=color_text, size=size.small, style=label.style_label_down)
if i_show_sess5
if sess5_started
label.new(bar_index, close, 'Start', yloc=yloc.abovebar, color=i_sess4_color, textcolor=color_text, size=size.small, style=label.style_label_down)
if sess5_ended
label.new(bar_index - session_end_offset, close, 'End' , yloc=yloc.abovebar, color=i_sess5_color, textcolor=color_text, size=size.small, style=label.style_label_down)
plot(i_alert3_show ? sess1_ohlc.high : na, 'sess1_high', style=plot.style_linebr, color=i_sess1_color)
plot(i_alert3_show ? sess1_ohlc.low : na, 'sess1_low' , style=plot.style_linebr, color=i_sess1_color, linewidth=2)
plot(i_alert3_show ? sess2_ohlc.high : na, 'sess2_high', style=plot.style_linebr, color=i_sess2_color)
plot(i_alert3_show ? sess2_ohlc.low : na, 'sess2_low' , style=plot.style_linebr, color=i_sess2_color, linewidth=2)
plot(i_alert3_show ? sess3_ohlc.high : na, 'sess3_high', style=plot.style_linebr, color=i_sess3_color)
plot(i_alert3_show ? sess3_ohlc.low : na, 'sess3_low' , style=plot.style_linebr, color=i_sess3_color, linewidth=2)
plot(i_alert3_show ? sess4_ohlc.high : na, 'sess4_high', style=plot.style_linebr, color=i_sess4_color)
plot(i_alert3_show ? sess4_ohlc.low : na, 'sess4_low' , style=plot.style_linebr, color=i_sess4_color, linewidth=2)
plot(i_alert3_show ? sess5_ohlc.high : na, 'sess5_high', style=plot.style_linebr, color=i_sess5_color)
plot(i_alert3_show ? sess5_ohlc.low : na, 'sess5_low' , style=plot.style_linebr, color=i_sess5_color, linewidth=2)
plotshape(i_alert3_show and (not is_sess1) and ta.crossover (close, sess1_ohlc.high) ? sess1_ohlc.high : na, 'cross sess1_high', color=i_sess1_color, style=shape.triangleup , location=location.absolute, size=size.tiny)
plotshape(i_alert3_show and (not is_sess1) and ta.crossunder(close, sess1_ohlc.low) ? sess1_ohlc.low : na, 'cross sess1_low' , color=i_sess1_color, style=shape.triangledown, location=location.absolute, size=size.tiny)
plotshape(i_alert3_show and (not is_sess2) and ta.crossover (close, sess2_ohlc.high) ? sess2_ohlc.high : na, 'cross sess2_high', color=i_sess2_color, style=shape.triangleup , location=location.absolute, size=size.tiny)
plotshape(i_alert3_show and (not is_sess2) and ta.crossunder(close, sess2_ohlc.low) ? sess2_ohlc.low : na, 'cross sess2_low' , color=i_sess2_color, style=shape.triangledown, location=location.absolute, size=size.tiny)
plotshape(i_alert3_show and (not is_sess3) and ta.crossover (close, sess3_ohlc.high) ? sess3_ohlc.high : na, 'cross sess3_high', color=i_sess3_color, style=shape.triangleup , location=location.absolute, size=size.tiny)
plotshape(i_alert3_show and (not is_sess3) and ta.crossunder(close, sess3_ohlc.low) ? sess3_ohlc.low : na, 'cross sess3_low' , color=i_sess3_color, style=shape.triangledown, location=location.absolute, size=size.tiny)
plotshape(i_alert3_show and (not is_sess4) and ta.crossover (close, sess4_ohlc.high) ? sess4_ohlc.high : na, 'cross sess4_high', color=i_sess4_color, style=shape.triangleup , location=location.absolute, size=size.tiny)
plotshape(i_alert3_show and (not is_sess4) and ta.crossunder(close, sess4_ohlc.low) ? sess4_ohlc.low : na, 'cross sess4_low' , color=i_sess4_color, style=shape.triangledown, location=location.absolute, size=size.tiny)
//////////////
// Analysis //
var text_color = #e1e2e4
var bgcolor = #1a1c20
var color_green = ac.monokai('green')
var color_orange = ac.monokai('orange')
var color_red = ac.monokai('red')
var color_ind_green = ac.tradingview('green')
var color_ind_gray = color.new(ac.tradingview('gray'), 30)
var color_white = #e1e2e4
i_show_op_analysis = false//input.bool(true, 'Opening range table')
i_show_analysis2 = false//input.bool(false)
if i_show_info and barstate.islast
data = array.new()
if array.size(sess1_data.price_ranges) > 0
data.push(sess1_data)
if array.size(sess2_data.price_ranges) > 0
data.push(sess2_data)
if array.size(sess3_data.price_ranges) > 0
data.push(sess3_data)
if array.size(sess4_data.price_ranges) > 0
data.push(sess4_data)
var tbl_avg = table.new(position.top_right, 5, 5, frame_width=2, bgcolor=bgcolor, frame_color=#25272c, border_width=1, border_color=#25272c)
table.cell(tbl_avg, 0, 0, 'Session', text_color=color.new(text_color, 60), text_size=i_info_size, text_halign=text.align_center)
table.cell(tbl_avg, 1, 0, '', text_color=color.new(text_color, 60), text_size=i_info_size)
table.cell(tbl_avg, 2, 0, 'Cur', text_color=color.new(text_color, 60), text_size=i_info_size)
table.cell(tbl_avg, 3, 0, 'Avg('+str.tostring(i_info_period)+')', text_color=color.new(text_color, 60), text_size=i_info_size)
table.cell(tbl_avg, 4, 0, '%', text_color=color.new(text_color, 60), text_size=i_info_size)
table.merge_cells(tbl_avg, 0, 0, 1, 0)
if array.size(data) > 0
for i = 0 to array.size(data) - 1
my_data = array.get(data, i)
in_session = my_data.in_session and session.ismarket
p = my_data.ohlc.hl / my_data.price_range_avg
col_cur = p < 0.75 ? color_green : p < 1.25 ? color_orange : color_red
v1 = i_info_value_type == 'Price' ? str.tostring(my_data.ohlc.hl, format.mintick) : str.tostring(util.toPips(my_data.ohlc.hl), '#.#')
v2 = i_info_value_type == 'Price' ? str.tostring(my_data.price_range_avg, format.mintick) : str.tostring(util.toPips(my_data.price_range_avg), '#.#')
v3 = in_session ? '◉' : '●'
color_name = in_session ? color_white : color.new(ac.monokai('gray'), 30)
color_ind = in_session ? color_ind_green : color_ind_gray
color_cur = in_session ? col_cur : color.new(col_cur, 60)
table.cell(tbl_avg, 0, i + 1, my_data.name, text_color=color_name, text_size=i_info_size, text_halign=text.align_left)
table.cell(tbl_avg, 1, i + 1, v3, text_color=color_ind , text_size=size.tiny, text_halign=text.align_center, text_valign=text.align_center)
table.cell(tbl_avg, 2, i + 1, v1, text_color=color_cur , text_size=i_info_size, text_halign=text.align_right, text_font_family=font.family_monospace)
table.cell(tbl_avg, 3, i + 1, v2, text_color=color_name, text_size=i_info_size, text_halign=text.align_right, text_font_family=font.family_monospace)
table.cell(tbl_avg, 4, i + 1, str.format('{0,number,percent}', p), text_color=color_cur, text_size=i_info_size, text_halign=text.align_right, text_font_family=font.family_monospace)
if i_show_op_analysis and (barstate.islast or barstate.isconfirmed)
data = array.new()
if sess1_data.op.reached_count > 0
array.unshift(data, sess1_data)
if sess2_data.op.reached_count > 0
array.unshift(data, sess2_data)
if sess3_data.op.reached_count > 0
array.unshift(data, sess3_data)
if sess4_data.op.reached_count > 0
array.unshift(data, sess4_data)
var tbl_op = table.new(position.bottom_right, 7, 5, frame_width=2, bgcolor=bgcolor, frame_color=#25272c, border_width=1, border_color=#25272c)
table.cell(tbl_op, 0, 0, 'Opening range' + (array.size(data) == 0 ? ' (No data)' : ''), text_size=i_info_size)
table.merge_cells(tbl_op, 0, 0, 6, 0)
if array.size(data) > 0
table.cell(tbl_op, 0, 1, 'Session', text_size=i_info_size)
table.cell(tbl_op, 1, 1, 'Sum', text_size=i_info_size)
table.cell(tbl_op, 2, 1, 'R1', text_size=i_info_size)
table.cell(tbl_op, 3, 1, 'S1', text_size=i_info_size)
table.cell(tbl_op, 4, 1, 'R2', text_size=i_info_size)
table.cell(tbl_op, 5, 1, 'S2', text_size=i_info_size)
table.cell(tbl_op, 6, 1, 'Total', text_size=i_info_size)
row_index = 2
for i = 0 to array.size(data) -1
my_data = array.get(data, i)
table.cell(tbl_op, 0, row_index + i, my_data.name, text_size=i_info_size, text_color=color_white, text_halign=text.align_left)
table.cell(tbl_op, 1, row_index + i, str.format('{0,number,percent}', my_data.op.reached_count / my_data.op.total_count), text_font_family=font.family_monospace, text_halign=text.align_right, text_color=color_white, text_size=i_info_size)
table.cell(tbl_op, 2, row_index + i, str.format('{0,number,percent}', my_data.op.reached_R1_count / my_data.op.total_count), text_font_family=font.family_monospace, text_halign=text.align_right, text_color=color_white, text_size=i_info_size)
table.cell(tbl_op, 3, row_index + i, str.format('{0,number,percent}', my_data.op.reached_S1_count / my_data.op.total_count), text_font_family=font.family_monospace, text_halign=text.align_right, text_color=color_white, text_size=i_info_size)
table.cell(tbl_op, 4, row_index + i, str.format('{0,number,percent}', my_data.op.reached_R2_count / my_data.op.total_count), text_font_family=font.family_monospace, text_halign=text.align_right, text_color=color_white, text_size=i_info_size)
table.cell(tbl_op, 5, row_index + i, str.format('{0,number,percent}', my_data.op.reached_S2_count / my_data.op.total_count), text_font_family=font.family_monospace, text_halign=text.align_right, text_color=color_white, text_size=i_info_size)
table.cell(tbl_op, 6, row_index + i, str.tostring(my_data.op.total_count), text_font_family=font.family_monospace, text_halign=text.align_right, text_color=color_white, text_size=i_info_size)
if i_show_analysis2 and barstate.islast
max = 100
g_base = ta.lowest(max)
s3_count = 0
s2_count = 0
var g_lines = array.new()
x = bar_index + 20
util.clear_lines(g_lines, 0)
array.push(g_lines, line.new(x + 0, g_base, x + 0, g_base + sess1_data.price_range_avg, color=sess1_data.colour, width=3))
array.push(g_lines, line.new(x + 2, g_base, x + 2, g_base + sess2_data.price_range_avg, color=sess2_data.colour, width=3))
array.push(g_lines, line.new(x + 4, g_base, x + 4, g_base + sess3_data.price_range_avg, color=sess3_data.colour, width=3))
array.push(g_lines, line.new(x + 6, g_base, x + 6, g_base + sess4_data.price_range_avg, color=sess4_data.colour, width=3))
if array.size(sess1_data.price_ranges) > 0 and array.size(sess3_data.price_ranges) > 0
for i = 0 to array.size(sess1_data.price_ranges) - 1
s1 = array.get(sess1_data.price_ranges, i)
s3 = array.get(sess3_data.price_ranges, i)
if s3 / s1 > 1
s3_count := s3_count + 1
tbl = table.new(position.bottom_right, 3, 3, frame_width=2, bgcolor=bgcolor, frame_color=#25272c, border_width=1, border_color=#25272c)
table.cell(tbl, 0, 0, sess3_data.name + ' > ' + sess1_data.name, text_color=#e1e2e4)
table.cell(tbl, 1, 0, str.tostring(s3_count) + ' / ' + str.tostring(array.size(sess1_data.price_ranges)), text_color=#e1e2e4)
table.cell(tbl, 2, 0, str.format('{0,number,percent}', s3_count / array.size(sess1_data.price_ranges) ), text_color=#e1e2e4)
table.cell(tbl, 0, 1, syminfo.ticker + '('+ syminfo.currency +')', text_color=#e1e2e4)
table.merge_cells(tbl, 0, 1, 2, 1)
// --- Input Definitions ---
range_start_hour = input.int(4, "Range Start Hour", group="START", inline="start", minval=0, maxval=23)
range_start_minute = input.int(0, "Minutes", group="START", inline="start", minval=0, maxval=59)
range_end_hour = input.int(12, "Range End Hour", group="END", inline="end", minval=0, maxval=23)
range_end_minute = input.int(0, "Minutes", group="END", inline="end", minval=0, maxval=59)
timezone_offset_hours = input.int(0, "Timezone UTC Offset Hours", group="Time Zone Offset", minval=-12, maxval=14)
timezone_offset_minutes = input.int(0, "Timezone UTC Offset Minutes", group="Time Zone Offset", minval=-59, maxval=59)
count = input(3, "Count")
colorTop = input(color.green, "Top Color", group="STYLING")
colorBetween = input(color.new(color.gray, 50), "Between Color", group="STYLING")
colorBottom = input(color.red, "Bottom Color", group="STYLING")
colorRange = input(color.blue, "Range Color", group="STYLING")
rangeIsDotted = input(true, "Dash Line Style For The Range", group="STYLING")
plot_mid = input(true, "Plot Mid Lines")
close_to_close = input(false, "Close To Close (instead of low to high distance)")
// --- Variable Initialization ---
var float range_high = na
var float range_low = na
var float distance = na
var int startIDX = na
// Function to calculate adjusted time based on timezone offset
getAdjustedTime(hour, minute, offset_hours, offset_minutes) =>
total_minutes = hour * 60 + minute + offset_hours * 60 + offset_minutes
// Function to normalize time to minutes from the start of the week
normalizeTimeToWeek(hour, minute) =>
(dayofweek - 1) * 24 * 60 + hour * 60 + minute
// Adjusted Time Calculations
= getAdjustedTime(range_start_hour, range_start_minute, timezone_offset_hours, timezone_offset_minutes)
= getAdjustedTime(range_end_hour, range_end_minute, timezone_offset_hours, timezone_offset_minutes)
// Normalize times to minutes from the start of the week
start_time_minutes = normalizeTimeToWeek(adjusted_start_hour, adjusted_start_minute)
end_time_minutes = normalizeTimeToWeek(adjusted_end_hour, adjusted_end_minute)
// Adjust the end time if the range spans over midnight
if adjusted_start_hour > adjusted_end_hour or (adjusted_start_hour == adjusted_end_hour and adjusted_start_minute > adjusted_end_minute)
end_time_minutes := end_time_minutes + 7 * 24 * 60 // Add 7 days worth of minutes
// Current time normalized to minutes from the start of the week
current_time_minutes = normalizeTimeToWeek(hour, minute)
// Detect if the current time is before the start of the week normalized time
if current_time_minutes < start_time_minutes
current_time_minutes := current_time_minutes + 7 * 24 * 60 // Adjust for new week
// Determine if we are in the plotting range
isInRange = current_time_minutes >= start_time_minutes and current_time_minutes <= end_time_minutes
// Main Logic
if isInRange
if na(range_high) // If this is the first bar to plot
startIDX := bar_index
range_high := close_to_close ? close : high
range_low := close_to_close ? close : low
else
range_high := math.max(range_high, close_to_close ? close : high)
range_low := math.min(range_low, close_to_close ? close : low)
distance := range_high - range_low
else if not na(range_high) // If we have completed the range
// Draw the range lines
line.new(startIDX, range_high, bar_index , range_high, xloc=xloc.bar_index, style=rangeIsDotted ? line.style_dashed : line.style_solid, color=colorRange)
line.new(startIDX, range_low, bar_index , range_low, xloc=xloc.bar_index, style=rangeIsDotted ? line.style_dashed : line.style_solid, color=colorRange)
// Draw additional lines based on the count input
for i = 1 to count
line.new(startIDX, range_high + i * distance, bar_index , range_high + i * distance, xloc=xloc.bar_index, style=line.style_solid, color=colorTop)
line.new(startIDX, range_low - i * distance, bar_index , range_low - i * distance, xloc=xloc.bar_index, style=line.style_solid, color=colorBottom)
if plot_mid
line.new(startIDX, range_high + (i - 0.5) * distance, bar_index , range_high + (i - 0.5) * distance, xloc=xloc.bar_index, style=line.style_dashed, color=colorBetween)
line.new(startIDX, range_low - (i - 0.5) * distance, bar_index , range_low - (i - 0.5) * distance, xloc=xloc.bar_index, style=line.style_dashed, color=colorBetween)
// Reset the variables after plotting
range_high := na
range_low := na
distance := na
startIDX := na
Jc Position Size Calculatortool for calculate position size or profit base on input setting
can set fix risk mode or fix lot mode
need to enter how much one integer point of the product is worth in US dollars (the example in the picture is MNQ, one integer point is $2)
offer 4 value per price option for frequency usage
設定說明:
1:需要自行輸入該商品一個整數點值多少美元(圖中範例為MNQ 一個整數點$2)
2:手數變化跳動單位(期貨手數沒有小數點所以設為1,算法為除後無條件捨去)
3.1:文字是否顯示固定風險模式
3.2:固定風險值設定
4.1:文字是否顯示固定手數模式
4.2:固定手數值設定
--
Tool is for the convenience of use, users should bear all risks for their investment decisions. The tool information is for reference only and does not provide any guarantees.
工具為方便使用,使用者應為自己任何投資決策行為承擔所有風險,工具資訊僅供參考,不提供任何保證。