LBR Indicator Watchlist Column for ThinkorSwim


Active member
2019 Donor
I wanted to pick up on the discussion yesterday of the LBR paint bars. I looked online for a description of how Linda derived them and how they should be used, but I couldn't find anything except how they are calculated. Does anyone know of a good resource on this topic?

I have been working on this for a while. I've managed to get the color columns but I can't figure out the crossings since I believe both the 3, 10 are the same. I think. Anyway this is as far as I got. I want the 3/10 crossing above the slow 16. HELP! Driving me bonkers.

Here is the script for the indicator: and below that is what I've made so far. I don't know how to script but I managed a few things.

# TD Ameritrade IP Company, Inc. (c) 2011-2019

declare lower;

input price = close;
input calculationMode = {default Normal, Alternate};

plot FastLine;
switch (calculationMode) {
case Normal:
    FastLine = Average(price, 3) - Average(price, 10);
case Alternate:
    FastLine = Average(price - Average(price[3], 3), 2);
plot SlowLine = Average(FastLine, 16);
plot Hist = FastLine;
plot ZeroLine = 0;

Hist.DefineColor("Positive", Color.UPTICK);
Hist.DefineColor("Negative", Color.DOWNTICK);
Hist.AssignValueColor(if Hist >= 0 then Hist.color("Positive") else Hist.color("Negative"));

So far:

INPUT ma1 = 3;

INPUT ma2 = 16;

DEF ALERT =SimpleMovingAvg("length" = ma1)."SMA" crosses SimpleMovingAvg("length" = ma2)."SMA";
Alert(ALERT, "MA CROSSES MA2", Alert.BAR, Sound.Ring);
AddLabel(yes, IF
SimpleMovingAvg("length" = ma1)."SMA" >
SimpleMovingAvg("length" = ma2)."SMA" THEN
ma1 ELSE ma2 ,IF
SimpleMovingAvg("length" = ma1)."SMA" <
SimpleMovingAvg("length" = ma2)."SMA" then
color.RED else color.GREEN);

AssignBackgroundColor (IF
SimpleMovingAvg("length" = ma1)."SMA" <
SimpleMovingAvg("length" = ma2)."SMA" then
color.RED else color.Light_GREEN);

#ALERT.AssignValueColor(if CLOSE  > ma1 then Color.DARK_GREEN else Color.Orange);
Last edited by a moderator:


Well-known member
@MBF As I read through your request it appears to me that you're looking to implement a moving average crossover on the watchlist
If that is the case, here is a real simple starter script. I've used the 50/200 moving average, so feel free to use the MA of your choice in the code
Not quite sure I see the association with the LBR study you referenced

input fastLength = 50;
input slowLength = 200;
input AvgType = AverageType.SIMPLE;
input price = close;

plot FastAvg = MovingAverage(AvgType, price, fastLength);
plot SlowAvg = MovingAverage(AvgType, price, slowLength);

AddLabel(FastAvg crosses SlowAvg, if FastAvg > SlowAvg then "CROSS ABOVE" else "CROSS BELOW", if FastAvg > SlowAvg then Color.GREEN else Color.RED);

AssignBackgroundColor(if FastAvg > SlowAvg then Color.GREEN else Color.RED);


Well-known member
Hi @MBF try this tutorial. This is a worthwhile code for you. Your code attempt needs Inputs or Def's first. Once that's put together, post it. Hopefully you'll get some help.
@tomsk is this what you were thinking of in regards to a tutorial? I don't remember where I got it.

% Above - Below 200 SMA  AddLabel() displays a STRING value. So, it will be sorted alphabetically. Plot displays a numeric value and will be sorted numerically.
#HINT: This is a custom watchlist column looking for xx% percent above or below moving average line. \n It provides a visual alert with the percent from MA line where you expect price to revert to the mean by reversing to return to the MA line.

## because this is a watchlist column there is no Edit box.  therefore def could have been used insted of input.  To change type of price and/or type of moving average, click on the word "Inspector" top right of this box and click on the word close or the word AverageType.SIMPLE and the Inspector will show you your other choices.
input price = close;
input length = 200;
input Average_Type = AverageType.SIMPLE;
input percent_from_MA = 0.2;

## these def or "define a new word to ThinkScript" did not have to be used, but it saved a lot of time and typing later in the code by providing ability to use the new "words" instead of typing the math formula multiple times in different lines later in the code

def Avg = MovingAverage(average_Type, price, length);
def MA_below_price = price > Avg;
def MA_above_price = price < Avg;
def percent_away = if MA_below_price or MA_above_price then (close / avg) - 1 else 0;

def oversold = percent_away * 100 <= percent_from_MA * (-1);
def overbought = percent_away * 100 >= (Percent_from_MA);

### AddLabel needs (1) condition to trigger it to be visible or the word yes if always visible, (2) text to appear in quotes + data to appear in the label, (3) color for the label which can be static color or can be dynamic using if __ then __ else ___

#AddLabel(yes, if oversold then " oversold " + AsPercent(percent_away) else if overbought then " overbought " + AsPercent(percent_away) else AsPercent(percent_away), color.BLACK);
#AssignBackgroundColor(if oversold then color.GREEN else if overbought then color.lIGHT_RED else color.LIGHT_GRAY);
AddLabel(yes, if oversold then " below " + AsPercent(percent_away) else if overbought then " above " + AsPercent(percent_away) else AsPercent(percent_away), color.BLACK);
AssignBackgroundColor(if oversold then color.DARK_ORANGE else if overbought then color.Green else color.LIGHT_GRAY);

# end code ------------------


Active member
2019 Donor
@horserider @tomsk @markos

Here is the crossovers, in the circles. The problem I have is the 3/10 is the difference btwn the two and plots as one MA. So I tried adding a third MA3 but then I got confused on how to write the rest. So at one point I had MA1=3, MA2=10, MA3=16. I am looking for the 3/10MA to cross above the slow 16MA.
Here is a photo.



Well-known member
@markos Let's step back and look at the bigger picture.

FastLine measures the difference between 2 moving averages.
SlowLine is a moving average of the fast line, so it smoothens it out a bit,
Typically a moving average measures price, e.g. 16 SMA would measure the 16 period moving average based on price

My understanding is that the requester wants to compare that FastLine/SlowLine cross with SMA(16) which is based on price
The underlying parameters are different not quite sure if that comparison is really the intent.


New member
So what you want is the 3ma and the 10ma represented as one colored line... line to be one color(blue) if the 3ma is above the 10ma and another color if below (magenta). Next you want a 16ma line. What conditions do you want to happen when ma1=3/10 crosses the ma2=16. An arrow or another color change?

I am trying to write a script for a watchlist column for the LBR 3/10 Oscillator. I wanted to know when the histogram crosses above the fastline. Can anyone help? I have the script I wrote but it isn't working correctly.


Well-known member
Here it is! @MBF this is from the OneNote.
@tomsk are you able to cross check this script to find it's origin? JQ didn't have a citation in the ON.
# WLC for LBR_ThreeTenOscillator
#hint:<b>A WLC that shows the minutes-ago since the last turn of the moving average either up or down.</b>\nMay be use multiple times with each column set to a different aggregation. The exclusion of after-hours is recommended.

input price = close;#hint price: The price used to calculate the average. <b>(Default is CLOSE)</b>
input Length = 30;#hint Length: The number of bars used to calculate the moving average. <b>(Default is 30)</b>
input AvgType = {default Simple, Exponential, Weighted, Wilders, Hull};#hint AvgType: Type of the fast moving average to be used for calculation. <b>(Default is SIMPLE)</b>
input TurnType = {default ThreeBarTurn, FiveBarTurn};#hint TurnType:A <b>ThreeBarTurn</b> is one using a single before and after bar to define the turn.\n A <b>FiveBarTurn</b> is one using two bars before and two bars after to define a turn.

def AvgToUse;
switch (AvgType) {
case Simple:
AvgToUse = Average(price, Length);
case Exponential:
AvgToUse = ExpAverage(price, Length);
case Weighted:
AvgToUse = wma(price, Length);
case Wilders:
AvgToUse = WildersAverage(price, Length);
case Hull:
AvgToUse = HullMovingAvg(price, Length);

Def TurnDown;
Case ThreeBarTurn:
   TurnDown = if AvgToUse[1] < AvgToUse && AvgToUse[-1] < AvgToUse then 1 else 0;
Case  FiveBarTurn:
TurnDown = if AvgToUse[2] < AvgToUse[1] && AvgToUse[1] < AvgToUse && AvgToUse[-1] < AvgToUse && AvgToUse[-2] < AvgToUse[-1] then 1 else 0;

Def TurnUp;
Case ThreeBarTurn:
   TurnUp = if AvgToUse[1] > AvgToUse && AvgToUse[-1] > AvgToUse then 1 else 0;
Case  FiveBarTurn:
   TurnUp = if AvgToUse[2] > AvgToUse[1] && AvgToUse[1] > AvgToUse && AvgToUse[-1] > AvgToUse && AvgToUse[-2] > AvgToUse[-1]  then 1 else 0;

Def IsUp = If TurnUp then 1 else 0;
Def IsDown = If TurnDown then 1 else 0;
Def NumbOfBars = If IsUp then sum(IsUp) else if IsDown then sum(IsDown) else double.nan;

#===== Define the bars-to-minutes factor ===========
Def Factor =  if getAggregationPeriod() == AggregationPeriod.MIN then 1 else if 
getAggregationPeriod() == AggregationPeriod.TWO_MIN then 2 else if
getAggregationPeriod() == AggregationPeriod.THREE_MIN then 3 else if 
getAggregationPeriod() == AggregationPeriod.FOUR_MIN then 4 else if
getAggregationPeriod() == AggregationPeriod.FIVE_MIN then 5 else if 
getAggregationPeriod() == AggregationPeriod.TEN_MIN then 10 else if
getAggregationPeriod() == AggregationPeriod.FIFTEEN_MIN then 15 else if 
getAggregationPeriod() == AggregationPeriod.TWENTY_MIN then 20 else if
getAggregationPeriod() == AggregationPeriod.THIRTY_MIN then 30 else if 
getAggregationPeriod() == AggregationPeriod.HOUR then 60 else if
getAggregationPeriod() == AggregationPeriod.TWO_HOURS then 120 else if 
getAggregationPeriod() == AggregationPeriod.FOUR_HOURS then 240 else if
getAggregationPeriod() == AggregationPeriod.DAY then 1440 else if 
getAggregationPeriod() == AggregationPeriod.TWO_DAYS then 2880 else if
getAggregationPeriod() == AggregationPeriod.THREE_DAYS then 4320 else if
getAggregationPeriod() == AggregationPeriod.FOUR_DAYS then 5750 else if
getAggregationPeriod() == AggregationPeriod.WEEK then 7200 else if
getAggregationPeriod() == AggregationPeriod.MONTH then 28800 
else double.nan;

Def MinsSinceTurn = factor * NumbOfBars; #Minutes Since Polarity Change ms

Plot Data_MST = MinsSinceTurn;
AssignBackgroundColor(if IsUp  then color.dark_green
else if IsDown then
else color.current);


Well-known member
@markos JQ is pretty good at noting the source of studies he posts to the ON. I know that in addition to him, there are other folks that have edit privileges. Perhaps one of them posted that. BTW I don't recall seeing that study in TSL, but I have missed a few days


Well-known member
It says NaN on all aggregations. Is this a template that I fill in?
It should work as advertised.
@tomsk or anyone else, could you take a look at this tonight to see what you can find out? I am on mobile today/tonight. Thanks.
@MBF Is it giving you a warning of any type? It may be "complicated" and thus take TOS a while to populate. Please let us know if it occurs when you scan the S&P 100. That smaller list might help. Please give the particulars.


Well-known member
@markos Per your request, I looked into the problem that was reported. Loading it onto the watchlist, I see NaN across all timeframes in the watchlist, daily, and intraday. That tells me that there is no data, or the underlying data sequence is being calculated incorrectly. Hence no data is being presented in the watchlist.

Since you say you obtained this from JQ's ON, probably best to check if he knows where the code originated from, perhaps it might have been an interim or works in progress version. I just don't know

Please post the exact link to the ON where you found it this study, which in my assessment is fubar, so probably best not to use it. If you like, I'll ask a friend to check in with JQ and ask him for the attribution and other details. Personally I don't use JQ's ON as I find that there are some instances of code being posted without having undergone QA.

Hope that helps @markos


Well-known member
@markos As a follow up to your previous note, I had a friend contact JQ. Apparantly this study was in StanL’s Treebase. In case you are unaware, StanL was a lounge librarian of sorts who passed on in 2014. The WLC was found in a directory titled SFL Coded Studies. There is no header or attribution detail in the treebase.

After looking through the contents, he found a previous version of the study dated Feb 2012. Here is the code... I tested it on my watchlist (daily), and it performs MUCH better - no more NaN gibberish. However reviewing the code, it has nothing to do with LBR Three Ten oscillator, so perhaps that was something that was works in progress and uncompleted. Best to ditch that previous study

Hope this helps

#hint:Here's updated code that facilitates monitoring where in the intraday's high-low range a stock currently is. This is used in as a watchlist-gadget column as well as in TOS' 'MarketWatch/Quotes' tab. A Hi is definable and above that value will be highlighted with a green background. Likewise for a Lo but with a red. A dark red or dark green means that the current price is below yesterday's close.

#Title = %HL, Revision 2/22/12
#Please post any problems or suggestions with this code for 'Stan L' on TOS' Thinkscript Lounge chatroom

input HiPct = 0.90;
input LoPct = 0.10;

def diffclose = close[1] - close;
def diffH = high - close;
def diffTotal = high - low;
def Range = 1 - (diffH / diffTotal);
#def down = close < close[1];
plot data = round(Range);
data. assignvaluecolor(if Range >= HiPct then
else if Range < LoPct then else color.yellow);

Assignbackgroundcolor (if Range >= HiPct and (close > close[1]) then
else if Range >= HiPct and (close < close[1]) then color.dark_green
else if Range <= LoPct and (close > close[1]) then color.RED
else if Range <= LoPct and (close < close[1]) then color.Dark_RED
#------End of Code--------
Last edited:


Well-known member
Thanks @tomsk I can work with that and a few snippets to help her come up with the code. She's ( @MBF ) tuned into the LBR code, so I'll try this weekend. @Townsend added a new entry on scanning in Tutorials, so I asked him if he could add this to his tutorial. Thanks again!
  • Love
Reactions: MBF


Well-known member
@markos Since there is so much interest in LBR by quite a few readers, I looked up my files and found this LBR Paintbars study from Linda Raschke that you might like to check out. Sure looks good visually IMHO

# LBR Paint Bars, showing ATR bands, added cloud
# Best trades above and below the LBR cloud
# Linda Bradford Raschke

input HLLength = 16;
input ATRLength = 9;
input factor = 2.5;
input paintBars = yes;
input averageType = AverageType.SIMPLE;

assert(factor > 0, "'factor' must be positive: " + factor);

def AATR = factor * MovingAverage(averageType, MovingAverage(averageType, TrueRange(high, close, low), ATRLength), ATRLength);
def band1 = Lowest(low, HLLength) + AATR;
def band2 = Highest(high, HLLength) - AATR;

plot UpperVolatility = close > band1 and close > band2;
plot LowerVolatility = close < band1 and close < band2;

# Plots added
plot ln = band1;
ln.SetDefaultColor(CreateColor(250, 250, 0));

plot ln1 = band2;
#ln.AssignValueColor(if ln > ln1[1] then CreateColor(250, 250, 0) else Color.cyan);

ln1.SetDefaultColor(CreateColor( 0, 0,0));
ln.AssignValueColor(if ln1 > ln[1] then CreateColor(250,250, 250) else;

AddCloud(data1 = ln, data2 = ln1, color2 = Color.LIGHT_GRAY, color1 = Color.LIGHT_GRAY);

# PaintBar
DefineGlobalColor("Bullish", CreateColor( 0, 250, 0));
DefineGlobalColor("Bearish", CreateColor( 250, 0, 0));

AssignPriceColor(if !paintBars
    then Color.CURRENT
    else if UpperVolatility
        then globalColor("Bullish")
        else if LowerVolatility
            then globalColor("Bearish")
else if  open < close then CreateColor(0,200, 250)
            else CreateColor( 255, 255, 255));

@markos Ah! now I see what LBR refers to - Linda Bradford Raschke. Learning something new everyday!


Active member
2019 Donor
She is one of my favorites, dropping a note here to say how impressive and nice it is to see everyone trying to help so much. This is great experience for me. I'm very grateful. Fretfully trying to work on it on my own, a little humorous, but I have to try! Again thank you from the bottom of my bank account. ;)

I am trying to plot a signal and for some reason having quite a time with it. The signal id from two different indicators. Slow Stoch, using the K and the LBR Oscillator, using the slowline. I have the two scripts in and then added them together. My plot statement for a signal is not working. Any help?


Well-known member
Now that it's clear what LBR stands for, I Googled "Linda Radschke Three Ten Oscillator" and found quite a number of hits. Hence it must be a trading system of some sort. Looking at the TOS version of this oscillator, there are essentially 4 plots.

The FastLine is calculated based on the DIFFERENCE between SMA(3) and SMA(10) which is based on PRICE
The SlowLine is the SMA(16) of the FastLine
The Hist is the histogram version of the FastLine - essentially it displays the exact same values as the FastLine
The ZeroLine is self explanatory

Usually when we look at moving averages, it is based on price. Here we have a very different situation. The FastLine is not based on price alone per se but is derived from the difference between SMA(3) and SMA(10). The SlowLine is not based on price, but is the SMA(16) of the computation of FastLine

My belief is that it is important to have clarity because this might be the cause of confusion as to what @MBF mentioned earlier. Now we have a clear relationship between what the SMA(3), SMA(10) and the SMA(16) are truly measuring. For all intents and purposes we can ignore the histogram, so all we're left with are the FastLine and the SlowLine plots. Perhaps one simple way to look at this is just to look at the crossover of these two plots

Hope this helps clear up some of the confusion

Based on my post above, here then is the study based on crossUp as requested by @MBF earlier, if my interpretation is correct. The user interface can be used to select cross down signals, just whatever style you prefer

I have tested this, ready to go out of the box.

# LBR Three Ten Signal Arrows
# tomsk
# 12.11.2019

# Displays signals when the FastLine crosses the SlowLine.
# Configure your preferences to display CrossUp/CrossDn signals

input showCrossUp = yes;
input showCrossDn = no;
input price = close;
input calculationMode = {default Normal, Alternate};

def FastLine;
switch (calculationMode) {
case Normal:
    FastLine = Average(price, 3) - Average(price, 10);
case Alternate:
    FastLine = Average(price - Average(price[3], 3), 2);
def SlowLine = Average(FastLine, 16);

plot crossUp = if showCrossUp and FastLine crosses above SlowLine then 0.995 * close else Double.NaN;

plot crossDn = if showCrossDn and FastLine crosses below SlowLine then 1.005 * close else Double.NaN;
# End LBR Three Ten Signal Arrows
Thread starter Similar threads Forum Replies Date
B Adhara AI Indicator Questions 3
C NOPE Indicator Playground 3
T SFI Indicator - Buy/Sell Signal for Forex Trading Questions 5
germanburrito GANN Square Of 9 Indicator for ThinkorSwim Indicators 71
R BBTrend Indicator Questions 6

Similar threads