• The price of VIP membership is increasing to $199 beginning June 1. Click here to lock in the current rate of $149.

Gap Info Watchlist Column for ThinkorSwim

BenTen

Administrative
Staff
VIP
Here is the code to display gap up / gap down as your watchlist column.
  • Green background = stock has gapped up
  • Red background = stock has gapped down
It also includes the price difference between the previous close and today's opening. In other words, if you see -1.5, that means the ticker has a gap of $1.50 to the downside.

R5zkwac.png


thinkScript Code

Code:
# Gap watchlist column
# Assembled by BenTen at UseThinkScript.com

input aggregationPeriod = AggregationPeriod.DAY;
def open = open(period = aggregationPeriod);
def close = close(period = aggregationPeriod)[1];

def o = open;
def c = close;

def gu = o > c;
def gd = o < c;

def diff = o - c;
def av = (o + c) / 2;
def d = (diff / av) * 100;
plot gap = d;

AssignBackgroundColor(if gap > 0 then color.dark_green else if gap < 0 then color.dark_red else color.gray);
 

arsalaan

New member
In a nut shell the entire thinkscript feature set is available to you in Studies. A subset of thinkscript is available in conditional orders, custom quotes, study alerts, and study filters. Sadly the only way to discover what functionality is not available is to write your scripts and see if they blow up or they execute without error.

In reading some of the recent posts, it seems that the display column on the left side of TOS can be customized with studies in with the same method that you just described. In this way I would be able to customize a column of what shows up on my watch list. If that can be done then I could have a column displaying the morning gap direction of either "UP" or "DOWN" on my watch list. Is that correct?

That's called a custom quote in TOS parlance. And it may be correct, it depends on the complexity of the script. So here's an example of a Gap Analysis, I define a gap as everything for today is high(lower) than yesterday and so I made that the default. Others think it's simply the OPEN today is higher(lower) than yesterday's close, so that's the option. I divide the custom column in two parts, 1) the main logic of what I want to do I put into a chart study, and 2) in the custom quoted I reference that chart study. So here's the two scripts:

1) GapAnalysisSTUDY.ts

Code:
declare lower;

input gapType = { default highLow, openClose };

def _gapUp;
def _gapDown;
switch( gapType ) {
  case highLow:
    _gapUp    = low > high[1];
    _gapDown  = high < low[1];
  case openClose:
    _gapUp    = open > close[1];
    _gapDown  = open < close[1];
}

plot GapUp    = _gapUp;
plot GapDown  = _gapDown;

2) Gap custom column:

Code:
def GapUp = GapAnalysis().GapUp;
def GapDown = GapAnalysis().GapDown;
plot Gap = if GapUp then 100 else if GapDown then -100 else 0;
Gap.AssignValueColor( if GapUp then Color.UPTICK else if GapDown then Color.DOWNTICK else CreateColor( 236, 236, 236 ) );
AssignBackgroundColor( if GapUp then Color.UPTICK else if GapDown then Color.DOWNTICK else CreateColor( 236, 236, 236 ) );

Note that in a custom quote you must have one and only one plot. The CreateColor( 236, 236, 236 ) should be replaced with your background color, this one works well with the GunMetal TOS scheme. A lot of people I've seen uses the scheme with the black background, if you're one of those you'd change the Create... to Color.Black. If you use the White scheme, you'd change it to Color.WHITE. This technique of coloring the plot and the background the same color so the numbers disappear, unless a line has focus then the whole line is some TOS chosen color, usually blue.
 

Wave

New member
VIP
Ben, could you please make a version where it indicates a gap in percents instead of dollars?

Thank you.
 

BenTen

Administrative
Staff
VIP
@Wave Sure, here you go:

Code:
# Gap watchlist column
# Assembled by BenTen at UseThinkScript.com

input aggregationPeriod = AggregationPeriod.DAY;
def open = open(period = aggregationPeriod);
def close = close(period = aggregationPeriod)[1];

def o = open;
def c = close;

def gu = o > c;
def gd = o < c;

def diff = o - c;
def av = (o + c) / 2;
def d = (diff / av) * 100;

def nr = absValue(o - c) * 100 / o;
plot gap = nr;

AssignBackgroundColor(if d > 0 then color.dark_green else if d < 0 then color.dark_red else color.gray);
 

computernut

New member
Ben - Thanks for this! Could you possible share the code for that RV column as well? There's a few I found throughout the site so I'm curious which one you are using there. Thanks.
 

BenTen

Administrative
Staff
VIP
@computernut You can find it here.

Script:

Code:
def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1];
def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD());
def vol = if isRollover and beforeStart then volume else if beforeStart then vol[1] + volume else Double.NaN;
def PMV = if IsNaN(vol) then PMV[1] else vol;
def AV = AggregationPeriod.DAY;
def x = Average(Volume(period=AV)[1],60);
def y1 = Round((PMV/x),2);
def L = Lg(y1);
def p = if L>=1 then 0 else if L>=0 then 1 else 2;
def y2 = Round(y1,p);
plot z = y2;
z.assignValueColor(if z>=10 then color.CYAN else if z>=1 then createcolor(255,153,153) else createcolor(0,215,0));
 

Similar threads

Top