High Impact News

Put labels on charts in the future so News Events are not forgotten

TradingView Link

Add this useful indicator to your TradingView chart with the link below. Always free and open source!

  • Before going to TradingView check out the description and screenshots below
TradingView Link

High Impact News

Do you have a difficult time remembering high-impact news events throughout the trading week? Now there is an indicator that allows the user to put labels directly on their charts at specific times in the future so news events won’t sneak up on the user.

Description

The “High Impact News” TradingView indicator by Infinity Trading gives the user complete control of three labels that can be set to any time and day of the trading week, even in the future. Each label can be displayed at a specific time, on a unique day of the week, and with custom text. Also, each label has a choice of over 20 emojis to display on the chart along with user-defined text. The text color and size can be independently adjusted.

The position of the labels on the chart can be easily moved up or down with 5 built-in presents: Current Week High, Current Day High, Current Price, Current Day Low, and Current Week Low. Additionally, each label has a separate buffer that allows the users to move the label up or down in increments of five. All of these user-controls ensure the labels are exactly where the user wants them on their charts.

Limitations

This indicator displays labels in the future. TradingView sets a limit of 500 bars/candles in the future you can interact on. This TradingView limit means that labels can only be drawn 500 candles in the future on any timeframe. On larger timeframes this is not a problem and one trading week can easily display any labels. But on smaller timeframes labels multiple days in the future will exceed the 500 candle limit. When a label exceeds the 500 candle limit the indicator will have a temporary error. THIS IS NOT A PROBLEM. Simply go back to a higher timeframe or wait until the label is within 500 candles. All of your Settings will be saved! This is just a limit placed by TradingView that cannot be overwritten.

Attention: This indicator IS NOT SMART. The user must specify the day and time for each label

Important Notice

As stated above, this indicator draws labels in the future on your charts. To achieve future labels, this indicator draws labels in the present and shifts them to the right (which is the future) certain number of bars. Please be aware of the following characteristics of this indicator:

  • Labels will not appear until after midnight EST on Monday of each trading week
  • Labels will not appear over the weekends
  • Labels set to “Monday” won’t appear until midnight EST on Monday (or later)
  • Labels set to “Tuesday” through “Friday” won’t appear until the time specified in the Settings on Monday. For example, a FOMC label set to 2pm EST on Wednesday will not appear on the chart until 2pm EST on Monday
  • On 1-Hour or 2-Hour charts, please note that labels with a non-hour time will be shifted slightly so they appear on the chart. For example, a label at 8:15 am on the 5-min chart will be adjusted to 8:00 am on the 1-Hour chart so the label will appear

The above characteristics are a result of having to draw the labels at a specified time (of the trading week) and then calculating how many bars it takes to get the label to the correct time in the future.

Attention: This indicator IS NOT SMART. The user must specify the day and time for each label

Screenshots

high impact news tradingview indicator
high impact news tradingview indicator
High Impact News TradingView Indicator

High Impact News TradingView Indicator

Code

// © Infinity_Trading_
// Last Modified: 12/12/2022

//@version=5
indicator(title="High Impact News", shorttitle="High Impact News", overlay=true)

// The “High Impact News” TradingView indicator by Infinity Trading gives the user complete control of three labels that can be set to any time and day of the trading week, even in the future.
// Each label can be displayed at a specific time, on a unique day of the week, and with custom text.
// Also, each label has a choice of over 20 emojis to display on the chart along with user-defined text. The text color and size can be independently adjusted.

// The position of the labels on the chart can be easily moved up or down with 5 built-in presents: Current Week High,
// Current Day High, Current Price, Current Day Low, and Current Week Low.
// Additionally, each label has a separate buffer that allows the users to move the label up or down in increments of five.

