Mega Moving Average For ThinkOrSwim

Mega Moving Average version 1.3(Updated!)📈📉📈📉📈

The divergence feature is now updated and working on the hourly chart as intended. Also, two new additional features added! Remember to not solely rely on an indicator or indicators and do your own " due diligence" before making trading decisions. Stay informed with a news feed and other resources, study the charts, and draw your supply and demand levels. in other words. Check below for a detailed summary of the 1.3 version. 👇 Stay informed! Hope you enjoy and happy trading! 💯



#Mega Moving Average version 1.3 update created by Trader4TOS 06-28-2023

#"Mega Moving Average version 1.3," has the following new features and updates:

#Multiple Moving Averages: It combines different types of moving averages such as DEMA, TEMA, SMA, and additional custom lengths into one indicator.(version1.2)

#Combined Moving Average: The indicator calculates the average value of all the moving averages to create a single combined moving average line.(version1.2)

#On Balance Volume (OBV): The indicator incorporates the calculation of OBV, which tracks the cumulative volume based on changes in closing price. It helps identify buying and selling pressure.

#Color Change Condition: The indicator includes a color change condition based on volume exceeding a certain threshold compared to its average volume.(version1.2)

#Color-Coded Indicator: The combined moving average is plotted as a line with different colors based on the color change condition and the relationship between the closing price and the combined moving average.(version1.2)

#Trending Market Condition: Updated!(version 1.3)Using the ATR. Determines if the market is in a trending state based on the Average True Range (ATR) value. A threshold of 0.01 is used, but you can adjust it according to your preference.

#Price and OBV Divergence: The indicator detects bullish and bearish divergences between price and OBV, highlighting potential reversal signals.(version1.2)

#Tracking Highest High and Lowest Low: Keeps track of the highest high and lowest low values over time.(version1.2)
#Price Range: Calculates the price range by subtracting the lowest low from the highest high.(version1.2)


#Divergence Alerts:updated! (version1.3) Improved accuracy and will only display on the hourly charts and further. The plot was changed a abandonedBaby small dot above, below is indicator the middle of the candle.

#Bullish Divergence Alert: Plots a dot at the low price when a bullish divergence occurs, and the market is trending, the current high is the highest high, and the price range is greater than 4.
#Bearish Divergence Alert: Plots a dot at the high price when a bearish divergence occurs, and the market is trending, the current low is the lowest low, and the price range is greater than 4.

# New Features of versions 1.3
#The Trend Continuation feature in the provided script helps identify potential continuation of an ongoing trend in the market. It focuses on three specific instruments: ES, NQ, and YM. Here's how it works:

#Enable/Disable: The script provides the option to enable or disable the Trend Continuation feature for each instrument. You can choose which instruments you want to consider for trend continuation analysis.

#Higher High and Lower Low: The script compares the current closing price of each instrument (ES, NQ, YM) with the previous high and low prices, respectively.

#Higher High: If the current closing price is higher than the previous high, it indicates that the instrument is potentially continuing an upward trend.
#Lower Low: If the current closing price is lower than the previous low, it indicates that the instrument is potentially continuing a downward trend.
#Trend Continuation Criteria: The script evaluates the higher high and lower low conditions for each instrument separately.

#ES Trend Continuation: Determines if there is a higher high or lower low in the ES instrument, based on the enableTrendContinuation and enableESTrend settings.
#NQ Trend Continuation: Determines if there is a higher high or lower low in the NQ instrument, based on the enableTrendContinuation and enableNQTrend settings.
#YM Trend Continuation: Determines if there is a higher high or lower low in the YM instrument, based on the enableTrendContinuation and enableYMTrend settings.
#Label Display: The script adds a label on the chart, labeled as "TC" (Trend Continuation). The label appears in yellow color if all the enabled instruments (ES, NQ, YM) meet the trend continuation criteria (i.e., at least one instrument has a higher high or lower low), indicating potential trend continuation. If any of the enabled instruments do not meet the trend continuation criteria, the label appears in gray color.

#The Trend Continuation feature helps you visually identify whether the current price action in the specified instruments suggests a continuation of the existing trend. It can be a useful tool to assist in trend-following strategies or to confirm the persistence of a trend before making trading decisions.

#The Trend Continuation feature in the provided script helps identify potential continuation of an ongoing trend in the market. It focuses on three specific instruments: /ES, /NQ, and /YM futures. Here's how it works:

#Enable/Disable: The script provides the option to enable or disable the Trend Continuation feature for each instrument. You can choose which instruments you want to consider for trend continuation analysis.

#Higher High and Lower Low: The script compares the current closing price of each instrument (ES, NQ, YM) with the previous high and low prices, respectively.

#Higher High: If the current closing price is higher than the previous high, it indicates that the instrument is potentially continuing an upward trend.
#Lower Low: If the current closing price is lower than the previous low, it indicates that the instrument is potentially continuing a downward trend.
#Trend Continuation Criteria: The script evaluates the higher high and lower low conditions for each instrument separately.

#ES Trend Continuation: Determines if there is a higher high or lower low in the ES instrument, based on the enableTrendContinuation and enableESTrend settings.
#NQ Trend Continuation: Determines if there is a higher high or lower low in the NQ instrument, based on the enableTrendContinuation and enableNQTrend settings.
#YM Trend Continuation: Determines if there is a higher high or lower low in the YM instrument, based on the enableTrendContinuation and enableYMTrend settings.
#Label Display: The script adds a label on the chart, labeled as "TC" (Trend Continuation). The label appears in yellow color if all the enabled instruments (ES, NQ, YM) meet the trend continuation criteria (i.e., at least one instrument has a higher high or lower low), indicating potential trend continuation. If any of the enabled instruments do not meet the trend continuation criteria, the label appears in gray color.

