0% found this document useful (0 votes)
763 views7 pages

Asset Bender Algo Indicator

Pinescript code

Uploaded by

warumonokisou
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)
763 views7 pages

Asset Bender Algo Indicator

Pinescript code

Uploaded by

warumonokisou
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
You are on page 1/ 7

//@version=4

study("Asset Bender Algo", overlay = true)


Periods = 10 // input(title="ATR Period", type=input.integer, defval=10)
src = hl2 //input(hl2, title="Source")
Multiplier = input(title="Sensitivity (0.5 - 2.5)", type=input.float, step=0.1,
defval=2.0, minval=0.5, maxval=2.5)
changeATR= true//input(title="Change ATR Calculation Method ?", type=input.bool,
defval=true)
showsignals = true//input(title="Show Buy/Sell Signals ?", type=input.bool,
defval=true)
highlighting = true //input(title="Highlighter On/Off ?", type=input.bool,
defval=true)
show_cloud = input(true, title="Show Cloud MA")
autolines = input(false, title="Auto Trend Lines")
show_macross = input(true, title="Show MA Cross")

atr2 = sma(tr, Periods)


atr= changeATR ? atr(Periods) : atr2
up=src-(Multiplier*atr)
up1 = nz(up[1],up)
up := close[1] > up1 ? max(up,up1) : up
dn=src+(Multiplier*atr)
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? min(dn, dn1) : dn

trend = 1
trend := nz(trend[1], trend)
trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend
upPlot = plot(autolines and trend == 1 ? up : na, title="Up Trend",
style=plot.style_linebr, linewidth=2, color=color.white)
buySignal = trend == 1 and trend[1] == -1

dnPlot = plot(autolines and trend ==-1 ? dn : na, title="Down Trend",


style=plot.style_linebr, linewidth=2, color=color.white)
sellSignal = trend == -1 and trend[1] == 1

long = buySignal
short= sellSignal

pos = 0.0
pos:= long? 1 : short? -1 : pos[1]

longCond = long and pos[1]!= 1


shortCond = short and pos[1]!=-1

long_entry = valuewhen(longCond , close, 0)


short_entry = valuewhen(shortCond, close, 0)

i_sl = input(2.0, title="Stop Loss % (0 to Disable)", minval=0)


sl = i_sl >0? i_sl /100 : 99999

sl_long = long_entry * (1 - sl)


sl_short = short_entry * (1 + sl)

tp_long1 = long_entry * (1 + sl)


tp_short1 = short_entry * (1 - sl)
tp_long2 = long_entry * (1 + sl*2)
tp_short2 = short_entry * (1 - sl*2)

tp_long3 = long_entry * (1 + sl*3)


tp_short3 = short_entry * (1 - sl*3)

// Position Adjustment
long_sl = low <sl_long and pos[1]==1
short_sl = high>sl_short and pos[1]==-1

final_long_tp = high>tp_long3 and pos[1]==1


final_short_tp = low <tp_short3 and pos[1]==-1

if long_sl or short_sl or final_long_tp or final_short_tp


pos:=0

long_index = valuewhen(longCond, bar_index, 0)


short_index= valuewhen(shortCond, bar_index, 0)

lastcol = pos==1? #03dbfc : #b1b4b5

if barstate.islast and pos!=0


line_e = line.new(bar_index, pos>0?long_entry :short_entry , pos>0?
long_index:short_index, pos>0?long_entry :short_entry , color=lastcol )
line.delete(line_e [1])

line_sl = line.new(bar_index, pos>0?sl_long :sl_short , pos>0?


long_index:short_index, pos>0?sl_long :sl_short , color=color.red )
line_tp1 = line.new(bar_index, pos>0?tp_long1:tp_short1, pos>0?
long_index:short_index, pos>0?tp_long1:tp_short1, color=color.green)
line_tp2 = line.new(bar_index, pos>0?tp_long2:tp_short2, pos>0?
long_index:short_index, pos>0?tp_long2:tp_short2, color=color.green)
line_tp3 = line.new(bar_index, pos>0?tp_long3:tp_short3, pos>0?
long_index:short_index, pos>0?tp_long3:tp_short3, color=color.green)
line.delete(line_sl [1])
line.delete(line_tp1[1])
line.delete(line_tp2[1])
line.delete(line_tp3[1])