// Limitations
//
// Can only draw 500 bars/candles into the future https://www.tradingview.com/pine-script-docs/en/v5/writing/Limitations.html#maximum-bars-forward
// THIS IS A LIMIT SET BY TRADINGVIEW
// Many times when the user is on a lower timeframe the label will be set days into the future. But because of a lower timeframe the number of bars
//      between now and then will exceed 500. This will cause the TradingView indicator to fail. THIS IS OK. The script isn't broken.
//      All of the settings are still saved and when the user goes to a higher timeframe or the time is closer to the future event, the label will appear.
//      AGAIN NOTHING IS WRONG WITH THIS SCRIPT. :-)

// Important
//
// If the News Event is selected for Monday, the label won't appear on the chart until Monday Midnight EST
// If the News Event is selected for Tuesday thru Friday, the label won't appear on the chart until Monday of the the same time specified in the Settings
// If no labels appear on the chart JUST WAIT. They will appear when either of the rules above are satisfied.


// Labels only appear on charts with a timeframe 2 hours and less

///////////////////////////////////////////////////////////////////////////////// CONSTANTS

c_session_tooltip = "For best results create a 1-minute time session span"
c_label_position_tooltip = "CWH = Current Week High \nCDH = Current Day High \n Current = current price \n CDL = Current Day Low \n CWL = Current Week Low"
c_price_buffer_tooltip = "Moves label in increments of 5 points up or down from the current label price"
c_milliseconds_in_day = 24 * 60 * 60 * 1000
c_display_days_back = 5

///////////////////////////////////////////////////////////////////////////////// INPUTS


