Tick Charts & Time Charts

Does anyone know how to reference time based charts in a thinkscript study that is being applied to a tick-based chart.

For example, I have a thinkscript strategy for RTY that uses 1000 ticks. I only want to make trades if RTY 2 min charts are trending up. Any creative way to solve this would be amazing!

All the best,
Mitch
 
Flexible grid... put the two side by side. There really isn't a better way that I know of. I've got scripts that will draw 2 or 5 minute close (or anything really) on a tick chart, but you can't do studies on them... so it'll plot the closes as a line, but that's all it'll do. If you're interested, I'll post the code tomorrow.

-mashume
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

OK.

VERY messy code. But it draws minute open close blocks on a tick chart. It does NOT draw wicks. It has some problems that perhaps someone here can help me fix..

It does not get the close of the 'bar' accurately and I can't sort out why.

Code:
declare upper;

def trade_time_s = SecondsFromTime(0000);
def delta_t_s = trade_time_s - trade_time_s[1];
def delta_t_m = delta_t_s / 60;
input minutes = 5;

def trades = tick_count();
# def trades = Volume;
def trades_per_minute = trades / delta_t_m;

def average = SimpleMovingAvg(trades_per_minute, 5);

# def five_min = if (trade_time_s % 300) == 0 then 1 else 0;
def min_blocks = trade_time_s % (60 * minutes);

# AddVerticalLine(min_blocks < min_blocks[1], "5m", Color.BLACK);

def upper = average + ( 4 * StandardDeviation(average, length = 5) );

def change = if close - close[1] > 0 then 1 else -1;

def v = (average * change) + v[1];
# plot velocity = v;

def c5 = if min_blocks[0] < min_blocks[1] then close()[-2] else c5[1];
def o5 = if min_blocks[0] < min_blocks[1] then open()[0] else o5[1];
def c = c5;
def o = o5;
#close5m.EnableApproximation();
#open5m.EnableApproximation();

# AddCloud(o,  c,  Color.RED,  Color.GREEN);

#plot MA5m = Average(c, 100);
#MA5m.EnableApproximation();
#o.SetPaintingStrategy(paintingStrategy.HORIZONTAL);
#close5m.SetPaintingStrategy(paintingStrategy.HORIZONTAL);

def barStart = if min_blocks[0] < min_blocks[1]  then 1 else 0;
def barEnd = if min_blocks[-1] < min_blocks[0]  then 1 else 0;
#Find the middle bar in the lower timeframe
# def midBar = if modTime == halfAgg then 1 else 0;
#If start or end of bar - used to draw side border of candle body
def openbar = if barStart or barEnd then 1 else 0;

def na = double.nan;

#------------------------------------
# ADD CLOUDS
#------------------------------------
input addcloud = yes;

def side;
if min_blocks < min_blocks[1] then{
    if side[1] == 1 then{
        side = 2;
    }
    else{
        side = 1;
    }
}else{ 
    side = side[1];
}
DEF sider = side;
def doji = C==O;
 

AddCloud( if (addcloud and sider == 2 and !doji) then o else Double.NaN, if (addcloud and sider == 2 and !doji) then C else Double.NaN, Color.LIGHT_RED, Color.LIGHT_GREEN, yes);
AddCloud( if (addcloud and sider == 1 and !doji) then O else Double.NaN, if (addcloud and sider == 1 and !doji) then C else Double.NaN, Color.LIGHT_RED, Color.LIGHT_GREEN, yes);
AddCloud( if (addcloud and sider == 1 and doji) then O else Double.NaN, if (addcloud and sider == 1 and doji) then C else Double.NaN, Color.WHITE, Color.WHITE, yes);
AddCloud( if (addcloud and sider == 2 and doji) then O else Double.NaN, if (addcloud and sider == 2 and doji) then C else Double.NaN, Color.WHITE, Color.WHITE, yes);
#plot barType = midBar;
#plot barType = Sync;
#barType.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
#barType.AssignValueColor(color.WHITE);

### making stuff up here drawing the wick through the middle candle.
def nan = double.nan;
def up = c > o;


def ubh = nan;
def ubc = nan;
def ubo = nan;
def ubl = nan;

def dbh = nan;
def dbc = nan;
def dbo = nan;
def dbl = nan;

def djbh = nan;
def djbc = nan;
def djbo = nan;
def djbl = nan;

def sideuh = if up and openbar then C else nan;
def sideul = if up and openbar then O else nan;
def sidedh = if !up and !doji and openbar then O else nan;
def sidedl = if !up and !doji and openbar then C else nan;
def sidedjh = if doji and openbar then O else nan;
def sidedjl = if doji and openbar then C else nan;

#Draw Upper Wick Green
# AddChart(high = ubh, low = ubc, open = na, close = na, type = ChartType.bar , growcolor = if 1 then color.LIGHT_GREEN else color.light_green);

#Draw Upper Wick Red
# AddChart(high = dbh, low = dbo, open = na, close = na, type = ChartType.bar, growcolor = color.LIGHT_RED);

#Draw Upper Wick White - Doji
# AddChart(high = djbh, low = djbo, open = na, close = na, type = ChartType.bar, growcolor = color.WHITE);

#Draw Lower Wick Green
# AddChart(high = ubo, low = ubl, open = na, close = na, type = ChartType.bar, growcolor = color.LIGHT_GREEN);

#Draw Lower Wick Red
# AddChart(high = dbc, low = dbl, open = na, close = na, type = ChartType.bar, growcolor = color.LIGHT_RED);

