• Get $40 off VIP by signing up for a free account! Sign Up

Profit target area for ThinkorSwim

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


here are a couple quick conversions.
i didn't define the exact colors


code1
Ruby:
# Profit_target_area_a

#addlabel(1, "Profit_target_area_0", color.white);
# https://usethinkscript.com/threads/convert-tradingview-profit-target-area-for-thinkorswim.10975/
# https://www.tradingview.com/script/DkJccTOH-Profit-target-area/

# study("Profit target area", overlay = true)
# fn_descending(src) => (nz(src[0]) <= nz(src[1])) and (nz(src[1]) <= nz(src[2]))  and (nz(src[2]) <= nz(src[3]))
#fn_ascending(src) => (nz(src[0]) >= nz(src[1])) and (nz(src[1]) >= nz(src[2]))  and (nz(src[2]) >= nz(src[3]))
#sl = fn_ascending(low) and not fn_ascending(low[1])
#sh = fn_descending(high) and not fn_descending(high[1])
#st = sh?true:(sl?false: nz(st[1]))
#h = st[0] and not st[1]?highest(high,10):nz(h[1])
#l = not st[0] and st[1]?lowest(low,10):nz(l[1])
#f = h - l
#h38 = l + f/(1-0.382)
#h62 = l + f/(1-0.618)
#l38 = h - f/(1-0.382)
#l62 = h - f/(1-0.618)
#ph = plot(h,color=green, title="resistance")
#pl = plot(l,color=red, title="support")
#p3 = plot(h38, color=#CCEECC, title="38% above")
#p1 = plot(h62, color=#DDDDFF, title="62% above")
#p2 = plot(l62, color=#DDDDFF, title="62% below")
#p4 = plot(l38, color=#CCEECC,  title="38% below")
#fill(p1,p3,color=#DDDDFF, transp=0,  title="62% above")
#fill(p3,ph,color=#CCEECC, transp=0,  title="38% above")
#fill(p2,p4,color=#DDDDFF, transp=0,  title="62% below")
#fill(p4,pl,color=#CCEECC, transp=0,  title="38% below")


script fn_descending {
input src = close;
def x = (src[0] <= src[1]) and (src[1] <= src[2]) and (src[2] <= src[3]);
plot z = x;
}

script fn_ascending {
input src = close;
def x = (src[0] >= src[1]) and (src[1] >= src[2]) and (src[2] >= src[3]);
plot z = x;
}

def sl = fn_ascending(low) and !fn_ascending(low[1]);
def sh = fn_descending(high) and !fn_descending(high[1]);
def st = if sh then 1 else if sl then 0 else st[1];
def h = if (st[0] and !st[1]) then highest(high,10) else h[1];
def l = if (!st[0] and st[1]) then lowest(low,10) else l[1];
def f = h - l;
def h38 = l + f/(1-0.382);
def h62 = l + f/(1-0.618);
def l38 = h - f/(1-0.382);
def l62 = h - f/(1-0.618);

plot ph = h;
plot pl = l;
ph.setdefaultcolor(color.green);
pl.setdefaultcolor(color.red);
plot p3 = h38;
plot p1 = h62;
plot p2 = l62;
plot p4 = l38;
p3.setdefaultcolor(color.gray);
p1.setdefaultcolor(color.gray);
p2.setdefaultcolor(color.gray);
p4.setdefaultcolor(color.gray);

addcloud(p1, p3, color.violet, color.violet);
addcloud(p3, ph, color.light_green, color.light_green);
addcloud(p2, p4, color.violet, color.violet);
addcloud(p4, pl, color.light_green, color.light_green);
#


code 2
Ruby:
# Profit_target_area_b


#addlabel(1, "Profit_target_area_b", color.white);
# https://usethinkscript.com/threads/convert-tradingview-profit-target-area-for-thinkorswim.10975/
# https://www.tradingview.com/script/6xyzUC1G-Profit-target-area/

input bars = 3;
input exbars = 10;

def descent_cnt = if (high <= high[1]) then (descent_cnt[1])+1 else 0;
def ascent_cnt = if (low >= low[1]) then ascent_cnt[1]+1 else 0;
def descent = (descent_cnt >= bars);
def ascent = (ascent_cnt >= bars);
def st = if ascent then 1 else if descent then 0 else st[1];

def h = if (st[1] and !st) then highest(high,exbars) else h[1];
def l = if (!st[1] and st) then lowest(low,exbars) else l[1];
def f = h - l;
def h38 = l + f/(1-0.382);
def h62 = l + f/(1-0.618);
def l38 = h - f/(1-0.382);
def l62 = h - f/(1-0.618);