lbl_e = label.new(bar_index, pos>0?long_entry :short_entry , color=lastcol ,


textcolor=#000000, style=label.style_label_left, text="Entry: " + tostring(pos>0?
long_entry :short_entry ))
label.delete(lbl_e[1])

lbl_sl = label.new(bar_index, pos>0?sl_long :sl_short , color=color.red ,


textcolor=#000000, style=label.style_label_left, text="Stop Loss: " +
tostring(round((pos>0?sl_long :sl_short) *100)/100))
lbl_tp1 = label.new(bar_index, pos>0?tp_long1:tp_short1, color=color.green,
textcolor=#000000, style=label.style_label_left, text="(1-1) Take Profit: " +
tostring(round((pos>0?tp_long1:tp_short1) * 100)/100))
lbl_tp2 = label.new(bar_index, pos>0?tp_long2:tp_short2, color=color.green,
textcolor=#000000, style=label.style_label_left, text="(2-1) Take Profit: " +
tostring(round((pos>0?tp_long2:tp_short2) * 100)/100))
lbl_tp3 = label.new(bar_index, pos>0?tp_long3:tp_short3, color=color.green,
textcolor=#000000, style=label.style_label_left, text="(3-1) Take Profit: " +
tostring(round((pos>0?tp_long3:tp_short3) * 100)/100))
label.delete(lbl_sl [1])
label.delete(lbl_tp1[1])
label.delete(lbl_tp2[1])
label.delete(lbl_tp3[1])

plotshape(longCond ? up : na, title="UpTrend Begins", location=location.belowbar,


style=shape.circle, size=size.tiny, color=#03dbfc, transp=0)
plotshape(longCond and showsignals ? up : na, title="Buy", text="Buy",
location=location.belowbar, style=shape.labelup, size=size.tiny, color=#03dbfc,
textcolor=color.white, transp=0)
plotshape(shortCond ? dn : na, title="DownTrend Begins",
location=location.abovebar, style=shape.circle, size=size.tiny, color=#b1b4b5,
transp=0)
plotshape(shortCond and showsignals ? dn : na, title="Sell", text="Sell",
location=location.abovebar, style=shape.labeldown, size=size.tiny, color=#b1b4b5,
textcolor=color.white, transp=0)

mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)


longFillColor = highlighting ? (trend == 1 ? color.blue: color.white) : color.white
shortFillColor = highlighting ? (trend == -1 ? color.red : color.white) :
color.white

long_alert_text = tostring(syminfo.ticker) + " BUY ALERT! " +


"Entry: " + tostring(long_entry) +
", Take Profit 1: " + tostring(tp_long1) +
", Take Profit 2: " + tostring(tp_long2) +
", Take Profit 3: " + tostring(tp_long3) +
", Stop Loss: " + tostring(sl_long)

short_alert_text = tostring(syminfo.ticker) + " SELL ALERT!" +


", Entry: " + tostring(short_entry) +
", Take Profit 1: " + tostring(tp_short1) +
", Take Profit 2: " + tostring(tp_short2) +
", Take Profit 3: " + tostring(tp_short3) +
", Stop Loss: " + tostring(sl_short)

json_data_long = '{"content": "' + long_alert_text + '"}'


json_data_short = '{"content": "' + short_alert_text + '"}'

if longCond
alert(json_data_long, alert.freq_once_per_bar_close)
// alert('{"content": "' +tostring(long_entry)+ '"}')

if shortCond
alert(json_data_short, alert.freq_once_per_bar_close)
// alert('{"content": "' +tostring(long_entry) + '"}')

// alertcondition(longCond, title="Buy", message= long_alert_text)


