Tapatalk

Syntax highlighting wordfile for scripting language Thinkscript

Syntax highlighting wordfile for scripting language Thinkscript

5

Post4:09 - Mar 29#1

I've recently upgraded to UE 2025.2. The upgrade went well, but my ancient custom wordfile that worked perfectly in my prior version, does not work now.

Also, below is a link to the Thinkscript reference documentation. While it is a little sparse documentation-wise, I'm hoping it will prove helpful in some manner.

https://toslc.thinkorswim.com/center/reference/thinkScript

I welcome your thoughts and insights.

Thanks in advance.

6,825625
Grand MasterGrand Master
6,825625

Post9:06 - Mar 29#2

The former attached thinkscript.uew is NOT an UltraEdit syntax highlighting wordfile.

Please post a thinkScript script code block and the really used syntax highlighting wordfile.

5

Post12:17 - Mar 29#3

Thank you for the swift reply.

I am chagrined to read that the thinkscript.uew I previously attached is not an UE syntax highlighting wordfile, for that is all I have. As for a thinkscript code block, below is a sample for your review and a screenshot of what the script looks like in the Thinkorswim Thinkscript editor:

Code: Select all

declare lower;

input length = 2;
input averageType = AverageType.WILDERS;

input price = close;

def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

plot RSI = 50 * (ChgRatio + 1);
RSI.SetDefaultColor(CreateColor(0, 102, 204));
RSI.SetLineWeight(3);


I hope this helps to illustrate what I'm hoping to achieve.

Does UE provide any documentation/guidelines if I have to build a UE 2025.2 compliant wordfile from scratch?

Thanks again for your reply/inquiry, @Mofi...Much appreciated.

Best regards,

@netarchitech
202603290739_thinkscript_sample_.png (115.07KiB)

6,825625
Grand MasterGrand Master
6,825625

Post14:24 - Mar 29#4

Open in UltraEdit 2025.2.0.21 Advanced - Settings or Configuration - Editor display - Syntax highlighting and click on button Help which opens the help page Syntax Highlighting (Configuration - Editor Display). There is described on this help page which definitions can be used in an UltraEdit syntax highlighting wordfile. Switch back from the help page to the UltraEdit configuration dialog window, select one of the installed languages (=wordfiles) like the one for the language C/C++ and click on button Open. Next Open also your wordfile for Thinkscript and close the configuration dialog window with a click on symbol X. There can be seen on the opened wordfile like c_cplusplus.uew how a syntax highlighting wordfile for UltraEdit should be structured.

There is also the sticky forum topic: Template for syntax highlighting language wordfile
That template can also be used to create an UltraEdit syntax highlighting wordfile from scratch.

The first to do is the definition of the first line of the wordfile beginning with /L20"Thinksript" … and the other keywords and definitions which must be on first line like those for case-sensitivity, string highlighting, line and block comments and finally as last definition on first line File Extensions = and the file extension(s) used by default for Thinkscript files.

The second line should be the /Delimiters = line which should contain all characters being interpreted as word delimiters by UltraEdit including a space and usually also a horizontal tab character (as second and fourth word delimiting characters for better seeing these two whitespace delimiters inside the list of delimiters).

Then the up to 20 color groups should be defined with the lines /C1"Reserved words", /C2"Functions", /C3"Constants", /C4"Declarations", /C5"Operators", etc. The Thinkscript language reference must be used for this task to get the list of words and add them to the color groups in the wordfile according to the rules for these word lists.

I wrote and published several macros for wordfile creators to help getting the words sorted correct in the color groups in a syntax highlighting wordfile, avoid duplicates and check for invalid word definitions. See the sticky forum topic: The ultimate syntax highlighting tools

The syntax highlight wordfile can be fine-tuned once the syntax highlighting of reserved words, functions, constants, declarations, operators, etc. is working as expected by adding open/close fold strings for the code folding feature, open/close brace strings for the brace matching/highlighting feature, indent/unindent strings for the automatic indent/unindent feature and last but not least the UltraEdit or Perl regular expression strings to find useful strings for a flat or hierarchical list displayed in the Function List view.

