Monday, November 17, 2008

Using Time Conditionals in thinkScript


This study is a very simple example of how to use the time functions in thinkScript. This will plot the close during market hours only (8:30am CT – 3:00pm CT) and it will plot 0 if outside of the time range. Please note that the closing bar is not the bar at 3:00pm CT (16:00 ET) rather, it is the last bar before that time. Thus, as you can see, the logic in evaluating the end function (which is the function that tells us when the market closes) excludes zero as the bar at 1600 isn’t included in the market hours. However, the begin function includes zero (greater than or equal to expression) as the market open does include the 8:30am CT bar (9:30am ET).

Please recall that the time functions in thinkScript only will work if you use 24-hour time format and it is stated in Eastern Time.

Note, for simplicity and layout purposes, this study has been coded as a lower study...

!!! FOR EDUCATIONAL PURPOSES ONLY !!!! PLEASE READ DISCLAIMER POST!

declare lower;

input begin_time = 930;

input end_time = 1600;


def begin = secondstilltime(begin_time);

def end = secondstilltime(end_time);

plot data = if(begin<=0 and end>0,close,0);

Thursday, November 13, 2008

thinkScript - Highest and Lowest of last 20 bars


This simple indicator will plot the highest and the lowest values of the last 20 bars.


!!! FOR EDUCATIONAL PURPOSES ONLY !!!! PLEASE READ DISCLAIMER POST!


input low_price = low;

input high_price = high;


plot down = lowest(low_price, 20);

plot up = highest(high_price,20);

thinkScript - Linear Regression Indicator - price based colors


This is just a very simple study that paints the Linear Regression Indicator line in your default uptick color if the current bar's close is above the LRI, or downtick if the current bar's close is lower than the LRI...

!!!! FOR EDUCATIONAL PURPOSES ONLY!!! PLEASE READ DISCLAIMER POST!



input length = 25;

input price = close;

plot lri = reference linearregrindicator(length, price);

lri.assignvalueColor(if close>lri then color.green else color.red);

thinkScript - Previous day's HLC + Today's Open


This study will chart the HLC of the previous trading day, and it will also plot today's opening price.

The “TIME” input, you will need to manually type in the specific time aggregation you are using, i.e. if you are looking at 5 minute chart, you must enter 5, if you are using 15 minute bars in your chart, you will enter 15 as the TIME.

As for the MARKET_OPEN input, this is the first bar of the day. The MARKET_CLOSE is a bit more complex…. This is the very last bar of the day. So, if you are looking at 15 minute bars, you must enter 1545. If you are looking at 5 minute bars, you must enter 1555.


Please recall that the times is stated in a 24hour form and it is Eastern Time. So, for example, 1600 is 4:00pm ET.

This will NOT work with TICK charts. Please note that this will only work if you are looking at "Trading Hours Only" within the Charts tab...


!!! FOR EDUCATIONAL PURPOSES ONLY!!! - PLEASE READ DISCLAIMER POST


input market_open = 930;

input market_close = 1545;

input time = 15;

rec begin_open = if(secondsTillTime(market_open) == 0, open,begin_open[1]);

rec begin_high = if(secondsTillTime(market_close) == 0, Highest(high, ((390 / time))),begin_high[1]);

rec begin_low = if(secondsTillTime(market_close) == 0, lowest(low, ((390 / time))), begin_low[1]);

rec begin_close = if(secondsTillTime(market_close) == 0, close, begin_close[1]);

plot highest = if(begin_high == 0, double.nan, begin_high);

highest.setdefaultcolor(color.orange);

plot lowest = if(begin_low == 0, double.nan, begin_low);

lowest.setdefaultcolor(color.light_red);

plot end = if(begin_close == 0, double.nan, begin_close);

end.setdefaultcolor(color.dark_gray);

plot opening = if(begin_open == 0,double.nan,begin_open);

opening.setdefaultcolor(color.blue);

thinkScript - Current Day's Opening Price


This study will plot the current day's open price at 8:30am CT. This will only work if you are using a time aggregation period of less than 1 hour, i.e. 30min, 15min, 5min, etc...

Also, note that the open price of the 8:30am CT bar may not be the same as the actual OPEN quote.

The inputs will allow you to select your own market open time (based on Eastern Time and on a 24 hour format) and the price input will allow you to select which price you wish to chart, i.e. open, high, low, close...

It will NOT work with tick charts!

!!!! FOR EDUCATIONAL PURPOSES ONLY - PLEASE READ DISCLAIMER POST!!!!



input time = 930;

input price=open;

rec time_value = if(secondstilltime(time)== 0,price,time_value[1]);

plot open = if(time_value==0, double.nan,time_value);

Previous day's HLC for Index Futures


What this study will do is that it will chart the high, low and close for previous trading day for the Index Futures that close at 3:15pm CT, reopen at 3:30pm CT, close at 4:30pm CT and reopen at 5:00pm CT.

The study's inputs are start & time. The START input allows you to set the opening time of the index future, i.e. 3:30pm CT (remember that it is in Eastern Time and it written using a 24 syntax, i.e. 1630 for 4:30pm ET).

The time input allows you to control the time aggregation you are using on the chart as the study is specific to the time aggregation you are using. Thus, if you are looking at 5 minute bars, you will enter 5 as the Time input, if you are using 15 minute bars, you will use 15 in the time input.

Please note that this will ONLY work with index futures that close close at 3:15pm CT, reopen at 3:30pm CT, close at 4:30pm CT and reopen at 5:00pm CT, i.e. /ES, /NQ, /YM, etc..

Picture will come shortly...

!!!!!!!!!!!!!!!!!! FOR EDUCATIONAL PURPOSES ONLY! !!!!!!!!!!!!!!!!!!!!!!

input start = 1630;

input time = 15;

rec begin_high = if(secondsTillTime(start) == 0, Highest(high, ((1395 / time))), begin_high[1]);

rec begin_low = if(secondsTillTime(start) == 0, lowest(low, ((1395 / time))), begin_low[1]);

rec begin_close = if(secondsTillTime(start) == 0, close[1], begin_close[1]);

plot highest = if(begin_high == 0, double.nan, begin_high);

highest.setdefaultcolor(color.orange);

plot lowest = if(begin_low == 0, double.nan, begin_low);

lowest.setdefaultcolor(color.light_red);

plot end = if(begin_close == 0, double.nan, begin_close);

end.setdefaultcolor(color.dark_gray);




DISCLAIMER

DISCLAIMER

PLEASE ONLY USE THE INFORMATION HEREIN PROVIDED IF YOU AGREE TO THIS DISCLAIMER!

I'm going to start a blog posting all the scripts that I've written so far to create studies within thinkScript. I assume no liability for errors and any code you see here can be used at your own risk.

FOR EDUCATIONAL PURPOSES ONLY!!!!!!!