#Draw Lower Wick White - Doji
# AddChart(high = djbc, low = djbl, open = na, close = na, type = ChartType.bar, growcolor = color.WHITE);

#Draw Side of Body Green
AddChart(high = sideuh, low = sideul, open = na, close = na, type = ChartType.bar, growcolor = color.LIGHT_GREEN);

#Draw Side of Body Red
AddChart(high = sidedh, low = sidedl, open = na, close = na, type = ChartType.bar, growcolor = color.LIGHT_RED);

#Draw Side of Body White
AddChart(high = sidedjh, low = sidedjl, open = na, close = na, type = ChartType.bar, growcolor = color.WHITE);


plot highs = ubh;
highs.setpaintingStrategy(PaintingStrategy.POINTS);
highs.setDefaultColor(Color.Green);
plot lhighs = dbh;
lhighs.setpaintingStrategy(paintingstrategy.points);
lhighs.setdefaultColor(Color.Red);
plot lows = ubl;
lows.setpaintingStrategy(PaintingStrategy.Points);
lows.setdefaultColor(Color.Green);
plot llows = dbl;
llows.setpaintingStrategy(PaintingStrategy.POINTS);
llows.SetDefaultColor(Color.Red);


# end


9uMFsmj.png
 
Hey guys!

I have been thinking about an indicator, sort of an oscillator, that can depict the speed that ticks are printing in a determined spot in the market. Letting you see the speed of the tick. If you grab say a 3000tk chart you will see some candles take 3-4 mins to complete while sometimes when the volatility is higher they take 1 minute or less. I want to be able to see when this speed increases in a time based chart in a normalized way.

Does someone know how can I achieve something like this?

Thanks a lot

M
 
Hey guys!

I have been thinking about an indicator, sort of an oscillator, that can depict the speed that ticks are printing in a determined spot in the market. Letting you see the speed of the tick. If you grab say a 3000tk chart you will see some candles take 3-4 mins to complete while sometimes when the volatility is higher they take 1 minute or less. I want to be able to see when this speed increases in a time based chart in a normalized way.

Does someone know how can I achieve something like this?

Thanks a lot

M
I moved your post here. You could try to use the script in this thread as your starting point.
 
Howdy folks. Been trying to figure out how to make a simple overlay for a tick chart that plots a vertical line every 30 minutes (or variable) AND that, in text printed with each vertical line the number of bars since the last vertical line/time marking. So after thirty minutes, say, it'll plot a line with "100" on it, indicating 100 bars since open, then "250" or whatever for the next vertical line. Apologies to the following code's creator- couldn't find the original to cite and it's not mine (might not have been from this site) but it's super simple and managed to get the vertical line part done beautifully. The time interval is minutes.

Code:
input time_interval = 30
def x = (getTime() % (60 * time_interval * 1000));
addVerticalLine(x < x[1], BarNumber(), color.black);

You'll notice I've stuck the BarNumber() in the text field of the addVerticalLine and it basically does what I want. However, it starts counting from the beginning of the loaded data, so if it's 5 days of tick info I get cumulative numbers that don't reset (of course) at each open. I would think it'd be possible to query the current BarNumber from the current GetTime and simply subtract the BarNumber from the previous GetTime, or using the modulo to retrieve the time to query barnumber for subtraction - but the catch is I'm a rookie programmer and feel like the solution might be simple, whereas I keep digging for answers and am not quite getting it. Right now I just hammer it out on a calculator or do it in my head, roughly.

Anyone with an assist?
 
I did that study a while back, I have modified to add bar counts since the last vertical as the label for you:
Code:
declare upper;

input time_interval = 10;

def x = (getTime() % (60 * time_interval * 1000));
def boundary = if x < x[1] then 1 else 0;
def c = if boundary[1] == 1 then 1 else c[1] + 1;

addVerticalLine( boundary == 1, " " + c, color.black);

Let me know if that does what you were expecting.

-mashume
 
Searched for you but not hard enough - thanks for both the original and this update. That's exactly it.

Curious because the logic seems clear but I lack the know how to confirm: this is running each tick and if it's not a boundary [if boundary is 0] it's adding 1 to the previous def c which starts at 1 when there's a new boundary using the last boundary [boundary[1]==1 then 1] as the first value of the next cycle. Not sure I got that right but its damn clever work, mashume, thanks.
 
This indicator is exactly what I was looking for, but I see how the candle closes aren't quite right. Any progress on this? Also wondering if the wicks can be added? I went through some settings and didn't see an option to draw them. Anyways, great work on this script so far!
 
Hey guys!

I have been thinking about an indicator, sort of an oscillator, that can depict the speed that ticks are printing in a determined spot in the market. Letting you see the speed of the tick. If you grab say a 3000tk chart you will see some candles take 3-4 mins to complete while sometimes when the volatility is higher they take 1 minute or less. I want to be able to see when this speed increases in a time based chart in a normalized way.

Does someone know how can I achieve something like this?

Thanks a lot

M
Code:
declare lower;

def t = getTime() / 1000;

plot delta_t = t - t[1];

This plots the time in seconds for each candle to generate. (I think)

-mashume
 
This indicator is exactly what I was looking for, but I see how the candle closes aren't quite right. Any progress on this? Also wondering if the wicks can be added? I went through some settings and didn't see an option to draw them. Anyways, great work on this script so far!
Nope. Haven't touched it in ages. It isn't hard to see the highs and lows, and getting wicks to draw when you don't know where the center of the 'bar' should be is neigh on impossible.

Not sure what's up with candle closes, but that's life. ;-)

-mashume
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
349 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top