It is advisable on creating a wordfile to have a file syntax highlighted by the wordfile opened in same instance of UltraEdit as the wordfile to create/edit. A save of the wordfile results in UltraEdit re-parsing the syntax highlighting wordfile and applying the changes on the syntax highlighted file according to the edited and just saved wordfile. There is necessary for some special features like code folding or the function list view to use on the syntax highlighted file the command Revert to saved to trigger a parsing for open/close fold strings and searching with the regular expressions for strings to display in the Function List view after saving the edited wordfile with modified fold strings or modified regular expressions.

Let me know if you need more help on creation of the UltraEdit syntax highlighting wordfile for Thinkscript. It would not be the first time that I created a wordfile for a language not used by me at all for another user of UltraEdit and fine tune it together with the user to make it as much useful as possible for the user. I can at least verify the syntax highlighting wordfile and check it for syntax mistakes or suggest some further improvements.

5

Post14:50 - Mar 29#5

Thank you for your latest reply. I really appreciate all of the information you've forwarded and your very generous offer of assistance. I must admit it looks like it will be a significant investment in time and effort, but I feel it will be well worth it in the end :)

I will keep you posted via this thread in terms of progress and potential follow-up questions, if I may. Thanks again!

Best regards,

@netarchitech

Post22:16 - Mar 29#6

Here's what I have so far:

Code: Select all

/L20 "Thinkscript" Line Comment = # Nocase File Extensions = TXT TS

/C1 "Reserved Words"
and between case declare def default do else equals fold
if input boolean enum float integer price string no or
plot rec reference script switch then to with yes

/C2 "Declarations"
all_for_one hide_on_intraday lower on_volume real_size
upper zerobase

/C3 "Functions"
close high hl2 hlc3 imp_volitility low ohlc4 open open_interest
volume vwap

/C4 "Option Related" Functions
delta gamma getDaysToExpiration getStrike getUnderlyingSymbol
isEuropean isOptionable isPut optionPrice rho theta vega

/C5 "Tech Analysis" Functions
AccumDist Average AvgTrueRange BodyHeight Ema2 ExpAverage
FastKCustom GetMaxValueOffset GetMinValueOffset Highest
HighestAll HighestWeighted IsAscending IsDecending Lowest
LowestAll LowestWeighted MidBodyVal moneyflow TrueRange Ulcer
WildersAverage wma

/C6 Math & Trig Functions
AbsValue ACos ASin ATan Ceil Cos Crossover exp Floor IsInfinite
IsNaN lg log Max Min Power Random round roundDown roundUp Sign
Sin Sqr Sqrt sum Tan TotalSum

/C7 Statistical Functions
correlation covariance Inertia InertiaAll lindev stdev stdevAll
sterr sterrAll

/C8 Date & Time Functions
daysFromDate daysTillDate getDay getDayOfMonth getDayOfWeek
getLastDay getLastMonth getLastWeek getLastYear getMonth getWeek
getYear getYyyyMmDd reqularTradingEnd reqularTradingStart
secondsFromTime secondsTillTime

/C9 Corporate Actions Functions
getActualEarnings getDividend getEstimatedEarnings
getSplitDenominator getSplitNumerator hasConferenceCall hasEarnings

/C10 Look & Feel Functions
AddChartBubble AddChartLabel AddCloud AddVerticalLine AssignBackgroundColor
AssignNormGradientColor AssignPriceColor AssignValueColor color
CreateColor DefineColor DefineGlobalColor EnableApproximation
GetColor globalColor hide HideBubble HideTitle SetDefaultColor
setHiding SetLineWeight SetPaintingStrategy SetStyle TakeValueColor

/C10 Other Functions
addProfile alert barnumber between compundValue concat first
getAggregationPeriod getInterestRate getSymbolPart getValue
getYield tickSize tickValue

/C11 Constants
AggregationPeriod CHART DAY FOUR_DAYS HOUR MIN MONTH OPT_EXP THREE_DAYS TWO_DAYS WEEK
Alert BAR ONCE TICK
Color BLACK BLUE CURRENT CYAN DARK_GRAY DARK_GREEN DARK_ORANGE DAR_RED DOWNTICK GRAY
GREEN LIGHT_GRAY LIGHT_GREEN LIGHT_ORANGE LIGHT_RED LIME MAGENTA ORANGE PINK PLUM RED UPTICK VIOLET WHITE YELLOW
Curve FIRM INEDITABLE LONG_DASH POINTS SHORT_DASH
Double E NaN Pi
PaintingStrategy ARROW_DOWN ARROW_UP BOOLEAN_ARROW_DOWN BOOLEAN_ARROW_UP
BOOLEAN_POINTS DASHES HISTOGRAM LINE LINE_VS_POINTS LINE_VS_SQAURES
LINE_VS_TRIANGLES POINTS VALUES_ABOVE VALUES_BELOW
PricePerRow AUTOMATIC TICKSIZE
Profile TIME VOLUME
Sound Bell Chimes Ding NoSound Ring
 
 
 Unsure about what to do with the following:
 
 /Delimiters = !@$%()-+=/{}[]:;, .*&

