Mega Moving Average For ThinkOrSwim

08-08-23 Updated Version 1.4
https://usethinkscript.com/threads/mega-moving-average-for-thinkorswim.15858/post-129691

Combining major moving averages into a single indicator can be a useful approach to gain a holistic view of the market's trend and potential support/resistance levels. However, it's essential to consider other factors, such as price action, volume, and market context, to make well-informed trading decisions. So I created a moving average that combines the 9,21,50,100,200 and 300 exponential moving averages into one indicator reflected on the chart. It uses the EMA's to provide you with a comprehensive view of the overall trend and potential support/resistance levels in the price action. This can be useful for identifying trend reversals, determining entry/exit points, and understanding the overall strength of the market. Furthermore,
here are a few points to consider when using the Mega Moving Average indicator:
  1. Selecting relevant moving averages: Choose moving averages that align with your trading strategy and the timeframe you are focusing on. Common choices include the 50-day, 100-day, and 200-day moving averages, which are widely followed by traders and investors.
  2. Customizing parameters: Adjust the parameters of the moving averages (e.g., length, type) to suit your analysis. Different combinations may yield different results, so it's essential to experiment and find the settings that work best for your trading style.
  3. Consider the context: It's crucial to interpret the moving average crossovers and interactions within the context of the overall market conditions. For example, a bullish crossover may carry more weight in an up-trending market, while a bearish crossover may be more significant during a downtrend.
  4. Use additional confirmation: While moving averages can provide valuable insights, it's often beneficial to use them in conjunction with other technical indicators or chart patterns to strengthen your analysis and reduce false signals.

In addition to combining all the major moving averages. I also added a volume surge/spike detection feature and all these are adjustable within the options menu.

Ultimately, Due diligence must be applied and one should not solely depend on indicators to make trading decisions. Only to give guidance and support your technical findings and or confirm in the midst of speculations.

Hope someone finds it as useful as it has been to my trading.

Ruby:
# created by Trader4TOS


# 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;

# Volume surge/spike detection
input volumeThreshold = 2.0; # Adjust the threshold according to your preference
def averageVolume = VolumeAvg(length = 20);
def volumeSurge = volume >= averageVolume * volumeThreshold;

# Color change condition
def colorChangeCondition = volumeSurge;

# Plot the combined moving average with color change
plot Indicator = combinedMA;
Indicator.SetDefaultColor(GetColor(1));
Indicator.SetPaintingStrategy(PaintingStrategy.LINE);
Indicator.AssignValueColor(if colorChangeCondition then Color.BLACK else Color.Light_GREEN);
 
Last edited:

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

Here is a beta release of the Mega Moving Average version 1.2. In this update, I have added the On Balance Volume indicator to alert divergence signals in the form of a text bubble with the letter "D" and color-coded. This should give you a heads-up before a change of trend occurs. in addition, I color-coded the Mega MA to change color from dark green to dark red depending on if the price breaks above or below the Mega MA. It will also change to a Cyan color to signal a volume spike/surge more accurately. Remember that this is a beta release and you might see some false signals with the divergence feature. Please feel free to provide feedback on all errors, issues, or suggestions. Enjoy and happy trading!







#Mega Moving Average version 1.2 update created by Trader4TOS 06-21-2023

#"Mega Moving Average version 1.2," has the following features:

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

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

#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.

#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.

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

#Divergence Bubbles: The indicator plots a color-coded letter "D" to visualize the detected divergences. Green D represent bullish divergences, and red D represents bearish divergences.

#These features provide a comprehensive view of the market by combining moving averages, volume analysis, and divergence signals.

# 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 trendingMarket = AbsValue(combinedMA - combinedMA[1]) > 0.01;

# 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 > 2 then low else Double.NaN;
AddChartBubble(bullishDivergence and trendingMarket and high == highestHigh and priceRange > 2, bullishDivergenceAlert, "D", Color.GREEN, no);

def bearishDivergenceAlert = if bearishDivergence and trendingMarket and low == lowestLow and priceRange > 2 then high else Double.NaN;
AddChartBubble(bearishDivergence and trendingMarket and low == lowestLow and priceRange > 2, bearishDivergenceAlert, "D", Color.RED, yes);
 
Last edited:
Combining major moving averages into a single indicator can be a useful approach to gain a holistic view of the market's trend and potential support/resistance levels. However, it's essential to consider other factors, such as price action, volume, and market context, to make well-informed trading decisions. So I created a moving average that combines the 9,21,50,100,200 and 300 exponential moving averages into one indicator reflected on the chart. It uses the EMA's to provide you with a comprehensive view of the overall trend and potential support/resistance levels in the price action. This can be useful for identifying trend reversals, determining entry/exit points, and understanding the overall strength of the market. Furthermore,
here are a few points to consider when using the Mega Moving Average indicator:
  1. Selecting relevant moving averages: Choose moving averages that align with your trading strategy and the timeframe you are focusing on. Common choices include the 50-day, 100-day, and 200-day moving averages, which are widely followed by traders and investors.
  2. Customizing parameters: Adjust the parameters of the moving averages (e.g., length, type) to suit your analysis. Different combinations may yield different results, so it's essential to experiment and find the settings that work best for your trading style.
  3. Consider the context: It's crucial to interpret the moving average crossovers and interactions within the context of the overall market conditions. For example, a bullish crossover may carry more weight in an up-trending market, while a bearish crossover may be more significant during a downtrend.
  4. Use additional confirmation: While moving averages can provide valuable insights, it's often beneficial to use them in conjunction with other technical indicators or chart patterns to strengthen your analysis and reduce false signals.

In addition to combining all the major moving averages. I also added a volume surge/spike detection feature and all these are adjustable within the options menu.

Ultimately, combining major moving averages into a single indicator can be a useful approach to gain a holistic view of the market's trend and potential support/resistance levels. However, it's essential to consider other factors, such as price action, volume, and market context, to make well-informed trading decisions.

Hope someone finds it as useful as it has been to my trading.

Ruby:
# created by Trader4TOS
# generated with chatGPT

# 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;

# Volume surge/spike detection
input volumeThreshold = 2.0; # Adjust the threshold according to your preference
def averageVolume = VolumeAvg(length = 20);
def volumeSurge = volume >= averageVolume * volumeThreshold;

# Color change condition
def colorChangeCondition = volumeSurge;

# Plot the combined moving average with color change
plot Indicator = combinedMA;
Indicator.SetDefaultColor(GetColor(1));
Indicator.SetPaintingStrategy(PaintingStrategy.LINE);
Indicator.AssignValueColor(if colorChangeCondition then Color.BLACK else Color.Light_GREEN);
Will it work with 1min, 5mins and 30Mins timeframe?
 
Here is a beta release of the Mega Moving Average version 1.2. In this update, I have added the On Balance Volume indicator to alert divergence signals in the form of a text bubble with the letter "D" and color-coded. This should give you a heads-up before a change of trend occurs. in addition, I color-coded the Mega MA to change color from dark green to dark red depending on if the price breaks above or below the Mega MA. It will also change to a Cyan color to signal a volume spike/surge more accurately. Remember that this is a beta release and you might see some false signals with the divergence feature. Please feel free to provide feedback on all errors, issues, or suggestions. Enjoy and happy trading!







#Mega Moving Average version 1.2 update created by Trader4TOS 06-21-2023

#"Mega Moving Average version 1.2," has the following features:

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

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

#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.

#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.

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

#Divergence Bubbles: The indicator plots a color-coded letter "D" to visualize the detected divergences. Green D represent bullish divergences, and red D represents bearish divergences.

#These features provide a comprehensive view of the market by combining moving averages, volume analysis, and divergence signals.

# 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 trendingMarket = AbsValue(combinedMA - combinedMA[1]) > 0.01;

# 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 > 2 then low else Double.NaN;
AddChartBubble(bullishDivergence and trendingMarket and high == highestHigh and priceRange > 2, bullishDivergenceAlert, "D", Color.GREEN, no);

def bearishDivergenceAlert = if bearishDivergence and trendingMarket and low == lowestLow and priceRange > 2 then high else Double.NaN;
AddChartBubble(bearishDivergence and trendingMarket and low == lowestLow and priceRange > 2, bearishDivergenceAlert, "D", Color.RED, yes);
can you inverse the indicator to plot the ma above price?
 
Should be able to. But the goal of the MMA is to display one average to look at that price will ride above or below upon trend change, long term or short term depending on what time frame you are observing. Also, we take into consideration how far the price is from the MMA which shows you momentum strength and duration when combined with the RSI Levels indicator and the additional features the MMA displays. That being the volume spike/surge feature which shows when a bigger move is coming in either direction and the divergence alert provides added guidance.
 
Should be able to. But the goal of the MMA is to display one average to look at that price will ride above or below upon trend change, long term or short term depending on what time frame you are observing. Also, we take into consideration how far the price is from the MMA which shows you momentum strength and duration when combined with the RSI Levels indicator and the additional features the MMA displays. That being the volume spike/surge feature which shows when a bigger move is coming in either direction and the divergence alert provides added guidance.
Thank you for sharing this tool with community.
If is not too much trouble, to understand better how to use it,
a) would it be possible to create video or add further screenshots/examples to demonstrate it in action as part of your decision making.
b) would it be possible for you to share your setup? It would help to understand how this indicator is used in correlation with other used by you.
Thank you again!
 
Thank you for sharing this tool with community.
If is not too much trouble, to understand better how to use it,
a) would it be possible to create video or add further screenshots/examples to demonstrate it in action as part of your decision making.
b) would it be possible for you to share your setup? It would help to understand how this indicator is used in correlation with other used by you.
Thank you again!
I will try my best to put together a video or images with a tutorial. I greatly appreciate your feedback. I am currently working on version 1.3. The beta version might be released today. It has major improvements in divergence detection and display. I have changed the plot to something that does not cause too much clutter on the chart and only provides the divergence signals on the hourly chart as it should. I am testing the new features as we speak. lol One new cool feature called the "TC" (trend continuation) alert I am still working on and don't guarantee it will be operable for the beta release. The idea behind the mega moving average is to solely have one primary moving average that you can use to see the price action strength, direction, momentum, and trend change. When you see the price above the MMA(Mega Moving Average). It shows you a bullish movement. As the price moves further away from the MMA this shows an increase in momentum and or possible price exhaustion. It is color-coded to turn green or red to make the trend more apparent when the price goes above or below. In addition to this, you will see volume spikes/ surges displayed on the MMA by a color change to cyan in specific areas. which tells you when a bigger move is coming either on an uptrend or downtrend. I highly recommend you use this in correlation with the RSI Levels indicator for additional insight. When the RSI Levels are showing "very oversold" or "extremely oversold" you can get a very clear picture of what the price will do next. As it will show you when there is pullback, consolidation, breakouts, and reversals. I have a multi-screen set up where I can see the 5min,15min,30min,1hr, and daily charts. It also depends on your trading style. I use it for scalps on the lower time frames(5,15,30) and swings on the higher time frame(hourly,daily,weekly). All the best to you and happy trading!
 
Last edited:
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.













# 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:
I will try my best to put together a video or images with a tutorial. I greatly appreciate your feedback. I am currently working on version 1.3. The beta version might be released today. It has major improvements in divergence detection and display. I have changed the plot to something that does not cause too much clutter on the chart and only provides the divergence signals on the hourly chart as it should. I am testing the new features as we speak. lol One new cool feature called the "TC" (trend continuation) alert I am still working on and don't guarantee it will be operable for the beta release. The idea behind the mega moving average is to solely have one primary moving average that you can use to see the price action strength, direction, momentum, and trend change. When you see the price above the MMA(Mega Moving Average). It shows you a bullish movement. As the price moves further away from the MMA this shows an increase in momentum and or possible price exhaustion. It is color-coded to turn green or red to make the trend more apparent when the price goes above or below. In addition to this, you will see volume spikes/ surges displayed on the MMA by a color change to cyan in specific areas. which tells you when a bigger move is coming either on an uptrend or downtrend. I highly recommend you use this in correlation with the RSI Levels indicator for additional insight. as if the RSI Levels are showing "very oversold" or "extremely oversold" you can get a very clear picture of what the price will do next. As pullback, consolidation, breakouts, and reversals. I have a multi-screen set up where I can see the 5min,15min,30min,1hr, and daily charts. It also depends on your trading style. I use it for scalps on the lower time frames(5,15,30) and swings on the higher time frame(hourly,daily,weekly). All the best to you and happy trading!
Thank you very much for you quick reply and contribution!
This is a lot of research and testing.
  • Would this be possible to add RSI levels vs using RSI indicator separately ?
  • Have you backtested this indicator as strategy ? would be interesting to see results ?
Looking forward to learning about how to use it for trading.
Great job!
 
Thank you very much for you quick reply and contribution!
This is a lot of research and testing.
  • Would this be possible to add RSI levels vs using RSI indicator separately ?
  • Have you backtested this indicator as strategy ? would be interesting to see results ?
Looking forward to learning about how to use it for trading.
Great job!
I recommend the RSI Levels. The script is available on my thread. The MMA is currently undergoing backtesting and going through adaptations based on the feedback from the community. Always looking to improve and provide free resources to the thinkscript community. So we can all stay "In the game!" and benefit. (y)
 
In v1.3. I can only get the Divergence to show as an arrow or a dot. I like the D bubble that was in v1.2, but that appears to be gone in v1.3.
 
In v1.3. I can only get the Divergence to show as an arrow or a dot. I like the D bubble that was in v1.2, but that appears to be gone in v1.3.
The bubble "D" plot was crowding up the chart. So I turned it into a dot that can be easily seen and only on the hourly chart which is best to spot divergence. here is the script to turn it back into the bubble plot.

def bullishDivergenceAlert = if bullishDivergence and trendingMarket and high == highestHigh and priceRange > 4 then low else Double.NaN;
AddChartBubble(bullishDivergence and trendingMarket and high == highestHigh and priceRange > 4, bullishDivergenceAlert, "D", Color.GREEN, no);


def bearishDivergenceAlert = if bearishDivergence and trendingMarket and low == lowestLow and priceRange > 4 then high else Double.NaN;
AddChartBubble(bearishDivergence and trendingMarket and low == lowestLow and priceRange >4, bearishDivergenceAlert, "D", Color.RED, yes);



you will be replacing the lower study. 👇

# 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);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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