Dividend Vertical Lines indicator – customising the indicator script

There might be occasions where you have a chart indicator, and you would like to tweak it a little. In the example shown in the screen shot below, the supplied “Dividend Vertical Lines” indicator has been tweaked by adding in a calculation for the Dividend Yield, along with some extra text. This KnowledgeBase article explains how to edit the indicator script to achieve this.

Dividend Date Vertical Lines - customised
A screenshot of the Dividend Date Vertical Lines indicator, with customisations

The BullCharts script

The final script that produces the above indicator is shown in the graphic below. It includes script comments (the green text in curly braces) to help explain the script.

Customised Dividend Vertical Lines indicator - script
Customised Dividend Vertical Lines indicator – script

If you use the Indicator Builder (or the indicator properties) to view the script in the supplied version of this indicator, and compare it to the above script, you will see there is not much difference between the two.

Further tweaks

Note that to exactly achieve the appearance of the text in the initial screen shot above, you will need to edit the properties of the indicator, and manually change the colour of the chart elements (the vertical lines, and perhaps the text), and also for the “DivAmount” text, you can change the “Position” to be “Above”, rather than the default value of “Below” as shown in the following screenshot.

Dividend Date Vertical Lines - defaults
Dividend Date Vertical Lines – defaults

Copying the script

In case you want to copy the BullScript itself, the script for this indicator is included at the bottom of this KB article. You can simply “scrape” the mouse cursor over the text below, and use the Windows “copy” and “paste” functions to paste it into your own BullCharts Indicator Builder script.

TIP for copying the script below: For the first mouse click+hold, click past the end of the script, and move the mouse cursor up toward the top of the script – this is always easier than clicking at the top and scraping down the page. Also, don’t forget to include the last semi-colon at the bottom of the script.

Author: Robert Brain (aka Brainy)
BullCharts User Group convenor


 

The Script for this indicator

NOTE: When you copy and paste the text below into your BullCharts Indicator Builder: the paste operation will probably paste the double quotation marks using a different and incorrect ASCII character that will give you a script error. The simple fix for this is for you to do the paste, and then find the few double quotation marks at fault (they are not little vertical lines, but angled lines), and simply delete each one and replace it by typing the double quotation mark from the keyboard. This does not apply to any quotation mark which is embedded within the script comments. Unfortunately, I cannot find a way to avoid this glitch in the text below.

The offending characters are the double quotation marks ” in the following 4 lines of script (have a good look at those in your script in your Indicator Builder, and observe that they are probably angled, and not vertical):

“Div: $”+security.CurrentDividendAmount +
” = “+div_percent,undefined) +
“% (when Close = $”+
close+”)”

You will find in the Indicator Builder script-editing that the editor will display the error message, and it will position the screen cursor before the first offending quotation mark. You can always click on the “Check” button in the lower right corner of the Builder window to perform a check, and as you progress through fixing these characters, the editor will position the cursor in front of the next offending character.

*** The script follows ***

[Description=”It can be useful to know when the ex-dividend date is approaching.
This indicator applies a vertical line to the price chart on the ex-dividend date.”]
[Category=”Fundamental | Security Info”]
[target=Price]

{ Calculate the Div percent resulting in just 2 decimal places}
div_percent1 := security.CurrentDividendAmount * 10000 / c;
div_percent := int(div_percent1) /100;

[linestyle=text]
[textalign=Above,Right]

{ “security.exdate” = (internal variable) the ex-dividend date }
{ “OnOrSkipped” – means if the “security.exdate” is the current date, or just skipped due to holiday for instance, then apply it}

[linestyle=verticalmarker;name=ExDate:<<date>>;target=price]
OnOrSkipped(security.exdate);

[target=Price]
[linestyle=verticalmarker; name=ExDate|<<Amount>>]
[linestyle=text; name=DivAmount;dp=2; textalign=bottom,left]

if(OnOrSkipped(security.exdate),
“Div: $”+security.CurrentDividendAmount +
” = “+div_percent,undefined) +
“% (when Close = $”+
close+”)”
; Close

{ “security.DividendPayableDate” = (internal variable) the dividend paid date }
{ Including the vertical bar between “DivPaid:” and “<<date>> will force the output text to straddle the target date}
[linestyle=verticalmarker; name=DivPaid:|<<date>>; target=price]
OnOrSkipped(security.DividendPayableDate)
;

*** End of Script ***

Was this article helpful?

Related Articles