0% found this document useful (0 votes)
10 views13 pages

Trading Indicator Script for Analysis

The document is a Pine Script code for a trading indicator called 'Help4Help+'. It includes various calculations for trend analysis, support and resistance levels, and alerts for buy/sell signals based on market conditions. The script also features customizable inputs for users to adjust settings related to channel lengths, overbought/oversold levels, and visual elements.

Uploaded by

skabdulafridi53
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views13 pages

Trading Indicator Script for Analysis

The document is a Pine Script code for a trading indicator called 'Help4Help+'. It includes various calculations for trend analysis, support and resistance levels, and alerts for buy/sell signals based on market conditions. The script also features customizable inputs for users to adjust settings related to channel lengths, overbought/oversold levels, and visual elements.

Uploaded by

skabdulafridi53
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

//@version=5

//Conbined by Hamza le 02-12-2024

indicator(title="Help4Help+",overlay=false)
n1 = [Link](10, "Channel Length")
n2 = [Link](21, "Average Length")
obLevel1 = [Link](60, "Over Bought Level 1")
obLevel2 = [Link](53, "Over Bought Level 2")
osLevel1 = [Link](-60, "Over Sold Level 1")
osLevel2 = [Link](-53, "Over Sold Level 2")

ap = hlc3
esa = [Link](ap, n1)
d = [Link]([Link](ap - esa), n1)
ci = (ap - esa) / (0.015 * d)
tci = [Link](ci, n2)

wt1 = tci
wt2 = [Link](wt1,4)

plot(0, color=[Link])
plot(obLevel1, color=[Link])
plot(osLevel1, color=[Link])
plot(obLevel2, color=[Link], style=plot.style_circles)
plot(osLevel2, color=[Link], style=plot.style_circles)

plot(wt1, color=[Link])
plot(wt2, color=[Link], style=plot.style_line)
plot(wt1-wt2, color=[Link], style=plot.style_areabr)

///////////////////////////////////////////////////////////////////////////////////
/

var string calcGroup = 'Calculation'


length = [Link](title='ATR Period', defval=22, group=calcGroup)
mult = [Link](title='ATR Multiplier', step=0.1, defval=3.0, group=calcGroup)
useClose = [Link](title='Use Close Price for Extremums', defval=true,
group=calcGroup)

var string visualGroup = 'Visuals'


showLabels = [Link](title='Show Buy/Sell Labels', defval=false,
group=visualGroup)
highlightState = [Link](title='Highlight State', defval=true,
group=visualGroup)

var string alertGroup = 'Alerts'


awaitBarConfirmation = [Link](title="Await Bar Confirmation", defval=true,
group=alertGroup)

atr = mult * [Link](length)

longStop = (useClose ? [Link](close, length) : [Link](length)) - atr


longStopPrev = nz(longStop[1], longStop)
longStop := close[1] > longStopPrev ? [Link](longStop, longStopPrev) : longStop

shortStop = (useClose ? [Link](close, length) : [Link](length)) + atr


shortStopPrev = nz(shortStop[1], shortStop)
shortStop := close[1] < shortStopPrev ? [Link](shortStop, shortStopPrev) :
shortStop

var int dir = 1


dir := close > shortStopPrev ? 1 : close < longStopPrev ? -1 : dir

var color longColor = [Link]


var color shortColor = [Link]
var color longFillColor = [Link]([Link], 90)
var color shortFillColor = [Link]([Link], 90)
var color textColor = [Link]([Link], 0)

longStopPlot = plot(dir == 1 ? longStop : na, title='Long Stop',


style=plot.style_linebr, linewidth=1, color=[Link](longColor,
0),force_overlay=true)
buySignal = dir == 1 and dir[1] == -1
plotshape(buySignal ? longStop : na, title='Long Stop Start',
location=[Link], style=[Link], size=[Link],
color=[Link](longColor, 0),force_overlay=true)
plotshape(buySignal and showLabels ? longStop : na, title='Buy Label', text='Buy',
location=[Link], style=[Link], size=[Link],
color=[Link](longColor, 0), textcolor=textColor,force_overlay=true)

shortStopPlot = plot(dir == 1 ? na : shortStop, title='Short Stop',


style=plot.style_linebr, linewidth=1, color=[Link](shortColor,
0),force_overlay=true)
sellSignal = dir == -1 and dir[1] == 1
plotshape(sellSignal ? shortStop : na, title='Short Stop Start',
location=[Link], style=[Link], size=[Link],
color=[Link](shortColor, 0),force_overlay=true)
plotshape(sellSignal and showLabels ? shortStop : na, title='Sell Label',
text='Sell', location=[Link], style=[Link], size=[Link],
color=[Link](shortColor, 0), textcolor=textColor,force_overlay=true)

midPricePlot = plot(ohlc4, title='', style=plot.style_circles, linewidth=1,


display=[Link], editable=false,force_overlay=true)

longStateFillColor = highlightState ? dir == 1 ? longFillColor : na : na


shortStateFillColor = highlightState ? dir == -1 ? shortFillColor : na : na
fill(midPricePlot, longStopPlot, title='Long State Filling',
color=longStateFillColor)
fill(midPricePlot, shortStopPlot, title='Short State Filling',
color=shortStateFillColor)

await = awaitBarConfirmation ? [Link] : true


alertcondition(dir != dir[1] and await, title='Alert: CE Direction Change',
message='Chandelier Exit has changed direction!')
alertcondition(buySignal and await, title='Alert: CE Buy', message='Chandelier Exit
Buy!')
alertcondition(sellSignal and await, title='Alert: CE Sell', message='Chandelier
Exit Sell!')

///////////////////////////////////////////////////////////////////////////////////
/////

//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
lengtht = [Link](14, 'Swing Detection Lookback')
multt = [Link](1., 'Slope', minval = 0, step = .1)
calcMethod = [Link]('Atr', 'Slope Calculation Method', options =
['Atr','Stdev','Linreg'])
backpaint = input(true, tooltip = 'Backpainting offset displayed elements in the
past. Disable backpainting to see real time information returned by the
indicator.')

//Style
upCss = [Link]([Link], 'Up Trendline Color', group = 'Style')
dnCss = [Link]([Link], 'Down Trendline Color', group = 'Style')
showExt = input(true, 'Show Extended Lines')

//-----------------------------------------------------------------------------}
//Calculations
//-----------------------------------------------------------------------------{
var upper = 0.
var lower = 0.
var slope_ph = 0.
var slope_pl = 0.

var offset = backpaint ? lengtht : 0

n = bar_index
src = close

ph = [Link](lengtht, lengtht)
pl = [Link](lengtht, lengtht)

//Slope Calculation Method


slope = switch calcMethod
'Atr' => [Link](lengtht) / lengtht * multt
'Stdev' => [Link](src,lengtht) / lengtht * multt
'Linreg' => [Link]([Link](src * n, lengtht) - [Link](src, lengtht) *
[Link](n, lengtht)) / [Link](n, lengtht) / 2 * multt

//Get slopes and calculate trendlines


slope_ph := ph ? slope : slope_ph
slope_pl := pl ? slope : slope_pl

upper := ph ? ph : upper - slope_ph


lower := pl ? pl : lower + slope_pl

var upos = 0
var dnos = 0
upos := ph ? 0 : close > upper - slope_ph * length ? 1 : upos
dnos := pl ? 0 : close < lower + slope_pl * length ? 1 : dnos

//-----------------------------------------------------------------------------}
//Extended Lines
//-----------------------------------------------------------------------------{
var uptl = [Link](na,na,na,na, color = upCss, style = line.style_dashed, extend
= [Link],force_overlay=true)
var dntl = [Link](na,na,na,na, color = dnCss, style = line.style_dashed, extend
= [Link],force_overlay=true)

if ph and showExt
uptl.set_xy1(n-offset, backpaint ? ph : upper - slope_ph * lengtht)
uptl.set_xy2(n-offset+1, backpaint ? ph - slope : upper - slope_ph *
(lengtht+1))

if pl and showExt
dntl.set_xy1(n-offset, backpaint ? pl : lower + slope_pl * lengtht)
dntl.set_xy2(n-offset+1, backpaint ? pl + slope : lower + slope_pl *
(lengtht+1))

//-----------------------------------------------------------------------------}
//Plots
//-----------------------------------------------------------------------------{
plot(backpaint ? upper : upper - slope_ph * lengtht, 'Upper', color = ph ? na :
upCss, offset = -offset,force_overlay=true)
plot(backpaint ? lower : lower + slope_pl * lengtht, 'Lower', color = pl ? na :
dnCss, offset = -offset,force_overlay=true)

//Breakouts
plotshape(upos > upos[1] ? low : na, "Upper Break"
, [Link]
, [Link]
, upCss
, text = "B"
, textcolor = [Link]
, size = [Link],force_overlay=true)

plotshape(dnos > dnos[1] ? high : na, "Lower Break"


, [Link]
, [Link]
, dnCss
, text = "B"
, textcolor = [Link]
, size = [Link],force_overlay=true)

//-----------------------------------------------------------------------------}
//Alerts
//-----------------------------------------------------------------------------{
alertcondition(upos > upos[1], 'Upward Breakout', 'Price broke the down-trendline
upward')
alertcondition(dnos > dnos[1], 'Downward Breakout', 'Price broke the up-trendline
downward')

//-----------------------------------------------------------------------------}
///////////////////////////////////////////////////////////////////////////////////
///////////////////

showRevBands = [Link](true, "Show Reversal Bands", group="REVERSAL BANDS")


lenRevBands = [Link](30, "Length", group="REVERSAL BANDS")

// Functions
f_kc(src, len, sensitivity) =>
basis = [Link](src, len)
span = [Link](len)
[basis + span * sensitivity, basis - span * sensitivity]

[upperKC1, lowerKC1] = f_kc(close, lenRevBands, 3)


[upperKC2, lowerKC2] = f_kc(close, lenRevBands, 4)
[upperKC3, lowerKC3] = f_kc(close, lenRevBands, 5)
[upperKC4, lowerKC4] = f_kc(close, lenRevBands, 6)
cyan = #3179f5, cyan30 = [Link](cyan, 70)
pink = #f23645, pink30 =[Link](pink, 70)
red = #f23645, red30 = [Link](red , 70)
zoneupper1=plot(showRevBands ? upperKC1 : na, "[Link] Upper 1",
red30,force_overlay=true)
zoneupper2=plot(showRevBands ? upperKC2 : na, "[Link] Upper 2",
red30,force_overlay=true)
zonelower2=plot(showRevBands ? lowerKC2 : na, "[Link] Lower 2",
cyan30,force_overlay=true)
zonelower1=plot(showRevBands ? lowerKC1 : na, "[Link] Lower 1",
cyan30,force_overlay=true)
fill(zoneupper1, zoneupper2, color = red30)
fill(zonelower1, zonelower2, color = cyan30)

///////////////////////////////////////////////////////////////////////////////////
/////

// This work is licensed under Creative Commons Attribution-NonCommercial-


ShareAlike 4.0 International
// © BigBeluga

//@version=5
//indicator("Premium & Discount Delta Volume [BigBeluga]", overlay = true,
max_lines_count = 2, max_boxes_count = 3)

// INPUTS
-----------------------------------------------------------------------------------
---------------------------
// @variable: Toggle to show Support and Resistance levels
bool showSR = [Link](true, "", inline = "0")
// @variable: Lookback period for calculating Support and Resistance
int srPeriod = [Link](50, "Premium & Discount Lookback Period", minval = 10,
step = 10, inline = "0",
tooltip = "Lookback period for Premium & Discount Levels
with Delta Volume")
// @variable: Toggle to show macro High and Low levels
bool showMacro = [Link](true, "", inline = "1")
// @variable: Lookback period for calculating macro Highs and Lows
int macroPeriod = [Link](200, "Macro Lookback Period", minval = 10, step = 10,
inline = "1",
tooltip = "Lookback period for Macro Highs/Lows and
Delta Volume")
// Color variables for trends
color upColor = [Link](#79c1f1, "Discount", inline = "col", group =
"Color")
color downColor = [Link](#f19579, "Premium", inline = "col", group =
"Color")

// ARRAYS FOR STORING DATA


-----------------------------------------------------------------------------------
----------
// Arrays to store high/low data for S/R levels
var float[] srHighs = array.new_float(srPeriod, 0.)
var float[] srLows = array.new_float(srPeriod, 0.)
// Arrays to store high/low data for Macro levels
var float[] macroHighs = array.new_float(macroPeriod, 0.)
var float[] macroLows = array.new_float(macroPeriod, 0.)
// Arrays to store delta volume data
var float[] posVolSR = array.new_float(srPeriod, 0.)
var float[] negVolSR = array.new_float(srPeriod, 0.)
var float[] posVolMacro = array.new_float(macroPeriod, 0.)
var float[] negVolMacro = array.new_float(macroPeriod, 0.)

// VARIABLES FOR DELTA VOLUME CALCULATIONS


-----------------------------------------------------------------------------
// Variables to store delta volume percentages for S/R and Macro periods
var float deltaVolSR = na
var float deltaVolMacro = na

// VARIABLES FOR BOX DRAWING


-----------------------------------------------------------------------------------
---------
// Variables for box indices for both S/R and Macro periods
int srStartIdx = bar_index - srPeriod
int srEndIdx = bar_index + 50
int macroStartIdx = bar_index - macroPeriod
int macroEndIdx = bar_index + 70

// Variables for box drawing


var box srUpperBox = na
var box srLowerBox = na
var box macroUpperBox = na
var box macroLowerBox = na
var box midBox = na

// ATR for box scaling


float atrValue = [Link](200)*0.8

// VOLUME DELTA CALCULATIONS


-----------------------------------------------------------------------------------
--------
// @description: Calculate the delta volume for Macro period
if [Link] and showMacro
for int i = 0 to macroPeriod - 1
[Link](macroHighs, high[i])
[Link](macroLows, low[i])
// Store positive and negative volume based on candle direction
if close[i] > open[i]
[Link](i, volume[i])
if close[i] < open[i]
[Link](i, -volume[i])
// Calculate Macro Delta Volume
deltaVolMacro := ([Link]() / [Link]() + 1) * 100
deltaVolMacro := [Link]([Link](deltaVolMacro, -100), 100) // Cap delta
volume between -100 and 100

// Calculate the delta volume for S/R period


if [Link] and showSR
for int i = 0 to srPeriod - 1
[Link](srHighs, high[i])
[Link](srLows, low[i])
// Store positive and negative volume based on candle direction
if close[i] > open[i]
[Link](i, volume[i])
if close[i] < open[i]
[Link](i, -volume[i])
// Calculate S/R Delta Volume
deltaVolSR := ([Link]() / [Link]() + 1) * 100
deltaVolSR := [Link]([Link](deltaVolSR, -100), 100) // Cap delta volume
between -100 and 100

// BOX HANDLING AND UPDATING


-----------------------------------------------------------------------------------
--------
// Update and manage boxes based on crossover conditions
if [Link](low, srUpperBox.get_top()) or [Link](high,
srLowerBox.get_bottom()) or bar_index % 100 == 0
// Set new bounds for S/R and Macro boxes
srUpperBox.set_top([Link]() + atrValue)
srUpperBox.set_bottom([Link]())
srLowerBox.set_top([Link]())
srLowerBox.set_bottom([Link]() - atrValue)

macroUpperBox.set_top([Link]() + atrValue)
macroUpperBox.set_bottom([Link]())
macroLowerBox.set_top([Link]())
macroLowerBox.set_bottom([Link]() - atrValue)

// Delete previous boxes


[Link](srUpperBox[1])
[Link](srLowerBox[1])
[Link](macroUpperBox[1])
[Link](macroLowerBox[1])

// DRAW AND UPDATE BOXES


-----------------------------------------------------------------------------------
-------------
// Draw and update lower box if not initialized for S/R period
if na(srLowerBox) and [Link] and showSR
srLowerBox := [Link](srStartIdx, [Link](), srEndIdx, [Link]() -
atrValue,
upColor, 1,
bgcolor = [Link](upColor, 100),
text = "DISCOUNT: " + [Link]([Link](),
[Link]),
text_size = [Link],
text_color= chart.fg_color, force_overlay =
true,force_overlay=true)
else
srLowerBox.set_text("DISCOUNT: " + [Link]([Link](), [Link]))
box.set_left(srLowerBox, srStartIdx)
box.set_right(srLowerBox, srEndIdx)
[Link](srLows)

// Draw and update upper box if not initialized for S/R period
if na(srUpperBox) and [Link] and showSR
srUpperBox := [Link](srStartIdx, [Link]() + atrValue, srEndIdx,
[Link](),
downColor, 1,
bgcolor = [Link](downColor, 100),
text = "PREMIUM: " + [Link]([Link](),
[Link]),
text_size = [Link],
text_color= chart.fg_color, force_overlay =
true,force_overlay=true)
else
srUpperBox.set_text("PREMIUM: " + [Link]([Link](), [Link]))
box.set_left(srUpperBox, srStartIdx)
box.set_right(srUpperBox, srEndIdx)
[Link](srHighs)

// DRAW BOXES FOR MACRO PERIOD


-----------------------------------------------------------------------------------
-------
// Draw and update upper box for Macro period
if na(macroUpperBox) and [Link] and showMacro
macroUpperBox := [Link](
macroStartIdx, [Link]() + atrValue,
macroEndIdx, [Link](),
downColor, 0,
bgcolor = [Link](downColor, 60),
text = [Link]([Link](),
[Link]),
text_size = [Link],
text_color = chart.fg_color,
text_halign= showSR ? text.align_right :
text.align_center,force_overlay=true
)
else
macroUpperBox.set_text([Link]([Link](), [Link]))
box.set_left(macroUpperBox, macroStartIdx)
box.set_right(macroUpperBox, macroEndIdx)
[Link](macroHighs)

// Draw and update lower box for Macro period


if na(macroLowerBox) and [Link] and showMacro
macroLowerBox := [Link](
macroStartIdx, [Link](), macroEndIdx,
[Link]() - atrValue,
upColor, 0,
bgcolor = [Link](upColor, 60),
text = [Link]([Link](),
[Link]),
text_size = [Link],
text_color = chart.fg_color,
text_halign= showSR ? text.align_right :
text.align_center,force_overlay=true
)
else
macroLowerBox.set_text([Link]([Link](), [Link]))
box.set_left(macroLowerBox, macroStartIdx)
box.set_right(macroLowerBox, macroEndIdx)
[Link](macroLows)

// ADDITIONAL PLOTTING
-----------------------------------------------------------------------------------
---------------
// Draw line for equilibrium and box for delta volume display
if [Link] and showSR
float mid = [Link](srLowerBox.get_top(), srUpperBox.get_bottom())
[Link]([Link](srStartIdx, mid, srEndIdx, mid, color=chart.fg_color,
style=line.style_dashed,force_overlay=true)[1])

midBox := [Link](srStartIdx, srUpperBox.get_bottom(), srEndIdx,


srLowerBox.get_top(),
na, 0,
bgcolor = [Link](deltaVolSR > 0 ? upColor :
downColor, 93),
text = "Delta Volume\n" + [Link](deltaVolSR,
[Link]),
text_size = [Link], text_color=deltaVolSR > 0 ?
upColor : downColor,
text_halign = text.align_right,
text_valign=text.align_bottom,force_overlay=true)

[Link](midBox[1])

// If only macro levels are shown, handle box and line drawing
if not showSR and showMacro and [Link]
float midMacro = [Link](macroLowerBox.get_top(), macroUpperBox.get_bottom())
[Link]([Link](macroStartIdx, midMacro, macroEndIdx, midMacro,
color=chart.fg_color,
style=line.style_dashed,force_overlay=true)[1])

// Display Macro Delta Volume as a table


if showMacro and [Link]
var table deltaTable = [Link](position.top_right, 5, 5,force_overlay=true)
[Link](deltaTable, 0, 0,
text = "Macro\n Delta Volume:\n" +
[Link](deltaVolMacro, [Link]),
text_color = deltaVolMacro > 0 ? upColor : downColor,
text_size = [Link])

///////////////////////////////////////////////////////////////////////////////////
/////////////////////////

// Input parameters

candle_stability_index_param = [Link](0.5, 'Candle Stability Index', 0, 1,


step=0.1, group='Technical', tooltip='Candle Stability Index measures the ratio
between the body and the wicks of a candle. Higher - more stable.')

rsi_index_param = [Link](50, 'RSI Index', 0, 100, group='Technical',


tooltip='RSI Index measures how overbought/oversold is the market. Higher - more
overbought/oversold.')

candle_delta_length_param = [Link](5, 'Candle Delta Length', 3,


group='Technical', tooltip='Candle Delta Length measures the period over how many
candles the price increased/decreased. Higher - longer period.')

disable_repeating_signals_param = [Link](true, 'Disable Repeating Signals',


group='Technical', tooltip='Removes repeating signals. Useful for removing clusters
of signals and general clarity')

// ATR parameters

atr_length = [Link](14, 'ATR Length', group='Risk Management', tooltip='ATR


Length determines the number of periods for calculating ATR.')

atr_multiplier_tp = [Link](1.5, 'ATR Take-Profit Multiplier', 0.1, 10,


step=0.1, group='Risk Management')
atr_multiplier_sl = [Link](1.0, 'ATR Stop-Loss Multiplier', 0.1, 10, step=0.1,
group='Risk Management')

// Trailing Stop parameters

use_trailing_stop = [Link](true, 'Enable Trailing Stop-Loss', group='Risk


Management', tooltip='Enable trailing stop-loss to lock in profits.')

trailing_stop_multiplier = [Link](1.0, 'Trailing Stop ATR Multiplier', 0.1,


10, step=0.1, group='Risk Management')

// Colors and styles

GREEN = [Link](29, 255, 40)

RED = [Link](255, 0, 0)

TRANSPARENT = [Link](0, 0, 0, 100)

label_size = [Link]('normal', 'Label Size', options=['huge', 'large',


'normal', 'small', 'tiny'], group='Cosmetic')

label_style = [Link]('text bubble', 'Label Style', ['text bubble',


'triangle', 'arrow'], group='Cosmetic')

buy_label_color = input(GREEN, 'BUY Label Color', inline='Highlight',


group='Cosmetic')

sell_label_color = input(RED, 'SELL Label Color', inline='Highlight',


group='Cosmetic')

label_text_color = input([Link], 'Label Text Color', inline='Highlight',


group='Cosmetic')

// Calculations

atr_value = [Link](atr_length)

// Technical signals

stable_candle = [Link](close - open) / [Link] > candle_stability_index_param

rsig = [Link](close, 14)

bullish_engulfing = close[1] < open[1] and close > open and close > open[1]
rsi_below = rsig < rsi_index_param

decrease_over = close < close[candle_delta_length_param]

bull = bullish_engulfing and stable_candle and rsi_below and decrease_over and


[Link]

bearish_engulfing = close[1] > open[1] and close < open and close < open[1]

rsi_above = rsig > 100 - rsi_index_param

increase_over = close > close[candle_delta_length_param]

bear = bearish_engulfing and stable_candle and rsi_above and increase_over and


[Link]

// Track last signal

var string last_signal = na

if bull and (disable_repeating_signals_param ? (last_signal != 'buy') : true)

// Calculate BUY take-profit and stop-loss

take_profit_buy = close + (atr_value * atr_multiplier_tp)

stop_loss_buy = close - (atr_value * atr_multiplier_sl)

// Plot BUY label with TP and SL

if label_style == 'text bubble'

[Link](bar_index, low, 'BUY\nTP: ' + [Link](take_profit_buy,


"#.##") + '\nSL: ' + [Link](stop_loss_buy, "#.##"), color=buy_label_color,
style=label.style_label_up, textcolor=label_text_color,
size=label_size,force_overlay=true)

else if label_style == 'triangle'

[Link](bar_index, low, 'BUY\nTP: ' + [Link](take_profit_buy,


"#.##") + '\nSL: ' + [Link](stop_loss_buy, "#.##"), yloc=[Link],
color=buy_label_color, style=label.style_triangleup, textcolor=TRANSPARENT,
size=label_size,force_overlay=true)

else if label_style == 'arrow'

[Link](bar_index, low, 'BUY\nTP: ' + [Link](take_profit_buy,


"#.##") + '\nSL: ' + [Link](stop_loss_buy, "#.##"), yloc=[Link],
color=buy_label_color, style=label.style_arrowup, textcolor=TRANSPARENT,
size=label_size,force_overlay=true)

last_signal := 'buy'

if bear and (disable_repeating_signals_param ? (last_signal != 'sell') : true)

// Calculate SELL take-profit and stop-loss

take_profit_sell = close - (atr_value * atr_multiplier_tp)

stop_loss_sell = close + (atr_value * atr_multiplier_sl)

// Plot SELL label with TP and SL

if label_style == 'text bubble'

[Link](bar_index, high, 'SELL\nTP: ' + [Link](take_profit_sell,


"#.##") + '\nSL: ' + [Link](stop_loss_sell, "#.##"), color=sell_label_color,
style=label.style_label_down, textcolor=label_text_color,
size=label_size,force_overlay=true)

else if label_style == 'triangle'

[Link](bar_index, high, 'SELL\nTP: ' + [Link](take_profit_sell,


"#.##") + '\nSL: ' + [Link](stop_loss_sell, "#.##"), yloc=[Link],
color=sell_label_color, style=label.style_triangledown, textcolor=TRANSPARENT,
size=label_size,force_overlay=true)

else if label_style == 'arrow'

[Link](bar_index, high, 'SELL\nTP: ' + [Link](take_profit_sell,


"#.##") + '\nSL: ' + [Link](stop_loss_sell, "#.##"), yloc=[Link],
color=sell_label_color, style=label.style_arrowdown, textcolor=TRANSPARENT,
size=label_size,force_overlay=true)

last_signal := 'sell'

// Alerts

alertcondition(bull, 'BUY Signals', 'New signal: BUY')

alertcondition(bear, 'SELL Signals', 'New signal: SELL')


// Trailing Stop-Loss Logic

var float trailing_stop = na

if use_trailing_stop

if last_signal == 'buy' and close > trailing_stop[1] + (atr_value *


trailing_stop_multiplier)

trailing_stop := close - (atr_value * trailing_stop_multiplier)

if last_signal == 'sell' and close < trailing_stop[1] - (atr_value *


trailing_stop_multiplier)

trailing_stop := close + (atr_value * trailing_stop_multiplier)

You might also like