# Colour Scheme

Hi,

I have a question about the “Colour Scheme” property. At the moment there are the following “Time Intervals” possible: Sessions, Daily, Weeks, Months, Years, 5 Years.

Here is a chart example:

Is it possible to create via a script time intervals for “Quarters” and “10 Years”?

I use for better visualizations a “step line” for selected time periods. Here is a chart example:

As you can see the “step line” is the closing price of the pervious years.

The script for yearly closing prices is very simple:

YEAR()[1]

For monthly closing prices the script for the “step line” is also simple:

MONTH()[1]

BUT what are the scripts for a “step line” for quarterly, 5-year, and 10-year closing prices?

Thomas

Hi Thomas,

For the step line you can use something like:

//10 Year
YEAR(PERIODAMOUNT=10)[1]

//Quarterly
MONTH(PERIODAMOUNT=3)[1]

1 Like

Hi Matthew,

Thank you very much. An easy script solution, a one code line script!

Is there also a script solution for the “Quarters” and “10 Years" time intervals (see first chart)?

Thanks,
Thomas

Hi Thomas,

That one is a little trickier. This is one way you could do it that is not timeframe-specific to the chart you are applying it to.

// Get the current bar index
brIndex = BARINDEX();
// Calculate the value of barIndex modulo 120 to create a cycle
modValue = MOD(brIndex, VALUE=120);
// Determine if the modValue is less than 60 for the first half of the cycle, making it true
isTrue = modValue < 60;
isTrue

In this instance, i want every 60 bars one colour, and the other 60 bars a different colour.

You can modify this script to use whichever Bar interval you want, you just need to modify the bar values (in this example, 60 and 120). The mod value should always be double the bar interval you are looking for, so 50 would be 100, 70 would be 140, etc.

Hi Matthew,

Wow, what a script, brilliant!

I hope I’m not annoying you, but is it possible to add a start date on which the count should begin, e.g. 01/01/1900?

Thanks,
Thomas

Hi Thomas,

I can’t think of a way to get the cycle going from a specific date. The only way would be to adjust the charts Date Range to use that specific start date.

1 Like

Hi Thomas,

For quarterly colours you could use MONTHNUM() in the script so it’s based on date rather than number of bars. This will show Q1 and Q3 one colour, and Q2 and Q4 another:

M1=MONTHNUM();
M1<4 or (M1>6 and M1<10)

1 Like

Hi Matthew and Darren,

Thank you very much for your help. For the quarter colors I use Matthew’s script with “Show Plot”. It is perfect.

For decade and quarter coloring I have hard coded the time periods. It was easy but a little bit cumbersome. But on the other hand it was a one time job.

Here is the script for the decades:

D1 = BARDATE()>STRDATE(DATE=1849-12-31) and BARDATE()<STRDATE(DATE=1859-12-31) ;
D2 = BARDATE()>STRDATE(DATE=1869-12-31) and BARDATE()<STRDATE(DATE=1879-12-31) ;
D3 = BARDATE()>STRDATE(DATE=1889-12-31) and BARDATE()<STRDATE(DATE=1899-12-31) ;

D4 = BARDATE()>STRDATE(DATE=1909-12-31) and BARDATE()<STRDATE(DATE=1919-12-31) ;
D5 = BARDATE()>STRDATE(DATE=1929-12-31) and BARDATE()<STRDATE(DATE=1939-12-31) ;
D6 = BARDATE()>STRDATE(DATE=1949-12-31) and BARDATE()<STRDATE(DATE=1959-12-31) ;
D7 = BARDATE()>STRDATE(DATE=1969-12-31) and BARDATE()<STRDATE(DATE=1979-12-31) ;
D8 = BARDATE()>STRDATE(DATE=1989-12-31) and BARDATE()<STRDATE(DATE=1999-12-31) ;

D9 = BARDATE()>STRDATE(DATE=2009-12-31) and BARDATE()<STRDATE(DATE=2019-12-31) ;
D10 = BARDATE()>STRDATE(DATE=2029-12-31) and BARDATE()<STRDATE(DATE=2039-12-31) ;
D11 = BARDATE()>STRDATE(DATE=2049-12-31) and BARDATE()<STRDATE(DATE=2059-12-31) ;
D12 = BARDATE()>STRDATE(DATE=2069-12-31) and BARDATE()<STRDATE(DATE=2079-12-31) ;
D13 = BARDATE()>STRDATE(DATE=2089-12-31) and BARDATE()<STRDATE(DATE=2099-12-31) ;

EOD = D1 or D2 or D3 or D4 or D5 or D6 or D7 or D8 or D9 or D10 or D11 or D12 or D13 ;
EOD

For the quarters it is the same procedure but a lot more work! For the step line in decade chart I have created a csv file in Excel and update it via a VBA macro. So there is no daily time consuming work.

Here are the great Optuma charts:

Last but not least, for the vertical decade separating lines in the decade chart I have also created a script and placed it using “Show Bar”.

Thanks for your help and ideas.
Thomas