// alert(shortCond, title="Sell", message= short_alert_text)
changeCond = trend != trend[1]
alertcondition(changeCond, title="Trend Direction Change", message="Trend has
changed direction!")

barcolor(trend == -1? #b1b4b5 : #03dbfc)


last_line = trend == 1 ? up : dn
l = label.new(bar_index, last_line, style=label.style_label_left, color=trend == -
1? #b1b4b5 : #03dbfc, textcolor=#000000, text=trend == -1? "Bearish" : "Bullish")
label.delete(l[1])

// MACD Cloud
cloud_val = 10 // input(title = "Cloud SMA", defval = 100, minval = 5, maxval =
500, type = input.integer)
sma_high = ema(high,cloud_val)
sma_low = ema(low, cloud_val)
plot_high = plot(show_cloud? sma_high : na, color = na, transp = 1, editable =
false)
plot_low = plot(show_cloud? sma_low : na, color = na, transp = 1, editable =
false)
[macdLine, signalLine, histLine] = macd(close, 12, 26, 9)

// To be able to properly configure colors in input field need to treat these as 4


different conditions vs one complex line.
fill(plot_high, plot_low, color = (macdLine > 0) and (macdLine[0] > macdLine[1]) ?
#03dbfc : na, title = "Positive Uptrend")
fill(plot_high, plot_low, color = macdLine > 0 and macdLine[0] < macdLine[1] ?
#03dbfc : na, title = "Positive Downtrend")
fill(plot_high, plot_low, color = macdLine < 0 and macdLine[0] < macdLine[1] ?
#fde5e4 : na, title = "Negative Uptrend")
fill(plot_high, plot_low, color = macdLine < 0 and macdLine[0] > macdLine[1] ?
#fde5e4 : na, title = "Negative Downtrend")

//// MA CROSS
//shortx = sma(close, 9)
//longx = sma(close, 21)
//plot(show_macross?shortx :na, color = #f27979)
//plot(show_macross?longx :na, color = #03cdff)
//plot(show_macross and cross(shortx, longx) ? shortx : na, style =
plot.style_cross, linewidth = 4)

// S/R
show_sr = input(true, title='Show S/R')
line_width = 1 // input(4, type = input.integer, title="SR Level line Width")
level_min_lengh = input(4, type = input.integer, title="Set minimum number of bars
from level start to qualify a level")
y = "Orange" // input("Orange", "Line Color", options=["Red", "Lime", "Orange",
"Teal", "Yellow", "White", "Black"])
line_extend = input(false, type = input.bool, title = "Extend Level line Right") ?
extend.right : extend.none
sr_tf = input("", type = input.resolution, title="SR Timeframe")

//color function
colour(z) => z=="Red"?color.red:z=="Lime"?color.lime:z=="Orange"?
color.orange:z=="Teal"?
color.teal:z=="Yellow"?color.yellow:z=="Black"?color.black:color.white

//Legacy RSI calc


rsi_src = close, len = 9
upx1 = rma(max(change(rsi_src), 0), len)
downx1 = rma(-min(change(rsi_src), 0), len)
legacy_rsi = downx1 == 0 ? 100 : upx1 == 0 ? 0 : 100 - (100 / (1 + upx1 / downx1))
//CMO based on HMA
length = 1
src1 = hma(open, 5)[1] // legacy hma(5) calculation gives a resul with one candel
shift, thus use hma()[1]
src2 = hma(close, 12)
momm1 = change(src1)
momm2 = change(src2)
f1(m, n) => m >= n ? m : 0.0
f2(m, n) => m >= n ? 0.0 : -m
m1 = f1(momm1, momm2)
m2 = f2(momm1, momm2)
sm1 = sum(m1, length)
sm2 = sum(m2, length)
percent(nom, div) => 100 * nom / div
cmo_new = percent(sm1-sm2, sm1+sm2)

//Legacy Close Pivots calcs.


len5 = 2
hh = highest(len5)
h1 = dev(hh, len5) ? na : hh
hpivot = fixnan(h1)
ll = lowest(len5)
l1 = dev(ll, len5) ? na : ll
lpivot = fixnan(l1)

//Calc Values

rsi_new = rsi(close,9)
lpivot_new = lpivot // use legacy pivots calculation as integrated
pivotlow/pivothigh functions give very different result
hpivot_new = hpivot

sup = rsi_new < 25 and cmo_new > 50 and lpivot_new


res = rsi_new > 75 and cmo_new < -50 and hpivot_new
calcXup() =>
var xup = 0.0
xup := sup ? low : xup[1]
calcXdown() =>
var xdown = 0.0
xdown := res ? high : xdown[1]

//Lines drawing variables


tf1 = security(syminfo.tickerid, sr_tf, calcXup(), lookahead=barmerge.lookahead_on)
tf2 = security(syminfo.tickerid, sr_tf, calcXdown(),
lookahead=barmerge.lookahead_on)

//SR Line plotting


var tf1_line = line.new(0, 0, 0, 0)
var tf1_bi_start = 0
var tf1_bi_end = 0
tf1_bi_start := change(tf1) ? bar_index : tf1_bi_start[1]
tf1_bi_end := change(tf1) ? tf1_bi_start : bar_index
if change(tf1)
if (line.get_x2(tf1_line) - line.get_x1(tf1_line)) < level_min_lengh
line.delete(tf1_line)
if show_sr
tf1_line := line.new(tf1_bi_start, tf1, tf1_bi_end, tf1, color = #0fdfe6,
width = line_width, extend = line_extend)
line.set_x2(tf1_line, tf1_bi_end)
var tf2_line = line.new(0, 0, 0, 0)
var tf2_bi_start = 0
var tf2_bi_end = 0
tf2_bi_start := change(tf2) ? bar_index : tf2_bi_start[1]
tf2_bi_end := change(tf2) ? tf2_bi_start : bar_index
if change(tf2)
if (line.get_x2(tf2_line) - line.get_x1(tf2_line)) < level_min_lengh
line.delete(tf2_line)
if show_sr
tf2_line := line.new(tf2_bi_start, tf2, tf2_bi_end, tf2, color = #0fdfe6,
width = line_width, extend = line_extend)
line.set_x2(tf2_line, tf2_bi_end)

// TENDLINES
lb = input(30, title="Trendline Left Bars", minval=1)
rb = input(30, title="Trendline Right Bars", minval=1)
showpivot = false //input(true, title="Trendline - Show Pivot Points")
chdashed = input(true, title="Show Old Trend Line as Dashed")
mb = lb + rb + 1
float top = na
float bot = na
top := iff(not na(high[mb]), iff(highestbars(high, mb) == -rb, high[rb], na),
na) // Pivot High
bot := iff(not na(low[mb]), iff(lowestbars(low, mb) == -rb, low[rb], na), na) //
Pivot Low
plotshape(top and showpivot, text="[PH]", style=shape.labeldown, color=color.white,
textcolor=color.black, location=location.abovebar, transp=0, offset = -rb)
plotshape(bot and showpivot, text="[PL]", style=shape.labeldown, color=color.white,
textcolor=color.black, location=location.belowbar, transp=0, offset = -rb)
ltop = valuewhen(top, top, 1)
bst = 0
bst := top ? 1 : nz(bst[1]) + 1

float t_angle = 0.0


t_angle := t_angle[1]

if not na(ltop) and not na(top)


line tline = na
if ltop > top
tline := line.new(bar_index - bst[1] - rb, high[bst[1] + rb], bar_index -
rb, high[rb], color = #03cdff, extend = extend.right)
t_angle := (high[bst[1] + rb] - high[rb]) / bst[1]
if t_angle < t_angle[1] and t_angle[1] != 0
line.set_extend(tline[1], extend = extend.none)
if t_angle > t_angle[1] and t_angle[1] != 0
line.set_extend(tline, extend = extend.none)
if ltop <= top
t_angle := 0.0
if chdashed
line.set_style(tline[1], style = line.style_dashed)
lbot = valuewhen(bot, bot, 1)
bsb = 0
bsb := bot ? 1 : nz(bsb[1]) + 1
float b_angle = 0.0
b_angle := b_angle[1]
if not na(lbot) and not na(bot)
line bline = na
if lbot < bot
bline := line.new(bar_index - bsb[1] - rb, low[bsb[1] + rb], bar_index -
rb, low[rb], color = #03cdff, extend = extend.right)
b_angle := (low[bsb[1] + rb] - low[rb]) / bsb[1]
if b_angle > b_angle[1] and b_angle[1] != 0
line.set_extend(bline[1], extend = extend.none)
if b_angle < b_angle[1] and b_angle[1] != 0
line.set_extend(bline, extend = extend.none)
if lbot >= bot
b_angle := 0.0
if chdashed
line.set_style(bline[1], style = line.style_dashed)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy