You are on page 1of 5

//@version=5

// SOL / USDT -re van beállítva 30min időkereten

//CREDITS to HPotter for the orginal code. The guy trying to sell this as his own
is a scammer lol.
strategy(title='2 UT Bot Strategy', overlay=true, default_qty_type =
strategy.cash, default_qty_value = 1000, initial_capital = 1000, currency =
currency.USDT)
//================= INPUT Time WINDOW RANGE
===================================================================================
=====
FromYear = input(defval = 2024, title = "From Year",
inline = "05", group = "INPUT Time WINDOW RANGE")
FromMonth = input.int(defval = 1, title = "From Month", minval = 1, maxval = 12,
inline = "06", group = "INPUT Time WINDOW RANGE")
FromDay = input.int(defval = 1, title = "From Day", minval = 1, maxval = 31,
inline = "06", group = "INPUT Time WINDOW RANGE")
ToDay = 1
ToMonth = 1
ToYear = 9999
start = timestamp(FromYear, FromMonth, FromDay,00,00) // start of window
finish = timestamp(ToYear, ToMonth, ToDay, 00, 00) // end of window
window() => time >= start and time <= finish ? true :false // creates the
function "within window of time"
//
===================================================================================
===============================================
// ===================== Inputs
===================================================================================
================
a = input.int(defval = 2, title='Key Vaule. \'This changes the
sensitivity\'', minval = 1)
c = input.int(defval = 11, title='ATR Period', minval = 1)
h = input.bool(defval = false,title = 'Signals from Heikin Ashi Candles')
LongTP1 = input.float(defval = 1, title = "LongTP1", minval = 0, step = 0.1,
inline = "01", group = "Long TP/SL/Qty")
qtyLong1 = input.float(defval = 30, title = "QtyTP1", minval = 0, maxval =
100, step = 2, inline = "01", group = "Long TP/SL/Qty")
LongTP2 = input.float(defval = 3.7, title = "LongTP2", minval = 0, step = 0.2,
inline = "02", group = "Long TP/SL/Qty")
qtyLong2 = input.float(defval = 10, title = "QtyTP2", minval = 0, maxval =
100, step = 2, inline = "02", group = "Long TP/SL/Qty")
LongTP3 = input.float(defval = 5.7, title = "LongTP3", minval = 0, maxval =
100, step = 0.2, inline = "03", group = "Long TP/SL/Qty")
qtyLong3 = input.float(defval = 10, title = "QtyTP3", minval = 0, maxval =
100, step = 2, inline = "03", group = "Long TP/SL/Qty")
LongSL = input.float(defval = 4.8, title = "LongSL", minval = 0, step = 0.1,
inline = "04", group = "Long TP/SL/Qty")
ShortTP1 = input.float(defval = 1, title = "ShortTP1", minval = 0, step = 0.1,
inline = "01", group = "Short TP/SL/Qty")
qtyShort1 = input.float(defval = 40, title = "QtyTP1", minval = 0, maxval =
100, step = 2, inline = "01", group = "Short TP/SL/Qty")
ShortTP2 = input.float(defval = 3.2, title = "ShortTP2", minval = 0, step = 0.2,
inline = "02", group = "Short TP/SL/Qty")
qtyShort2 = input.float(defval = 40, title = "QtyTP2", minval = 0, maxval =
100, step = 2, inline = "02", group = "Short TP/SL/Qty")
ShortTP3 = input.float(defval = 5, title = "ShortTP3", minval= 0, maxval = 100,
step = 0.2, inline = "03", group = "Short TP/SL/Qty")
qtyShort3 = input.float(defval = 20, title = "QtyTP3", minval = 0, maxval =
100, step = 2, inline = "03", group = "Short TP/SL/Qty")
ShortSL = input.float(defval = 4, title = "ShortSL", minval = 0, step = 0.1,
inline = "04", group = "Short TP/SL/Qty")
//
===================================================================================
================================================
// =================== UT Bot Strategy
===================================================================================
==========
xATR = ta.atr(c)
nLoss = a * xATR
src = h ? request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period,
close, lookahead=barmerge.lookahead_off) : close
xATRTrailingStop = 0.0
iff_1 = src > nz(xATRTrailingStop[1], 0) ? src - nLoss : src + nLoss
iff_2 = src < nz(xATRTrailingStop[1], 0) and src[1] < nz(xATRTrailingStop[1], 0) ?
math.min(nz(xATRTrailingStop[1]), src + nLoss) : iff_1
xATRTrailingStop := src > nz(xATRTrailingStop[1], 0) and src[1] >
nz(xATRTrailingStop[1], 0) ? math.max(nz(xATRTrailingStop[1]), src - nLoss) : iff_2
pos = 0
iff_3 = src[1] > nz(xATRTrailingStop[1], 0) and src < nz(xATRTrailingStop[1], 0) ?
-1 : nz(pos[1], 0)
pos := src[1] < nz(xATRTrailingStop[1], 0) and src > nz(xATRTrailingStop[1], 0) ? 1
: iff_3
xcolor = pos == -1 ? color.red : pos == 1 ? color.green : color.blue
ema = ta.ema(src, 1)
above = ta.crossover(ema, xATRTrailingStop) // Cross
below = ta.crossover(xATRTrailingStop, ema) // Cross
buy = src > xATRTrailingStop and above and window() // buy logic
sell = src < xATRTrailingStop and below and window() // sell logic
barbuy = src > xATRTrailingStop
barsell = src < xATRTrailingStop
plotshape(buy, title='Buy', text='Buy', style=shape.labelup,
location=location.belowbar, color=color.new(color.green, 0),
textcolor=color.new(color.white, 0), size=size.tiny)
plotshape(sell, title='Sell', text='Sell', style=shape.labeldown,
location=location.abovebar, color=color.new(color.red, 0),
textcolor=color.new(color.white, 0), size=size.tiny)
barcolor(barbuy ? color.green : na)
barcolor(barsell ? color.red : na)
// =================== UT Bot Strategy
===================================================================================
=======
//
===================================================================================
============================================
// = It may not be good in this form / Ebben a formában nem biztos, hogy jó!
=====================================================
i_alert_txt_start_long = input.text_area(defval = "", title = "Long Start
Message", group = "Alerts")
i_alert_txt_longTP1 = input.text_area(defval = "", title = "LongTP1 Message",
group = "Alerts")
i_alert_txt_longTP2 = input.text_area(defval = "", title = "LongTP2 Message",
group = "Alerts")
i_alert_txt_longTP3 = input.text_area(defval = "", title = "LongTP3 Message",
group = "Alerts")
i_alert_txt_start_short = input.text_area(defval = "", title = "Short Start
Message", group = "Alerts")
i_alert_txt_shortTP1 = input.text_area(defval = "", title = "ShortTP1 Message",
group = "Alerts")
i_alert_txt_shortTP2 = input.text_area(defval = "", title = "ShortTP2 Message",
group = "Alerts")
i_alert_txt_shortTP3 = input.text_area(defval = "", title = "ShortTP3 Message",
group = "Alerts")
i_alert_txt_close_long = input.text_area(defval = "", title = "Long Close
Message", group = "Alerts")
i_alert_txt_close_short = input.text_area(defval = "", title = "Short Close
Message", group = "Alerts")
//
===================================================================================
============================================
//=========================== TP/SL/QTY
===================================================================================
======
LONGTP1 = strategy.position_avg_price * (1 + (LongTP1/100)) // Long TP1 price
LONGTP2 = strategy.position_avg_price * (1 + (LongTP2/100)) // Long TP2 price
LONGTP3 = strategy.position_avg_price * (1 + (LongTP3/100)) // Long TP3 price
LONGSL = strategy.position_avg_price * (1 - (LongSL/100)) // Long SL price
SHORTTP1 = strategy.position_avg_price * (1 - (ShortTP1/100)) // Short TP1 price
SHORTTP2 = strategy.position_avg_price * (1 - (ShortTP2/100)) // Short TP2 proce
SHORTTP3 = strategy.position_avg_price * (1 - (ShortTP3/100)) // Short TP3 proce
SHORTSL = strategy.position_avg_price * (1 + (ShortSL/100)) // Short SL proce
//
===================================================================================
===========================================
// ================================== Buy/Sell orders
==========================================================================
if buy
strategy.entry(id = "Long", direction = strategy.long, comment = "Long") //
Long Start
alert(i_alert_txt_start_long)
strategy.close(id = "Short", comment = "Sx") // Sx Short Close
alert(i_alert_txt_close_short)
if sell
strategy.entry(id = "Short", direction = strategy.short, comment = "SS") //
Short Start
alert(i_alert_txt_start_short)
strategy.close(id = "Long", comment = "Lx") // Lx Long Close
alert(i_alert_txt_close_long)
//================================== Long / Stop trail
=========================================================================
//longStopPrice = 0.0
//longStopPrice := if strategy.position_size > 0
// stopValue = low * (1 - LTrail/100)
// math.max(stopValue, longStopPrice[1])
//else
// 0
//shortStopPrice = 0.0
//shortStopPrice := if strategy.position_size < 0
// stopValue = close * (1 + Strail/100)
// math.min(stopValue, shortStopPrice[1])
//else
// 999999
// ================================= if Long position open
====================================================================
if strategy.position_size > 0
strategy.exit(id = "LongTP1", from_entry = "Long", qty_percent = qtyLong1,
limit = LONGTP1, comment_profit = "LongTP1")
strategy.exit(id = "LongTP2", from_entry = "Long", qty_percent = qtyLong2,
limit = LONGTP2, comment_profit = "LongTP2")
strategy.exit(id = "LongTP3", from_entry = "Long", qty_percent = qtyLong3,
limit = LONGTP3, comment_profit = "LongTP3")
strategy.exit(id = "LongSL", from_entry = "Long",
stop = LONGSL, comment_loss = "LongSL")
//================================= if Short position open
====================================================================
if strategy.position_size < 0
strategy.exit(id = "ShortTP1", from_entry = "Short", qty_percent = qtyShort1,
limit = SHORTTP1, comment_profit = "ShortTP1")
strategy.exit(id = "ShortTP2", from_entry = "Short", qty_percent = qtyShort2,
limit = SHORTTP2, comment_profit = "ShortTP2")
strategy.exit(id = "ShortTP3", from_entry = "Short", qty_percent = qtyShort3,
limit = SHORTTP3, comment_profit = "ShortTP3")
strategy.exit(id = "ShortSL", from_entry = "Short",
stop = SHORTSL, comment_loss = "ShortSL")
//
===================================================================================
==========================================

//....................................
Table .............................................................................
........
exitStats() =>
int LTP1Count = 0
int LTP2Count = 0
int LTP3Count = 0
int LSLCount = 0
int STP1Count = 0
int STP2Count = 0
int STP3Count = 0
int SSLCount = 0
if strategy.closedtrades > 0
for i = 0 to strategy.closedtrades - 1
switch strategy.closedtrades.exit_comment(i)
"LongTP1" => LTP1Count += 1
"LongTP2" => LTP2Count += 1
"LongTP3" => LTP3Count += 1
"LongSL" => LSLCount += 1
"ShortTP1" => STP1Count += 1
"ShortTP2" => STP2Count += 1
"ShortTP3" => STP3Count += 1
"ShortSL" => SSLCount += 1
[LSLCount, SSLCount, STP1Count, STP2Count, STP3Count, LTP1Count, LTP2Count,
LTP3Count]
//---
var testTable = table.new(position.bottom_right, 1, 9, color.orange, border_width =
1)
if barstate.islastconfirmedhistory
[LSLCount, SSLCount, STP1Count, STP2Count, STP3Count, LTP1Count, LTP2Count,
LTP3Count] = exitStats()
table.cell(testTable, 0, 0, "Closed trades (" +
str.tostring(strategy.closedtrades) +") stats:")
table.cell(testTable, 0, 1, "Long Stop: " + str.tostring(LSLCount))
table.cell(testTable, 0, 2, "Short Stop: " + str.tostring(SSLCount))
table.cell(testTable, 0, 3, "Short TP1: " + str.tostring(STP1Count))
table.cell(testTable, 0, 4, "Short TP2: " + str.tostring(STP2Count))
table.cell(testTable, 0, 5, "Short TP3: " + str.tostring(STP3Count))
table.cell(testTable, 0, 6, "Long TP1: " + str.tostring(LTP1Count))
table.cell(testTable, 0, 7, "Long TP2: " + str.tostring(LTP2Count))
table.cell(testTable, 0, 8, "Long TP3: " + str.tostring(LTP3Count))
//.................................................................................
...............................................

You might also like