#The Trend Continuation feature helps you visually identify whether the current price action in the specified instruments suggests a continuation of the existing trend. It can be a useful tool to assist in trend-following strategies or to confirm the persistence of a trend before making trading decisions.

#New Feature of version 1.3
#Squeeze Levels & Activation
# It is highly recommended to use multiple charts to benefit from this feature. As you can see when all the charts (5minute,15min,30min,1hour and Daily) are synchronized (best when all charts are in sycn at level 10) and find entries for scalp on the lower time frames and swings for the higher time frames.
#Squeeze Activation: When a squeeze fires, meaning a transition from a non-squeezed state to a squeezed state(from 1 to 10 is the transition phase), the script displays the label "SqzActive" in yellow. This visually alerts you to the occurrence of a squeeze, which is often considered a potential signal for a significant price move. It can help you identify periods of increased volatility and potential trading opportunities.

#Squeeze Level: The script also displays the "SqzLevel" label, which indicates the level of squeeze. The level is represented by the value of sumSqueeze, which is the sum of squeeze values over the last 10 bars. The label shows the squeeze level in gray or orange, depending on whether there is an ongoing squeeze or not. This information helps you gauge the intensity or strength of the squeeze. Higher squeeze levels may suggest stronger potential price moves.

#By providing visual cues for squeeze activations and displaying the squeeze level, this script can help you identify potential trading opportunities during periods of increased volatility and price momentum. It enhances your ability to spot and track squeeze conditions, which are often associated with potential breakouts or significant market moves. 0.


Ruby:
# DEMA
input demaLength = 9;
def demaValue = DEMA(close, demaLength);

# TEMA
input temaLength = 21;
def temaValue = TEMA(close, temaLength);

# SMA
input smaLength = 50;
def smaValue = SimpleMovingAvg(close, smaLength);

# Additional lengths
input maLength1 = 100;
def maValue1 = SimpleMovingAvg(close, maLength1);

input maLength2 = 200;
def maValue2 = SimpleMovingAvg(close, maLength2);

input maLength3 = 300;
def maValue3 = SimpleMovingAvg(close, maLength3);

# Combine moving averages into one
def combinedMA = (demaValue + temaValue + smaValue + maValue1 + maValue2 + maValue3) / 6;

# On Balance Volume (OBV)
def obv = if close > close[1] then obv[1] + volume
else if close < close[1] then obv[1] - volume
else obv[1];

# Calculate price and OBV divergences
def bullishDivergence = low > low[1] and obv < obv[1];
def bearishDivergence = high < high[1] and obv > obv[1];

# Color change condition
def colorChangeCondition = volume >= average(volume, 20) * 2.0;

# Trending market condition
def atrLength = 14;
def atr = MovingAverage(AverageType.WILDERS, TrueRange(high, close, low), atrLength);

def trendingMarket = atr > 0.01; # Adjust the threshold according to your preference

# Track highest high and lowest low
def highestHigh = if high > high[1] then high else highestHigh[1];
def lowestLow = if low < low[1] then low else lowestLow[1];

# Calculate the price range
def priceRange = highestHigh - lowestLow;

# Plot the combined moving average
plot Indicator = combinedMA;
Indicator.SetDefaultColor(Color.GRAY);
Indicator.SetPaintingStrategy(PaintingStrategy.LINE);
Indicator.SetLineWeight(2); # Set the weight to 2
Indicator.AssignValueColor(
if colorChangeCondition then Color.CYAN
else if close < combinedMA then Color.DARK_RED
else Color.DARK_GREEN
);

# Divergence Alerts
def bullishDivergenceAlert = if bullishDivergence and trendingMarket and high == highestHigh and priceRange > 4 then low else Double.NaN;
def bearishDivergenceAlert = if bearishDivergence and trendingMarket and low == lowestLow and priceRange > 4 then high else Double.NaN;

# Plot the divergence signals as moving lines
plot BullishDivergenceLine = if bullishDivergenceAlert and trendingMarket and high == highestHigh and priceRange > 4 then low else Double.NaN;
BullishDivergenceLine.SetDefaultColor(Color.DARK_GREEN);
BullishDivergenceLine.SetPaintingStrategy(PaintingStrategy.LINE);
BullishDivergenceLine.SetLineWeight(5);

plot BearishDivergenceLine = if bearishDivergenceAlert and trendingMarket and low == lowestLow and priceRange > 4 then high else Double.NaN;
BearishDivergenceLine.SetDefaultColor(Color.DARK_RED);
BearishDivergenceLine.SetPaintingStrategy(PaintingStrategy.LINE);
BearishDivergenceLine.SetLineWeight(5);

# Trend Continuation Criteria
input enableTrendContinuation = yes;
input enableESTrend = yes;
input enableNQTrend = yes;
input enableYMTrend = yes;

def esHigherHigh = enableTrendContinuation and enableESTrend and close("/ES") > high("/ES")[1];
def esLowerLow = enableTrendContinuation and enableESTrend and close("/ES") < low("/ES")[1];
def esTrendContinuation = esHigherHigh or esLowerLow;

def nqHigherHigh = enableTrendContinuation and enableNQTrend and close("/NQ") > high("/NQ")[1];
def nqLowerLow = enableTrendContinuation and enableNQTrend and close("/NQ") < low("/NQ")[1];
def nqTrendContinuation = nqHigherHigh or nqLowerLow;

def ymHigherHigh = enableTrendContinuation and enableYMTrend and close("/YM") > high("/YM")[1];
def ymLowerLow = enableTrendContinuation and enableYMTrend and close("/YM") < low("/YM")[1];
def ymTrendContinuation = ymHigherHigh or ymLowerLow;

# Add a label for trend continuation
AddLabel(yes, "TC", if esTrendContinuation and nqTrendContinuation and ymTrendContinuation then Color.YELLOW else Color.GRAY);

def squeeze = if TTM_Squeeze().SqueezeAlert == 0 then 1 else 0;
def sumSqueeze = Sum(squeeze, 10);
def squeezeFired = if TTM_Squeeze().SqueezeAlert[1] == 0 and TTM_Squeeze().SqueezeAlert == 1 then 1 else 0;

AddLabel(squeezeFired, "SqzActive", if squeezeFired then color.yellow else color.black);
AddLabel(squeeze, "Level: " + sumSqueeze, if squeeze then color.gray else color.orange);
AddLabel(!squeezeFired and !squeeze, " ", color.black);
Hi and thank you for your hard work on this! Is there anyway to have options to pick a different combinations of the MA's? For example if I just wanted to choose say the TEMA, DEMA and EMA as a Mega Moving Avg's (MMA) and exclude the others or visa versa? Also can this be used for a scan too? Thank you.
 
Last edited:
Hi and thank you for your hard work on this! Is there anyway to have options to pick a different combinations of the MA's? For example if I just wanted to choose say the TEMA, DEMA and EMA as a Mega Moving Avg's (MMA) and exclude the others or visa versa? Also can this be used for a scan too? Thank you.
Thanks. Try this one. 👇


#Mega Moving Average version 1.3 update created by Trader4TOS 06-28-2023

#"Mega Moving Average version 1.3," has the following new features and updates:

#Multiple Moving Averages: It combines different types of moving averages such as DEMA, TEMA, SMA, and additional custom lengths into one indicator.(version1.2)

#Combined Moving Average: The indicator calculates the average value of all the moving averages to create a single combined moving average line.(version1.2)

#On Balance Volume (OBV): The indicator incorporates the calculation of OBV, which tracks the cumulative volume based on changes in closing price. It helps identify buying and selling pressure.

#Color Change Condition: The indicator includes a color change condition based on volume exceeding a certain threshold compared to its average volume.(version1.2)

#Color-Coded Indicator: The combined moving average is plotted as a line with different colors based on the color change condition and the relationship between the closing price and the combined moving average.(version1.2)

#Trending Market Condition: Updated!(version 1.3)Using the ATR. Determines if the market is in a trending state based on the Average True Range (ATR) value. A threshold of 0.01 is used, but you can adjust it according to your preference.

#Price and OBV Divergence: The indicator detects bullish and bearish divergences between price and OBV, highlighting potential reversal signals.(version1.2)

#Tracking Highest High and Lowest Low: Keeps track of the highest high and lowest low values over time.(version1.2)
#Price Range: Calculates the price range by subtracting the lowest low from the highest high.(version1.2)


#Divergence Alerts:updated! (version1.3) Improved accuracy and will only display on the hourly charts and further. The plot was changed a abandonedBaby small dot above, below is indicator the middle of the candle.

#Bullish Divergence Alert: Plots a dot at the low price when a bullish divergence occurs, and the market is trending, the current high is the highest high, and the price range is greater than 4.
#Bearish Divergence Alert: Plots a dot at the high price when a bearish divergence occurs, and the market is trending, the current low is the lowest low, and the price range is greater than 4.

# New Features of versions 1.3
#The Trend Continuation feature in the provided script helps identify potential continuation of an ongoing trend in the market. It focuses on three specific instruments: ES, NQ, and YM. Here's how it works:

#Enable/Disable: The script provides the option to enable or disable the Trend Continuation feature for each instrument. You can choose which instruments you want to consider for trend continuation analysis.

#Higher High and Lower Low: The script compares the current closing price of each instrument (ES, NQ, YM) with the previous high and low prices, respectively.

#Higher High: If the current closing price is higher than the previous high, it indicates that the instrument is potentially continuing an upward trend.
#Lower Low: If the current closing price is lower than the previous low, it indicates that the instrument is potentially continuing a downward trend.
#Trend Continuation Criteria: The script evaluates the higher high and lower low conditions for each instrument separately.

#ES Trend Continuation: Determines if there is a higher high or lower low in the ES instrument, based on the enableTrendContinuation and enableESTrend settings.
#NQ Trend Continuation: Determines if there is a higher high or lower low in the NQ instrument, based on the enableTrendContinuation and enableNQTrend settings.
#YM Trend Continuation: Determines if there is a higher high or lower low in the YM instrument, based on the enableTrendContinuation and enableYMTrend settings.
#Label Display: The script adds a label on the chart, labeled as "TC" (Trend Continuation). The label appears in yellow color if all the enabled instruments (ES, NQ, YM) meet the trend continuation criteria (i.e., at least one instrument has a higher high or lower low), indicating potential trend continuation. If any of the enabled instruments do not meet the trend continuation criteria, the label appears in gray color.

#The Trend Continuation feature helps you visually identify whether the current price action in the specified instruments suggests a continuation of the existing trend. It can be a useful tool to assist in trend-following strategies or to confirm the persistence of a trend before making trading decisions.

#The Trend Continuation feature in the provided script helps identify potential continuation of an ongoing trend in the market. It focuses on three specific instruments: /ES, /NQ, and /YM futures. Here's how it works:

#Enable/Disable: The script provides the option to enable or disable the Trend Continuation feature for each instrument. You can choose which instruments you want to consider for trend continuation analysis.

#Higher High and Lower Low: The script compares the current closing price of each instrument (ES, NQ, YM) with the previous high and low prices, respectively.

#Higher High: If the current closing price is higher than the previous high, it indicates that the instrument is potentially continuing an upward trend.
#Lower Low: If the current closing price is lower than the previous low, it indicates that the instrument is potentially continuing a downward trend.
#Trend Continuation Criteria: The script evaluates the higher high and lower low conditions for each instrument separately.

#ES Trend Continuation: Determines if there is a higher high or lower low in the ES instrument, based on the enableTrendContinuation and enableESTrend settings.
#NQ Trend Continuation: Determines if there is a higher high or lower low in the NQ instrument, based on the enableTrendContinuation and enableNQTrend settings.
#YM Trend Continuation: Determines if there is a higher high or lower low in the YM instrument, based on the enableTrendContinuation and enableYMTrend settings.
#Label Display: The script adds a label on the chart, labeled as "TC" (Trend Continuation). The label appears in yellow color if all the enabled instruments (ES, NQ, YM) meet the trend continuation criteria (i.e., at least one instrument has a higher high or lower low), indicating potential trend continuation. If any of the enabled instruments do not meet the trend continuation criteria, the label appears in gray color.

#The Trend Continuation feature helps you visually identify whether the current price action in the specified instruments suggests a continuation of the existing trend. It can be a useful tool to assist in trend-following strategies or to confirm the persistence of a trend before making trading decisions.

#New Feature of version 1.3
#Squeeze Levels & Activation
# It is highly recommended to use multiple charts to benefit from this feature. As you can see when all the charts (5minute,15min,30min,1hour and Daily) are synchronized (best when all charts are in sycn at level 10) and find entries for scalp on the lower time frames and swings for the higher time frames.
#Squeeze Activation: When a squeeze fires, meaning a transition from a non-squeezed state to a squeezed state(from 1 to 10 is the transition phase), the script displays the label "SqzActive" in yellow. This visually alerts you to the occurrence of a squeeze, which is often considered a potential signal for a significant price move. It can help you identify periods of increased volatility and potential trading opportunities.

#Squeeze Level: The script also displays the "SqzLevel" label, which indicates the level of squeeze. The level is represented by the value of sumSqueeze, which is the sum of squeeze values over the last 10 bars. The label shows the squeeze level in gray or orange, depending on whether there is an ongoing squeeze or not. This information helps you gauge the intensity or strength of the squeeze. Higher squeeze levels may suggest stronger potential price moves.

#By providing visual cues for squeeze activations and displaying the squeeze level, this script can help you identify potential trading opportunities during periods of increased volatility and price momentum. It enhances your ability to spot and track squeeze conditions, which are often associated with potential breakouts or significant market moves.
Ruby:
# DEMA
input demaLength = 9;
input enabledemaLength = yes;
def demaValue = DEMA(close, demaLength);

# TEMA
input temaLength = 21;
input enabletemaLength = yes;
def temaValue = TEMA(close, temaLength);

# SMA
input smaLength = 50;
input enablesmaLength = yes;
def smaValue = SimpleMovingAvg(close, smaLength);

# Additional lengths
input maLength1 = 100;
input enablemaLength1 = yes;
def maValue1 = SimpleMovingAvg(close, maLength1);

input maLength2 = 200;
input enablemaLength2 = yes;
def maValue2 = SimpleMovingAvg(close, maLength2);

input maLength3 = 300;
input enablemaLength3 = yes;
def maValue3 = SimpleMovingAvg(close, maLength3);

# Combine moving averages into one
def combinedMA = (demaValue + temaValue + smaValue + maValue1 + maValue2 + maValue3) / 6;
input enablecombineMA = yes;

# On Balance Volume (OBV)
def obv = if close > close[1] then obv[1] + volume
else if close < close[1] then obv[1] - volume
else obv[1];
input enableobv = yes;

# Calculate price and OBV divergences
def bullishDivergence = low > low[1] and obv < obv[1];
def bearishDivergence = high < high[1] and obv > obv[1];

# Color change condition
def colorChangeCondition = volume >= average(volume, 20) * 2.0;

# Trending market condition
def atrLength = 14;
def atr = MovingAverage(AverageType.WILDERS, TrueRange(high, close, low), atrLength);

def trendingMarket = atr > 0.01; # Adjust the threshold according to your preference

# Track highest high and lowest low
def highestHigh = if high > high[1] then high else highestHigh[1];
def lowestLow = if low < low[1] then low else lowestLow[1];

# Calculate the price range
def priceRange = highestHigh - lowestLow;

# Plot the combined moving average
plot Indicator = combinedMA;
Indicator.SetDefaultColor(Color.GRAY);
Indicator.SetPaintingStrategy(PaintingStrategy.LINE);
Indicator.SetLineWeight(2); # Set the weight to 2
Indicator.AssignValueColor(
if colorChangeCondition then Color.CYAN
else if close < combinedMA then Color.DARK_RED
else Color.DARK_GREEN
);

# Divergence Alerts
def bullishDivergenceAlert = if bullishDivergence and trendingMarket and high == highestHigh and priceRange > 4 then low else Double.NaN;
def bearishDivergenceAlert = if bearishDivergence and trendingMarket and low == lowestLow and priceRange > 4 then high else Double.NaN;

# Plot the divergence signals as moving lines
plot BullishDivergenceLine = if bullishDivergenceAlert and trendingMarket and high == highestHigh and priceRange > 4 then low else Double.NaN;
BullishDivergenceLine.SetDefaultColor(Color.DARK_GREEN);
BullishDivergenceLine.SetPaintingStrategy(PaintingStrategy.LINE);
BullishDivergenceLine.SetLineWeight(5);
input enableBullishDivergenceLine = yes;

