//
//-- Merged By Hamza le 12-09-2029
//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)
create_trend_line(float sensitivity, float fib) =>
high_line = ta.highest(high, int(sensitivity))
low_line = ta.lowest(low, int(sensitivity))
channel_range = high_line - low_line
high_line - channel_range * fib
//FUNCTIONS
// TYPES AND METHODS
type Strategy_settings
float sensitivity = 0
float risk_percent = 1
string break_even_target = "1"
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
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
method calc_profit(Trade trade, bool show_labels) =>
label trade_info_label = na
label entry_hit_label = na
label tp1_hit_label = na
label tp2_hit_label = na
label tp3_hit_label = na
label tp4_hit_label = na
label sl_hit_label = na
label be_hit_label = na
float profit = 0.0
if trade.side == "LONG"
if low <= trade.entry_price and not trade.entry_hit
trade.start_bar_index := bar_index
trade.entry_hit := true
entry_hit_label := label.new(trade.start_bar_index, trade.entry_price,
str.tostring("ENTRY HIT"), style = label.style_label_right)
trade_info_label := label.new(bar_index, high, "Trade info:" + "\
nEntry: " + str.tostring(trade.entry_price) + "\nTp1: " +
str.tostring(trade.tp1_price) + "\nTp2: " + str.tostring(trade.tp2_price) + "\
nTp3:" + str.tostring(trade.tp3_price) + "\nTp4: " + str.tostring(trade.tp4_price)
+ "\nSl: " + str.tostring(trade.sl_price))
if high >= trade.tp1_price and not trade.tp1_hit and trade.entry_hit
trade.tp1_hit := true
trade.position_size_left -= trade.tp1_percent_fix
profit += calc_rr(trade.entry_price, trade.sl_price, trade.tp1_price) *
trade.tp1_percent_fix / 100 * trade.risk_percent
tp1_hit_label := label.new(trade.start_bar_index, trade.tp1_price,
str.tostring("TP1 HIT +") + str.tostring(profit, "#.##") + "%" + "\nPosition size
%: " + str.tostring(trade.position_size_left), style = label.style_label_right)
if high >= trade.tp2_price and not trade.tp2_hit and trade.entry_hit
trade.tp2_hit := true
trade.can_break_even := true
trade.position_size_left -= trade.tp2_percent_fix
profit += calc_rr(trade.entry_price, trade.sl_price, trade.tp2_price) *
trade.tp2_percent_fix / 100 * trade.risk_percent
tp2_hit_label := label.new(trade.start_bar_index, trade.tp2_price,
str.tostring("TP2 HIT +") + str.tostring(profit, "#.##") + "%" + "\nPosition size
%: " + str.tostring(trade.position_size_left), style = label.style_label_right)
if high >= trade.tp3_price and not trade.tp3_hit and trade.entry_hit
trade.tp3_hit := true
trade.position_size_left -= trade.tp3_percent_fix
profit += calc_rr(trade.entry_price, trade.sl_price, trade.tp3_price) *
trade.tp3_percent_fix / 100 * trade.risk_percent
tp3_hit_label := label.new(trade.start_bar_index, trade.tp3_price,
str.tostring("TP3 HIT +") + str.tostring(profit, "#.##") + "%" + "\nPosition size
%: " + str.tostring(trade.position_size_left), style = label.style_label_right)
if high >= trade.tp4_price and not trade.tp4_hit and trade.entry_hit
trade.tp4_hit := true
trade.is_closed := true
trade.position_size_left -= trade.tp4_percent_fix
profit += calc_rr(trade.entry_price, trade.sl_price, trade.tp4_price) *
trade.tp4_percent_fix / 100 * trade.risk_percent
tp4_hit_label := label.new(trade.start_bar_index, trade.tp4_price,
str.tostring("TP4 HIT +") + str.tostring(profit, "#.##") + "%" + "\nPosition size
%: " + str.tostring(trade.position_size_left), style = label.style_label_right)
if high >= trade.break_even_price and not trade.can_break_even and
trade.entry_hit
trade.can_break_even := true
//BE ENTRY HIT
if trade.can_break_even and trade.entry_hit
if low <= trade.entry_price and not (close >= open) and bar_index !=
trade.start_bar_index
trade.is_closed := true
be_hit_label := label.new(bar_index, trade.entry_price,
str.tostring("BE HIT"), style = label.style_label_left)
// SL HIT
if low <= trade.sl_price and not trade.can_break_even and trade.entry_hit
and bar_index != trade.start_bar_index
trade.sl_hit := true
trade.is_closed := true
profit += -trade.risk_percent * trade.position_size_left / 100
sl_hit_label := label.new(bar_index, trade.sl_price, str.tostring("SL
HIT ") + str.tostring(profit, "#.##") + "%", color = color.red, style =
label.style_label_left)
else
if high >= trade.entry_price and not trade.entry_hit
trade.start_bar_index := bar_index
trade.entry_hit := true
entry_hit_label := label.new(trade.start_bar_index, trade.entry_price,
str.tostring("ENTRY HIT"), style = label.style_label_right)
trade_info_label := label.new(bar_index, high, "Trade info:" + "\
nEntry: " + str.tostring(trade.entry_price) + "\nTp1: " +
str.tostring(trade.tp1_price) + "\nTp2: " + str.tostring(trade.tp2_price) + "\
nTp3:" + str.tostring(trade.tp3_price) + "\nTp4: " + str.tostring(trade.tp4_price)
+ "\nSl: " + str.tostring(trade.sl_price))
if low <= trade.tp1_price and not trade.tp1_hit and trade.entry_hit
trade.tp1_hit := true
trade.position_size_left -= trade.tp1_percent_fix
profit += calc_rr(trade.entry_price, trade.sl_price, trade.tp1_price) *
trade.tp1_percent_fix / 100 * trade.risk_percent
tp1_hit_label := label.new(trade.start_bar_index, trade.tp1_price,
str.tostring("TP1 HIT +") + str.tostring(profit, "#.##") + "%" + "\nPosition size
%: " + str.tostring(trade.position_size_left), style = label.style_label_right)
if low <= trade.tp2_price and not trade.tp2_hit and trade.entry_hit
trade.tp2_hit := true
trade.position_size_left -= trade.tp2_percent_fix
profit += calc_rr(trade.entry_price, trade.sl_price, trade.tp2_price) *
trade.tp2_percent_fix / 100 * trade.risk_percent
tp2_hit_label := label.new(trade.start_bar_index, trade.tp2_price,
str.tostring("TP2 HIT +") + str.tostring(profit, "#.##") + "%" + "\nPosition size
%: " + str.tostring(trade.position_size_left), style = label.style_label_right)
if low <= trade.tp3_price and not trade.tp3_hit and trade.entry_hit
trade.tp3_hit := true
trade.position_size_left -= trade.tp3_percent_fix
profit += calc_rr(trade.entry_price, trade.sl_price, trade.tp3_price) *
trade.tp3_percent_fix / 100 * trade.risk_percent
tp3_hit_label := label.new(trade.start_bar_index, trade.tp3_price,
str.tostring("TP3 HIT +") + str.tostring(profit, "#.##") + "%" + "\nPosition size
%: " + str.tostring(trade.position_size_left), style = label.style_label_right)
if low <= trade.tp4_price and not trade.tp4_hit and trade.entry_hit
trade.tp4_hit := true
trade.is_closed := true
trade.position_size_left -= trade.tp4_percent_fix
profit += calc_rr(trade.entry_price, trade.sl_price, trade.tp4_price) *
trade.tp4_percent_fix / 100 * trade.risk_percent
tp4_hit_label := label.new(trade.start_bar_index, trade.tp4_price,
str.tostring("TP4 HIT +") + str.tostring(profit, "#.##") + "%" + "\nPosition size
%: " + str.tostring(trade.position_size_left), style = label.style_label_right)
if low <= trade.break_even_price and not trade.can_break_even and
trade.entry_hit
trade.can_break_even := true
//BE ENTRY HIT
if trade.can_break_even and trade.entry_hit
if high >= trade.entry_price and not (close <= open) and bar_index !=
trade.start_bar_index
trade.is_closed := true
be_hit_label := label.new(bar_index, trade.entry_price,
str.tostring("BE HIT"), style = label.style_label_left)
// SL HIT
if high >= trade.sl_price and not trade.can_break_even and trade.entry_hit
and bar_index != trade.start_bar_index
trade.sl_hit := true
trade.is_closed := true
profit += -trade.risk_percent * trade.position_size_left / 100
sl_hit_label := label.new(bar_index, trade.sl_price, str.tostring("SL
HIT ") + str.tostring(profit, "#.##") + "%", color = color.red, style =
label.style_label_left)
trade.profit += profit
if not show_labels
label.delete(entry_hit_label)
label.delete(tp1_hit_label)
label.delete(tp2_hit_label)
label.delete(tp3_hit_label)
label.delete(tp4_hit_label)
label.delete(sl_hit_label)
label.delete(be_hit_label)
label.delete(trade_info_label)
method close_trade(Trade trade, bool show_labels) =>
float profit = 0.0
label trade_closed_label = na
trade.force_closed := true
if not trade.sl_hit
if trade.side == "SHORT"
trade.is_closed := true
trade.close_price := close
if close <= trade.entry_price
percent_from_entry_to_close_price_at_trend_change =
math.abs((close / trade.entry_price) * 100)
percent_from_entry_to_sl_price = math.abs((trade.entry_price /
trade.sl_price) * 100)
profit := calc_rr(trade.entry_price, trade.sl_price, close) *
trade.position_size_left / 100 * trade.risk_percent
else
profit := calc_rr(trade.entry_price, trade.sl_price, close) *
trade.position_size_left / 100 * trade.risk_percent
string sign = profit >= 0 ? "+" : na
trade_closed_label := label.new(bar_index, high, str.tostring("TRADE
CLOSED ") + sign + str.tostring(profit, "#.##") + "%")
else
trade.is_closed := true
trade.close_price := close
if close <= trade.entry_price
percent_from_entry_to_close_price_at_trend_change =
math.abs((close / trade.entry_price - 1) * 100)
percent_from_entry_to_sl_price = math.abs((trade.entry_price /
trade.sl_price - 1) * 100)
profit := -trade.risk_percent *
(percent_from_entry_to_close_price_at_trend_change /
percent_from_entry_to_sl_price) * trade.position_size_left / 100 + trade.profit
else
profit := calc_rr(trade.entry_price, trade.sl_price, close) *
trade.position_size_left / 100 * trade.risk_percent
string sign = profit >= 0 ? "+" : na
trade_closed_label := label.new(bar_index, low, str.tostring("TRADE
CLOSED ") + sign + str.tostring(profit, "#.##") + "%", style =
label.style_label_up)
if not show_labels
label.delete(trade_closed_label)
trade.profit += profit
// TYPES AND METHODS
// 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
string STRATEGIES = "STRATEGIES"
string POSITION = "POSITION"
string ENTRY = "ENTRY"
string TAKE_PROFITS = "TAKE PROFITS"
string STOP_LOSS = "STOPLOSS"
string rsi_group = "RSI"
string main_group = "MAIN"
string info_panel_group = "INFOPANELS"
string dev_settings = "DEVELOPER MODE"
int fibo_lines_transparend = 60
int fill_best_transparend = 95
int fill_worst_transparend = 98
color high_line_color = color.rgb(36, 255, 44, fibo_lines_transparend)
color fib_236_color = color.rgb(130, 228, 74, fibo_lines_transparend)
color fib_382_color = color.rgb(171, 224, 174, fibo_lines_transparend)
color fib_618_color = color.rgb(235, 255, 51, fibo_lines_transparend)
color fib_786_color = color.rgb(255, 131, 73, fibo_lines_transparend)
color low_line_color = color.rgb(255, 82, 82, fibo_lines_transparend)
color high_best_fill_color = color.rgb(48, 255, 55, fill_best_transparend)
color high_worst_fill_color = color.rgb(37, 255, 44, fill_worst_transparend)
color low_best_fill_color = color.rgb(255, 54, 54, fill_best_transparend)
color low_worst_fill_color = color.rgb(255, 43, 43, fill_worst_transparend)
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
//@version=5
indicator(title='[IMBA] ALGO', shorttitle='[IMBA] ALGO', overlay=true,
max_lines_count = 500, max_labels_count = 500, max_bars_back = 1)
//---------------------------------------------------
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
strategy_input = input.string(title = "STRATEGY", options = [
"MANUAL",
"UNIVERSAL 15m",
"===============",
"-------A-------",
"-------B-------",
"-------C-------",
"-------D-------",
"-------E-------",
"-------F-------",
"-------G-------",
"-------H-------",
"-------I-------",
"-------J-------",
"-------K-------",
"-------L-------",
"-------M-------",
"-------N-------",
"-------O-------",
"-------P-------",
"-------Q-------",
"-------R-------",
"-------S-------",
"SOL 5m",
"-------T-------",
"-------U-------",
"-------V-------",
"-------W-------",
"-------X-------",
"-------Y-------",
"-------Z-------"
], defval = "MANUAL", tooltip = "EN:\nTo manually configure the strategy,
select MANUAL otherwise, changing the settings won't have any effect\nRU:\nЧтобы
настроить стратегию вручную, выберите MANUAL в противном случае изменение настроек
не будет иметь никакого эффекта")
// 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
var int trend_started_bar_index = na
var line tp1_line = na
var label tp1_label = na
var line tp2_line = na
var label tp2_label = na
var line tp3_line = na
var label tp3_label = na
var line tp4_line = na
var label tp4_label = na
var line entry_line = na
var label entry_label = na
var line close_line = na
var line sl_line = na
var label sl_label = na
var label lable_at_signal = na
var int signal_closed_bar = na
var Strategy_settings strategy_s = na
var float dep = initial_deposit_input
//-----------------------------------------------------
MAIN------------------------------------------------------------\\
// STRATEGY
strategy_s := strategy_input == "MANUAL" ? Strategy_settings.new(sensitivity_input,
risk_percent_input, break_even_target_input, tp1_percent_input,
tp1_percent_fix_input, tp2_percent_input, tp2_percent_fix_input, tp3_percent_input,
tp3_percent_fix_input, tp4_percent_input, tp4_percent_fix_input, fixed_stop_input,
sl_percent_input) : selector(strategy_input)
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
is_trend_change := is_short_trend_started or is_long_trend_started
plotshape(is_long_trend and is_long_trend_started ? imba_trend_line : na,
title="Long", style=shape.triangleup, location=location.belowbar,
color=color.green, size=size.small)
plotshape(is_short_trend and is_short_trend_started ? imba_trend_line : na,
title="Short", style=shape.triangledown, location=location.abovebar,
color=color.red, size=size.small)
plot(imba_trend_line, color = is_long_trend[1] ? color.green : color.red, linewidth
= 3)
// 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)
1 1️⃣ 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
alertcondition(can_long and na(trade), "Long signal", "Long")
alertcondition(can_short and na(trade), "Short signal", "Short")
alertcondition(can_short or can_long and na(trade), "New signal", "Check chart to
see signal direction")
if can_long or can_short and na(trade)
first_trade_date := trade_count == 0 ? timestamp(year, month, dayofmonth, hour,
minute) : first_trade_date
trade := Trade.new()
trade.side := can_long ? "LONG" : "SHORT"
trade.entry_price := close
trade.entry_hit := true
trade.sl_price := math.round_to_mintick(can_long ? fixed_stop ?
trade.entry_price * (1 - sl_percent) : fib_786 * (1 - sl_percent) : fixed_stop ?
trade.entry_price * (1 + sl_percent) : fib_236 * (1 + sl_percent))
trade.tp1_price := math.round_to_mintick(can_long ? trade.entry_price * (1 +
tp1_percent) : trade.entry_price * (1 - tp1_percent))
trade.tp1_percent_fix := tp1_percent_fix * 100
trade.tp2_price := math.round_to_mintick(can_long ? trade.entry_price * (1 +
tp2_percent) : trade.entry_price * (1 - tp2_percent))
trade.tp2_percent_fix := tp2_percent_fix * 100
trade.tp3_price := math.round_to_mintick(can_long ? trade.entry_price * (1 +
tp3_percent) : trade.entry_price * (1 - tp3_percent))
trade.tp3_percent_fix := tp3_percent_fix * 100
trade.tp4_price := math.round_to_mintick(can_long ? trade.entry_price * (1 +
tp4_percent) : trade.entry_price * (1 - tp4_percent))
trade.tp4_percent_fix := tp4_percent_fix * 100
trade.break_even_price := switch break_even_target
"1" => trade.tp1_price
"2" => trade.tp2_price
"3" => trade.tp3_price
"WITHOUT" => trade.tp4_price
trade.risk_percent := risk_percent
trade.risk_reward := calc_rr(trade.entry_price, trade.sl_price,
trade.tp4_price)
trade.start_bar_index := bar_index
alert_message = "\n{\n" + " \"side\": \"" + str.tostring(trade.side) +
"\",\n \"entry\": \"" + str.tostring(trade.entry_price) + "\",\n \"tp1\": \""
+ str.tostring(trade.tp1_price) + "\",\n \"tp2\": \"" +
str.tostring(trade.tp2_price) + "\",\n \"tp3\": \"" +
str.tostring(trade.tp3_price) + "\",\n \"tp4\": \"" +
str.tostring(trade.tp4_price) + "\",\n \"winrate\": \"" +
str.tostring(RoundUp(profit_trades / trade_count * 100, 2)) + "%" + "\",\
n \"strategy\": \"" + strategy_input + "\",\n \"beTargetTrigger\": \"" +
break_even_target + "\",\n \"stop\": \"" + str.tostring(trade.sl_price) + "\"\
n}\n"
alert(alert_message, alert.freq_once_per_bar_close)
if show_tp_enty_sl
entry_line := line.new(x1=trade.start_bar_index, y1=trade.entry_price,
x2=bar_index, y2=trade.entry_price, color=entry_color, style = line.style_solid,
width = 2)
entry_label := label.new(bar_index, trade.entry_price,
str.tostring(trade.entry_price), style = label.style_label_left, color =
color.rgb(255, 255, 255, 100), textcolor = color.gray)
sl_line := line.new(x1=trade.start_bar_index, y1=trade.sl_price,
x2=bar_index, y2=trade.sl_price, color=sl_color, style = line_style, width = 2)
sl_label := label.new(bar_index, trade.sl_price,
str.tostring(trade.sl_price), style = label.style_label_left, color =
color.rgb(255, 255, 255, 100), textcolor = color.red)
tp1_line := line.new(x1=trade.start_bar_index, y1=trade.tp1_price,
x2=bar_index, y2=trade.tp1_price, color=tp_color, style = line_style, width = 2)
tp1_label := label.new(bar_index, trade.tp1_price,
str.tostring(trade.tp1_price), style = label.style_label_left, color =
color.rgb(255, 255, 255, 100), textcolor = color.green)
tp2_line := line.new(x1=trade.start_bar_index, y1=trade.tp2_price,
x2=bar_index, y2=trade.tp2_price, color=tp_color, style = line_style, width = 2)
tp2_label := label.new(bar_index, trade.tp2_price,
str.tostring(trade.tp2_price), style = label.style_label_left, color =
color.rgb(255, 255, 255, 100), textcolor = color.green)
tp3_line := line.new(x1=trade.start_bar_index, y1=trade.tp3_price,
x2=bar_index, y2=trade.tp3_price, color=tp_color, style = line_style, width = 2)
tp3_label := label.new(bar_index, trade.tp3_price,
str.tostring(trade.tp3_price), style = label.style_label_left, color =
color.rgb(255, 255, 255, 100), textcolor = color.green)
tp4_line := line.new(x1=trade.start_bar_index, y1=trade.tp4_price,
x2=bar_index, y2=trade.tp4_price, color=tp_color, style = line_style, width = 2)
tp4_label := label.new(bar_index, trade.tp4_price,
str.tostring(trade.tp4_price), style = label.style_label_left, color =
color.rgb(255, 255, 255, 100), textcolor = color.green)
lable_at_signal := label.new(bar_index, is_long_trend ? trade.tp4_price *
1.004 : trade.tp4_price * 0.996, "", style = label.style_label_center, textcolor =
color.white)
//------------------------------------------------------
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])
var table profit_table = na
if show_profit_panel
profit_table := table.new(position.top_right, 3, 10, border_color =
color.green, border_width = 0)
table.cell(profit_table, 0, 0, "═════════════════════════════" + "\n" + "[IMBA]
ALGO" + "\n" + "═════════════════════════════", bgcolor = color.rgb(0, 0, 0, 87),
text_color = color.green, width = 6, height = 5, text_size = size.normal)
table.cell(profit_table, 1, 0, "", bgcolor = color.rgb(0, 0, 0, 87), text_color
= color.green, width = 6, height = 3, text_size = size.normal)
table.merge_cells(profit_table, 0,0,1,0)
table.cell(profit_table, 0, 1, "First trade:", bgcolor = color.rgb(0, 0, 0,
87), text_color = color.green, width = 8, height = 3, text_size = size.normal,
text_halign = text.align_left)
table.cell(profit_table, 1, 1, str.format("{0,date,long}", first_trade_date),
bgcolor = color.rgb(0, 0, 0, 87), text_color = color.green, width = 8, height = 3,
text_size = size.normal)
table.cell(profit_table, 0, 2, "Total trades:", bgcolor = color.rgb(0, 0, 0,
87), text_color = color.green, width = 5, height = 3, text_size = size.normal,
text_halign = text.align_left)
table.cell(profit_table, 1, 2, str.tostring(trade_count), bgcolor =
color.rgb(0, 0, 0, 87), text_color = color.green, width = 5, height = 3, text_size
= size.normal)
table.cell(profit_table, 0, 3, "Profit trades:", bgcolor = color.rgb(0, 0, 0,
87), text_color = color.green, width = 5, height = 3, text_size = size.normal,
text_halign = text.align_left)
table.cell(profit_table, 1, 3, str.tostring(profit_trades), bgcolor =
color.rgb(0, 0, 0, 87), text_color = color.green, width = 5, height = 3, text_size
= size.normal)
table.cell(profit_table, 0, 4, "Loss trades:", bgcolor = color.rgb(0, 0, 0,
87), text_color = color.green, width = 5, height = 3, text_size = size.normal,
text_halign = text.align_left)
table.cell(profit_table, 1, 4, str.tostring(loss_trades), bgcolor =
color.rgb(0, 0, 0, 87), text_color = color.green, width = 5, height = 3, text_size
= size.normal)
table.cell(profit_table, 0, 5, "Winrate:", bgcolor = color.rgb(0, 0, 0, 87),
text_color = color.green, width = 5, height = 3, text_size = size.normal,
text_halign = text.align_left)
table.cell(profit_table, 1, 5, str.tostring(RoundUp(profit_trades / trade_count
* 100, 2)) + "%", bgcolor = color.rgb(0, 0, 0, 87), text_color = color.green, width
= 5, height = 3, text_size = size.normal)
table.cell(profit_table, 0, 6, "Win streak:", bgcolor = color.rgb(0, 0, 0, 87),
text_color = color.green, width = 5, height = 3, text_size = size.normal,
text_halign = text.align_left)
table.cell(profit_table, 1, 6, str.tostring(win_streak), bgcolor = color.rgb(0,
0, 0, 87), text_color = color.green, width = 5, height = 3, text_size =
size.normal)
table.cell(profit_table, 0, 7, "Loss streak:", bgcolor = color.rgb(0, 0, 0,
87), text_color = color.green, width = 5, height = 3, text_size = size.normal,
text_halign = text.align_left)
table.cell(profit_table, 1, 7, str.tostring(loss_streak), bgcolor =
color.rgb(0, 0, 0, 87), text_color = color.green, width = 5, height = 3, text_size
= size.normal)
table.cell(profit_table, 0, 8, "Deposit: ", bgcolor = color.rgb(0, 0, 0, 87),
text_color = color.green, width = 5, height = 3, text_size = size.normal,
text_halign = text.align_left)
table.cell(profit_table, 1, 8, str.tostring(dep, "##.##"), bgcolor =
color.rgb(0, 0, 0, 87), text_color = color.green, width = 5, height = 3, text_size
= size.normal)
table.cell(profit_table, 0, 9, "═════════════════════════════" + "\n" + "💰
Profit: " + str.tostring(total_profit, "#.##") + "% 💰" + "\n" +
"═════════════════════════════", bgcolor = color.rgb(0, 0, 0, 87), text_color =
color.green, width = 5, height = 10, text_size = size.normal, text_halign =
text.align_center, text_valign = text.align_top)
table.cell(profit_table, 1, 9,"", bgcolor = color.rgb(0, 0, 0, 87), text_color
= color.green, width = 5, height = 3, text_size = size.normal)
table.merge_cells(profit_table, 0, 9, 1, 9)
var table strategy_table = na
if show_strategy_panel
strategy_table := table.new(position.bottom_right, 5, 6, border_color =
color.green)
table.cell(strategy_table, 1, 0, "══════════════════════════════════════════" +
"\n" + syminfo.ticker + " " + timeframe.period + " | WR: " +
str.tostring(profit_trades / (profit_trades + (trade_count - profit_trades)) * 100,
"##,##") + "%" + " | TT: " + str.tostring(trade_count) + " | P: " +
str.tostring(total_profit, "#.##") + "%" + "\n" +
"══════════════════════════════════════════", bgcolor = color.rgb(0, 0, 0, 87),
text_color = color.green, width = 6, height = 7, text_size = size.normal,
text_valign = text.align_bottom)
table.cell(strategy_table, 2, 0, "", bgcolor = color.rgb(0, 0, 0, 87),
text_color = color.green, width = 6, height = 3, text_size = size.normal)
table.cell(strategy_table, 3, 0, "", bgcolor = color.rgb(0, 0, 0, 87),
text_color = color.green, width = 6, height = 3, text_size = size.normal)
table.cell(strategy_table, 4, 0, "", bgcolor = color.rgb(0, 0, 0, 87),
text_color = color.green, width = 6, height = 3, text_size = size.normal)
table.merge_cells(strategy_table, 1,0,4,0)
table.cell(strategy_table, 1, 1, "Strategy:", bgcolor = color.rgb(0, 0, 0, 87),
text_color = color.green, width = 6, height = 3, text_size = size.normal,
text_halign = text.align_left)
table.cell(strategy_table, 2, 1, strategy_input, bgcolor = color.rgb(0, 0, 0,
87), text_color = color.green, width = 6, height = 3, text_size = size.normal)
table.cell(strategy_table, 1, 2, "Sensitivity:", bgcolor = color.rgb(0, 0, 0,
87), text_color = color.green, width = 5, height = 3, text_size = size.normal,
text_halign = text.align_left)
table.cell(strategy_table, 2, 2, str.tostring(sensitivity / 10), bgcolor =
color.rgb(0, 0, 0, 87), text_color = color.green, width = 5, height = 3, text_size
= size.normal)
table.cell(strategy_table, 1, 3, "Risk:", bgcolor = color.rgb(0, 0, 0, 87),
text_color = color.green, width = 5, height = 3, text_size = size.normal,
text_halign = text.align_left)
table.cell(strategy_table, 2, 3, str.tostring(risk_percent) + "%", bgcolor =
color.rgb(0, 0, 0, 87), text_color = color.green, width = 5, height = 3, text_size
= size.normal)
table.cell(strategy_table, 1, 4, "BE target:", bgcolor = color.rgb(0, 0, 0,
87), text_color = color.green, width = 5, height = 3, text_size = size.normal,
text_halign = text.align_left)
table.cell(strategy_table, 2, 4, str.tostring(break_even_target), bgcolor =
color.rgb(0, 0, 0, 87), text_color = color.green, width = 5, height = 3, text_size
= size.normal)
table.cell(strategy_table, 1, 5, "Fixed stop:", bgcolor = color.rgb(0, 0, 0,
87), text_color = color.green, width = 5, height = 3, text_size = size.normal,
text_halign = text.align_left)
table.cell(strategy_table, 2, 5, str.tostring(fixed_stop), bgcolor =
color.rgb(0, 0, 0, 87), text_color = color.green, width = 5, height = 3, text_size
= size.normal)
table.cell(strategy_table, 3, 1, "TP1:", bgcolor = color.rgb(0, 0, 0, 87),
text_color = color.green, width = 4, height = 3, text_size = size.normal)
table.cell(strategy_table, 4, 1, str.tostring(tp1_percent * 100) + "%" + " (" +
str.tostring(tp1_percent_fix * 100) + "%)", bgcolor = color.rgb(0, 0, 0, 87),
text_color = color.green, width = 5, height = 3, text_size = size.normal)
table.cell(strategy_table, 3, 2, "TP2:", bgcolor = color.rgb(0, 0, 0, 87),
text_color = color.green, width = 4, height = 3, text_size = size.normal)
table.cell(strategy_table, 4, 2, str.tostring(tp2_percent * 100) + "%" + " (" +
str.tostring(tp2_percent_fix * 100) + "%)", bgcolor = color.rgb(0, 0, 0, 87),
text_color = color.green, width = 5, height = 3, text_size = size.normal)
table.cell(strategy_table, 3, 3, "TP3:", bgcolor = color.rgb(0, 0, 0, 87),
text_color = color.green, width = 4, height = 3, text_size = size.normal)
table.cell(strategy_table, 4, 3, str.tostring(tp3_percent * 100) + "%" + " (" +
str.tostring(tp3_percent_fix * 100) + "%)", bgcolor = color.rgb(0, 0, 0, 87),
text_color = color.green, width = 5, height = 3, text_size = size.normal)
table.cell(strategy_table, 3, 4, "TP4:", bgcolor = color.rgb(0, 0, 0, 87),
text_color = color.green, width = 4, height = 3, text_size = size.normal)
table.cell(strategy_table, 4, 4, str.tostring(tp4_percent * 100) + "%" + " (" +
str.tostring(tp4_percent_fix * 100) + "%)", bgcolor = color.rgb(0, 0, 0, 87),
text_color = color.green, width = 5, height = 3, text_size = size.normal)
table.cell(strategy_table, 3, 5, "Stop:", bgcolor = color.rgb(0, 0, 0, 87),
text_color = color.green, width = 4, height = 3, text_size = size.normal)
table.cell(strategy_table, 4, 5, str.tostring(sl_percent * 100) + "%", bgcolor
= color.rgb(0, 0, 0, 87), text_color = color.green, width = 8, height = 3,
text_size = size.normal)
//--------------------------------------------------------------------------//
//--- Fin Imba
//@version=5
//Fibonacci Trading
//This simple script draw Fibonacci Retracement to define pullback level and draw
Fibonacci Extension to define target level of a upward wave or Downward wave
//1. Upward wave
//1.1 Fibonacci Retracement
//+ Fibonacci Retracement measuare from support to nearest resistance on the right.
//+ Retracement Level 0 named as "Breake Even"
//+ Retracement Level 100 named as "Long Invalidation"
//+ Retracement Level 50 and 61.8 is ploted as blue line
//+ The zone between Retracement Level 50 and 100 is filled by blue color and named
as "Buy zone"
//1.2 Fibonacci Extension
//+ Fibonacci Extension measuare from Retracement Level 61.8 to Retracement Level 0
//+ Fibonacci Extension Level 161.8 named as "Tp1 (Target point 1)"
//+ Fibonacci Extension Level 261.8 named as "Tp2 (Target point 2)"
//2. Downward wave
//2.1 Fibonacci Retracement
//+ Fibonacci Retracement measuare from resistance to nearest support on the right.
//+ Retracement Level 0 named as "Breake Even"
//+ Retracement Level 100 named as "Short Invalidation"
//+ Retracement Level 50 and 61.8 is ploted as red line
//+ The zone between Retracement Level 50 and 100 is filled by red color and named
as "Sell zone"
//2.2 Fibonacci Extension
//+ Fibonacci Extension measuare from Retracement Level 61.8 to Retracement Level 0
//+ Fibonacci Extension Level 161.8 named as "Tp1 (Target point 1)"
//+ Fibonacci Extension Level 261.8 named as "Tp2 (Target point 2)"
//3. Trading Setup
//3.1 Long Only: Only display Fibonacci of Upward wave
//3.2 Short Only: Only display Fibonacci of Downward wave
//3.3 Both: Display both Fibonacci of Upward wave and Downward wave
//3.4 MA Cycle: When EMA above SMA auto display Fibonacci of Upward wave, When EMA
below SMA auto display Fibonacci of Downward wave.
//Notes: When EMA above SMA, background is filled by blue. When EMA below SMA,
background is filled by red. Uncheck Fill background to disable filling.
//3.5 RSI_MACD:
//When RSI crossdown over sold level and then MACD create Buy Signal this script
auto display Fibonacci of Upward wave
//When RSI crossup over bought level and then MACD create Sell Signal this script
auto display Fibonacci of Downward wave
//Notes:
//When MACD create Buy Signal after RSI oversold, background is filled by blue.
//When MACD create Sell Signal after RSI overbought, background is filled by red.
//Uncheck "RSI MACD Background Filling" to disable filling.
//3.6 Gaussian Filter: When price above Gaussian Filter auto display Fibonacci of
Upward wave, When price below Gaussian Filter auto display Fibonacci of Downward
wave.
//Notes: When price above Gaussian Filter, background is filled by blue. When price
below Gaussian Filter, background is filled by red. Uncheck Fill background to
disable filling.
//indicator('Fibonacci Trading', overlay=true, max_lines_count = 500,
max_labels_count = 500)
ma_tt="=== Moving Average Cycle ==="
_source=close
_p=input(50,title="Period", inline="set1", group=ma_tt)
macycle_note_1=input(false,"1. MA Cycle above 0, background is filled by
blue",group = ma_tt)
macycle_note_2=input(false,"2. MA Cycle below 0, background is filled by red",group
= ma_tt)
_fill=input.bool(true,title = "Fill background", group=ma_tt)
_c=ta.ema(close,_p) - ta.sma(close,_p)
//
rsi_tt = '=== RSI ==='
rsi_len = input.int(14, title='Period', inline='set', group=rsi_tt)
rsi_ovb_lv = input.int(70, title='Overbought', inline='set2', group=rsi_tt)
rsi_ovs_lv = input.int(30, title='Oversold', inline='set2', group=rsi_tt)
rsi_note_1=input(false,"1. RSI Overbought show as Hot Face",group = rsi_tt)
rsi_note_2=input(false,"2. RSI Oversold show as Cold Face",group = rsi_tt)
_rsi_show = input(true, title='Show RSI',inline='set3', group=rsi_tt)
_rsi = ta.rsi(close, rsi_len)
_rsi_ovb=_rsi[0]>rsi_ovb_lv[0]
_rsi_ovs=_rsi[0]<rsi_ovs_lv[0]
plotshape(_rsi_show and _rsi_ovb?_rsi:na,
title="RSI Overbought",
style=shape.labeldown,
location = location.bottom,
color = color.new(color.aqua, 100),
offset=0,
text="🥵",
textcolor=color.new(color.black,0))
plotshape(_rsi_show and _rsi_ovs?_rsi:na,
title="RSI Oversold",
style=shape.labeldown,
location = location.bottom,
color = color.new(color.aqua, 100),
offset=0,
text="🥶",
textcolor=color.new(color.black,0))
_rsi_ovb_log=_rsi_ovb[1]==false and _rsi_ovb==true
_rsi_ovs_log=_rsi_ovs[1]==false and _rsi_ovs==true
_rsi_ovb_index=bar_index>0?bar_index-ta.valuewhen(_rsi_ovb_log,bar_index,0):1
_rsi_ovs_index=bar_index>0?bar_index-ta.valuewhen(_rsi_ovs_log,bar_index,0):1
//MACD
macd_tt = '=== MACD ==='
macd_source = close
macd_fast = input.int(12, title='Fast', inline='set1', group=macd_tt)
macd_slow = input.int(26, title='Slow', inline='set1', group=macd_tt)
macd_sig = input.int(9, title='Signal', inline='set1', group=macd_tt)
macd_note_1=input(false,"1. MACD show as circle",group = macd_tt)
macd_note_2=input(false,"2. MACD Buy Signal show as Arrow Up",group = macd_tt)
macd_note_3=input(false,"3. MACD Sell Signal show as Arrow Down",group = macd_tt)
_macd_show = input(true, title='Show MACD',inline='set2', group=macd_tt)
[_macd, _signal, _hist] = ta.macd(macd_source, macd_fast, macd_slow, macd_sig)
_macd_buy_signal=_macd[1]<_signal[1] and _macd[0]>_signal[0]
_macd_sell_signal=_macd[1]>_signal[1] and _macd[0]<_signal[0]
plotshape(_macd_show and _macd_buy_signal==false and _macd_sell_signal==false?
_macd:na,
title="MACD",
style=shape.circle,
location = location.bottom,
color = _macd>_signal?color.new(color.lime, 0) :
color.new(color.red, 0),
offset=0)
plotshape(_macd_show and _macd_buy_signal?_macd:na,
title="MACD Buy Signal",
style=shape.arrowup,
location = location.bottom,
color = color.new(color.lime, 0),
offset=0)
plotshape(_macd_show and _macd_sell_signal?_macd:na,
title="MACD Sell Signal",
style=shape.arrowdown,
location = location.bottom,
color = color.new(color.red, 0),
offset=0)
//
var _rsi_val=0, _m=0
if _rsi_ovb_index<_rsi_ovs_index
_rsi_val:=-1
else
if _rsi_ovb_index>_rsi_ovs_index
_rsi_val:=1
else
_rsi_val:=_rsi_val[1]
if _rsi_val==-1 and _macd_sell_signal==true
_m:=-1
else
if _rsi_val==1 and _macd_buy_signal==true
_m:=1
else
_m:=_m[1]
//
rsi_macd="RSI MACD Background Filling"
rsi_macd_note_1=input(false,"1. MACD Buy Signal after RSI Oversold, background is
filled by blue",group = rsi_macd)
rsi_macd_note_2=input(false,"2. MACD Sell Signal after RSI Overbought, background
is filled by red",group = rsi_macd)
_fill_rsi_macd=input.bool(true,title = "Fill background", group=rsi_macd)
//Gaussian Filter script by Alex Orekhov (everget)
gf_tt="=== Gaussian Filter ==="
cyclePeriod = input.int(title='Period', minval=1, defval=100,inline="set",group =
gf_tt)
src = input(title='Source', defval=close,inline="set",group = gf_tt)
gf_note_1=input(false,"1. Price moving above Gaussian Filter, background is filled
by blue",group = gf_tt)
gf_note_2=input(false,"2. Price moving below Gaussian Filter, background is filled
by red",group = gf_tt)
_fill_gf=input.bool(true,title = "Fill background", group=gf_tt)
//Calculate GF with Number of Poles = 4
PI = 2 * math.asin(1)
beta = (1 - math.cos(2 * PI / cyclePeriod)) / (math.pow(2, 1 / 4.0) - 1)
alpha = -beta + math.sqrt(math.pow(beta, 2) + 2 * beta)
getGF() =>
filter = 0.0
filter := math.pow(alpha, 4) * src + 4 * (1 - alpha) * nz(filter[1]) - 6 *
math.pow(1 - alpha, 2) * nz(filter[2]) + 4 * math.pow(1 - alpha, 3) * nz(filter[3])
- math.pow(1 - alpha, 4) * nz(filter[4])
filter
gf = getGF()
_g=close>gf?1:-1
//
sr_group="=== Support Resistance ==="
Left = input.int(6,title="Number of bars from the left of fractal", minval=1, group
= sr_group)
Right = input.int(6,title="Number of bars from the right of fractal", minval=0,
group = sr_group)
trading_group="=== Trading Setup ==="
trading_setup = input.string("MA Cycle",title="Setup",options = ["Long Only","Short
Only","Both","MA Cycle","RSI_MACD","Gaussian_Filter"],group = trading_group)
var Long=false, Short=false
if trading_setup=="Long Only"
Long := true
Short := false
else if trading_setup=="Short Only"
Long := false
Short := true
else if trading_setup=="MA Cycle"
if _c>0
Long := true
Short := false
else
Long := false
Short := true
else if trading_setup=="RSI_MACD"
if _m>0
Long := true
Short := false
else
Long := false
Short := true
else if trading_setup=="Gaussian_Filter"
if _g>0
Long := true
Short := false
else
Long := false
Short := true
else
Long := true
Short := true
//Background Filling
bgcolor(color = _fill and trading_setup=="MA Cycle"?_c>0?
color.new(color.blue,80):color.new(color.red,80):na,offset=0)
bgcolor(color = _fill_rsi_macd and trading_setup=="RSI_MACD"?_m>0?
color.new(color.blue,80):color.new(color.red,80):na,offset=0)
bgcolor(color = _fill_gf and trading_setup=="Gaussian_Filter"?_g>0?
color.new(color.blue,80):color.new(color.red,80):na,offset=0)
isFractal(x) =>
ta.highestbars(x, Left+Right+1) == -Right
sF = isFractal(-low)
support = low
support := sF ? low[Right] : support[1]
rF = isFractal(high)
resistance = high
resistance := rF ? high[Right] : resistance[1]
//plot(support, title="Support", color=sF ? #00000000 : color.blue, linewidth=2,
offset=-Right)
//plot(resistance, title="Resistance", color=rF ? #00000000 : color.red,
linewidth=2, offset=-Right)
plotshape(sF?low[Right]:na,title="Fractal Low", style = shape.circle, location =
location.absolute, color=color.blue, offset = -Right, size = size.tiny)
plotshape(rF?high[Right]:na,title="Fractal High", style = shape.circle, location =
location.absolute, color=color.red, offset = -Right, size = size.tiny)
drawLabel(_offset, _pivot, _text, _style, _color, _textColor) =>
if not na(_pivot)
label.new(bar_index[_offset], _pivot, _text, style=_style, color=_color,
textcolor=_textColor)
//label.new(bar_index[_offset], _pivot, _text+str.tostring(_pivot,
format.mintick), style=_style, color=_color, textcolor=_textColor)
drawLine(x1,y1,x2,y2,ext,clr,sty,wid) =>
if not na(x1)
line.new(x1,y1,x2,y2,xloc=xloc.bar_index,extend =
ext,color=clr,style=sty,width=wid)
//Value & Index
ph = rF
ph_val = ta.valuewhen(ph,resistance,0)
res = ph_val
ph_index = ta.valuewhen(ph,bar_index-Right,0)
pl = sF
pl_val = ta.valuewhen(pl,support,0)
sup = pl_val
pl_index = ta.valuewhen(pl,bar_index-Right,0)
//Long setup
var long_sup_index=0,long_sup_val=0.0,long_res_val=0.0
if pl_index<ph_index
long_sup_index:=pl_index
long_sup_val:=pl_val
long_res_val:=ph_val
else
long_sup_index:=long_sup_index[1]
long_sup_val:=long_sup_val[1]
if long_sup_index==long_sup_index[1]
long_res_val:=long_res_val[1]
//Long Condition
long_cond=(close>long_sup_val and Long)
//Resistance Line
long_res_x1=long_sup_index
long_res_y1=long_cond?long_res_val:na
long_res_x2=bar_index
long_res_y2=long_res_y1
long_res_ext=extend.right
long_res_clr=color.new(color.red,0)
long_res_textColor=color.new(color.white,0)
long_res_sty=line.style_dotted
long_res_width=2
long_res_line=drawLine(long_res_x1,long_res_y1,long_res_x2,long_res_y2,long_res_ext
,long_res_clr,long_res_sty,long_res_width)
line.delete(long_res_line[1])
//Label
long_ph_lab=drawLabel(0, long_cond?long_res_y1:na, "Break
Even",label.style_label_left, color.red, color.white)
label.delete(long_ph_lab[1])
//Value
plot(long_cond?long_res_y1:na,title="Break Even",color=color.new(color.red,100))
//Support Line
long_sup_x1=long_sup_index
long_sup_y1=Long?long_sup_val:na
long_sup_x2=bar_index
long_sup_y2=long_sup_y1
long_sup_ext=extend.right
long_sup_clr=color.new(color.blue,0)
long_sup_textColor=color.new(color.white,0)
long_sup_sty=line.style_dotted
long_sup_width=2
long_sup_line=drawLine(long_sup_x1,long_sup_y1,long_sup_x2,long_sup_y2,long_sup_ext
,long_sup_clr,long_sup_sty,long_sup_width)
line.delete(long_sup_line[1])
//Label
long_pl_lab=drawLabel(0, Long?long_sup_val:na, "Long Invalidation",
label.style_label_left, color.blue, color.white)
label.delete(long_pl_lab[1])
//Value
plot(Long?long_sup_val:na,title="Long
Invalidation",color=color.new(color.blue,100))
//Fib50 Line
long_fib50_x1=long_sup_index
long_fib50_y1=long_cond?(long_res_y1+long_sup_y1)*0.5:na
long_fib50_x2=bar_index
long_fib50_y2=long_fib50_y1
long_fib50_ext=extend.right
long_fib50_clr=color.new(color.blue,0)
long_fib50_textColor=color.new(color.white,0)
long_fib50_sty=line.style_dotted
long_fib50_width=2
long_fib50_line=drawLine(long_fib50_x1,long_fib50_y1,long_fib50_x2,long_fib50_y2,lo
ng_fib50_ext,long_fib50_clr,long_fib50_sty,long_fib50_width)
line.delete(long_fib50_line[1])
//Label
long_fib50_lab=drawLabel(0, long_cond?long_fib50_y1:na, "Level 50",
label.style_label_left, color.blue, color.white)
label.delete(long_fib50_lab[1])
//Value
plot(long_cond?long_fib50_y1:na,title="Level 50",color=color.new(color.blue,100))
//Fib618 Line
long_fib618_x1=long_sup_index
long_fib618_y1=long_cond?long_res_y1-(long_res_y1-long_sup_y1)*0.618:na
long_fib618_x2=bar_index
long_fib618_y2=long_fib618_y1
long_fib618_ext=extend.right
long_fib618_clr=color.new(color.blue,0)
long_fib618_textColor=color.new(color.white,0)
long_fib618_sty=line.style_dotted
long_fib618_width=2
long_fib618_line=drawLine(long_fib618_x1,long_fib618_y1,long_fib618_x2,long_fib618_
y2,long_fib618_ext,long_fib618_clr,long_fib618_sty,long_fib618_width)
line.delete(long_fib618_line[1])
//Label
long_fib618_lab=drawLabel(0, long_cond?long_fib618_y1:na, "Level 61.8",
label.style_label_left, color.blue, color.white)
label.delete(long_fib618_lab[1])
//Value
plot(long_cond?long_fib618_y1:na,title="Level
61.8",color=color.new(color.blue,100))
//tp1
long_tp1_x1=long_sup_index
long_tp1_y1=long_cond?long_res_y1+(long_res_y1-long_sup_y1)*0.382:na
long_tp1_x2=bar_index
long_tp1_y2=long_tp1_y1
long_tp1_ext=extend.right
long_tp1_clr=color.new(color.blue,0)
long_tp1_textColor=color.new(color.white,0)
long_tp1_sty=line.style_dotted
long_tp1_width=2
long_tp1_line=drawLine(long_tp1_x1,long_tp1_y1,long_tp1_x2,long_tp1_y2,long_tp1_ext
,long_tp1_clr,long_tp1_sty,long_tp1_width)
line.delete(long_tp1_line[1])
//Label
long_tp1_lab=drawLabel(0, long_cond?long_tp1_y1:na, "Tp1", label.style_label_left,
color.blue, color.white)
label.delete(long_tp1_lab[1])
//Value
plot(long_cond?long_tp1_y1:na,title="Tp1",color=color.new(color.blue,100))
//tp2
long_tp2_x1=long_sup_index
long_tp2_y1=long_cond?long_res_y1+(long_res_y1-long_sup_y1):na
long_tp2_x2=bar_index
long_tp2_y2=long_tp2_y1
long_tp2_ext=extend.right
long_tp2_clr=color.new(color.blue,0)
long_tp2_textColor=color.new(color.white,0)
long_tp2_sty=line.style_dotted
long_tp2_width=2
long_tp2_line=drawLine(long_tp2_x1,long_tp2_y1,long_tp2_x2,long_tp2_y2,long_tp2_ext
,long_tp2_clr,long_tp2_sty,long_tp2_width)
line.delete(long_tp2_line[1])
//Label
long_tp2_lab=drawLabel(0, long_cond?long_tp2_y1:na, "Tp2", label.style_label_left,
color.blue, color.white)
label.delete(long_tp2_lab[1])
//Value
plot(long_cond?long_tp2_y1:na,title="Tp2",color=color.new(color.blue,100))
//Buy Zone
if long_cond
linefill.new(long_fib50_line,long_sup_line,color.new(color.blue,90))
//Short setup
var short_res_index=0,short_res_val=0.0,short_sup_val=0.0
if pl_index>ph_index
short_res_index:=ph_index
short_res_val:=ph_val
short_sup_val:=pl_val
else
short_res_index:=short_res_index[1]
short_res_val:=short_res_val[1]
if short_res_index==short_res_index[1]
short_sup_val:=short_sup_val[1]
//Short Condition
short_cond=(close<short_res_val and Short)
//Resistance Line
short_res_x1=short_res_index
short_res_y1=Short?short_res_val:na
short_res_x2=bar_index
short_res_y2=short_res_y1
short_res_ext=extend.right
short_res_clr=color.new(color.red,0)
short_res_textColor=color.new(color.white,0)
short_res_sty=line.style_dotted
short_res_width=2
short_res_line=drawLine(short_res_x1,short_res_y1,short_res_x2,short_res_y2,short_r
es_ext,short_res_clr,short_res_sty,short_res_width)
line.delete(short_res_line[1])
//Label
short_ph_lab=drawLabel(0, Short?short_res_val:na, "Short
Invalidation",label.style_label_left, color.red, color.white)
label.delete(short_ph_lab[1])
//Value
plot(Short?short_res_val:na,title="Short
Invalidation",color=color.new(color.red,100))
//Support Line
short_sup_x1=short_res_index
short_sup_y1=short_cond?short_sup_val:na
short_sup_x2=bar_index
short_sup_y2=short_sup_y1
short_sup_ext=extend.right
short_sup_clr=color.new(color.blue,0)
short_sup_textColor=color.new(color.white,0)
short_sup_sty=line.style_dotted
short_sup_width=2
short_sup_line=drawLine(short_sup_x1,short_sup_y1,short_sup_x2,short_sup_y2,short_s
up_ext,short_sup_clr,short_sup_sty,short_sup_width)
line.delete(short_sup_line[1])
//Label
short_pl_lab=drawLabel(0, short_cond?short_sup_y1:na, "Break Even",
label.style_label_left, color.blue, color.white)
label.delete(short_pl_lab[1])
//Value
plot(short_cond?short_sup_y1:na,title="Break Even",color=color.new(color.blue,100))
//Fib50 Line
short_fib50_x1=short_res_index
short_fib50_y1=short_cond?(short_res_y1+short_sup_y1)*0.5:na
short_fib50_x2=bar_index
short_fib50_y2=short_fib50_y1
short_fib50_ext=extend.right
short_fib50_clr=color.new(color.red,0)
short_fib50_textColor=color.new(color.white,0)
short_fib50_sty=line.style_dotted
short_fib50_width=2
short_fib50_line=drawLine(short_fib50_x1,short_fib50_y1,short_fib50_x2,short_fib50_
y2,short_fib50_ext,short_fib50_clr,short_fib50_sty,short_fib50_width)
line.delete(short_fib50_line[1])
//Label
short_fib50_lab=drawLabel(0, short_cond?short_fib50_y1:na, "Level 50",
label.style_label_left, color.red, color.white)
label.delete(short_fib50_lab[1])
//Value
plot(short_cond?short_fib50_y1:na,title="Level 50",color=color.new(color.red,100))
//Fib618 Line
short_fib618_x1=short_res_index
short_fib618_y1=short_cond?short_sup_y1+(short_res_y1-short_sup_y1)*0.618:na
short_fib618_x2=bar_index
short_fib618_y2=short_fib618_y1
short_fib618_ext=extend.right
short_fib618_clr=color.new(color.red,0)
short_fib618_textColor=color.new(color.white,0)
short_fib618_sty=line.style_dotted
short_fib618_width=2
short_fib618_line=drawLine(short_fib618_x1,short_fib618_y1,short_fib618_x2,short_fi
b618_y2,short_fib618_ext,short_fib618_clr,short_fib618_sty,short_fib618_width)
line.delete(short_fib618_line[1])
//Label
short_fib618_lab=drawLabel(0, short_cond?short_fib618_y1:na, "Level 61.8",
label.style_label_left, color.red, color.white)
label.delete(short_fib618_lab[1])
//Value
plot(short_cond?short_fib618_y1:na,title="Level
61.8",color=color.new(color.red,100))
//tp1
short_tp1_x1=short_res_index
short_tp1_y1=short_cond?short_sup_y1-(short_res_y1-short_sup_y1)*0.382:na
short_tp1_x2=bar_index
short_tp1_y2=short_tp1_y1
short_tp1_ext=extend.right
short_tp1_clr=color.new(color.red,0)
short_tp1_textColor=color.new(color.white,0)
short_tp1_sty=line.style_dotted
short_tp1_width=2
short_tp1_line=drawLine(short_tp1_x1,short_tp1_y1,short_tp1_x2,short_tp1_y2,short_t
p1_ext,short_tp1_clr,short_tp1_sty,short_tp1_width)
line.delete(short_tp1_line[1])
//Label
short_tp1_lab=drawLabel(0, short_cond?short_tp1_y1:na, "Tp1",
label.style_label_left, color.red, color.white)
label.delete(short_tp1_lab[1])
//Value
plot(short_cond?short_tp1_y1:na,title="Tp1",color=color.new(color.red,100))
//tp2
short_tp2_x1=short_res_index
short_tp2_y1=short_cond?short_sup_y1-(short_res_y1-short_sup_y1):na
short_tp2_x2=bar_index
short_tp2_y2=short_tp2_y1
short_tp2_ext=extend.right
short_tp2_clr=color.new(color.red,0)
short_tp2_textColor=color.new(color.white,0)
short_tp2_sty=line.style_dotted
short_tp2_width=2
short_tp2_line=drawLine(short_tp2_x1,short_tp2_y1,short_tp2_x2,short_tp2_y2,short_t
p2_ext,short_tp2_clr,short_tp2_sty,short_tp2_width)
line.delete(short_tp2_line[1])
//Label
short_tp2_lab=drawLabel(0, short_cond?short_tp2_y1:na, "Tp2",
label.style_label_left, color.red, color.white)
label.delete(short_tp2_lab[1])
//Value
plot(short_cond?short_tp2_y1:na,title="Tp2",color=color.new(color.red,100))
//Sell Zone
if short_cond
linefill.new(short_fib50_line,short_res_line,color.new(color.red,90))
//Alert
long_buy_zone=(close<long_fib50_y1 and long_cond)
short_sell_zone=(close>short_fib50_y1 and short_cond)
alertcondition(long_buy_zone or short_sell_zone,title="Alert
active",message="Inside the zone")
//EOF