TradingView
processingclouds
14 фев 2022 г., 21:45

HighLow Box Highlight between Earnings 

COMMONWEALTH BANK OF AUSTRALIA.ASX

Описание

HighLow Box Highlight between Earnings

This is an indicator to highlight area between two earning periods and their highest and lowest points.
  • It also alternates the highlight color in each subsequent block.
  • Tested to work in 1D charts and 1M charts
  • Just drop a message, if you want this further developed with more features.


Note: This was requested by user Meatpye on a forum.

Информация о релизе

v2 - To avoid Error: Study references too many candles in history, set max candles to 1000.

NOTE: If you cannot see beginning boxes, tradingView (tV) has garbage disposal service, so after drawing max number of boxes, it will start to delete old ones to accommodate new ones in FIFO method i.e. First In First Out(delete).

Информация о релизе

  • Added Custom Box Inputs.
    e.g. Input Dates 20210901,20211101,20211205,20220201
    e.g. Input Colors e.g. orange,clear,purple
    Separate dates and colors by commas
    Input in form of DATE, DATE,.... DATE where DATE=yyyymmdd
  • Supported colors are blue, yellow, green, purple, orange, gray, red, olive, clear
  • Added Error Handling of Inputs and Output Error in Top Center
  • ERROR in Custom Inputs:
    1.Make sure dates are formatted as yyyymmdd.
    2.Number of colors is one less than number of dates.
    3.Dates are in ascending order.
    4. There must be atleast 2 dates.

Информация о релизе

Updated the Chart to show custom boxes as Orange and Purple using inputs as:
Dates: 20210901,20211101,20211205,20220201
Colors: orange,clear,purple

Also updated Input Color Tooltip text

Информация о релизе

v5 - Updated Tags
Updated error message

Информация о релизе

v6 - Fixed a bug where lowest and highest were sometimes not being updated correctly. Had to reset them after each box drawing.

Информация о релизе

v7
  • Cleaned color part of the code - It is a separate function and less lines of code
  • Added error check so it removes blank spaces from color input i.e. spaces after comma separated colors do not result in error
  • Added option to choose which boxes to display, you can choose "both" to display earnings and custom boxes, or select either to display as stand alone
  • Just to clarify - Custom box input takes dates in form of yyyymmdd. Each two dates next to each other represent a range.
    e.g. 20210601,20210901,20220101,20220201 - This represents three time periods, one from Jun2021 to Sep2021, the next as Sep2021 to Jan2022, and last as Jan2022 to Feb2022
    For the colors as there are 3 time periods, we need to input only 3 colors (even though 4 dates are specified), e.g. green, clear, purple - This will color first time period in green, next as blank, and the other as purple
    So if you input the color as "clear" it will not highlight that period which can be used to ignore periods between input dates
-
// - Added error check, so it removes blanks from color string input
// - Added option to choose which boxes to display
Комментарии
silver007
Hello,
i like this indicator but i need some adjustments to use it perfect for my trading-concept.
Are you able to do this adjustments for me ?
cooney_s
Cool tool! Thanks for sharing. This would be great to use for Futures traders based on Contract Switch dates! :)
processingclouds
@cooney_s, Glad it could be of help.

Regards
@processingclouds - Turning ideas to reality
MeatPye
Hi ProcessingClouds,
I am trying to draw a diagonal line across the box. From the Start of Box to End of the Box, connecting the High and Low (or Low and High)

I tried to add the following code just below the "drawBox"

drawLine := line.new(bar_index[count], highest, bar_index, lowest, color=color.red, width=2)

drawBox := box.new(bar_index[count], highest, bar_index, lowest,
border_color = color.green,border_width=1, border_style=line.style_dotted,
bgcolor=(flip ? color.new(color.blue, 70) : color.new(color.yellow,70)))

The error message I have is "Study Error"
Object Positioned using xloc.bar_index cannot be drawn further than 500 bars into the future.

Any suggestion on how I can fix this error?

Thanks,
Meatpye
MeatPye
Hi Processingclouds,

Thank you for this script! It is very useful!

I was wondering if it is possible to modify this script so it will draw boxes between the dates I nominate? (ie. what if the date is not in trading view?)

For Example
firstDate = timestamp('UTC', 2019, 02, 05, 00, 00, 00)
secondDate = timestamp('UTC', 2020, 01, 25, 00, 00, 00)
thirdDate = timestamp('UTC', 2021, 02, 12, 00, 00, 00)
fourthDate = timestamp('UTC', 2021, 08, 25, 00, 00, 00)
fifthDate = timestamp('UTC', 2021, 12, 10, 00, 00, 00)
or something like
Timeframe = timestamp('UTC', 2019, 02, 05, 00, 00, 00) , timestamp('UTC', 2020, 01, 25, 00, 00, 00) , timestamp('UTC', 2021, 02, 12, 00, 00, 00), timestamp('UTC', 2021, 08, 25, 00, 00, 00), timestamp('UTC', 2021, 12, 10, 00, 00, 00)

Any idea or pointers will be greatly appreciated.

Thank you in advance!
Meatpye
processingclouds
@MeatPye, We can add custom box drawing to this too, how many custom boxes are you trying to add though ?
MeatPye
@processingclouds, thank you for your response, I am excited. To be honest with you, I was hoping for as many custom boxes as possible.

Currently, I am calculating this in Excel (dates + high\low) and hard-coding this back into trading view. At a minimum, I was hoping to have at least 50 dates. The more boxes I have, the less "indicators" I will need to re-use \ duplicate \ replicate. I do understand there is a system processing limitation from Tradingview, so I will be happy with whatever is available.

Thank you again, Processingclouds!
Meatpye
processingclouds
@MeatPye, we can add many custom inputs, only issue is, we still have to specify the number in advance. Pinescript as per my knowledge does not allow inputs to be created using a loop i,e, define number of inputs and create that many custom input fields from initial input.

Interestingly we do have an option, though, we can add string input with multiple timeframes in single string separated by commas. Just to clarify something, will each corresponding date be showing closing of previous period ?
MeatPye
@processingclouds, thanks again for helping me with the code.

In answer to your question, "will each corresponding date be showing closing of previous period ?"
Are you asking if the boxes will be joined?

1. Is it possible to code the box color as "blank" or "clear?" (Therefore if the boxes do not join, I will just code it as clear or blank?
2. Is it possible to specify colors for each box in a separate string? eg.
String 1 (dates) = Date1, Date2, Date3, Date4, Date5, Date6, Date 7, Date8, Date9, Date10
String 2 (colors) = Blue, Blue, Yellow, Blue, Blue, Clear, Yellow, Blue, Clear, Blue

For the sample, I am to go with 10 (you can just use 01 Jan each year or random dates). This way, I can increase the size of the string and variable as needed.
1000 inputs will be plenty! Thank you! :-)
processingclouds
@MeatPye, to answer your points
1. We can have clear box or work on not displaying box when string 2 has clear color specified in it.
2. We can define colors too in a string. (But if you have 10 dates, than there should be 9 colors)

I will work on implementing custom boxes, and see where it leads us. Will put date input string simply like yyyyddmm,yyyyddmm, .... yyyyddmm and so on.

Just to go over your last unnumbered point, you will not be able to draw 1000 boxes. Let me quote you from the pinescript docs: "Lines and boxes consume server resources, which is why there is a limit to the total number of drawings per indicator or strategy. When too many are created, old ones are automatically deleted by the Pine runtime, in a process referred to as garbage collection." and also "limit to a value in range from 1 to 500"
So you will have max limit of 500 and that also if resources keep up according to your other drawings and functions.
Ещё