OPEN-SOURCE SCRIPT

Session Bar/Candle Coloring

Change the color of candles within a user-defined trading session. Borders and wicks can be changed as well, not just the body color.


PREFACE
This script can be used an educational resource for those who are interested in learning Pine Script. Therefore, the script is published open source and is organized in a manner that follows the recommended Style Guide.
While the main premise of the indicator is rather simple, the script showcases various things that can be achieved such as conditional plotting, alignment of indicator settings, user input validation, script optimization, and more. The script also has examples of taking into consideration the chart timeframe and/or different chart types (Heikin Ashi, Renko, etc.) that a user might be running it on. Note: for complete beginners, I strongly suggest going through the Pine Script User Manual (possibly more than once).


FEATURES
Besides being able to select a specific time window, the indicator also provides additional color settings for changing the background color or changing the colors of neutral/indecisive candles, as shown in the image below.
cuplikan
This allows for a higher level of customization beyond the TradingView chart settings or other similar scripts that are currently available.


HOW TO USE
  1. First, define the intraday trading session that will contain the candles to modify. The session can be limited to specific days of the week.
  2. Next, select the parts of the candles that should be modified: Body, Borders, Wick, and/or Background.
  3. For each of the candle parts that were enabled, you can select the colors that will be used depending on whether a candle is bullish (⇧), bearish (⇩), or neutral (⇆).

All other indicator settings will have a detailed tooltip to describe its usage and/or effect.


LIMITATIONS
  • The indicator is not intended to function on Daily or higher timeframes due to the intraday nature of session time windows.
  • The indicator cannot always automatically detect the chart type being used, therefore the user is requested to manually input the chart type via the "Chart Style" setting.
  • Depending on the available historical data and the selected choice for the "Portion of bar in session" setting, the indicator may not be able to update very old candles on the chart.



EXAMPLE USAGE
This section will show examples of different scenarios that the indicator can be used for.

cuplikan
Emphasizing a main trading session.

cuplikan
Defining a "Pre/post market hours background" like is available for some symbols (e.g., AAPL).

cuplikan
Highlighting in which bar the midnight candle occurs.

cuplikan
Hiding indecision bars (neutral candles).

cuplikan
Showing only "Regular Trading Hours" for a chart that does not have the option to toggle ETH/RTH. To achieve this, the actual chart data is hidden, and only the indicator is visible; alternatively, a 2nd instance of the indicator could change colors to match the chart background.

cuplikan
Using a combination of Bars and Japanese Candlesticks. Alternatively, this could be done by hiding the main chart data and using 2 instances of the indicator (one with "Chart Style" setting as Bars, and the other set to Candles).

cuplikan
Using a combination of thin and thick bars on Range charts. Note: requires disabling the "Thin Bars" setting for Bar charts in the TradingView chart settings.


NOTES
  • If using more than one instance of this indicator on the same chart, you can use the TradingView "Save Indicator Template" feature to avoid having to re-configure the multiple indicators at a later time.
  • This indicator is intended to work "out-of-the-box" thanks to the behind_chart option introduced to Pine Script in October 2024. But you can always manually bring the indicator to the front just in case the color changes are not being seen (using the "More" option in the indicator status line: More > Visual Order > Bring to front).
  • Many thanks to fikira for their help and inspiring me to create open source scripts.
  • Any feedback including bug reports or suggestions for improving the indicator (or source code itself) are always welcome in the comments section.
barcolorcoloredbarscoloredcandlescolorschemeeducationalPine utilitiessessions

Skrip open-source

Dengan semangat TradingView yang sesungguhnya, penulis skrip ini telah menerbitkannya sebagai sumber terbuka, sehingga para trader dapat memahami dan memverifikasinya. Hormat untuk penulisnya! Anda dapat menggunakannya secara gratis, namun penggunaan kembali kode ini dalam publikasi diatur oleh Tata Tertib. Anda dapat memfavoritkannya untuk digunakan pada chart

Inggin menggunakan skrip ini pada chart?

Pernyataan Penyangkalan