Repaints Market Structure Indicator For ThinkOrSwim

Repaints
The suitability of detecting large orders immediately depends on the specific time frame and trading style you are using. However, in general, shorter time frames such as intraday charts (e.g., 1-minute, 5-minute) are more suitable for detecting orders in real-time or near real-time.

When using shorter time frames, the script will analyze volume differences between consecutive bars, allowing for more immediate detection of large orders. However, it's important to note that the script's effectiveness may vary based on market liquidity, volatility, and the specific stocks or securities you are trading.

For longer time frames (e.g., daily, weekly), the script may still detect large orders, but it may not provide immediate or intraday insights since it relies on the comparison of volume differences between bars. It has many customizable features in the options menu.

Ultimately, the suitability of the script for detecting orders immediately depends on your trading preferences, time frame, and the specific requirements of your trading strategy. You may need to experiment with different time frames and adjust the script parameters to align with your trading goals.

The Market Structure indicator combines the Order Block concept with the Zero Lag Zigzag indicator. Let's go through the different color-coded prices and their interpretations:

  1. Bullish Order Blocks:
    • ObBull1 (White Values Below): This plots the low of a bullish order block. It represents a potential support level where buyers have shown strength, pushing the price higher.
    • bull1 (White Dashes): This plots the high of a bullish order block. It represents a potential resistance level where sellers may enter the market and push the price lower.
    • bull2 (White Values): This plots the low of a bullish order block. It complements the bullish order block's high (bull1) and indicates a support level.
    • ObBullAvg1 (White Dashes): This plots the average price (midpoint) of a bullish order block. It can serve as a reference point for evaluating the overall strength or weakness of the bullish order block.
  2. Bearish Order Blocks:
    • ObBear1 (Values Above): This plots the high of a bearish order block. It represents a potential resistance level where sellers have shown strength, pushing the price lower.
    • bear1 (Dashes): This plots the low of a bearish order block. It represents a potential support level where buyers may enter the market and push the price higher.
    • bear2 (Values): This plots the high of a bearish order block. It complements the bearish order block's low (bear1) and indicates a resistance level.
    • ObBearAvg1 (Dashes): This plots the average price (midpoint) of a bearish order block. It can serve as a reference point for evaluating the overall strength or weakness of the bearish order block.
  3. Zero Lag Zigzag:
    • obStartPlot (Cyan): This plots the start points of the identified order blocks based on the Zero Lag Zigzag indicator. It indicates potential turning points where price shifts from a downtrend to an uptrend.
    • obEndPlot (Magenta): This plots the end points of the identified order blocks based on the Zero Lag Zigzag indicator. It indicates potential turning points where price shifts from an uptrend to a downtrend.
Additionally, the indicator provides channels for the order blocks, indicated by the clouds:

  • Bullish Order Block Channel: It is shown as a light green cloud and represents the range between the start and end points of the bullish order block.
  • Bearish Order Block Channel: It is shown as a pink cloud and represents the range between the start and end points of the bearish order block.
These color-coded prices and channels help visualize the identified order blocks, their potential support and resistance levels, and the transition points in price trends.












Ruby:
#converted by Trader4TOS
# Order Block Indicator with Zero Lag Zigzag
declare lower;

input ShowCloud = yes;
input periods = 5; # "Relevant Periods to identify OB"
input threshold = 0.0; # "Min. Percent move to identify OB"
input useWicks = no; # "Use whole range [High/Low] for OB marking?" )
input showBullChannel = yes; # "Show latest Bullish Channel?"
input showBearChannel = yes; # "Show latest Bearish Channel?"

# Zero Lag Zigzag for structure
def highBar = high > high[1];
def lowBar = low < low[1];
def highZigzag = if highBar and !highBar[1] then high else if highBar and highBar[1] then Max(highZigzag[1], high) else Double.NaN;
def lowZigzag = if lowBar and !lowBar[1] then low else if lowBar and lowBar[1] then Min(lowZigzag[1], low) else Double.NaN;
def zigzag = if !IsNaN(highZigzag) then highZigzag else lowZigzag;
def isPeak = !IsNaN(highZigzag);
def isTrough = !IsNaN(lowZigzag);

# Calculate order blocks
def obStart = if isPeak and !isPeak[1] then highZigzag else Double.NaN;
def obEnd = if isTrough and !isTrough[1] then lowZigzag else Double.NaN;

# Order block filter
def highValue = high;
def lowValue = low;
def blockThreshold = threshold * (highValue - lowValue);
def isObStart = highValue - lowValue > blockThreshold;
def isObEnd = lowValue - highValue < -blockThreshold;