plot BearishDivergenceLine = if bearishDivergenceAlert and trendingMarket and low == lowestLow and priceRange > 4 then high else Double.NaN;
BearishDivergenceLine.SetDefaultColor(Color.DARK_RED);
BearishDivergenceLine.SetPaintingStrategy(PaintingStrategy.LINE);
BearishDivergenceLine.SetLineWeight(5);
input enableDivergenceLine = yes;


# Trend Continuation Criteria
input enableTrendContinuation = yes;
input enableESTrend = yes;
input enableNQTrend = yes;
input enableYMTrend = yes;

def esHigherHigh = enableTrendContinuation and enableESTrend and close("/ES") > high("/ES")[1];
def esLowerLow = enableTrendContinuation and enableESTrend and close("/ES") < low("/ES")[1];
def esTrendContinuation = esHigherHigh or esLowerLow;

def nqHigherHigh = enableTrendContinuation and enableNQTrend and close("/NQ") > high("/NQ")[1];
def nqLowerLow = enableTrendContinuation and enableNQTrend and close("/NQ") < low("/NQ")[1];
def nqTrendContinuation = nqHigherHigh or nqLowerLow;

def ymHigherHigh = enableTrendContinuation and enableYMTrend and close("/YM") > high("/YM")[1];
def ymLowerLow = enableTrendContinuation and enableYMTrend and close("/YM") < low("/YM")[1];
def ymTrendContinuation = ymHigherHigh or ymLowerLow;

# Add a label for trend continuation
AddLabel(yes, "TC", if esTrendContinuation and nqTrendContinuation and ymTrendContinuation then Color.YELLOW else Color.GRAY);
input enableTClabel = yes;

#Squeeze levels
def squeeze = if TTM_Squeeze().SqueezeAlert == 0 then 1 else 0;
def sumSqueeze = Sum(squeeze, 10);
def squeezeFired = if TTM_Squeeze().SqueezeAlert[1] == 0 and TTM_Squeeze().SqueezeAlert == 1 then 1 else 0;
input enablesqueezelabel = yes;
AddLabel(squeezeFired, "SqzActive", if squeezeFired then color.yellow else color.black);
AddLabel(squeeze, "Level: " + sumSqueeze, if squeeze then color.gray else color.orange);
AddLabel(!squeezeFired and !squeeze, " ", color.black);
 
Last edited:

MEGA MOVING AVERAGE VERSION 1.4. 08/08/23​

Features:​

  1. Auto Multi-Time Frame Candlesticks Analysis: The script automatically adapts to a specific time frame to analyze the single candlestick patterns. This can be useful for traders looking to identify patterns across different time frames.
  2. Wide Range of Patterns: The script is designed to detect several different candlestick patterns, including:
    • Doji
    • Long-Legged Doji
    • Dragonfly Doji
    • Gravestone Doji
    • Four Price Doji
    • Marubozu
    • Bullish Engulfing
    • Bearish Engulfing
    • Hammer
    • Bullish Harami
    • Bearish Harami
  3. Color Coding: Patterns detected are color-coded on the chart to visually indicate bullish or bearish signals. This makes it easier to identify patterns at a glance. The specific candle where the condition is met will be colored dark green or dark red. Very useful when you are viewing multiple timeframe charts at once for comparisons.
  4. Labeling: The script adds a label to the chart, providing a quick visual cue when a pattern is detected. The label will highlight from grey to yellow when the condition is activated and for the duration of it.

Benefits:​

  1. Versatility: By allowing the user to define the time frame, the script offers flexibility and can be adapted to different trading styles and strategies.
  2. Enhanced Decision Making: Candlestick patterns are widely used in technical analysis to predict future price movement. By automating the detection of these patterns, the script can help traders quickly identify potential trading opportunities.
  3. Time-Saving: Manual identification of candlestick patterns can be time-consuming, especially across multiple time frames. This script automates the process, saving time and reducing the possibility of human error.
  4. Customization: The script is written in ThinkScript, allowing users with coding knowledge to further customize or expand its functionality according to their specific needs and preferences.
  5. Can be used on the Daily as a moving average support level. The MMA is very effective at this as I've observed.

Limitations:​

While the script provides useful functionalities, it's essential to understand that no tool can guarantee success in trading. Candlestick patterns should be used in conjunction with other technical and fundamental analyses to make informed trading decisions. Additionally, the script may need to be tailored to fit specific market conditions, trading instruments, or individual trading styles.

Conclusion:​

The "Multiframe Candlestick Pattern Alert " script is a valuable tool for traders interested in automating the detection of various candlestick patterns across different time frames. By offering a range of features, including multi-time frame analysis, detection of various patterns, color coding, and labeling, it can enhance decision-making and streamline the trading process. However, like all trading tools, it should be used with caution and in conjunction with other analysis methods (ex: RSI Levels).

Divergence Detection
Updated! (08/19/23)

Made improvements to the divergence detection and now working well on the hourly chart.











# Mega Moving Average created by Trader4TOS

#Version 1.4 updates 08/08/23.
#Multiframe Candlesick Pattern Alert (Version 1.4)
#Designed for automating the detection of various candlestick patterns on different time frames and color coded.
##################################################################################################
#"Version 1.3," has the following new features and updates:
#Squeeze Levels & Activation
# It is highly recommended to use multiple charts to benefit from this feature. As you can see when all the charts (5minute,15min,30min,1hour and Daily) are synchronized (best when all charts are in sycn at level 10) and find entries for scalp on the lower time frames and swings for the higher time frames.
#Squeeze Activation: When a squeeze fires, meaning a transition from a non-squeezed state to a squeezed state(from 1 to 10 is the transition phase), the script displays the label "SqzActive" in yellow. This visually alerts you to the occurrence of a squeeze, which is often considered a potential signal for a significant price move. It can help you identify periods of increased volatility and potential trading opportunities.