plot modeline = if st[0] then l else h;
modeline.setdefaultcolor(color.white);
plot ph = h;
ph.setdefaultcolor(color.green);
plot pl = l;
pl.setdefaultcolor(color.red);

plot p3 = h38;
plot p1 = h62;
plot p2 = l62;
plot p4 = l38;
p3.setdefaultcolor(color.gray);
p1.setdefaultcolor(color.gray);
p2.setdefaultcolor(color.gray);
p4.setdefaultcolor(color.gray);

addcloud(p1, p3, color.violet, color.violet);
addcloud(p3, ph, color.light_green, color.light_green);

addcloud(p2, p4, color.violet, color.violet);
addcloud(p4, pl, color.light_green, color.light_green);

addcloud(ph, modeline, color.green, color.green);
addcloud(pl, modeline, color.red, color.red);


#--------------------------

#study("Profit target area", overlay=true)
#bars =input(title="Reversial pattern length (bars)", type=integer, defval=3, minval=1)
#exbars = input(title="S/R detection (bars)", type=integer, defval=10, minval=1)
#descent_cnt = high <= nz(high[1])?nz(descent_cnt[1])+1:0
#ascent_cnt = low >= nz(low[1])?nz(ascent_cnt[1])+1:0
#descent = descent_cnt >= bars
#ascent = ascent_cnt >= bars
#st = ascent?true:(descent?false:nz(st[1]))
#h = st[1] and not st?highest(high,exbars):nz(h[1])
#l = not st[1] and st?lowest(low,exbars):nz(l[1])
#f = h - l
#h38 = l + f/(1-0.382)
#h62 = l + f/(1-0.618)
#l38 = h - f/(1-0.382)
#l62 = h - f/(1-0.618)

#modeline = plot(st[0]?l:h,color=white,title="invisible plot", style=cross)
#ph = plot(h,color=green, title="resistance")
#pl = plot(l,color=red, title="support")
#p3 = plot(h38, color=#80FF80, title="38% above")
#p1 = plot(h62, color=#C0FFC0, title="62% above")
#p2 = plot(l62, color=#FFC0FF, title="62% below")
#p4 = plot(l38, color=#FF80FF,  title="38% below")
#fill(p1,p3,color=#80FF80, transp=80,  title="62% above")
#fill(p3,ph,color=#00FF00, transp=80,  title="38% above")
#fill(p2,p4,color=#FF80FF, transp=80,  title="62% below")
#fill(p4,pl,color=#FF00FF, transp=80,  title="38% below")
#fill(ph,modeline,color=green, transp=90, title="going up")
#fill(pl,modeline,color=red, transp=90, title="going down")
#
 
Ruby:
def bars = 3;
def exbars = 10;
script nz {
    input data = 0;
    def ret_val = if IsNaN(data) then 0 else data;
    plot return = ret_val;
}

def descent_cnt = if high <= nz(high[1]) then nz(descent_cnt[1]) + 1 else 0;
def ascent_cnt = if low >= nz(low[1]) then nz(ascent_cnt[1]) + 1 else 0;
def descent = descent_cnt >= bars;
def ascent = ascent_cnt >= bars;

def st;
if (ascent)
{
    st = yes;
}
else
{
    if (descent)
    {
        st = no;
    }
    else
    {
        st = nz(st[1]);
    }
}


def h;

if (st[1] and st == no)
{
    h = Highest(high, exbars);
}
else
{
    h = nz(h[1]);
}


def l;
if (st[1] == no and st == yes)
{
    l = Lowest(low, exbars);
}
else
{
    l = nz(l[1]);
}

def f = h - l;
def h38 = l + f / (1 - 0.382);
def h62 = l + f / (1 - 0.618);
def l38 = h - f / (1 - 0.382);
def l62 = h - f / (1 - 0.618);

plot modeline;
if (st[0])
{
    modeline = l;
}
else
{
    modeline = h;
}

plot ph = h;
ph.SetDefaultColor(GetColor(6));
plot pl = l;
pl.SetDefaultColor(GetColor(5));
plot p3 = h38;
p3.SetDefaultColor(GetColor(1));
plot p1 = h62;
p1.SetDefaultColor(GetColor(0));
plot p2 = l62;
p2.SetDefaultColor(GetColor(2));
plot p4 = l38;
p4.SetDefaultColor(GetColor(0));
AddCloud(p1, p3, color.Light_green, color.light_green);
AddCloud(p3, ph, color.green, color.green);
AddCloud(p2, p4, color.MAGENTA, color.MAGENTA);
AddCloud(p4, pl, color.red, color.red);
AddCloud(ph, modeline, color.black, color.black);
AddCloud(pl, modeline, color.downtick, color.downtick);
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
126 Online
Create Post

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