# Declare variables
def na = Double.NaN;
def ob_period = periods + 1;
def absmove = ((AbsValue(close[ob_period] - close[1])) / close[ob_period]) * 100;
def relmove = absmove >= threshold;
def bullishOB = close[ob_period] < open[ob_period];
def upcandles = Sum(close > open, periods + 1);
def OB_bull = bullishOB and upcandles == periods and relmove;
def OB_bull_high = if OB_bull then if useWicks then high[ob_period] else open[ob_period] else na;
def OB_bull_low = if OB_bull then low[ob_period] else na;
def OB_bull_avg = (OB_bull_high + OB_bull_low) / 2;
def bearishOB = close[ob_period] > open[ob_period];
def downcandles = Sum(close < open, periods + 1);
def OB_bear = bearishOB and downcandles == periods and relmove;
def OB_bear_high = if OB_bear then high[ob_period] else na;
def OB_bear_low = if OB_bear then if useWicks then low[ob_period] else open[ob_period] else na;
def OB_bear_avg = (OB_bear_low + OB_bear_high) / 2;

# Plotting
plot ObBull1 = if OB_bull then low else Double.NaN; #"Bullish OB"
ObBull1.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
ObBull1.SetDefaultColor(Color.WHITE);
ObBull1.SetLineWeight(2);

plot bull1 = if OB_bull_high then if useWicks then high else open else na;
bull1.SetPaintingStrategy(PaintingStrategy.DASHES);
bull1.SetDefaultColor(Color.WHITE);
bull1.SetLineWeight(2);

plot bull2 = if OB_bull_low then low else Double.NaN; #"Bullish OB Low"
bull2.SetPaintingStrategy(PaintingStrategy.DASHES);
bull2.SetDefaultColor(Color.WHITE);
bull2.SetLineWeight(2);

plot ObBullAvg1 = (bull1 + bull2) / 2; #"Bullish OB Average"
ObBullAvg1.SetPaintingStrategy(PaintingStrategy.DASHES);
ObBullAvg1.SetDefaultColor(Color.WHITE);
ObBullAvg1.SetLineWeight(2);

plot ObBear1 = if OB_bear then high else Double.NaN; # "Bearish OB"
ObBear1.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
ObBear1.SetDefaultColor(CreateColor(33,150,243));
ObBear1.SetLineWeight(2);

plot bear1 = if OB_bear_low then if useWicks then low else open else na;
bear1.SetPaintingStrategy(PaintingStrategy.DASHES);
bear1.SetDefaultColor(CreateColor(33,150,243));
bear1.SetLineWeight(2);

plot bear2 = if OB_bear_high then high else Double.NaN; # "Bearish OB High"
bear2.SetPaintingStrategy(PaintingStrategy.DASHES);
bear2.SetDefaultColor(CreateColor(33,150,243));
bear2.SetLineWeight(2);

plot ObBearAvg1 = (bear1 + bear2) / 2; #"Bearish OB Average"
ObBearAvg1.SetPaintingStrategy(PaintingStrategy.DASHES);
ObBearAvg1.SetDefaultColor(CreateColor(33,150,243));
ObBearAvg1.SetLineWeight(2);

# Zero Lag Zigzag Plots
plot obStartPlot = obStart;
plot obEndPlot = obEnd;
obStartPlot.SetDefaultColor(Color.CYAN);
obEndPlot.SetDefaultColor(Color.MAGENTA);

# Order Block Filtered by Zero Lag Zigzag
plot filteredObStart = if isObStart then obStart else Double.NaN;
plot filteredObEnd = if isObEnd then obEnd else Double.NaN;
filteredObStart.SetDefaultColor(Color.GREEN);
filteredObEnd.SetDefaultColor(Color.RED);

# Bullish Order Block Channels
def BullHLine = if ShowCloud and filteredObStart == filteredObStart[1] then filteredObStart else Double.NaN;
def BullLLine = if ShowCloud and filteredObEnd == filteredObEnd[1] then filteredObEnd else Double.NaN;
def BullALine = ObBullAvg1;
AddCloud(BullHLine, BullALine, Color.Light_Green);
AddCloud(BullLLine, BullALine, Color.PINK);

# Bearish Order Block Channels
def BearHLine = if ShowCloud and filteredObEnd == filteredObEnd[1] then filteredObEnd else Double.NaN;
def BearLLine = if ShowCloud and filteredObStart == filteredObStart[1] then filteredObStart else Double.NaN;
def BearALine = ObBearAvg1;
AddCloud(BearLLine, BearALine, Color.PINK);
AddCloud(BearHLine, BearALine, Color.Light_Green);
 
Last edited:

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