#Squeeze Level: The script also displays the "SqzLevel" label, which indicates the level of squeeze. The level is represented by the value of sumSqueeze, which is the sum of squeeze values over the last 10 bars. The label shows the squeeze level in gray or orange, depending on whether there is an ongoing squeeze or not. This information helps you gauge the intensity or strength of the squeeze. Higher squeeze levels may suggest stronger potential price moves.

#By providing visual cues for squeeze activations and displaying the squeeze level, this script can help you identify potential trading opportunities during periods of increased volatility and price momentum. It enhances your ability to spot and track squeeze conditions, which are often associated with potential breakouts or significant market moves.
##############################################################################################
#Multiple Moving Averages: It combines different types of moving averages such as DEMA, TEMA, SMA, and additional custom lengths into one indicator.(version1.2)

#Combined Moving Average: The indicator calculates the average value of all the moving averages to create a single combined moving average line.(version1.2)

#On Balance Volume (OBV): The indicator incorporates the calculation of OBV, which tracks the cumulative volume based on changes in closing price. It helps identify buying and selling pressure.

#Color Change Condition: The indicator includes a color change condition based on volume exceeding a certain threshold compared to its average volume.(version1.2)

#Color-Coded Indicator: The combined moving average is plotted as a line with different colors based on the color change condition and the relationship between the closing price and the combined moving average.(version1.2)

#Trending Market Condition: Updated!(version 1.3)Using the ATR. Determines if the market is in a trending state based on the Average True Range (ATR) value. A threshold of 0.01 is used, but you can adjust it according to your preference.

#Price and OBV Divergence: The indicator detects bullish and bearish divergences between price and OBV, highlighting potential reversal signals.(version1.2)

#Tracking Highest High and Lowest Low: Keeps track of the highest high and lowest low values over time.(version1.2)
#Price Range: Calculates the price range by subtracting the lowest low from the highest high.(version1.2)


#Divergence Alerts: Updated 08/19/23! (version1.4) Refinement of Divergence Conditions:
#Original: Divergences were simply based on the momentum of price.
#Improved: Divergence conditions were tied to RSI levels. Specifically, bullish divergences are only recognized when RSI is oversold (<30), and bearish divergences are recognized when RSI is overbought (>70). This refinement can help filter out less significant divergence signals and keep only those that align with an oversold/overbought market condition.

#RSI Calculations:

#The script calculates two RSIs (Relative Strength Index):
#A standard 14-period RSI (rsiValue).
#A longer-term 50-period RSI (longTermRsiValue), though this isn't utilized further in this specific version of the script.
#Price Definitions:

#price_Range: Computes the difference between the high and low of the current period.
#highest_High: Identifies the highest price over the last 14 periods.
#lowest_Low: Identifies the lowest price over the past 14 periods.
#Momentum Oscillator:

#momentum: Calculates the difference between the current close and the close 14 periods ago. This is used to identify divergences.
#RSI Overbought/Oversold Conditions:

#oversold: Determines when the 14-period RSI is below 30.
#overbought: Determines when the 14-period RSI is above 70.
#Bullish Divergence Detection:

#The script detects a bullish divergence (bullishDivergence) when:
#The market is in an oversold condition (RSI < 30).
#The price makes a new low compared to the previous period.
#The momentum oscillator is showing a higher value than its previous value.
#Bearish Divergence Detection:

#The script detects a bearish divergence (bearishDivergence) when:
#The market is in an overbought condition (RSI > 70).
#The price makes a new high compared to the previous period.
#The momentum oscillator is showing a lower value than its previous value.
#Timeframe Restriction:

#isOneHour: This feature ensures that the divergence indicators are only displayed when viewing a 1-hour chart, irrespective of the timeframe the script is applied to.
#Plotting of Divergences:

#BullishDivergenceLine: A line plotted at the low of the period where a bullish divergence is detected. This line is colored in LIGHT_GREEN, has a line as its painting strategy, and a line weight of 5 for visibility.
#BearishDivergenceLine: A line plotted at the high of the period where a bearish divergence is detected. This line is colored in LIGHT_RED, also uses a line as its painting strategy, and has a line weight of 5.

# New Features of versions 1.3
#The Trend Continuation feature in the provided script helps identify potential continuation of an ongoing trend in the market. It focuses on three specific instruments: ES, NQ, and YM. Here's how it works:

#Enable/Disable: The script provides the option to enable or disable the Trend Continuation feature for each instrument. You can choose which instruments you want to consider for trend continuation analysis.

#Higher High and Lower Low: The script compares the current closing price of each instrument (ES, NQ, YM) with the previous high and low prices, respectively.

#Higher High: If the current closing price is higher than the previous high, it indicates that the instrument is potentially continuing an upward trend.
#Lower Low: If the current closing price is lower than the previous low, it indicates that the instrument is potentially continuing a downward trend.
#Trend Continuation Criteria: The script evaluates the higher high and lower low conditions for each instrument separately.

