Change background color for newly issued stocks


Category:
0
0

Hey Pete,

I wanted to know if you can help me with some code .

I want to change the dailey chart background to white if less than 100 bars are shown on the dailey chart.

 

This is great for fresh IPOS which dont have alot of data yet.

 

Thank you

 

This is normally the case in fresh IPO tickers

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on April 7, 2022 6:03 am
48 views
0
Private answer

I updated the title of your question to include the full context of your request. This will also help others to locate this topic using the search function. And there was a typo in your original title, the correct spelling for the time frame is "Daily", not "Dailey".

Since this solution is intended to suite the needs of a wide variety of traders I have included a user input to set the "number of bars" used to trigger the change in background color. This allows users to apply this on any time frame they like and adjust the number of bars to suite their needs. I have also included the ability to change which background color is used. Some traders use a white background already so they need to be able to adjust that without modifying the code. You will find the color adjustment listed in the "Globals" section of the Edit Studies window.

Another item to note, it is possible to trick this chart study into changing the background color for stocks which have been around for ages. So users should be careful to note how many historical bars their charts are set to include in the viewable area of the chart. This chart study is only able to read the data that is included in the chart. For example if you have a chart of AAPL displaying 3 months of daily bars your chart will have less than 100 bars and trigger this background color change (using the default values of this chart study).

Here is the code to create your custom chart study:

input numberOfBars = 100;
DefineGlobalColor("background", Color.WHITE);
def barsOnChart = HighestAll(BarNumber());
AssignBackgroundColor(if barsOnChart < numberOfBars then GlobalColor("background") else Color.CURRENT);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on April 7, 2022 8:23 am
0
thank you, works great
( at April 7, 2022 4:50 pm)