The suitability of detecting large orders immediately depends on the specific time frame and trading style you are using. However, in general, shorter time frames such as intraday charts (e.g., 1-minute, 5-minute) are more suitable for detecting orders in real-time or near real-time.

When using shorter time frames, the script will analyze volume differences between consecutive bars, allowing for more immediate detection of large orders. However, it's important to note that the script's effectiveness may vary based on market liquidity, volatility, and the specific stocks or securities you are trading.

For longer time frames (e.g., daily, weekly), the script may still detect large orders, but it may not provide immediate or intraday insights since it relies on the comparison of volume differences between bars. It has many customizable features in the options menu.

Ultimately, the suitability of the script for detecting orders immediately depends on your trading preferences, time frame, and the specific requirements of your trading strategy. You may need to experiment with different time frames and adjust the script parameters to align with your trading goals.

The Market Structure indicator combines the Order Block concept with the Zero Lag Zigzag indicator. Let's go through the different color-coded prices and their interpretations:

  1. Bullish Order Blocks:
    • ObBull1 (White Values Below): This plots the low of a bullish order block. It represents a potential support level where buyers have shown strength, pushing the price higher.
    • bull1 (White Dashes): This plots the high of a bullish order block. It represents a potential resistance level where sellers may enter the market and push the price lower.
    • bull2 (White Values): This plots the low of a bullish order block. It complements the bullish order block's high (bull1) and indicates a support level.
    • ObBullAvg1 (White Dashes): This plots the average price (midpoint) of a bullish order block. It can serve as a reference point for evaluating the overall strength or weakness of the bullish order block.
  2. Bearish Order Blocks:
    • ObBear1 (Values Above): This plots the high of a bearish order block. It represents a potential resistance level where sellers have shown strength, pushing the price lower.
    • bear1 (Dashes): This plots the low of a bearish order block. It represents a potential support level where buyers may enter the market and push the price higher.
    • bear2 (Values): This plots the high of a bearish order block. It complements the bearish order block's low (bear1) and indicates a resistance level.
    • ObBearAvg1 (Dashes): This plots the average price (midpoint) of a bearish order block. It can serve as a reference point for evaluating the overall strength or weakness of the bearish order block.
  3. Zero Lag Zigzag:
    • obStartPlot (Cyan): This plots the start points of the identified order blocks based on the Zero Lag Zigzag indicator. It indicates potential turning points where price shifts from a downtrend to an uptrend.
    • obEndPlot (Magenta): This plots the end points of the identified order blocks based on the Zero Lag Zigzag indicator. It indicates potential turning points where price shifts from an uptrend to a downtrend.
Additionally, the indicator provides channels for the order blocks, indicated by the clouds:

  • Bullish Order Block Channel: It is shown as a light green cloud and represents the range between the start and end points of the bullish order block.
  • Bearish Order Block Channel: It is shown as a pink cloud and represents the range between the start and end points of the bearish order block.
These color-coded prices and channels help visualize the identified order blocks, their potential support and resistance levels, and the transition points in price trends.












Ruby:
#converted by Trader4TOS
# Order Block Indicator with Zero Lag Zigzag
declare lower;

input ShowCloud = yes;
input periods = 5; # "Relevant Periods to identify OB"
input threshold = 0.0; # "Min. Percent move to identify OB"
input useWicks = no; # "Use whole range [High/Low] for OB marking?" )
input showBullChannel = yes; # "Show latest Bullish Channel?"
input showBearChannel = yes; # "Show latest Bearish Channel?"

# Zero Lag Zigzag for structure
def highBar = high > high[1];
def lowBar = low < low[1];
def highZigzag = if highBar and !highBar[1] then high else if highBar and highBar[1] then Max(highZigzag[1], high) else Double.NaN;
def lowZigzag = if lowBar and !lowBar[1] then low else if lowBar and lowBar[1] then Min(lowZigzag[1], low) else Double.NaN;
def zigzag = if !IsNaN(highZigzag) then highZigzag else lowZigzag;
def isPeak = !IsNaN(highZigzag);
def isTrough = !IsNaN(lowZigzag);

# Calculate order blocks
def obStart = if isPeak and !isPeak[1] then highZigzag else Double.NaN;
def obEnd = if isTrough and !isTrough[1] then lowZigzag else Double.NaN;

# Order block filter
def highValue = high;
def lowValue = low;
def blockThreshold = threshold * (highValue - lowValue);
def isObStart = highValue - lowValue > blockThreshold;
def isObEnd = lowValue - highValue < -blockThreshold;