#ES Trend Continuation: Determines if there is a higher high or lower low in the ES instrument, based on the enableTrendContinuation and enableESTrend settings.
#NQ Trend Continuation: Determines if there is a higher high or lower low in the NQ instrument, based on the enableTrendContinuation and enableNQTrend settings.
#YM Trend Continuation: Determines if there is a higher high or lower low in the YM instrument, based on the enableTrendContinuation and enableYMTrend settings.
#Label Display: The script adds a label on the chart, labeled as "TC" (Trend Continuation). The label appears in yellow color if all the enabled instruments (ES, NQ, YM) meet the trend continuation criteria (i.e., at least one instrument has a higher high or lower low), indicating potential trend continuation. If any of the enabled instruments do not meet the trend continuation criteria, the label appears in gray color.

#The Trend Continuation feature helps you visually identify whether the current price action in the specified instruments suggests a continuation of the existing trend. It can be a useful tool to assist in trend-following strategies or to confirm the persistence of a trend before making trading decisions.

#The Trend Continuation feature in the provided script helps identify potential continuation of an ongoing trend in the market. It focuses on three specific instruments: /ES, /NQ, and /YM futures. Here's how it works:

#Enable/Disable: The script provides the option to enable or disable the Trend Continuation feature for each instrument. You can choose which instruments you want to consider for trend continuation analysis.

#Higher High and Lower Low: The script compares the current closing price of each instrument (ES, NQ, YM) with the previous high and low prices, respectively.

#Higher High: If the current closing price is higher than the previous high, it indicates that the instrument is potentially continuing an upward trend.
#Lower Low: If the current closing price is lower than the previous low, it indicates that the instrument is potentially continuing a downward trend.
#Trend Continuation Criteria: The script evaluates the higher high and lower low conditions for each instrument separately.

#ES Trend Continuation: Determines if there is a higher high or lower low in the ES instrument, based on the enableTrendContinuation and enableESTrend settings.
#NQ Trend Continuation: Determines if there is a higher high or lower low in the NQ instrument, based on the enableTrendContinuation and enableNQTrend settings.
#YM Trend Continuation: Determines if there is a higher high or lower low in the YM instrument, based on the enableTrendContinuation and enableYMTrend settings.
#Label Display: The script adds a label on the chart, labeled as "TC" (Trend Continuation). The label appears in yellow color if all the enabled instruments (ES, NQ, YM) meet the trend continuation criteria (i.e., at least one instrument has a higher high or lower low), indicating potential trend continuation. If any of the enabled instruments do not meet the trend continuation criteria, the label appears in gray color.

#The Trend Continuation feature helps you visually identify whether the current price action in the specified instruments suggests a continuation of the existing trend. It can be a useful tool to assist in trend-following strategies or to confirm the persistence of a trend before making trading decisions.












# DEMA
input demaLength = 9;
input enabledemaLength = yes;
def demaValue = DEMA(close, demaLength);

# TEMA
input temaLength = 21;
input enabletemaLength = yes;
def temaValue = TEMA(close, temaLength);

# SMA
input smaLength = 50;
input enablesmaLength = yes;
def smaValue = SimpleMovingAvg(close, smaLength);

# Additional lengths
input maLength1 = 100;
input enablemaLength1 = yes;
def maValue1 = SimpleMovingAvg(close, maLength1);

input maLength2 = 200;
input enablemaLength2 = yes;
def maValue2 = SimpleMovingAvg(close, maLength2);

input maLength3 = 300;
input enablemaLength3 = yes;
def maValue3 = SimpleMovingAvg(close, maLength3);

# Combine moving averages into one
def combinedMA = (demaValue + temaValue + smaValue + maValue1 + maValue2 + maValue3) / 6;
input enablecombineMA = yes;

# On Balance Volume (OBV)
def obv = if close > close[1] then obv[1] + volume
else if close < close[1] then obv[1] - volume
else obv[1];
input enableobv = yes;

# Calculate price and OBV divergences
def bullishDivergence2 = low > low[1] and obv < obv[1];
def bearishDivergence2 = high < high[1] and obv > obv[1];

# Color change condition
def colorChangeCondition = volume >= average(volume, 20) * 2.0;

# Trending market condition
def atrLength = 14;
def atr = MovingAverage(AverageType.WILDERS, TrueRange(high, close, low), atrLength);

def trendingMarket = atr > 0.01; # Adjust the threshold according to your preference

# Track highest high and lowest low
def highestHigh = if high > high[1] then high else highestHigh[1];
def lowestLow = if low < low[1] then low else lowestLow[1];

# Calculate the price range
def priceRange = highestHigh - lowestLow;

# Plot the combined moving average
plot Indicator = combinedMA;
Indicator.SetDefaultColor(Color.GRAY);
Indicator.SetPaintingStrategy(PaintingStrategy.LINE);
Indicator.SetLineWeight(2); # Set the weight to 2
Indicator.AssignValueColor(
if colorChangeCondition then Color.CYAN
else if close < combinedMA then Color.DARK_RED
else Color.DARK_GREEN
);

# Divergence Detection with Refined Conditions

# Define RSIs
def rsiValue = RSI("length" = 14);
def longTermRsiValue = RSI("length" = 50);

# Definitions
def price_Range = high - low;
def highest_High = Highest(high, 14); # Using a 14-period for the highest high
def lowest_Low = Lowest(low, 14); # Using a 14-period for the lowest low

# Simple momentum oscillator to help identify divergences
def momentum = close - close[14];

# Condition 2: Oversold/Overbought conditions
def oversold = rsiValue < 30;
def overbought = rsiValue > 70;

# Bullish Divergence: When prices are making a new low but momentum isn't
def bullishDivergence = oversold and low < lowestLow[1] and momentum > momentum[1];

# Bearish Divergence: When prices are making a new high but momentum isn't
def bearishDivergence = overbought and high > highestHigh[1] and momentum < momentum[1];

# Only display on the 1-hour chart
def isOneHour = GetAggregationPeriod() == AggregationPeriod.HOUR;

# Plot the divergence signals as moving lines
plot BullishDivergenceLine = if isOneHour and bullishDivergence then low else Double.NaN;
BullishDivergenceLine.SetDefaultColor(Color.LIGHT_GREEN);
BullishDivergenceLine.SetPaintingStrategy(PaintingStrategy.LINE);
BullishDivergenceLine.SetLineWeight(5);

plot BearishDivergenceLine = if isOneHour and bearishDivergence then high else Double.NaN;
BearishDivergenceLine.SetDefaultColor(Color.LIGHT_RED);
BearishDivergenceLine.SetPaintingStrategy(PaintingStrategy.LINE);
BearishDivergenceLine.SetLineWeight(5);


# Trend Continuation Criteria
input enableTrendContinuation = yes;
input enableESTrend = yes;
input enableNQTrend = yes;
input enableYMTrend = yes;

def esHigherHigh = enableTrendContinuation and enableESTrend and close("/ES") > high("/ES")[1];
def esLowerLow = enableTrendContinuation and enableESTrend and close("/ES") < low("/ES")[1];
def esTrendContinuation = esHigherHigh or esLowerLow;

def nqHigherHigh = enableTrendContinuation and enableNQTrend and close("/NQ") > high("/NQ")[1];
def nqLowerLow = enableTrendContinuation and enableNQTrend and close("/NQ") < low("/NQ")[1];
def nqTrendContinuation = nqHigherHigh or nqLowerLow;

def ymHigherHigh = enableTrendContinuation and enableYMTrend and close("/YM") > high("/YM")[1];
def ymLowerLow = enableTrendContinuation and enableYMTrend and close("/YM") < low("/YM")[1];
def ymTrendContinuation = ymHigherHigh or ymLowerLow;

# Add a label for trend continuation
AddLabel(yes, "TC", if esTrendContinuation and nqTrendContinuation and ymTrendContinuation then Color.YELLOW else Color.GRAY);
input enableTClabel = yes;

#Squeeze levels
def squeeze = if TTM_Squeeze().SqueezeAlert == 0 then 1 else 0;
def sumSqueeze = Sum(squeeze, 10);
def squeezeFired = if TTM_Squeeze().SqueezeAlert[1] == 0 and TTM_Squeeze().SqueezeAlert == 1 then 1 else 0;
input enablesqueezelabel = yes;
AddLabel(squeezeFired, "SqzActive", if squeezeFired then color.yellow else color.black);
AddLabel(squeeze, "Level: " + sumSqueeze, if squeeze then color.gray else color.orange);
AddLabel(!squeezeFired and !squeeze, " ", color.black);

##############################################################################################

#Multiframe Candlesick Pattern Alert Version 1.4

# Automatically detect the chart's time frame
def timeFrame = GetAggregationPeriod();
input enablepatternDetected = yes;

# Candlestick Pattern Definitions
def Doji = AbsValue(close(period = timeFrame) - open(period = timeFrame)) <= ((high(period = timeFrame) - low(period = timeFrame)) * 0.1);
def LongLeggedDoji = high(period = timeFrame) - low(period = timeFrame) > 3 * (open(period = timeFrame) - close(period = timeFrame)) and close(period = timeFrame) >= (open(period = timeFrame) + close(period = timeFrame))/2 - ((high(period = timeFrame) - low(period = timeFrame)) * 0.1) and close(period = timeFrame) <= (open(period = timeFrame) + close(period = timeFrame))/2 + ((high(period = timeFrame) - low(period = timeFrame)) * 0.1);
def DragonflyDoji = high(period = timeFrame) == close(period = timeFrame) and low(period = timeFrame) == open(period = timeFrame);
def GravestoneDoji = low(period = timeFrame) == close(period = timeFrame) and high(period = timeFrame) == open(period = timeFrame);
def FourPriceDoji = open(period = timeFrame) == high(period = timeFrame) and open(period = timeFrame) == low(period = timeFrame) and open(period = timeFrame) == close(period = timeFrame);
def Marubozu = AbsValue(close(period = timeFrame) - open(period = timeFrame)) >= 0.95 * (high(period = timeFrame) - low(period = timeFrame));
def BullishEngulfing = close[1] < open[1] and open < close and close > high[1] and open < low[1];
def BearishEngulfing = close[1] > open[1] and open > close and open > high[1] and close < low[1];
def Hammer = high(period = timeFrame) - Max(open(period = timeFrame), close(period = timeFrame)) <= (2 * (close(period = timeFrame) - low(period = timeFrame))) and AbsValue(open(period = timeFrame) - close(period = timeFrame)) / (high(period = timeFrame) - low(period = timeFrame)) <= 0.1;
def BullishHarami = close[1] < open[1] and open < close and open > close[1] and close < open[1];
def BearishHarami = close[1] > open[1] and open > close and open < close[1] and close > open[1];

# Pattern Detection
def patternDetected = Doji or LongLeggedDoji or DragonflyDoji or GravestoneDoji or FourPriceDoji or Marubozu or BullishEngulfing or BearishEngulfing or Hammer or BullishHarami or BearishHarami;

# Assign Color
AssignPriceColor(if patternDetected then if close > open then CreateColor(0, 128, 0) else CreateColor(128, 0, 0) else Color.CURRENT);

# Label
AddLabel(yes, if patternDetected then "📊️" else "📊️", if patternDetected then Color.YELLOW else Color.GRAY);
################################################################################################
 
Last edited:

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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