(Imba) Algo
(Imba) Algo
me/+UAk3hqvoD89jZTlk
//@version=5
indicator(title='[IMBA] ALGO | EYO', shorttitle='[IMBA] ALGO', overlay=true,
max_lines_count = 500, max_labels_count = 500, max_bars_back = 1)
//FUNCTIONS
RoundUp(number, decimals) =>
factor = math.pow(10, decimals)
math.ceil(number * factor) / factor
calc_rr(float entry_price, float sl_price, float take_price) =>
entry_price > sl_price ? (take_price - entry_price) / (entry_price -
sl_price) : (entry_price - take_price) / (sl_price - entry_price)
type Trade
int start_bar_index = 0
string side
float market_order_comission
float limit_order_comission
float entry_price
bool entry_hit = false
float sl_price
float tp1_price
float tp1_percent_fix
float tp2_price
float tp2_percent_fix
float tp3_price
float tp3_percent_fix
float tp4_price
float tp4_percent_fix
float break_even_price
bool sl_hit = false
bool tp1_hit = false
bool tp2_hit = false
bool tp3_hit = false
bool tp4_hit = false
float position_size_left = 100
float risk_percent
bool is_closed = false
float close_price = 0
bool can_break_even = false
bool force_closed = false
float profit = 0
float risk_reward
line entry_line
line stoploss_line
line target1_line
line target2_line
line target3_line
line target4_line
// STRATS
selector(string strategy_name) =>
strategy_settings = Strategy_settings.new()
switch strategy_name
"MANUAL" =>
strategy_settings.sensitivity := 18
strategy_settings.risk_percent := 1
strategy_settings.break_even_target := "1"
strategy_settings.tp1_percent := 1
strategy_settings.tp1_percent_fix := 40
strategy_settings.tp2_percent := 2
strategy_settings.tp2_percent_fix := 30
strategy_settings.tp3_percent := 3
strategy_settings.tp3_percent_fix := 20
strategy_settings.tp4_percent := 4
strategy_settings.tp4_percent_fix := 10
strategy_settings.fixed_stop := false
strategy_settings.sl_percent := 0.0
"UNIVERSAL 15m" =>
strategy_settings.sensitivity := 20
strategy_settings.risk_percent := 1
strategy_settings.break_even_target := "1"
strategy_settings.tp1_percent := 1
strategy_settings.tp1_percent_fix := 40
strategy_settings.tp2_percent := 2
strategy_settings.tp2_percent_fix := 30
strategy_settings.tp3_percent := 3
strategy_settings.tp3_percent_fix := 20
strategy_settings.tp4_percent := 4
strategy_settings.tp4_percent_fix := 10
strategy_settings.fixed_stop := false
strategy_settings.sl_percent := 0.0
"SOL 5m" =>
strategy_settings.sensitivity := 20
strategy_settings.risk_percent := 1
strategy_settings.break_even_target := "1"
strategy_settings.tp1_percent := 1
strategy_settings.tp1_percent_fix := 40
strategy_settings.tp2_percent := 2
strategy_settings.tp2_percent_fix := 30
strategy_settings.tp3_percent := 3
strategy_settings.tp3_percent_fix := 20
strategy_settings.tp4_percent := 4
strategy_settings.tp4_percent_fix := 10
strategy_settings.fixed_stop := false
strategy_settings.sl_percent := 0.0
strategy_settings
// STRATS
int fibo_lines_transparend = 60
int fill_best_transparend = 95
int fill_worst_transparend = 98
tp_sl_entry_transparent = 30
color tp_color = color.new(color.green, tp_sl_entry_transparent)
color entry_color = color.rgb(120, 123, 134, tp_sl_entry_transparent)
color sl_color = color.new(color.red, tp_sl_entry_transparent)
line_style = line.style_dotted
//---------------------------------------------------
SETTINGS----------------------------------------------------------\\
// STRATS
var float sensitivity = 18
float risk_percent = 1
string break_even_target = "2"
float tp1_percent = 0
float tp1_percent_fix = 0
float tp2_percent = 0
float tp2_percent_fix = 0
float tp3_percent = 0
float tp3_percent_fix = 0
float tp4_percent = 0
float tp4_percent_fix = 0
bool fixed_stop = false
float sl_percent = 0
// MAIN
sensitivity_input = input.float(title = 'Sensitive', step = 0.1, defval = 18)
start_date_input = input.time(defval = timestamp("1 June 2023"), title = "Start
calculating date")
// POSITION
show_tp_enty_sl = input.bool(defval = true, title = "Show", group = POSITION,
inline = "2.1")
fill_positions = input.bool(defval = true, title = "Fill", group = POSITION, inline
= "2.1")
risk_percent_input = input.float(title = "Risk %", step = 1, defval = 1, group =
POSITION, tooltip = "EN:\nMaximum allowable loss % of the deposit per 1 trade\nRU:\
nМаксимально допустимая потеря % от депозита на 1 сделку")
break_even_target_input = input.string(title = "BE target", options =
["WITHOUT","1","2","3"], defval = "1", group = POSITION)
initial_deposit_input = input.float(title = "Initial deposit", defval = 1000, step
= 100, group = POSITION)
// STOPLOSS
fixed_stop_input = input.bool(defval = false, title = "Fixed stoploss %", group =
STOP_LOSS, tooltip = "EN:\nIf choosed: stoploss will be calculated manually \nIf
NOT choosed: stoploss will be calculated automatic\nRU:\nЕсли выбрано: стоп будет
рассчитываться вручную \nЕсли НЕ выбрано: стоп будет рассчитываться автоматически")
sl_percent_input = input.float(title="SL %", step = 0.1, defval=0.00, group =
STOP_LOSS)
// TAKE PROFITS
tp1_percent_input = input.float(title="TP 1", step = 0.05, defval=1.00, minval = 0,
group = TAKE_PROFITS, inline = "2.2")
tp1_percent_fix_input = input.float(title = "Fix %", step = 5, defval=40, group =
TAKE_PROFITS, inline = "2.2")
tp2_percent_input = input.float(title="TP 2", step = 0.05, defval=2.00, minval = 0,
group = TAKE_PROFITS, inline = "2.3")
tp2_percent_fix_input = input.float(title = "Fix %", step = 5, defval=30, group =
TAKE_PROFITS, inline = "2.3")
tp3_percent_input = input.float(title="TP 3", step = 0.05, defval=3.00, minval = 0,
group = TAKE_PROFITS, inline = "2.4")
tp3_percent_fix_input = input.float(title = "Fix %", step = 5, defval=20, group =
TAKE_PROFITS, inline = "2.4")
tp4_percent_input = input.float(title="TP 4", step = 0.05, defval=4.00, minval = 0,
group = TAKE_PROFITS, inline = "2.5")
tp4_percent_fix_input = input.float(title = "Fix %", step = 5, defval=10, group =
TAKE_PROFITS, inline = "2.5")
// RSI
show_rsi = input.bool(defval = false, title = "Show", group = rsi_group, inline =
"3.1")
len = input(title="Length", defval=14, group = rsi_group, inline = "3.2")
overbought = input(title="Overbought", defval=78, group = rsi_group, inline =
"3.3")
oversold = input(title="Oversold", defval=22, group = rsi_group, inline = "3.3")
// INFO PANEL
show_profit_panel = input.bool(defval = true, title = "Show profit panel", group =
info_panel_group)
show_strategy_panel = input.bool(defval = false, title = "Show strategy panel",
group = info_panel_group)
show_old_panel = input.bool(defval = false, title = "Show old panel", group =
info_panel_group)
// DEV
show_dev_labels = input.bool(defval = false, title = "Show", group = dev_settings,
tooltip = "Shows all possible events")
//-----------------------------------------------GLOBAL
VARIABLES------------------------------------------------------\\
var float total_profit = 0.0
var int trade_count = 0
var int profit_trades = 0
var int loss_trades = 0
var int loss_streak = 0
var int loss_in_a_row = 0
var int win_streak = 0
var int wins_in_a_row = 0
var int first_trade_date = na
var Trade trade = na
var bool is_long_trend_started = false
var bool is_short_trend_started = false
var bool is_trend_change = na
var bool is_long_trend = false
var bool is_short_trend = false
var bool can_long = false
var bool can_short = false
sensitivity := strategy_s.sensitivity
risk_percent := strategy_s.risk_percent
break_even_target := strategy_s.break_even_target
tp1_percent := strategy_s.tp1_percent
tp1_percent_fix := strategy_s.tp1_percent_fix
tp2_percent := strategy_s.tp2_percent
tp2_percent_fix := strategy_s.tp2_percent_fix
tp3_percent := strategy_s.tp3_percent
tp3_percent_fix := strategy_s.tp3_percent_fix
tp4_percent := strategy_s.tp4_percent
tp4_percent_fix := strategy_s.tp4_percent_fix
fixed_stop := strategy_s.fixed_stop
sl_percent := strategy_s.sl_percent
sensitivity *= 10
tp1_percent /= 100
tp2_percent /= 100
tp3_percent /= 100
tp4_percent /= 100
tp1_percent_fix /= 100
tp2_percent_fix /= 100
tp3_percent_fix /= 100
tp4_percent_fix /= 100
sl_percent /= 100
high_line = ta.highest(high, int(sensitivity))
low_line = ta.lowest(low, int(sensitivity))
channel_range = high_line - low_line
fib_236 = high_line - channel_range * (0.236)
fib_382 = high_line - channel_range * 0.382
fib_5 = high_line - channel_range * 0.5
fib_618 = high_line - channel_range * 0.618
fib_786 = high_line - channel_range * (0.786)
imba_trend_line = fib_5
// CAN LONG/SHORT
if time >= start_date_input
can_long := close >= imba_trend_line and close >= fib_236 and not is_long_trend
can_short := close <= imba_trend_line and close <= fib_786 and not
is_short_trend
if can_long
is_long_trend := true
is_short_trend := false
is_long_trend_started := is_long_trend_started ? false : true
else if can_short
is_short_trend := true
is_long_trend := false
is_short_trend_started := is_short_trend_started ? false : true
else
is_trend_change := false
can_long := false
can_short := false
is_short_trend_started := false
is_long_trend_started := false
// LOGIC
if not na(trade)
calc_profit(trade, show_dev_labels)
if is_trend_change and not trade.is_closed
close_trade(trade, show_dev_labels)
if not trade.is_closed
label.set_x(entry_label, bar_index - 3)
label.set_text(entry_label, str.tostring(trade.side == "LONG" ? "🔰" : "🔰")
+ str.tostring(trade.entry_price))
label.set_x(sl_label, bar_index - 3)
label.set_text(sl_label, "⛔" + str.tostring(trade.sl_price))
label.set_x(tp1_label, bar_index - 3)
label.set_text(tp1_label, str.tostring(trade.tp1_hit ? "" : " ") +
1️⃣
str.tostring(trade.tp1_price))
label.set_x(tp2_label, bar_index - 3)
2️⃣
label.set_text(tp2_label, str.tostring(trade.tp2_hit ? "" : " ") +
str.tostring(trade.tp2_price))
label.set_x(tp3_label, bar_index - 3)
3️⃣
label.set_text(tp3_label, str.tostring(trade.tp3_hit ? "" : " ") +
str.tostring(trade.tp3_price))
label.set_x(tp4_label, bar_index - 3)
4️⃣
label.set_text(tp4_label, str.tostring(trade.tp4_hit ? "" : " ") +
str.tostring(trade.tp4_price))
line.set_xy1(tp1_line, trade.start_bar_index, trade.tp1_price)
line.set_xy2(tp1_line, bar_index + 1, trade.tp1_price)
line.set_xy1(tp2_line, trade.start_bar_index, trade.tp2_price)
line.set_xy2(tp2_line, bar_index + 1, trade.tp2_price)
line.set_xy1(tp3_line, trade.start_bar_index, trade.tp3_price)
line.set_xy2(tp3_line, bar_index + 1, trade.tp3_price)
line.set_xy1(tp4_line, trade.start_bar_index, trade.tp4_price)
line.set_xy2(tp4_line, bar_index + 1, trade.tp4_price)
line.set_xy1(entry_line, trade.start_bar_index, trade.entry_price)
line.set_xy2(entry_line, bar_index + 1, trade.entry_price)
line.set_xy1(sl_line, trade.start_bar_index, trade.sl_price)
line.set_xy2(sl_line, bar_index + 1, trade.sl_price)
lable_at_signal.set_x(int(math.avg(bar_index, trade.start_bar_index)))
sign = trade.profit >= 0 ? "+" : na
lable_at_signal.set_text(sign + str.tostring(trade.profit, "#.##") + "%")
lable_at_signal.set_color(trade.profit >= 0 ? color.green : color.red)
// FILLING
if fill_positions
if trade.tp1_hit
linefill.new(entry_line, tp1_line, color = color.new(color.green, 85))
if trade.tp2_hit
linefill.new(tp1_line, tp2_line, color = color.new(color.green, 85))
if trade.tp3_hit
linefill.new(tp2_line, tp3_line, color = color.new(color.green, 85))
if trade.tp4_hit
linefill.new(tp3_line, tp4_line, color = color.new(color.green, 85))
if trade.sl_hit
linefill.new(sl_line, entry_line, color = color.new(color.red, 85))
if trade.force_closed
close_line := line.new(x1=trade.start_bar_index, y1=trade.close_price,
x2=bar_index, y2=trade.close_price, color=color.white, style = line_style, width =
2)
if trade.profit <= 0
linefill.new(close_line, entry_line, color = color.new(color.red,
85))
if trade.is_closed
dep := (trade.profit / 100 * dep) + dep
label.delete(entry_label)
label.delete(sl_label)
label.delete(tp1_label)
label.delete(tp2_label)
label.delete(tp3_label)
label.delete(tp4_label)
total_profit += trade.profit
trade_count += 1
if trade.profit >= 0
profit_trades += 1
wins_in_a_row += 1
loss_in_a_row := 0
win_streak := wins_in_a_row > win_streak ? wins_in_a_row : win_streak
else
loss_trades += 1
loss_in_a_row += 1
wins_in_a_row := 0
loss_streak := loss_in_a_row > loss_streak ? loss_in_a_row :
loss_streak
trade := na
//------------------------------------------------------
RSI------------------------------------------------------------\\
rsi_value = ta.rsi(close, len)
is_overbought = rsi_value >= overbought
is_oversold = rsi_value <= oversold
plotshape(is_overbought and show_rsi ? high : na, color=color.red,
style=shape.cross, size=size.tiny, location=location.abovebar)
plotshape(is_oversold and show_rsi ? low : na, color=color.green,
style=shape.cross, size=size.tiny, location=location.belowbar)
//-----------------------------------------------------
PANELS------------------------------------------------------------\\
lim = "-------------------------------------------------------"
high_idk = "╔════════════════════════════╗"
low_idk = "╚════════════════════════════╝"
panel_str1 = high_idk + "\n" + "[IMBA] ALGO" + "\n" + low_idk
panel_str13 = "First signal: " + str.format("{0,date,hh:mm} {0,date,long}",
first_trade_date) + "\n" + lim
panel_str14 = "Signal closed: " + str.tostring(trade_count) + " " +
"Winrate: " + str.tostring(RoundUp(profit_trades / trade_count * 100, 2)) + "%"
panel_str15 = "Profit signals: " + str.tostring(profit_trades) + " " +
"Loss signals: " + str.tostring(trade_count - profit_trades)
panel_str16 = "Win streak: " + str.tostring(win_streak) + " " +
"Loss streak: " + str.tostring(loss_streak) + "\n" + lim
panel_str17 = "💰 Profit: " + str.tostring(total_profit, "#.##") + "% 💰"
panel_last = "╚════════════════════════════╝"
panel_str_arr = array.from(panel_str1, panel_str13, panel_str14, panel_str15,
panel_str16, panel_str17, panel_last)
if show_old_panel
label l = label.new(bar_index + 20, close, text=array.join(panel_str_arr, "\
n"), color=color.rgb(0, 0, 0, 87), style=label.style_label_left,
textcolor=color.rgb(76, 187, 72),textalign=text.align_center)
label.delete(l[1])