Help modify Stoploss finder indicator

Friends,

I found this indicator on tradingview and looking for help to get this converted into TOS. Your help is much appreciated
 
Last edited by a moderator:
Friends,

I found this indicator on tradingview and looking for help to get this converted into TOS. Your help is much appreciated

//@version=4
study(title="Average True Range Stop Loss Finder", shorttitle="ATR", overlay=true)
length = input(title="Length", defval=14, minval=1)
smoothing = input(title="Smoothing", defval="RMA", options=["RMA", "SMA", "EMA", "WMA"])
m = input(1.5, "Multiplier")
src1 = input(high)
src2 = input(low)
pline = input(true, "Show Price Lines")
col1 = input(color.blue, "ATR Text Color")
col2 = input(color.teal, "Low Text Color",inline ="1")
col3 = input(color.red, "High Text Color",inline ="2")
collong = input(color.teal, "Low Line Color",inline ="1")
colshort = input(color.red, "High Line Color",inline ="2")
ma_function(source, length) =>
if smoothing == "RMA"
rma(source, length)
else
if smoothing == "SMA"
sma(source, length)
else
if smoothing == "EMA"
ema(source, length)
else
wma(source, length)

a = ma_function(tr(true), length) * m
x = ma_function(tr(true), length) * m + src1
x2 = src2 - ma_function(tr(true), length) * m
p1 = plot(x, title = "ATR Short Stop Loss", color= colshort, transp=20, trackprice = pline ? true : false)
p2 = plot(x2, title = "ATR Long Stop Loss", color= collong, transp=20, trackprice = pline ? true : false)
var table Table = table.new(position.bottom_center, 3, 1, border_width = 3)
f_fillCell(_table, _column, _row, _value, _timeframe) =>
_cellText = _timeframe+ tostring(_value, "#.#")
table.cell(_table, _column, _row, _cellText, text_color = col1)
table.cell_set_text_color(Table, 1, 0, color.new(col3, transp = 0))
table.cell_set_text_color(Table, 2, 0, color.new(col2, transp = 0))

if barstate.islast
f_fillCell(Table, 0, 0, a, "ATR: " )
f_fillCell(Table, 1, 0, x, "H: " )
f_fillCell(Table, 2, 0, x2, "L: " )
try this.

CSS:
#//@version=4
#study(title="Average True Range Stop Loss Finder", shorttitle="ATR", overlay=true)
# Converted by Sam4Cok@Samer800 - 08/2022
input length = 14;#(title="Length", defval=14, minval=1)
input smoothing = {default RMA, SMA, EMA, WMA};#"Smoothing",
input ATRFactor = 1.0;       # Multiplier
input Target1   = 1.5;
input Target2   = 1.75;
input wicks = yes;
input addSrpead = yes;
input ShowBand = yes;#(true, "Show Price Lines")
input label = yes;

def c = close;
def h = high;
def l = low;


def ask  = Average(close(priceType = PriceType.ASK), 3);
def bid  = Average(close(priceType = PriceType.BID), 3);
def diff = AbsValue(ask - bid);

def spread = if IsNaN(diff) then 0 else diff;

#ma_function(type, source, length) =>
script ma_function {
    input smoothing = "RMA";
    input source = close;
    input length = 14;
    def maType;
        if smoothing == "RMA" {
            maType = WildersSmoothing(source, length);
        } else {
            if smoothing == "SMA" {
                maType = SimpleMovingAvg(source, length);
            } else {
                if smoothing == "EMA" {
                    maType =  ExpAverage(source, length);
                } else {
                    maType = WMA(source, length);
                }
            }
        }
        plot return = maType;
}
    def tr = TrueRange(h, c, l);
    def ATR = ma_function(smoothing, tr, length) + If(addSrpead, spread, 0);
    def ATR1 = ATR * ATRFactor;
    def ATRUp = ATR1 + If(wicks , h , c);
    def ATRDn = If(wicks , l , c) - ATR1;