var string N1 = "News Event #1"
i_news1_toggle = input.bool(defval = true, title="On/Off", group=N1)
i_news1_session = input.session(defval="0830-0831", title="News Time", group = N1, tooltip=c_session_tooltip)
i_news1_day_of_week = input.string(defval = "Monday", title = "Day of Week", options = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"], group = N1)
i_news1_text = input.string(defval = "News1", title = "Text, Color, Size", group = N1, inline = "news1-text")
i_news1_text_color = input.color(defval=color.new(#232572, 0), title="", group = N1, inline = "news1-text")
i_news1_text_size = input.string(defval="Normal", title="", options=["Tiny", "Small", "Normal", "Large", "Huge", "Auto"], group = N1, inline = "news1-text")
i_news1_icon = input.string(defval = "", title = "Icon", options = ["", "", "🕣", "🕘", "🕙", "🕑", "🕔", "", "", "˅", "", "", "˄", "📰", "📈", "📉", "", "", "🔥", "", "🌈"], group = N1)
i_news1_label_position = input.string(defval="Current", title="Label Position", options=["CWH", "CDH", "Current", "CDL", "CWL"], group=N1, tooltip = c_label_position_tooltip)
i_news1_price_buffer = input.int(defval=0, title="Price Buffer", step=5, minval=-100, maxval=100, group=N1, tooltip = c_price_buffer_tooltip)

var string N2 = "News Event #2"
i_news2_toggle = input.bool(defval = true, title="On/Off", group=N2)
i_news2_session = input.session(defval="0830-0831", title="News Time", group = N2, tooltip=c_session_tooltip)
i_news2_day_of_week = input.string(defval = "Tuesday", title = "Day of Week", options = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"], group = N2)
i_news2_text = input.string(defval = "News2", title = "Text, Color, Size", group = N2, inline = "news2-text")
i_news2_text_color = input.color(defval=color.new(#232572, 0), title="", group = N2, inline = "news2-text")
i_news2_text_size = input.string(defval="Normal", title="", options=["Tiny", "Small", "Normal", "Large", "Huge", "Auto"], group = N2, inline = "news2-text")
i_news2_icon = input.string(defval = "", title = "Icon", options = ["", "", "🕣", "🕘", "🕙", "🕑", "🕔", "", "", "˅", "", "", "˄", "📰", "📈", "📉", "", "", "🔥", "", "🌈"], group = N2)
i_news2_label_position = input.string(defval="Current", title="Label Position", options=["CWH", "CDH", "Current", "CDL", "CWL"], group=N2, tooltip = c_label_position_tooltip)
i_news2_price_buffer = input.int(defval=0, title="Price Buffer", step=5, minval=-100, maxval=100, group=N2, tooltip = c_price_buffer_tooltip)


var string N3 = "News Event #3"
i_news3_toggle = input.bool(defval = false, title="On/Off", group=N3)
i_news3_session = input.session(defval="0830-0831", title="News Time", group = N3, tooltip=c_session_tooltip)
i_news3_day_of_week = input.string(defval = "Wednesday", title = "Day of Week", options = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"], group = N3)
i_news3_text = input.string(defval = "News3", title = "Text, Color, Size", group = N3, inline = "news3-text")
i_news3_text_color = input.color(defval=color.new(#232572, 0), title="", group = N3, inline = "news3-text")
i_news3_text_size = input.string(defval="Normal", title="", options=["Tiny", "Small", "Normal", "Large", "Huge", "Auto"], group = N3, inline = "news3-text")
i_news3_icon = input.string(defval = "", title = "Icon", options = ["", "", "🕣", "🕘", "🕙", "🕑", "🕔", "", "", "˅", "", "", "˄", "📰", "📈", "📉", "", "", "🔥", "", "🌈"], group = N3)
i_news3_label_position = input.string(defval="Current", title="Label Position", options=["CWH", "CDH", "Current", "CDL", "CWL"], group=N3, tooltip = c_label_position_tooltip)
i_news3_price_buffer = input.int(defval=0, title="Price Buffer", step=5, minval=-100, maxval=100, group=N3, tooltip = c_price_buffer_tooltip)



///////////////////////////////////////////////////////////////////////////////// DAYS BACK

// Find the last bar on the chart
lastBarDate = timestamp(year(timenow), month(timenow), dayofmonth(timenow), hour(timenow), minute(timenow), second(timenow))
// Find the current bar that is being processed
thisBarDate = timestamp(year, month, dayofmonth, hour, minute, second)
// Find the number of days between these two bars
daysLeft = math.floor((lastBarDate - thisBarDate) / c_milliseconds_in_day)
// Only display the number of days specified in Constants above
in_days_back_range = daysLeft < c_display_days_back


///////////////////////////////////////////////////////////////////////////////// HELPER FUNCTIONS

// Function that converts Day of the Week string into an integer
day_of_the_week_function(string_dow) =>
    switch string_dow
        "Monday" => 0
        "Tuesday" => 1
        "Wednesday" => 2
        "Thursday" => 3
        "Friday" => 4

// Function that converts string inputs to text size code
text_size_function(string_size) =>
    switch string_size
        "Tiny" => size.tiny
        "Small" => size.small
        "Normal" => size.normal
        "Large" => size.large
        "Huge" => size.huge
        "Auto" => size.auto


///////////////////////////////////////////////////////////////////////////////// COMMON VARIABLES


yesterdays_high = request.security(syminfo.tickerid, "D", high)
yesterdays_low = request.security(syminfo.tickerid, "D", low)

current_week_high = request.security(syminfo.tickerid, "W", high)
current_week_low = request.security(syminfo.tickerid, "W", low)

// 23 hours in a trading day
periods_in_trading_day = 1380 / timeframe.multiplier

// Static weekly times
time_start_of_week_sunday = time(timeframe.period, "1800-1801" + ':1', "America/New_York")
time_midnight_monday = time(timeframe.period, "0000-0001" + ':2', "America/New_York")



///////////////////////////////////////////////////////////////////////////////// MAIN FUNCTIONS


// Parses the session times and makes them compatible with different chart timeframes
news_session_function(NEWS_SESSION) =>

    // Instantiate variables in function scope
    var string news_session_dynamic = na
    var string news_first_hour_str = na
    var string news_second_hour_str = na
    var float news_first_hour_number = 0.0
    var float news_second_hour_number = 0.0
    var int time_multiplier = 0

    // Create variables from the hours of the session time
    news_first_hour_str := str.substring(NEWS_SESSION, 0, 2)
    news_second_hour_str := str.substring(NEWS_SESSION, 5, 7)
    news_first_minutes_int = int(str.tonumber(str.substring(NEWS_SESSION, 2, 4)))
    // Convert session hours to numbers and check if they are even
    news_first_hour_even = str.tonumber(news_first_hour_str) % 2
    news_second_hour_even = str.tonumber(news_second_hour_str) % 2

    // Calculation of the number of candles from Monday midnight EST to the session time
    // Converts numbers to minutes
    news_monday_time_segments = (int(str.tonumber(news_first_hour_str)) * 60 + news_first_minutes_int) / timeframe.multiplier

    // Section "moves" session time to fit inside timeframe charts
    // e.g. 0720 doesn't display in the 2 hour chart. This section "moves" it so it will appear

    // If Timeframe == 1 hour then remove minutes
    if timeframe.isminutes and timeframe.multiplier == 60

        news_session_dynamic := news_first_hour_str + "00-" + news_second_hour_str + "01"

    // If Timeframe == 2 hour then remove minutes
    // If hours are odd increment by one
    else if timeframe.isminutes and timeframe.multiplier == 120

        // If first session hour is odd
        if news_first_hour_even != 0
            // Convert to a number and add 1 hour (so label will display on chart)
            news_first_hour_number := str.tonumber(news_first_hour_str) + 1

            // If hours < 8 then add extra '0'
            // Then convert back to a string
            if news_first_hour_number <= 8
                news_first_hour_str := "0" + str.tostring(news_first_hour_number)
            else
                news_first_hour_str := str.tostring(news_first_hour_number)


        // If second session hour is odd
        if news_second_hour_even != 0
            // Convert to a number and add 1 hour (so label will display on chart)
            news_second_hour_number := str.tonumber(news_second_hour_str) + 1

            // If hours < 8 then add extra '0'
            // Then convert back to a string
            if news_second_hour_number <= 8
                news_second_hour_str := "0" + str.tostring(news_second_hour_number)
            else
                news_second_hour_str := str.tostring(news_second_hour_number)

        // Combine hours back to dynamic session variable
        news_session_dynamic := news_first_hour_str + "00-" + news_second_hour_str + "01"

        // On 2-hour chart one period is lost somewhere. Adding it back
        time_multiplier := 1

    else
        news_session_dynamic := NEWS_SESSION

    // Returns 3 values from function call
    [news_session_dynamic, news_monday_time_segments, time_multiplier]



// Draws label in the future as configured by user in Settings
news_label_function(NEWS_TIME_MONDAY_EST, NEWS_MONDAY_TIME_SEGMENTS, TF_MULTIPLIER, NEWS_DAY_OF_WEEK, NEWS_TEXT, NEWS_TEXT_COLOR, NEWS_TEXT_SIZE, NEWS_ICON, NEWS_LABEL_POSITION, NEWS_PRICE_BUFFER) =>

    // Instantiate variables in function scope
    var label label_news = na

    // Convert string to code for text size
    news_text_size = text_size_function(NEWS_TEXT_SIZE)
    // Need to convert day of the week to integer for calculation
    news_day_of_week_integer = day_of_the_week_function(NEWS_DAY_OF_WEEK)

    // Calculates the number of candles between Monday and specified day of week in user Settings
    news_day_multiplier = periods_in_trading_day * news_day_of_week_integer

    // Section makes the label and updates its price (height)

    // Only display the specified number of days back
    if in_days_back_range

        // Only draw News events if chart is minute and less than 4 hour chart (so 2 hours and less)
        if timeframe.isminutes and timeframe.multiplier < 240

            // If news event is on Monday
            if news_day_of_week_integer == 0
                // Draw label when time as passed midnight of Monday morning
                if time_midnight_monday
                    label_news := label.new(x=bar_index + NEWS_MONDAY_TIME_SEGMENTS, y=high, xloc=xloc.bar_index, yloc=yloc.price, text = NEWS_ICON + "\n" + NEWS_TEXT, color=color.rgb(54, 58, 69, 100), style=label.style_label_down, textcolor=NEWS_TEXT_COLOR, size=news_text_size)
            // If news event NOT on Monday
            else
                if NEWS_TIME_MONDAY_EST
                    label_news := label.new(x=bar_index + news_day_multiplier + TF_MULTIPLIER, y=high, xloc=xloc.bar_index, yloc=yloc.price, text = NEWS_ICON + "\n" + NEWS_TEXT, color=color.rgb(54, 58, 69, 100), style=label.style_label_down, textcolor=NEWS_TEXT_COLOR, size=news_text_size)

            // Update price based upon Label Position and Price Buffer Settings
            // "CWH", "PDH", "Current", "PDL", "CWL"
            if NEWS_LABEL_POSITION == "CWH"
                // Update y-price to be the current weeks high
                if barstate.islast
                    label.set_y(label_news, current_week_high + NEWS_PRICE_BUFFER)
            else if NEWS_LABEL_POSITION == "CDH"
                // Update y-price to be the previous days high
                label.set_y(label_news, yesterdays_high + NEWS_PRICE_BUFFER)
            else if NEWS_LABEL_POSITION == "Current"
                // Update y-price to be the current price
                label.set_y(label_news, high + NEWS_PRICE_BUFFER)
            else if NEWS_LABEL_POSITION == "CDL"
                // Update y-price to be the previous days low
                label.set_y(label_news, yesterdays_low + NEWS_PRICE_BUFFER)
            else if NEWS_LABEL_POSITION == "CWL"
                // Update y-price to be the current weeks low
                if barstate.islast
                    label.set_y(label_news, current_week_low + NEWS_PRICE_BUFFER)




///////////////////////////////////////////////////////////////////////////////// NEWS EVENT #1

// Toggle News Event #1 on or off
if i_news1_toggle
    // Parse session times
    [news1_session_dynamic, news1_monday_time_segments, news1_timeframe_multiplier] = news_session_function(i_news1_session)

    // The time specified by the user (in EST) for News Event #2 but on Monday
    news1_time_monday_est = time(timeframe.period, news1_session_dynamic + ':2', "America/New_York")

    // Draw label on chart according to user Settings
    news_label_function(news1_time_monday_est, news1_monday_time_segments, news1_timeframe_multiplier, i_news1_day_of_week, i_news1_text, i_news1_text_color, i_news1_text_size, i_news1_icon, i_news1_label_position, i_news1_price_buffer)



///////////////////////////////////////////////////////////////////////////////// NEWS EVENT #2

// Toggle News Event #2 on or off
if i_news2_toggle
    // Parse session times
    [news2_session_dynamic, news2_monday_time_segments, news2_timeframe_multiplier] = news_session_function(i_news2_session)

    // The time specified by the user (in EST) for News Event #2 but on Monday
    news2_time_monday_est = time(timeframe.period, news2_session_dynamic + ':2', "America/New_York")

    // Draw label on chart according to user Settings
    news_label_function(news2_time_monday_est, news2_monday_time_segments, news2_timeframe_multiplier, i_news2_day_of_week, i_news2_text, i_news2_text_color, i_news2_text_size, i_news2_icon, i_news2_label_position, i_news2_price_buffer)



///////////////////////////////////////////////////////////////////////////////// NEWS EVENT #3

// Toggle News Event #1 on or off
if i_news3_toggle
    // Parse session times
    [news3_session_dynamic, news3_monday_time_segments, news3_timeframe_multiplier] = news_session_function(i_news3_session)

    // The time specified by the user (in EST) for News Event #2 but on Monday
    news3_time_monday_est = time(timeframe.period, news3_session_dynamic + ':2', "America/New_York")

    // Draw label on chart according to user Settings
    news_label_function(news3_time_monday_est, news3_monday_time_segments, news3_timeframe_multiplier, i_news3_day_of_week, i_news3_text, i_news3_text_color, i_news3_text_size, i_news3_icon, i_news3_label_position, i_news3_price_buffer)



/////////////////////////////////////////////////////////////////////////////////

You May Also Like

essential