Integer with - + or nothing in front
syn match tsNumber '\<\d\+'
syn match tsNumber '[-+]\d\+'

Floating point number with decimal no E or e (+,-)
syn match tsNumber '\<\d\+\.\d*'
syn match tsNumber '[-+]\d\+\.\d*'

Floating point like number with E and no decimal point (+,-)
syn match tsNumber '[-+]\=\d[[:digit:]]*[eE][\-+]\=\d\+'
syn match tsNumber '\<\d[[:digit:]]*[eE][\-+]\=\d\+'

Floating point like number with E and decimal point (+,-)
syn match tsNumber '[-+]\=\d[[:digit:]]*\.\d*[eE][\-+]\=\d\+'
syn match tsNumber '\<\d[[:digit:]]*\.\d*[eE][\-+]\=\d\+'

syn region tsString start='"' end='"'

syn match tsComment "#.*$"

hi def link tsReservedWords             Keyword
hi def link tsDeclarations              PreProc
hi def link tsFunctions                 Identifier
hi def link tsConstants                 Constant
hi def link tsNumber                    Number
hi def link tsComment                   Comment
hi def link tsString                    String

let b:current_syntax = "thinkscript"
For some unknown reason I'm experiencing difficulty trying to get the UE interface to recognize the thinkscript.uew file. Below please find screenshots illustrating what I'm seeing on this end:

202603291746_UE_syntax_highlighting_configuration_.png (31.72KiB)

What could "language 2" be? I should think thinkscript.uew should be listed instead.

202603291749_Add_Remove_Thinkscript_uew_file.png (10.95KiB)

I have followed your instructions and the help files very closely. Is there anything you can see that I overlooked or did wrong? I know I haven't gotten to the syntax coloring yet, but I thought having UE properly recognize the thinkscript.uew wordfile takes precedence.

I've taken the liberty of downloading your macros. Thank you for those :) I will look at them this evening.

Thanks again for your time and assistance in this endeavor. It is greatly appreciated.

Best regards,

@netarchitech
thinkscript.uew (3.87 KiB)   0

6,825625
Grand MasterGrand Master
6,825625

Post8:09 - Mar 30#7

There is no space allowed between the language number /L20 and the language name in double quotes.
There is no space allowed between the color group number /C1 and the color group name in double quotes.
I have corrected these syntax mistakes in the attached improved syntax highlighting file thinkscript.uew.

The character & should be avoided in names as that causes troubles in the theme file (XML file) because of & has a special meaning in XML syntax and requires to be replaced by the entity &amp; in an XML file like the theme file. I replaced therefore & in color group names by +.

There was twice /C10 as I could see quickly after opening the Function List view listing the color groups once being correct defined without a space after the color group number. Second /C10 is now /C11 and /C11 is now /C12.

I added also the color groups /C13"Operators" and /C14"Braces".

The /Delimiters = line is moved up to be the second line in the wordfile. I added a normal space and a horizontal tab character. This list of characters define for the UltraEdit syntax highlighting engine which characters are word delimiters. In other words it defines which characters are not word characters for this syntax highlighting language. Each word delimiter cannot be part of a word definition in the color groups below with the exception of the character itself is the entire word or as special exception the first character of a word in a color group can be also a word delimiter, but no other character of a word in a color group.

I do not know what should be the purpose of this block in the wordfile and removed it therefore completely:

Code: Select all

Integer with - + or nothing in front
syn match tsNumber '\<\d\+'
syn match tsNumber '[-+]\d\+'

Floating point number with decimal no E or e (+,-)
syn match tsNumber '\<\d\+\.\d*'
syn match tsNumber '[-+]\d\+\.\d*'