#def tar1 =
#def tar2 =

#///find TP SL
    def slLong  = Round(c - ATRDn, 2);
    def tp1Long = Round((Target1 * slLong), 2);
    def tp2Long = Round((Target2 * slLong), 2);

    def slShort  = Round(ATRUp - c, 2);
    def tp1Short = Round((Target1 * slShort), 2);
    def tp2Short = Round((Target2 * slShort), 2);


#### LAbel ##########################

    AddLabel (label, "ATR(" + Round(ATR1, 2) + ")", CreateColor(33, 150, 243));
    AddLabel (label, "SL(" + slLong + ") TP1(" + tp1Long + ") TP2(" + tp2Long + ")", Color.LIGHT_GREEN);
    AddLabel (label, "SL(" + slShort + ") TP1(" + tp1Short + ") TP2(" + tp2Short + ")", Color.PINK);

    plot p1 = ATRUp;#, title = "ATR Short Stop Loss", color= colshort, transp=20, trackprice = pline ? true : false)
    p1.SetDefaultColor(CreateColor(255, 82, 82));
    p1.SetHiding(!ShowBand);

    plot p2 = ATRDn;#e = "ATR Long Stop Loss", color= collong, transp=20, trackprice = pline ? true : false)
    p2.SetDefaultColor(CreateColor(0, 137, 123));
    p2.SetHiding(!ShowBand);

#---- END CODE
 

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

try this.

CSS:
#//@version=4
#study(title="Average True Range Stop Loss Finder", shorttitle="ATR", overlay=true)
# Converted by Sam4Cok@Samer800 - 08/2022
input length = 14;#(title="Length", defval=14, minval=1)
input smoothing = {default RMA, SMA, EMA, WMA};#"Smoothing",
input ATRFactor = 1.0;       # Multiplier
input Target1   = 1.5;
input Target2   = 1.75;
input wicks = yes;
input addSrpead = yes;
input ShowBand = yes;#(true, "Show Price Lines")
input label = yes;

def c = close;
def h = high;
def l = low;


def ask  = Average(close(priceType = PriceType.ASK), 3);
def bid  = Average(close(priceType = PriceType.BID), 3);
def diff = AbsValue(ask - bid);

def spread = if IsNaN(diff) then 0 else diff;

#ma_function(type, source, length) =>
script ma_function {
    input smoothing = "RMA";
    input source = close;
    input length = 14;
    def maType;
        if smoothing == "RMA" {
            maType = WildersSmoothing(source, length);
        } else {
            if smoothing == "SMA" {
                maType = SimpleMovingAvg(source, length);
            } else {
                if smoothing == "EMA" {
                    maType =  ExpAverage(source, length);
                } else {
                    maType = WMA(source, length);
                }
            }
        }
        plot return = maType;
}
    def tr = TrueRange(h, c, l);
    def ATR = ma_function(smoothing, tr, length) + If(addSrpead, spread, 0);
    def ATR1 = ATR * ATRFactor;
    def ATRUp = ATR1 + If(wicks , h , c);
    def ATRDn = If(wicks , l , c) - ATR1;
#def tar1 =
#def tar2 =

#///find TP SL
    def slLong  = Round(c - ATRDn, 2);
    def tp1Long = Round((Target1 * slLong), 2);
    def tp2Long = Round((Target2 * slLong), 2);

    def slShort  = Round(ATRUp - c, 2);
    def tp1Short = Round((Target1 * slShort), 2);
    def tp2Short = Round((Target2 * slShort), 2);


