Hyper MA Loop | QuantEdgeB For ThinkOrSwim

Author states: Hyper MA Loop | QuantEdgeB is an advanced trend-following indicator that leverages a custom Hyper Moving Average (HyMA) and an innovative loop-based scoring system to assess trend strength and direction. This tool is designed to provide a dynamic perspective on market momentum, allowing traders to capture trends effectively while filtering out market noise.

Use Cases:
✅ Ideal for trend-following traders looking for solid trends confirmation.
✅ Helps filter out choppy market conditions by adjusting sensitivity dynamically.
✅ Works well with other indicators (e.g., ADX, volume-based filters) for added confirmation.
✅ Suitable for both short-term and long-term trend analysis.
jR2CFb9.png


Here is the original Tradingview code:
https://www.tradingview.com/v/zGVsD0sB/

For the new ThinkOrSwim code, you must scroll down to the next post
 
Last edited by a moderator:

Upper Study:

CSS:
#// Indicator for TOS
#// © QuantEdgeB
#indicator("Hyper MA Loop | QuantEdgeB", overlay = false)
# Converted by Sam4Cok@Samer800    - 02/2025

input colorBars = yes;
input HyperMaSource = close; # "HyperMA Source"
input HyperMaLength = 2;     # "Hyper MA Length"
input strat_loop  = 1;       # 'Start'
input end_loop    = 60;      # 'End'
input ThresholdForLong = 40; # 'Threshold for long'
input ThresholdForShort = 8; # 'Threshold for short'

def na = Double.NaN;
def last = isNaN(close);

#// Hyper MA Calculation
Script f_HyMA {
input src = close;
input len = 2;
    def sum_hyp = fold i = 0 to len with p do
                  p + src[i] * (1 / (len - i));
    def sum_weights = fold j = 0 to len with q do
                     q + (1 / (len - j));
    def f_HyMA = if sum_weights > 0 then sum_hyp / sum_weights else Double.NaN;
    plot out = f_HyMA;
}
#// Loop Function
Script loop_f {
input a = 1;
input b = 60;
input ma = close;
    def sum2 = fold i = a to b + 1 with p do
               p + (if ma > ma[i] then 1 else -1);
    plot out = sum2;
}
def HyMa = f_HyMA(HyperMaSource, HyperMaLength);
def hyma_loop = loop_f(strat_loop , end_loop, HyMa);
#// Final Signal
def Long_C  = hyma_loop > ThresholdForLong;
def Short_C = hyma_loop < ThresholdForShort;
def QB = if Long_C and !Short_C then 1 else
         if Short_C then -1 else QB[1];
#// Color
def col = if QB > 0 then 1 else if QB < 0 then -1 else 0;
#// Extra Plots
def plotline1 = ExpAverage(close,3);
def plotline2 = ExpAverage(plotline1, 16*2);
def plotline3 = ExpAverage(plotline1, 16*3);
def plotline4 = ExpAverage(plotline1, 14);
def band_width = AbsValue(plotline2 - plotline4) / close;

#// Plots
def upCol = (col > 0 or col[-1] > 0);
def dnCol = (col < 0 or col[-1] < 0);
plot Line4 = if !last then plotline4 else na;

Line4.AssignValueColor(if col>0 then Color.CYAN else if col<0 then Color.MAGENTA else Color.GRAY);

AddCloud(if upCol then plotline4 else na, plotline3, Color.CYAN, Color.CYAN);
AddCloud(if upCol then plotline2 else na, plotline3, Color.CYAN, Color.CYAN);
AddCloud(if dnCol then plotline4 else na, plotline3, Color.PLUM, Color.PLUM);
AddCloud(if dnCol then plotline2 else na, plotline3, Color.PLUM, Color.PLUM);

AddCloud(if col > 0 and last[-2] then plotline2 else na, plotline3, Color.CYAN, Color.CYAN);
AddCloud(if col < 0 and last[-2] then plotline4 else na, plotline3, Color.PLUM, Color.PLUM);
AddCloud(if col < 0 and last[-2] then plotline2 else na, plotline3, Color.PLUM, Color.PLUM);

#-- Bar Color
AssignPriceColor(if !colorBars then Color.CURRENT else
                 if col>0 then Color.CYAN else if col<0 then Color.MAGENTA else Color.GRAY);

#-- END of CODE

Lower Study:

CSS:
#// Indicator for TOS
#// © QuantEdgeB
#indicator("Hyper MA Loop | QuantEdgeB", overlay = false)
# Converted by Sam4Cok@Samer800    - 02/2025
Declare lower;

input colorBars = yes;
input HyperMaSource = close; # "HyperMA Source"
input HyperMaLength = 2;     # "Hyper MA Length"
input strat_loop  = 1;       # 'Start'
input end_loop    = 60;      # 'End'
input ThresholdForLong = 40; # 'Threshold for long'
input ThresholdForShort = 8; # 'Threshold for short'

def na = Double.NaN;
def last = isNaN(close);

#// Hyper MA Calculation
Script f_HyMA {
input src = close;
input len = 2;
    def sum_hyp = fold i = 0 to len with p do
                  p + src[i] * (1 / (len - i));
    def sum_weights = fold j = 0 to len with q do
                     q + (1 / (len - j));
    def f_HyMA = if sum_weights > 0 then sum_hyp / sum_weights else Double.NaN;
    plot out = f_HyMA;
}
#// Loop Function
Script loop_f {
input a = 1;
input b = 60;
input ma = close;
    def sum2 = fold i = a to b + 1 with p do
               p + (if ma > ma[i] then 1 else -1);
    plot out = sum2;
}
def HyMa = f_HyMA(HyperMaSource, HyperMaLength);
def hyma_loop = loop_f(strat_loop , end_loop, HyMa);
#// Final Signal
def Long_C  = hyma_loop > ThresholdForLong;
def Short_C = hyma_loop < ThresholdForShort;
def QB = if Long_C and !Short_C then 1 else
         if Short_C then -1 else QB[1];
#// color
def col = if QB > 0 then 1 else if QB < 0 then -1 else 0;

#-- plot
plot HyperMALoop = if !last then hyma_loop else na; #"Hyper MA Loop"
plot LongTh = if !last then ThresholdForLong else na; #"Long Threshold"
plot ShortTh = if !last then ThresholdForShort else na ; # "Short Threshold"
HyperMALoop.SetLineWeight(2);
HyperMALoop.AssignValueColor(if col>0 then Color.CYAN else if col<0 then Color.MAGENTA else Color.GRAY);
LongTh.SetDefaultColor(Color.GREEN);
ShortTh.SetDefaultColor(Color.RED);

#-- Bar Color
AssignPriceColor(if !colorBars then Color.CURRENT else
                 if col>0 then Color.CYAN else if col<0 then Color.MAGENTA else Color.GRAY);

#-- END of CODE
 

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
491 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