Welcome! Log In Create A New Profile

Get Earnings and Seasonal Trends - Subscribe Today!


Fun with ThinkScript

Posted by robert 
Re: Fun with ThinkScript
January 17, 2018 05:59PM
In English the steps you need to plot the Composite Index are the following: This indicator is on all of Constance's Brown's chart and in her book. Just need to code it in TOS.

Step 1: create a 9-period momentum (momentum is indicator of a 14 period RSI. Yes, it is momentum on RSI, not price. This is an indicator on an indicator. I put the momentum formula below since TOS does not have this indicator.
Step 2: create a very short 3-period RSI and then a simple 3-period moving average of the 3-period RSI to smooth it slightly.
Step 3: add Steps 1 and 2 together to create the Composite Index.
Step 4: Create two simple moving averages of the Composite Index using the periods 13 and 33.
Step 5: Plot the Composite Index and its two simple averages as three lines in a separate frame under the price data.

momentum (M) is a comparison between the current closing price (CP) a closing price "n" periods ago (CPn). M = CP - CPn

How to plot Connie Brown's Composite Index in TradeStation:

Create two functions.
The function RSIMO9 is written:

RSIMO9 = MOMENTUM(RSI(Close,14),9)

The second function is written:


The formula is then written:

Plot1(RSIMO(+RSI3,"Plot1"winking smiley:
Plot2(average((plot1),13),"Plot2"winking smiley;

I would really appreciate anyone's help with this. If you have any questions or need to know something else just let me know. I would be more than happy to pay for it.
Re: Fun with ThinkScript
January 18, 2018 09:26AM
Can anyone help me create a paint bar thinkscript?

What I'm looking for is a quick easy way to visualize the difference between a base candle and a leg candle. Leg candles would be the paint bar.

A leg candle is one where the current candle closes outside of the previous candle's range ( high to low ).

A base candle is one where the current close is within the previous candle's range ( between high and low ).

Much like an inside bar. But with the closes. And if it could include my current inside bar thinkscript that would be great. Just using different color paint bars for base candles and inside bars.

Anyone know how to do this? Thank you

Inside bar script:
def insideBar = high < high[1] and low > low[1];
def insideMatch = insideBar and (high == high[1] or low == low[1]);
AssignPriceColor(if insideMatch then Color.blue else if insideBar then Color.MAGENTA else Color.CURRENT);
Re: Fun with ThinkScript
January 18, 2018 10:25PM

I am trying to draw an opening range that starts at 18:00pm eastern and ends at 9:00am eastern the following day. The lines will extend until 17:00pm. I tried to modify Robert's and ReadtheProspectus' OR scripts but I have zero coding background so I haven't been successful. Help anyone? Thanks in advance.
Re: Fun with ThinkScript
January 19, 2018 12:01AM
Hey there, first time posting! I'm hoping this ask isn't too difficult... In my TOS scanning, I'd love to see the stocks that had the first 5min candle of the day close above the 9ema and the last candle to close below the 9ema. It would be great for any help. Any thoughts or tricks?
Re: Fun with ThinkScript
January 19, 2018 09:27PM
Hi Tai,

I've been trying to come up with the thinkscript version of the Composite Index. There are a number of errors (highlighted in red), but here's what I have so far:

declare lower;

def length_rsi = 14;
def length_momentum = 9;
def price = close;

def averageType = AverageType.WILDERS;
def NetChgAvg = MovingAverage(averageType, price - price[1], length_rsi);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length_rsi);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);

def Momentum = price - price[length_momentum];

def RSIMO = Momentum(RSI(price, length_rsi), length_momentum);

def RSI3 = ExpAverage(RSI(price, 3), 3);

plot CompositeIndex = (RSIMO(RSI3));
plot avg13 = (ExpAverage(RSIMO, 13));
plot avg33 = (ExpAverage(RSIMO, 33));

I'll keep trying to see if I can get past the outstanding errors, but I hope what I have proves helpful in some way...
Re: Fun with ThinkScript
January 21, 2018 01:11PM

A fellow scripter on another forum provided the answer:

declare lower;
def RSIDelta = RSI(14) - RSI(14)[9];
def RSIsma = simpleMovingAvg(rsi(3),3);
plot plot1 = RSIDelta + RSIsma;
plot plot2 = simpleMovingAvg(plot1,13);
plot plot3 = simpleMovingAvg(plot1,33);

Hope that helps. Pay it forward smiling smiley

Hi all - new to TOS
January 21, 2018 07:21PM
Hello everyone.... I am new to thinkscript and find it fascinating.
I program and do stats as biostatistician in clinical trials (R and SAS), but ThinkScript is a different animal.

I would like to become more proficient. I am reading the TOS Learning Center, but am open to advice on how to improve.
I think I have to work with simple examples and develop from there.

For example I was hoping to calculate the avg % move in the week after each of the last 5 earnings for given optionable stocks that come up in a scan as straddle candidates. I know for many of you here, this is child's play, but for me it is a challenge. Any suggestions.


Edited 1 time(s). Last edit at 01/21/2018 07:22PM by denbois.
Re: Fun with ThinkScript
January 25, 2018 04:24PM
Can someone help me with a simple scan / script. I just want to do a scan for increasing volume for 3 consecutive bars(bar_0<bar_1<bar_2).

Thank you

Maybe like this?

input x = volume;
input length = 3;

plot scan = sum(x > x[1], length) == length;

Edited 1 time(s). Last edit at 01/25/2018 05:37PM by transiennt999.
Re: Fun with ThinkScript
January 27, 2018 07:13PM
Hey Robert,

I am looking to create a column just like this Custom Column using the simple moving average cross (2) above the (8) SMA.

Is there a way to have it continue past 1 and -1 to 15days? 1 2 3 , -1 -2 -3?

Please let me know or if you need something clarified! Thanks
session midpoint????
February 17, 2018 10:11AM
Hi all, and a big thank-you for looking at this....I am a newbie with programming so I have NO idea how the following script is NOT plotting the midpoint of today's session...The script is not mine and is publicly available. However, it plots something akin to the day's midline, but not really. Just to be clear I am defining midpoint of the session as ((highest high - lowest low)/2) + lowest low..... I would like to see where the plot has been during the day, much like one can see where the moving average has been throughout the day. Thanks to all..smiling smiley

input CapturePeriodStart = 0930;
input CapturePeriodEnd = 1615;

input StartPlotTime = 0930;
input EndPlotTime = 2359;

def CapturePeriodHasBegun = secondsFromTime(CapturePeriodStart) > 0;
def FirstBarOfCapturePeriod = !CapturePeriodHasBegun[1] and CapturePeriodHasBegun;
def PriorPeriod = secondsFromTime(CapturePeriodStart) > 0 or secondsFromTime(CapturePeriodEnd) < 0;
def PlotPeriod = secondsFromTime(StartPlotTime) > 0 && secondsTillTime(EndPlotTime) > 0;
rec PriorPeriodHigh = if IsNaN(PriorPeriodHigh[1]) or PriorPeriodHigh[1] < 2 then high
else if FirstBarOfCapturePeriod then high else if PriorPeriod && high > PriorPeriodHigh[1] then
high else PriorPeriodHigh[1];

rec PriorPeriodLow = if IsNaN(PriorPeriodLow[1]) or PriorPeriodLow[1] < 2 then low else
if FirstBarOfCapturePeriod then low else if PriorPeriod && low < PriorPeriodLow[1] then low else

def TheHigh = if PlotPeriod && PriorPeriodHigh > 2 then PriorPeriodHigh else

def TheLow = if PlotPeriod && PriorPeriodLow > 2 then PriorPeriodLow else
Re: Fun with ThinkScript
February 17, 2018 07:38PM
Actually was wondering how i can change them both to SMAperiod since the CC is simple moving averages and i have to change the length to you know what they are. . Could anyone expound on this ?? Thanks hope this could help out someone .

input EMAPeriod = 10;
input SMAPeriod = 20;
input price = close;
def na = double.nan;

plot fastema = ExpAverage(price, EMAPeriod);
plot slowema = Average(price, SMAPeriod);
def crossover = if fastema > slowema AND fastema[1] <= slowema[1] then 1 else 0;
def crossunder = if fastema < slowema AND fastema[1] >= slowema[1] then 1 else 0;

#Plot arrows
Plot up = if crossover then low - tickSize() else na;
Plot down = if crossunder then high + tickSize() else na;

#Trigger alerts
alert(crossover[1], "Crossover", Alert.Bar, Sound.Ding);
alert(crossunder[1], "Crossunder", Alert.Bar, Sound.Ding);

Edited 2 time(s). Last edit at 02/17/2018 11:47PM by Chris M.
Re: Fun with ThinkScript
February 17, 2018 11:25PM
Please don't post the numbers to the settings.
Re: Fun with ThinkScript
February 17, 2018 11:48PM
RichieRick Wrote:
> Please don't post the numbers to the settings.
Done , slipped my mind sorry. RichieRick can you give me a pionter or 2 to help me change this over to a CC alert . Thanks in advance.
Sorry, only registered users may post in this forum.

Click here to login