Floating point like number with E and no decimal point (+,-)
syn match tsNumber '[-+]\=\d[[:digit:]]*[eE][\-+]\=\d\+'
syn match tsNumber '\<\d[[:digit:]]*[eE][\-+]\=\d\+'

Floating point like number with E and decimal point (+,-)
syn match tsNumber '[-+]\=\d[[:digit:]]*\.\d*[eE][\-+]\=\d\+'
syn match tsNumber '\<\d[[:digit:]]*\.\d*[eE][\-+]\=\d\+'

syn region tsString start='"' end='"'

syn match tsComment "#.*$"

hi def link tsReservedWords             Keyword
hi def link tsDeclarations              PreProc
hi def link tsFunctions                 Identifier
hi def link tsConstants                 Constant
hi def link tsNumber                    Number
hi def link tsComment                   Comment
hi def link tsString                    String

let b:current_syntax = "thinkscript"
The syntax highlighting engine of UltraEdit automatically highlights every word beginning with a digit 0-9 with the predefined color group Numbers. If floating point numbers should be entirely highlighted as number, the dot character should be removed from the /Delimiters = line to get the dot interpreted as word character and not as word delimiter.

I executed next the macro SortLanguage for correcting sorting the words in the color groups.

I played also the macro TestForDuplicate reporting:

Code: Select all

Sorry! Found following duplicate words:

Min -> in /C6
MIN -> in /C12

color -> in /C10
Color -> in /C12

alert -> in /C11
Alert -> in /C12

tickSize -> in /C11
TICKSIZE -> in /C12
The syntax highlighting language is declared as being case-insensitive with Nocase in the first line. Therefore these words are indeed duplicates and I removed the duplicate word from the color group with the higher color group number. While for the syntax highlighting engine the word in the color group with the lower color group number matters, it could be nevertheless useful to add the duplicate words to the other color groups in case of using the Auto-complete feature to get, for example, after typing tick suggested automatically or after pressing Ctrl+Space the language keywords tickSize and TICKSIZE after adding TICKSIZE back to /C12"Constants" to line THREE_DAYS TICK TIME TWO_DAYS which becomes THREE_DAYS TICK TICKSIZE TIME TWO_DAYS.

The macro TestForInvalid found no invalid word definition which means a word in a color group containing a word delimiter.


The color and font style for each color group must be configured in the Manage Themes dialog window on tab Syntax for the language Thinkscript (language name as defined in the wordfile with /L20"Thinkscript").
In ribbon mode click on ribbon tab Layout in the first group Look and feel on second command Themes for opening the Manage Themes dialog window. In toolbar/menu mode with contemporary menus click in menu Layout in submenu Themes on first menu item Manage themes.  In toolbar/menu mode with traditional menus click in menu View in submenu Themes on first menu item Manage themes…. Each color and font style change made in the Manage Themes dialog window on tab Syntax for language Thinkscript is immediately applied on the syntax highlighting of an opened Thinkscript script file displayed below the Manage Themes dialog window.

I noticed that the javascript.uew as installed by default has also the file extension TS in the first line after File Extensions =. That was the reason why I saw in status bar at the bottom JavaScript instead of Thinkscript as I saved the new file with the Thinkscript code posted by you as Test.ts. I needed to remove the file extension TS from %APPDATA%\IDMComp\UltraEdit\wordfiles\javascript.uew to get files with file extension TS syntax highlighted according to %APPDATA%\IDMComp\UltraEdit\wordfiles\thinkscript.uew. The deletion of javascript.uew is also possible on never needed.

Extracting thinkscript.uew from the attached ZIP file into the directory %APPDATA%\IDMComp\UltraEdit\wordfiles\ and (re-)starting UltraEdit makes it possible to configure at Advanced - Settings or Configuration - Editor display for Highlight new file as the language Thinkscript as defined in the improved thinkscript.uew.

I added also open/close brace string definitions because () and [] are definitely used in Thinkscript language according to reference manual. I am not sure if {} are also used in Thinkscript language but added these braces too.

I added also # to the /Delimiters = list because this character is the beginning of a line comment and is therefore for sure a word delimiter, too.
thinkscript_v1.zip (1.8 KiB)   0
Syntax highlighting wordfile thinkscript.uew (version 1)

5

Post14:28 - Mar 30#8

Wow! That is terrific! 

Thank you so much for your time, expertise and assistance. It is greatly appreciated.

Best regards,

@netarchitech