#### LAbel ##########################

    AddLabel (label, "ATR(" + Round(ATR1, 2) + ")", CreateColor(33, 150, 243));
    AddLabel (label, "SL(" + slLong + ") TP1(" + tp1Long + ") TP2(" + tp2Long + ")", Color.LIGHT_GREEN);
    AddLabel (label, "SL(" + slShort + ") TP1(" + tp1Short + ") TP2(" + tp2Short + ")", Color.PINK);

    plot p1 = ATRUp;#, title = "ATR Short Stop Loss", color= colshort, transp=20, trackprice = pline ? true : false)
    p1.SetDefaultColor(CreateColor(255, 82, 82));
    p1.SetHiding(!ShowBand);

    plot p2 = ATRDn;#e = "ATR Long Stop Loss", color= collong, transp=20, trackprice = pline ? true : false)
    p2.SetDefaultColor(CreateColor(0, 137, 123));
    p2.SetHiding(!ShowBand);

#---- END CODE
@samer800 - I just realized it is not plotting SL, P1 and P2. could you please add the code to plot these values?
 
Hello Friends,

Have come across this scalping thread and found it interesting and I tried to modify this with below assumptions. This could be a simple trading indicator and can anyone help me to fine tune this

https://usethinkscript.com/threads/nq-1-minute-scalping-indicator-for-thinkorswim.11000/#post-96446

Assumptions

1. Long Entry Signal - close > open and low < low[1] and high < high[1] and low[1] < low[2] and high[1] < high[2];
2. Stop Loss - ATR value defined by user (see below)
3. Target 1 & 2 - Based on target points (in points defined i.e. (close - SL) * target 1/target 2

Need help on

I managed to get the signal and also SL but struggling to get the target points plotted(for some reason target1 when using formula (close - sl)*2 is going out of boundaries). Also want this line extended till the SL or target it met to validate next entry condition.

Appreciate can help me fix this

Code:
#SL_Finder
input length = 14;#(title="Length", defval=14, minval=1)
input smoothing = {default RMA, SMA, EMA, WMA};#"Smoothing",
input ATRFactor = 1.0;       # Multiplier
input Target1   = 1.5;
input Target2   = 1.75;
input wicks = yes;
input addSrpead = yes;
input ShowBand = yes;#(true, "Show Price Lines")
input label = yes;

def c = close;
def h = high;
def l = low;

def ask  = Average(close(priceType = PriceType.ASK), 3);
def bid  = Average(close(priceType = PriceType.BID), 3);
def diff = AbsValue(ask - bid);

def spread = if IsNaN(diff) then 0 else diff;

#ma_function(type, source, length) =>
script ma_function {
    input smoothing = "RMA";
    input source = close;
    input length = 14;
    def maType;
        if smoothing == "RMA" {
            maType = WildersSmoothing(source, length);
        } else {
            if smoothing == "SMA" {
                maType = SimpleMovingAvg(source, length);
            } else {
                if smoothing == "EMA" {
                    maType =  ExpAverage(source, length);
                } else {
                    maType = WMA(source, length);
                }
            }
        }
        plot return = maType;
}
    def tr = TrueRange(h, c, l);
    def ATR = ma_function(smoothing, tr, length) + If(addSrpead, spread, 0);
    def ATR1 = ATR * ATRFactor;
    def ATRUp = ATR1 + If(wicks , h , c);
    def ATRDn = If(wicks , l , c) - ATR1;


######

#Entry_Signal
def bull = close > open and low < low[1] and high < high[1] and low[1] < low[2] and high[1] < high[2];

plot upsignal = bull;
upsignal.SetDefaultColor(Color.UPTICK);
upsignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);


plot Long_Tgt_1 = if upsignal then atrup*target1 else Double.NaN;
plot Long_SL = if upsignal then atrDn else Double.NaN;
Long_Tgt_1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Long_SL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Long_Tgt_1.SetStyle(Curve.SHORT_DASH);
Long_SL.SetStyle(Curve.SHORT_DASH);
Long_Tgt_1.SetDefaultColor(Color.YELLOW);
Long_Tgt_1.SetLineWeight(2);
Long_SL.SetDefaultColor(Color.YELLOW);
Long_SL.setlineWeight(2);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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