Bid Ask Spread Visualizer For ThinkOrSwim
I've learned the hard way recently that successful daytrading requires careful consideration of the bid/ask spread. Attempting to daytrade or scalp symbols that tend to have large spreads relative to your profit target is a surefire way to lose money. So I pulled together two simple studies that allow visualization of the current and historical spread. The current spread can help inform where to place any tight limit or stop orders, and the historical spread can tell you whether you should even consider trading that particular symbol.
The first study simply plots arrows on the price plot corresponding to the current bid and ask prices. The second generates a lower plot showing the bid/ask spread history at the open for each bar. It's worth noting that the bid and ask prices are sometimes undefined, which can result in either of these studies briefly yielding NaN values that won't display. That will typically happen for a few seconds after a new bar opens.
Hopefully these will be of some use to other traders. Good luck out there!
http://tos.mx/QLRpbxE
http://tos.mx/zAzTejH
I've learned the hard way recently that successful daytrading requires careful consideration of the bid/ask spread. Attempting to daytrade or scalp symbols that tend to have large spreads relative to your profit target is a surefire way to lose money. So I pulled together two simple studies that allow visualization of the current and historical spread. The current spread can help inform where to place any tight limit or stop orders, and the historical spread can tell you whether you should even consider trading that particular symbol.
The first study simply plots arrows on the price plot corresponding to the current bid and ask prices. The second generates a lower plot showing the bid/ask spread history at the open for each bar. It's worth noting that the bid and ask prices are sometimes undefined, which can result in either of these studies briefly yielding NaN values that won't display. That will typically happen for a few seconds after a new bar opens.
Hopefully these will be of some use to other traders. Good luck out there!
http://tos.mx/QLRpbxE
Code:
# Plot current bid/ask arrows on price plot
# Author: CuiJinFu
# Version: 1 12/23/21
def lastBar = !IsNaN(close) && IsNaN(close[-1]);
plot lastAsk = if lastBar then close(priceType = "ASK") else Double.NaN;
lastAsk.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
lastAsk.SetDefaultColor(Color.YELLOW);
plot lastBid = if lastBar then close(priceType = "BID") else Double.NaN;
lastBid.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
lastBid.SetDefaultColor(Color.YELLOW);
http://tos.mx/zAzTejH
Code:
# Plot bid/ask history on a lower plot
# Use open price to avoid repainting
# Author: CuiJinFu
# Version: 1 12/23/21
declare lower;
input yellowval = 0.15;
input redval = 0.25;
plot spread = 100*(open(priceType = "ASK") - open(priceType = "BID"))/open;
spread.SetDefaultColor(Color.CYAN);
spread.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
plot zeroline = 0;
zeroline.SetDefaultColor(Color.GRAY);
zeroline.SetStyle(Curve.LONG_DASH);
plot yellowline = yellowval;
yellowline.SetDefaultColor(Color.YELLOW);
yellowline.SetStyle(Curve.LONG_DASH);
plot redline = redval;
redline.SetDefaultColor(Color.RED);
redline.SetStyle(Curve.LONG_DASH);
spread.AssignValueColor(if spread > redval then Color.RED else if spread > yellowval then Color.YELLOW else Color.GREEN);
Last edited by a moderator: