PA-Adaptive Hull Parabolic [Loxx] For ThinkOrSwim

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

Hi I was wondering if anyone can convert the following to thinkorswim or point me to a similar indicator?
https://www.tradingview.com/script/02TLSQgT-PA-Adaptive-Hull-Parabolic-Loxx/

//@version=5
//
indicator('PA-Adaptive Hull Parabolic [Loxx]', overlay=true)

import loxx/loxxpaaspecial/1

greencolor = #2DD204
redcolor = #D2042D

src = input.source(close, "Source", group = "Basic Settings")
Power = input.int(1, "Power", group = "Basic Settings")
fregcycles = input.float(1.0, "Phase Accumulation Cycles", group = "Basic Settings")
fregfilter = input.float(1.0, "Phase Accumulation Power", group = "Basic Settings")

bool colorbars = input.bool(true, "Color bars", group= "UI Options")
bool showSigs = input.bool(true, "Show signals", group= "UI Options")

iLwmp(src, len, pow) =>
sumw = math.pow(len, pow)
sum = sumw * src
for int k = 1 to len - 1
weight = math.pow(len - k, pow)
sumw += weight
sum += weight * nz(src[k])
sum / sumw

HmaLength = math.max(loxxpaaspecial.paa(src, fregcycles, fregfilter), 2)
HalfPeriod = math.floor(HmaLength / 2)
HullPeriod = math.floor(math.sqrt(HmaLength))

hullout = iLwmp(2.0 * iLwmp(src, HalfPeriod, Power) - iLwmp(src, HmaLength, Power), HullPeriod, Power)
sig = hullout[1]
colorout = hullout > sig ? greencolor: redcolor

bool goLong = ta.crossover(hullout, sig)
bool goShort = ta.crossunder(hullout, sig)
barcolor(colorbars ? colorout : na)

plot(hullout, color = colorout, linewidth=3)

plotshape(showSigs and goLong, title = "Long", color = color.yellow, textcolor = color.yellow, text = "L", style = shape.triangleup, location = location.belowbar, size = size.small)
plotshape(showSigs and goShort, title = "Short", color = color.fuchsia, textcolor = color.fuchsia, text = "S", style = shape.triangledown, location = location.abovebar, size = size.small)

alertcondition(goLong, title = "Long", message = "PA-Adaptive Hull Parabolic [Loxx]: Long\nSymbol: {{ticker}}\nPrice: {{close}}")
alertcondition(goShort, title = "Short", message = "PA-Adaptive Hull Parabolic [Loxx]: Short\nSymbol: {{ticker}}\nPrice: {{close}}")

end of code

Thank You
check the below

CSS:
#// @Loxx
#indicator('PA-Adaptive Hull Parabolic [Loxx]', overlay=true)
# Converted by Sam4Cok@Samer800    - 12/2023
input src = close;#, "Source", group = "Basic Settings")
input Power = 1;#, "Power", group = "Basic Settings")
input PhaseAccumulationCycles = 1.0;#, "Phase Accumulation Cycles", group = "Basic Settings")
input PhaseAccumulationPower = 1.0;#, "Phase Accumulation Power", group = "Basic Settings")
input colorBars = yes;#(true, "Color bars", group= "UI Options")
input showSigs = yes;#(true, "Show signals", group= "UI Options")