# Declare variables
def na = Double.NaN;
def ob_period = periods + 1;
def absmove = ((AbsValue(close[ob_period] - close[1])) / close[ob_period]) * 100;
def relmove = absmove >= threshold;
def bullishOB = close[ob_period] < open[ob_period];
def upcandles = Sum(close > open, periods + 1);
def OB_bull = bullishOB and upcandles == periods and relmove;
def OB_bull_high = if OB_bull then if useWicks then high[ob_period] else open[ob_period] else na;
def OB_bull_low = if OB_bull then low[ob_period] else na;
def OB_bull_avg = (OB_bull_high + OB_bull_low) / 2;
def bearishOB = close[ob_period] > open[ob_period];
def downcandles = Sum(close < open, periods + 1);
def OB_bear = bearishOB and downcandles == periods and relmove;
def OB_bear_high = if OB_bear then high[ob_period] else na;
def OB_bear_low = if OB_bear then if useWicks then low[ob_period] else open[ob_period] else na;
def OB_bear_avg = (OB_bear_low + OB_bear_high) / 2;

# Plotting
plot ObBull1 = if OB_bull then low else Double.NaN; #"Bullish OB"
ObBull1.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
ObBull1.SetDefaultColor(Color.WHITE);
ObBull1.SetLineWeight(2);

plot bull1 = if OB_bull_high then if useWicks then high else open else na;
bull1.SetPaintingStrategy(PaintingStrategy.DASHES);
bull1.SetDefaultColor(Color.WHITE);
bull1.SetLineWeight(2);

plot bull2 = if OB_bull_low then low else Double.NaN; #"Bullish OB Low"
bull2.SetPaintingStrategy(PaintingStrategy.DASHES);
bull2.SetDefaultColor(Color.WHITE);
bull2.SetLineWeight(2);

plot ObBullAvg1 = (bull1 + bull2) / 2; #"Bullish OB Average"
ObBullAvg1.SetPaintingStrategy(PaintingStrategy.DASHES);
ObBullAvg1.SetDefaultColor(Color.WHITE);
ObBullAvg1.SetLineWeight(2);

plot ObBear1 = if OB_bear then high else Double.NaN; # "Bearish OB"
ObBear1.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
ObBear1.SetDefaultColor(CreateColor(33,150,243));
ObBear1.SetLineWeight(2);

plot bear1 = if OB_bear_low then if useWicks then low else open else na;
bear1.SetPaintingStrategy(PaintingStrategy.DASHES);
bear1.SetDefaultColor(CreateColor(33,150,243));
bear1.SetLineWeight(2);

plot bear2 = if OB_bear_high then high else Double.NaN; # "Bearish OB High"
bear2.SetPaintingStrategy(PaintingStrategy.DASHES);
bear2.SetDefaultColor(CreateColor(33,150,243));
bear2.SetLineWeight(2);

plot ObBearAvg1 = (bear1 + bear2) / 2; #"Bearish OB Average"
ObBearAvg1.SetPaintingStrategy(PaintingStrategy.DASHES);
ObBearAvg1.SetDefaultColor(CreateColor(33,150,243));
ObBearAvg1.SetLineWeight(2);

# Zero Lag Zigzag Plots
plot obStartPlot = obStart;
plot obEndPlot = obEnd;
obStartPlot.SetDefaultColor(Color.CYAN);
obEndPlot.SetDefaultColor(Color.MAGENTA);

# Order Block Filtered by Zero Lag Zigzag
plot filteredObStart = if isObStart then obStart else Double.NaN;
plot filteredObEnd = if isObEnd then obEnd else Double.NaN;
filteredObStart.SetDefaultColor(Color.GREEN);
filteredObEnd.SetDefaultColor(Color.RED);

# Bullish Order Block Channels
def BullHLine = if ShowCloud and filteredObStart == filteredObStart[1] then filteredObStart else Double.NaN;
def BullLLine = if ShowCloud and filteredObEnd == filteredObEnd[1] then filteredObEnd else Double.NaN;
def BullALine = ObBullAvg1;
AddCloud(BullHLine, BullALine, Color.Light_Green);
AddCloud(BullLLine, BullALine, Color.PINK);

# Bearish Order Block Channels
def BearHLine = if ShowCloud and filteredObEnd == filteredObEnd[1] then filteredObEnd else Double.NaN;
def BearLLine = if ShowCloud and filteredObStart == filteredObStart[1] then filteredObStart else Double.NaN;
def BearALine = ObBearAvg1;
AddCloud(BearLLine, BearALine, Color.PINK);
AddCloud(BearHLine, BearALine, Color.Light_Green);
Hmmm tried this script on my 5m, not showing much. Could you post a shared chart link to your 5m chart with the script in action. Maybe i've done something wrong.

How to create a shared chart link:
https://usethinkscript.com/threads/how-to-share-a-chart-in-thinkorswim.14221/
 
Last edited by a moderator:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
346 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