def na = Double.NaN;
#calcComp(src, period)=>
Script calcComp {
input src = close;
    def out = (
         (0.0962 * src +
         0.5769 * src[2] -
         0.5769 * src[4] -
         0.0962 * src[6]) * (0.075 * src[1] + 0.54));
    plot return = out;
}
#iLwmp(src, len, pow) =>
script iLwmp {
    input src = close;
    input len1 = 10;
    input pow = 1;
    def len = if len1 < 2 then 2 else len1;
    def sumw_ = Power(len, pow);
    def sum_ = sumw_ * src;
    def sum1 = fold i = 1 to len with q=sum_ do 
               q + Power(len - i, pow) * GetValue(src, i);
    def sumw1 = fold k = 1 to len with p=sumw_ do 
               p + Power(len - k, pow);
    def sum = sum1;
    def sumw = sumw1;
    def iLwmp = sum / sumw;
    plot out = if isNaN(iLwmp) then (sum_/sumw_) else iLwmp;
}
#export paa(float src, float mult, float filt)=>
script paa {
    input src = close;
    input mult = 1;
    input filt = 0;
    def bar_index = AbsValue(BarNumber());
    def pi = Double.Pi;
    def degree = 180.0 / pi;
    def filter = Max(filt, 1);
    def I1;
    def Q1;
    def Phase;
    def period;
    def Smooth = if bar_index > 5 then
                 (4 * src + 3 * src[1] + 2 * src[2] + src[3]) / 10 else Smooth[1];
    def ts = calcComp(Smooth);
    def Detrender = if bar_index > 5 then ts else Detrender[1];
    def qs = calcComp(Detrender);
    def Q1_ = if bar_index > 5 then qs else Q1[1];
    def I1_ = if bar_index > 5 then Detrender[3] else I1[1];
        I1 = 0.15 * I1_ + 0.85 * I1[1];
        Q1 = 0.15 * Q1_ + 0.85 * Q1[1];
    def Phase1 = Phase[1];
    def Phase2 = if AbsValue(I1) > 0 then degree * ATan(AbsValue(Q1 / I1)) else Phase1;
    def Phase3 = if I1 < 0 and Q1 > 0 then 180 - Phase2 else Phase2;
    def Phase4 = if I1 < 0 and Q1 < 0 then 180 + Phase3 else Phase3;
        Phase  = if I1 > 0 and Q1 < 0 then 360 - Phase4 else Phase4;
    def DeltaPhase1 = Phase[1] - Phase;
    def DeltaPhase2 = if Phase[1] < 90 and Phase > 270 then
                      360 + Phase[1] - Phase else DeltaPhase1;
    def DeltaPhase3 = Max(Min(DeltaPhase2, 60), 7);
    def DeltaPhase = DeltaPhase3;
    def PhaseSum;
    def preSum;
    def count;
    if (PhaseSum[1] < (mult * 360) and count[1] < 4500) {
        preSum = GetValue(DeltaPhase, count[1]);
        PhaseSum = PhaseSum[1] + (if isNaN(preSum) then 0 else preSum);
        count = count[1] + 1;
    } else {
        preSum = 0;
        PhaseSum = PhaseSum[1];
        count = 0;
    }
    def InstPeriod = if count > 0 then count else InstPeriod[1];
    def alpha = 2.0 / (1.0 + filter);
    def period1 = period[1] + alpha * (InstPeriod - period[1]);
        period = if Floor(period1) < 1 then 1 else Floor(period1);
    def paa = Floor(period);
    plot return = if isNaN(paa) then 1 else paa;
}
def paa_ = paa(src, PhaseAccumulationCycles, PhaseAccumulationPower);
def HmaLength = if paa_ < 2 then 2 else paa_;
def HalfPrd    = HmaLength / 2;
def HullPrd    = Sqrt(HmaLength);
def HalfPeriod = Floor(HalfPrd);
def HullPeriod = Floor(HullPrd);
def iLwmpHalf_ = iLwmp(src, HalfPeriod, Power);
def iLwmpHma_  = iLwmp(src, HmaLength, Power);
def iLwmpHalf  = iLwmpHalf_;
def iLwmpHma = iLwmpHma_;
def iLwmSrc  = (2.0 * iLwmpHalf) - iLwmpHma;
def hullout_ = iLwmp(iLwmSrc, HullPeriod, Power);
def hullout = hullout_;
def sig = hullout[1];
def colorout = hullout > sig;
def goLong  = Crosses(hullout, sig, CrossingDirection.ABOVE);
def goShort = Crosses(hullout, sig, CrossingDirection.BELOW);

AssignPriceColor(if !colorBars then Color.CURRENT else
                 if colorout then Color.GREEN else Color.RED);

plot hullLine = hullout;
hullLine.SetLineWeight(2);
hullLine.AssignValueColor(if colorout then Color.CYAN else GetColor(2));

AddChartBubble(goLong, low, "L", Color.CYAN, no);
AddChartBubble(goShort, high, "S", GetColor(2));

#-- END of CODE
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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