BB
BB
0 at
https://mozilla.org/MPL/2.0/
// © BBScalper
//@version=5
///////////////////////////////////////////////////////////////////////////////////
///////////////////
///// Monospace fonts ////
//{
//
// Font source : https://fonts.adobe.com/fonts/courier?
mv=affiliate&mv2=red#recommendations-section //
//
//
///////////////////////////////////////////////////////////////////////////////////
///////////////////
///
//// STANDARD PINESCRIPT FONT ////
Pine_std_LC = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z"
Pine_std_UC = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"
Pine_std_DG = "0,1,2,3,4,5,6,7,8,9"
//
//// CUSTOM MONOSPACE FONT ////
// (a different font can be copy-pasted here, from the listed website or another
source)
//
// Sans-serif Std
std_LC = "𝚊,𝚋,𝚌,𝚍,𝚎,𝚏,𝚐,𝚑,𝚒,𝚓,𝚔,𝚕,𝚖,𝚗,𝚘,𝚙,𝚚,𝚛,𝚜,𝚝,𝚞,𝚟,𝚠,𝚡,𝚢,𝚣"
std_UC = "𝙰,𝙱,𝙲,𝙳,𝙴,𝙵,𝙶,𝙷,𝙸,𝙹,𝙺,𝙻,𝙼,𝙽,𝙾,𝙿,𝚀,𝚁,𝚂,𝚃,𝚄,𝚅,𝚆,𝚇,𝚈,𝚉"
std_DG = "𝟶,𝟷,𝟸,𝟹,𝟺,𝟻,𝟼,𝟽,𝟾,𝟿"
//
= "𝘢,𝘣,𝘤,𝘥,𝘦,𝘧,𝘨,𝘩,𝘪,𝘫,𝘬,𝘭,𝘮,𝘯,𝘰,𝘱,𝘲,𝘳,𝘴,𝘵,𝘶,𝘷,𝘸,𝘹,𝘺,𝘻"
// Sans-serif Std Italic
= "𝘈,𝘉,𝘊,𝘋,𝘌,𝘍,𝘎,𝘏,𝘐,𝘑,𝘒,𝘓,𝘔,𝘕,𝘖,𝘗,𝘘,𝘙,𝘚,𝘛,𝘜,𝘝,𝘞,𝘟,𝘠,𝘡"
std_it_LC
= "𝟢,𝟣,𝟤,𝟥,𝟦,𝟧,𝟨,𝟩,𝟪,𝟫"
std_it_UC
std_it_DG
//
= "𝗮,𝗯,𝗰,𝗱,𝗲,𝗳,𝗴,𝗵,𝗶,𝗷,𝗸,𝗹,𝗺,𝗻,𝗼,𝗽,𝗾,𝗿,𝘀,𝘁,𝘂,𝘃,𝘄,𝘅,𝘆,𝘇"
// Sans-serif Bold
= "𝗔,𝗕,𝗖,𝗗,𝗘,𝗙,𝗚,𝗛,𝗜,𝗝,𝗞,𝗟,𝗠,𝗡,𝗢,𝗣,𝗤,𝗥,𝗦,𝗧,𝗨,𝗩,𝗪,𝗫,𝗬,𝗭"
bld_LC
= "𝟬,𝟭,𝟮,𝟯,𝟰,𝟱,𝟲,𝟳,𝟴,𝟵"
bld_UC
bld_DG
//
= "𝙖,𝙗,𝙘,𝙙,𝙚,𝙛,𝙜,𝙝,𝙞,𝙟,𝙠,𝙡,𝙢,𝙣,𝙤,𝙥,𝙦,𝙧,𝙨,𝙩,𝙪,𝙫,𝙬,𝙭,𝙮,𝙯"
// Sans-serif Bold Italic
= "𝘼,𝘽,𝘾,𝘿,𝙀,𝙁,𝙂,𝙃,𝙄,𝙅,𝙆,𝙇,𝙈,𝙉,𝙊,𝙋,𝙌,𝙍,𝙎,𝙏,𝙐,𝙑,𝙒,𝙓,𝙔,𝙕"
bld_it_LC
= "𝟬,𝟭,𝟮,𝟯,𝟰,𝟱,𝟲,𝟳,𝟴,𝟵"
bld_it_UC
bld_it_DG
//}
///////////////////////////////////////////////////////////////////////////////////
///////////////////
///////////////////////////////////////////////////////////////////////////////////
///////////////////
//// Font arrays ////
//{
// Pine fonts
Pine_font_std_LC = str.split(Pine_std_LC, ",")
Pine_font_std_UC = str.split(Pine_std_UC, ",")
Pine_font_std_DG = str.split(Pine_std_DG, ",")
// Custom fonts
// Standard
Cust_font_std_LC = str.split(std_LC, ",")
Cust_font_std_UC = str.split(std_UC, ",")
Cust_font_std_DG = str.split(std_DG, ",")
// Standard italic
Cust_font_std_it_LC = str.split(std_it_LC, ",")
Cust_font_std_it_UC = str.split(std_it_UC, ",")
Cust_font_std_it_DG = str.split(std_it_DG, ",")
// Bold
Cust_font_bld_LC = str.split(bld_LC, ",")
Cust_font_bld_UC = str.split(bld_UC, ",")
Cust_font_bld_DG = str.split(bld_DG, ",")
// Bold italic
Cust_font_bld_it_LC = str.split(bld_it_LC, ",")
Cust_font_bld_it_UC = str.split(bld_it_UC, ",")
Cust_font_bld_it_DG = str.split(bld_it_DG, ",")
//}
//
-----------------------------------------------------------------------------------
----------------------------------------------------------
//
-----------------------------------------------------------------------------------
----------------------------------------------------------
// ------------------------------------------
// GLOBAL INPUTS
// ------------------------------------------
asset = input.string(title="Strategies", defval = " ### Dev Mode ### ", options=[
" ### Dev Mode ### ",
" ",
" ===== Crypto ===== ",
" ",
"_____ 30 min _____",
"BTCUSDT.P 30m | Binance - v1.4",
"ETHUSDT.P 30m | Binance - v1.5",
" ",
" ===== Commodities ===== ",
" ",
" ____ 15 min ____ ",
"GOLD 15m (US$/OZ) | CFD TVC - v1.3",
"SILVER 15m (US$/OZ) | CFD TVC - v1.0",
" ",
" ____ 30 min ____ ",
"USOIL 30m (WTI CRUDE OIL) | CFD TVC - v1.1"
])
ma_choice = input.string(title="MA Choice", defval = "EMA", options=["EMA", "HMA",
"RMA", "SMA", "VWAP", "VWMA", "WMA"])
ma_period = input.int(title='MA Period', defval=300, minval=0, maxval=10000)
leverage = input.int(title="Leverage", defval=20, minval=1, maxval=125)
renorm_coeff_comm = input.float(title="Renormalization", defval=1.0, minval=1.0,
maxval=20.0)
prob_stats_number = input.int(title='Number Trades StatistBB', defval=50, minval=1,
maxval=150)
// ------------------------------------------
// LONG INPUTS
// ------------------------------------------
std_deviation_period_long = input.int(title='Stdev Period', defval=14, minval=1,
maxval=1000, group="Long")
std_deviation_coefficient_long = input.float(title='Stdev Coeff', defval=0.5,
minval=0, maxval=100, step = 0.1, group="Long")
atr_period_long = input.int(title='ATR Period', defval=14, minval=1, maxval=1000,
group="Long")
atr_parameter_long = input.float(title='ATR Coeff', defval=0.5, minval=0.0,
maxval=100, step = 0.1, group = "Long")
long_entry_ma_distance_perc = input.float(title='MA Delta %', defval=0.5,
minval=0.0, maxval=100.0, step = 0.1, group="Long")
long_stop_price_perc = input.float(title="Stop Loss %", defval=4.5, minval=0,
maxval=100, group="Long")
// ------------------------------------------
// SHORT INPUTS
// ------------------------------------------
std_deviation_period_short = input.int(title='Stdev Period', defval=14, minval=1,
maxval=1000, group="Short")
std_deviation_coefficient_short = input.float(title='Stdev Coeff', defval=0.5,
minval=0, maxval=100, step = 0.1, group="Short")
atr_period_short = input.int(title='ATR Period', defval=14, minval=0, maxval=1000,
group="Short")
atr_parameter_short = input.float(title='ATR Coeff', defval=0.5, minval=0.0,
maxval=100, step = 0.1, group = "Short")
short_entry_ma_distance_perc = input.float(title='MA Delta %', defval=0.5,
minval=0.0, maxval=100.0, step = 0.1, group="Short")
short_stop_price_perc = input.float(title="Stop Loss %", defval=4.5, minval=0,
maxval=100, group="Short")
// ---------------------------------------------------
// CRYPTO
// ---------------------------------------------------
if asset == "ETHUSDT.P 30m | Binance - v1.5"
ma_period := 1
ma_choice := "VWAP"
std_deviation_period_long := 14
std_deviation_coefficient_long := 1
atr_period_long := 14
atr_parameter_long := 1.7
long_entry_ma_distance_perc := 1.7
long_stop_price_perc := 4.5
std_deviation_period_short := 14
std_deviation_coefficient_short := 1.5
atr_period_short := 14
atr_parameter_short := 1.7
short_entry_ma_distance_perc := 1.7
short_stop_price_perc := 4.5
std_deviation_period_long := 14
std_deviation_coefficient_long := 1
atr_period_long := 14
atr_parameter_long := 1.8
long_entry_ma_distance_perc := 1.8
long_stop_price_perc := 4.5
std_deviation_period_short := 10
std_deviation_coefficient_short := 0.8
atr_period_short := 14
atr_parameter_short := 1.6
short_entry_ma_distance_perc := 1.4
short_stop_price_perc := 4.5
// ---------------------------------------------------
// COMMODITIES
// ---------------------------------------------------
std_deviation_period_long := 10
std_deviation_coefficient_long := 0.2
atr_period_long := 14
atr_parameter_long := 0.5
long_entry_ma_distance_perc := 0.5
long_stop_price_perc := 4.5
std_deviation_period_short := 14
std_deviation_coefficient_short := 0.4
atr_period_short := 14
atr_parameter_short := 0.4
short_entry_ma_distance_perc := 0.4
short_stop_price_perc := 4.5
std_deviation_period_long := 14
std_deviation_coefficient_long := 0.3
atr_period_long := 14
atr_parameter_long := 0.5
long_entry_ma_distance_perc := 0.5
long_stop_price_perc := 4.5
std_deviation_period_short := 14
std_deviation_coefficient_short := 0.5
atr_period_short := 14
atr_parameter_short := 0.5
short_entry_ma_distance_perc := 0.5
short_stop_price_perc := 4.5
std_deviation_period_long := 11
std_deviation_coefficient_long := 1
atr_period_long := 14
atr_parameter_long := 1.5
long_entry_ma_distance_perc := 1.5
long_stop_price_perc := 4.5
std_deviation_period_short := 11
std_deviation_coefficient_short := 1
atr_period_short := 14
atr_parameter_short := 1.5
short_entry_ma_distance_perc := 1.5
short_stop_price_perc := 4.5
// ------------------------------------------
// GLOBAL CALCULATIONS
// ------------------------------------------
// Asset Precision
var float normalization = na
var int precision = 0
if barstate.isfirst
for i = 0 to 10
normalization := syminfo.mintick * math.pow(10, i)
if normalization == 1
precision := i
// TP Functions
tp_function_price(choice, entry, tp, renorm) =>
level = choice == "long" ? entry * (1 + 0.001 * tp/renorm) : choice ==
"short" ? entry * (1 - 0.001 * tp/renorm) : na
math.round(level, precision)
level_to_perc(n) =>
j = 1
k = 2
l = 3
perc := level_to_perc(tp_level)
price_level := tp_function_price(trade_type, effective_entry, perc * 10 /
leverage, renorm_coeff_comm)
price_level
// General MA Choice
var float ma_value = 0.0
ma_value := switch
ma_choice == "EMA" => ta.ema(close, ma_period)
ma_choice == "HMA" => ta.hma(close, ma_period)
ma_choice == "RMA" => ta.rma(close, ma_period)
ma_choice == "SMA" => ta.sma(close, ma_period)
ma_choice == "VWAP" => ta.vwap(close)
ma_choice == "VWMA" => ta.vwma(close, ma_period)
ma_choice == "WMA"=> ta.wma(close, ma_period)
// Avoid Averaging
var float perc_avoid_avg_long = na
var float perc_avoid_avg_short = na
perc_avoid_avg_long := level_to_perc(perc_avoid_avg_long_level)
perc_avoid_avg_short := level_to_perc(perc_avoid_avg_short_level)
// ------------------------------------------
// SPECIFIC CALCULATIONS
// ------------------------------------------
// Long
var float stdev_long = na
var float stdev_long_value = na
var float atr_long_value = na
var float long_entry_ma_value = na
// Short
var float stdev_short = na
var float stdev_short_value = na
var float atr_short_value = na
var float short_entry_ma_value = na
//
-----------------------------------------------------------------------------------
--------------------------------------------------------------------
// Useful Conditions
var bool first_long_candle = na
var bool first_short_candle = na
var bool second_long_candle = na
var bool second_short_candle = na
var bool bulk_long_cond = na
var bool bulk_short_cond = na
var bool bulk_long_increased_cond = na
var bool bulk_short_increased_cond = na
var bool long_closed_cond = na
var bool short_closed_cond = na
var bool next_candle_after_long_closed_cond = na
var bool next_candle_after_short_closed_cond = na
//
-----------------------------------------------------------------------------------
---------------------------------------------------
// Long
// Check Avg order first bar
long_check_current_bar_exec(level) =>
var bool result = na
result := ((ohlc_cond and low <= level) or (olhc_cond and level >= close)) and
level <= high
result
// Short
// Check Avg order first bar
short_check_current_bar_exec(level) =>
var bool result = na
result := ((ohlc_cond and level <= close) or (olhc_cond and high >= level)) and
level >= low
result
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////
// TRADE DETAILS
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////
// Perc Function
delta_perc_func(x_f,x_i) =>
r = ((x_f - x_i)/x_i) * 100 * leverage
r
// Reset
if next_candle_after_long_closed_cond // We
wait 1 candle because we need to store the peak into the array and compute the
statistBB
peak_profit_long := 0
if next_candle_after_short_closed_cond
peak_profit_short := 0
// Long
if first_long_candle
ath := high
peak_profit_long := math.round(delta_perc_func(ath, long_entry_price[1]), 2)
// We have long_entry[1] because label is placed when next candle forms
peak_profit_string_long := str.tostring(peak_profit_long)
positionMaxLabel_long := label.new(bar_index , ath, text ="Maximum Profit " +
peak_profit_string_long + "%",
textcolor = color.white, textalign = text.align_center, color = color.rgb(70,
130, 255, 30), style = label.style_label_down)
draw_long := close
draw_perc_long := math.round(delta_perc_func(draw_long, long_entry_price[1]),
2) < 0 ? math.round(delta_perc_func(draw_long, long_entry_price[1]), 2) : 0
label.set_x(positionMaxLabel_long, bar_index)
label.set_y(positionMaxLabel_long, ath)
label.set_text(positionMaxLabel_long, "Maximum Profit " +
peak_profit_string_long + "%")
label.set_x(positionMaxLabel_long, bar_index)
label.set_y(positionMaxLabel_long, ath)
label.set_text(positionMaxLabel_long, "Maximum Profit " +
peak_profit_string_long + "%")
// Short
if first_short_candle
atl := low
peak_profit_short := math.round(-delta_perc_func(atl, short_entry_price[1]), 2)
peak_profit_string_short := str.tostring(peak_profit_short)
positionMaxLabel_short := label.new(bar_index , atl, text ="Maximum Profit " +
peak_profit_string_short + "%",
textcolor = color.white, textalign = text.align_center, color = color.rgb(70,
130, 255, 30), style = label.style_label_up)
draw_short := close
draw_perc_short := math.round(-delta_perc_func(draw_short,
short_entry_price[1]), 2) < 0 ? math.round(-delta_perc_func(draw_short,
short_entry_price[1]), 2) : 0
label.set_x(positionMaxLabel_short, bar_index)
label.set_y(positionMaxLabel_short, atl)
label.set_text(positionMaxLabel_short, "Maximum Profit " +
peak_profit_string_short+ "%")
label.set_x(positionMaxLabel_short, bar_index)
label.set_y(positionMaxLabel_short, atl)
label.set_text(positionMaxLabel_short, "Maximum Profit " +
peak_profit_string_short+ "%")
//
-----------------------------------------------------------------------------------
------
// -----------------------------------------
// -------------- LONG ---------------------
// -----------------------------------------
var int long_array_size = na
long_array_size := number_averaging + 1
// ENTRY
if strategy.position_size <= 0 and trade_existence
strategy.entry("long", strategy.long, qty = quantity_contracts_long, stop =
long_entry_price, comment = "Long", disable_alert = true)
// AVERAGING
if first_long_candle and number_averaging != 0
for i = 0 to number_averaging
if i > 0
strategy.order("Avg_Long " + str.tostring(i), strategy.long,
qty = array.get(array_long_contracts_entries, i),
limit = array.get(array_long_entries, i),
stop = i == 1 ? array.get(array_long_entries, 0) :
long_check_current_bar_exec(array.get(array_long_entries, i - 1)) and
not long_check_current_bar_exec(array.get(array_long_entries, i)) ? na
:
array.get(array_long_entries, i - 1),
disable_alert = true
)
// Averaging Counting
if number_averaging != 0 and peak_profit_long < perc_avoid_avg_long
// First Candle
if first_long_candle
for i = 1 to number_averaging
if long_check_current_bar_exec(array.get(array_long_entries, i))
pyramiding_counter_long := i
// Second Candle
if second_long_candle and pyramiding_counter_long > 0
for i = 1 to pyramiding_counter_long //
The strategy recalculations after the filling of an Avg order during the first bar
causes the algo to place again
strategy.cancel("Avg_Long " + str.tostring(i)) //
the orders already executed. For this reason we remove them at the beginning of the
second candle
// Bulk Candles
if bulk_long_increased_cond
pyramiding_counter_long := math.round(pyramiding_counter_long[1] +
math.log(strategy.position_size/strategy.position_size[1])/math.log(1+m))
// Last Candle
if long_closed_cond
for i = 1 to number_averaging
if (math.round(low, precision) <= array.get(array_long_entries, i)) and
(short_entry_price[1] < array.get(array_long_entries, i))
pyramiding_counter_long := i
// Removing orders below the next short entry and replacing them in case the two
values flip again
if bulk_long_cond and peak_profit_long < perc_avoid_avg_long and
pyramiding_counter_long < number_averaging
for j = pyramiding_counter_long + 1 to number_averaging
if short_entry_price[1] >= array.get(array_long_entries, j)
array.set(array_long_avg_active, j, false)
strategy.cancel("Avg_Long " + str.tostring(j))
// Reset Counters
if second_short_candle or next_candle_after_long_closed_cond or number_averaging ==
0
pyramiding_counter_long := 0
for i = 1 to number_averaging
array.set(array_long_avg_active, i, true)
// EXIT
allow_averaging_cond_long = number_averaging != 0
and pyramiding_counter_long < number_averaging
and array.get(array_long_entries,
pyramiding_counter_long < number_averaging ? pyramiding_counter_long + 1 : 0) >
short_entry_price[1]
and (strategy.position_size > 0 or
strategy.position_size[1] > 0)
and peak_profit_long < perc_avoid_avg_long
if strategy.position_size > 0
strategy.exit("SL_Long", qty_percent = 100, stop = long_stop_price,
disable_alert = true)
strategy.exit("Flip_to_Short", qty_percent = 100, stop = short_entry_price,
disable_alert = true)
if allow_averaging_cond_long
strategy.cancel("SL_Long")
else
strategy.cancel("Flip_to_Short")
//
-----------------------------------------------------------------------------------
--------------------------------------------------------------------
// -----------------------------------------
// -------------- SHORT --------------------
// -----------------------------------------
var int short_array_size = na
short_array_size := number_averaging + 1
// ENTRY
if strategy.position_size >= 0 and trade_existence
strategy.entry("short", strategy.short, qty = quantity_contracts_short, stop =
short_entry_price, comment = "Short", disable_alert = true)
// AVERAGING
if first_short_candle and number_averaging != 0
for i = 0 to number_averaging
if i > 0
strategy.order("Avg_Short " + str.tostring(i), strategy.short,
qty = array.get(array_short_contracts_entries, i),
limit = array.get(array_short_entries, i),
stop = i == 1 ? array.get(array_short_entries, 0) :
short_check_current_bar_exec(array.get(array_short_entries, i - 1)) and not
short_check_current_bar_exec(array.get(array_short_entries, i)) ? na :
array.get(array_short_entries, i - 1),
disable_alert = true
)
// Averaging Counting
if number_averaging != 0 and peak_profit_short < perc_avoid_avg_short
// First Candle
if first_short_candle
for i = 1 to number_averaging
if short_check_current_bar_exec(array.get(array_short_entries, i))
pyramiding_counter_short := i
// Second Candle
if second_short_candle and pyramiding_counter_short > 0
for i = 1 to pyramiding_counter_short //
The strategy recalculations after the filling of an Avg order during the first bar
causes the algo to place again
strategy.cancel("Avg_Short " + str.tostring(i)) //
the orders already executed. For this reason we remove them at the beginning of the
second candle
// Bulk Candles
if bulk_short_increased_cond
pyramiding_counter_short := math.round(pyramiding_counter_short[1] +
math.log(strategy.position_size/strategy.position_size[1])/math.log(1+m))
// Last Candle
if short_closed_cond
for i = 1 to number_averaging
if (math.round(high, precision) >= array.get(array_short_entries, i))
and (long_entry_price[1] > array.get(array_short_entries, i))
pyramiding_counter_short := i
// Removing orders below the next short entry and replacing them in case the two
values flip again
if bulk_short_cond and peak_profit_short < perc_avoid_avg_short and
pyramiding_counter_short > 0 and pyramiding_counter_short < number_averaging
for j = pyramiding_counter_short + 1 to number_averaging
if long_entry_price[1] <= array.get(array_short_entries, j)
array.set(array_short_avg_active, j, false)
strategy.cancel("Avg_Short " + str.tostring(j))
// Reset Counters
if second_long_candle or next_candle_after_short_closed_cond or number_averaging ==
0
pyramiding_counter_short := 0
for i = 1 to number_averaging
array.set(array_short_avg_active, i, true)
// EXIT
allow_averaging_cond_short = number_averaging != 0
and pyramiding_counter_short < number_averaging
and array.get(array_short_entries,
pyramiding_counter_short < number_averaging ? pyramiding_counter_short + 1 : 0) <
long_entry_price[1]
and (strategy.position_size < 0 or
strategy.position_size[1] < 0)
and peak_profit_short < perc_avoid_avg_short
if strategy.position_size < 0
strategy.exit("SL_Short", qty_percent = 100, stop = short_stop_price,
disable_alert = true)
strategy.exit("Flip_to_Long", qty_percent = 100, stop = long_entry_price,
disable_alert = true)
if allow_averaging_cond_short
strategy.cancel("SL_Short")
else
strategy.cancel("Flip_to_Long")
//
-----------------------------------------------------------------------------------
--------------------------------------------------------------------
//
-----------------------------------------------------------------------------------
--------------------------------------------------------------------
//
-----------------------------------------------------------------------------------
--------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////
// STATISTBB
///////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////
// --------------------------------------------------------------
// Functions
// --------------------------------------------------------------
// Generic TP Counting
generic_tp_winrate(tp_perc, N) =>
var max_array = array.new_float()
var int max_array_size = na
var int tp_counter = 0
var float tp_prob = 0.0
if long_closed_cond
array.push(max_array, peak_profit_long)
if short_closed_cond
array.push(max_array, peak_profit_short)
max_array_size := array.size(max_array)
if long_closed_cond
array.push(max_array, peak_profit_long)
if short_closed_cond
array.push(max_array, peak_profit_short)
max_array_size := array.size(max_array)
if long_closed_cond
array.push(draw_array, draw_perc_long)
if short_closed_cond
array.push(draw_array, draw_perc_short)
draw_array_size := array.size(draw_array)
// Specific TP Counting
specific_tp_winrate(trade_type, tp_perc, N) =>
var max_array_long = array.new_float()
var max_array_short = array.new_float()
var int ath_array_size = na
var int atl_array_size = na
var int long_tp_counter = 0
var int short_tp_counter = 0
var float tp_prob = 0.0
if trade_type == "long"
if long_closed_cond
array.push(max_array_long, peak_profit_long)
ath_array_size := array.size(max_array_long)
if trade_type == "long"
if long_closed_cond
array.push(max_array_long, peak_profit_long)
ath_array_size := array.size(max_array_long)
//
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------------
//
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------------
//
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------------
// ------------------------------------------------------------------
// Cumulative Results
// ------------------------------------------------------------------
N100=generic_avg_max_profit(num_cum4)
N75=generic_avg_max_profit(num_cum3)
N50=generic_avg_max_profit(num_cum2)
N25=generic_avg_max_profit(num_cum1)
D100=generic_avg_draw(num_cum4)
D75=generic_avg_draw(num_cum3)
D50=generic_avg_draw(num_cum2)
D25=generic_avg_draw(num_cum1)
///////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////
current_entry := nz(strategy.position_avg_price)
current_tp1_level := strategy.position_size > 0 ? tp1_price_long :
strategy.position_size < 0 ? tp1_price_short : 0.0
current_tp2_level := strategy.position_size > 0 ? tp2_price_long :
strategy.position_size < 0 ? tp2_price_short : 0.0
current_tp3_level := strategy.position_size > 0 ? tp3_price_long :
strategy.position_size < 0 ? tp3_price_short : 0.0
current_tp4_level := strategy.position_size > 0 ? tp4_price_long :
strategy.position_size < 0 ? tp4_price_short : 0.0
current_tp5_level := strategy.position_size > 0 ? tp5_price_long :
strategy.position_size < 0 ? tp5_price_short : 0.0
current_tp6_level := strategy.position_size > 0 ? tp6_price_long :
strategy.position_size < 0 ? tp6_price_short : 0.0
current_tp7_level := strategy.position_size > 0 ? tp7_price_long :
strategy.position_size < 0 ? tp7_price_short : 0.0
current_tp8_level := strategy.position_size > 0 ? tp8_price_long :
strategy.position_size < 0 ? tp8_price_short : 0.0
if strategy.position_size > 0
if pyramiding_counter_long == number_averaging or peak_profit_long >=
perc_avoid_avg_long
current_stop := long_stop_price
else
current_stop := array.get(array_long_entries, pyramiding_counter_long + 1)
else if strategy.position_size < 0
if pyramiding_counter_short == number_averaging or peak_profit_short >=
perc_avoid_avg_short
current_stop := short_stop_price
else
current_stop := array.get(array_short_entries, pyramiding_counter_short +
1)
else
current_stop := 0.0
// Total Trades
var int tot_trades_long = 0
var int tot_trades_short = 0
if first_short_candle
tot_trades_short += 1
op_index_short := bar_index
else if first_long_candle
tot_trades_long += 1
op_index_long := bar_index
//
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------
table.merge_cells(stats_table, 0,5,3,5)
//
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------
table.merge_cells(stats_table, 0,6,1,6)
table.merge_cells(stats_table, 2,6,3,6)
//
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------
// Long/Short Probabilities
//
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------
table.cell(stats_table, 0, 7, text=
"TP 1: " + str.tostring(specific_tp_winrate("long", 0.5,
prob_stats_number)) + "%" + "\n" +
"TP 2: " + str.tostring(specific_tp_winrate("long", 0.8,
prob_stats_number)) + "%" + "\n" +
"TP 3: " + str.tostring(specific_tp_winrate("long", 1.3,
prob_stats_number)) + "%" + "\n" +
"TP 4: " + str.tostring(specific_tp_winrate("long", 2.1,
prob_stats_number)) + "%",
width=10, height=9, text_valign=text.align_center,
text_halign=text.align_center, bgcolor=table_txt_bg_color,
text_color=table_txt_color, text_size=table_txt_size)
table.cell(stats_table, 1, 7, text=
"TP 5: " + str.tostring(specific_tp_winrate("long", 3.4,
prob_stats_number)) + "%" + "\n" +
"TP 6: " + str.tostring(specific_tp_winrate("long", 5.5,
prob_stats_number)) + "%" + "\n" +
"TP 7: " + str.tostring(specific_tp_winrate("long", 8.9,
prob_stats_number)) + "%" + "\n" +
"TP 8: " + str.tostring(specific_tp_winrate("long", 14.4,
prob_stats_number)) + "%",
width=10, height=9, text_valign=text.align_center,
text_halign=text.align_center, bgcolor=table_txt_bg_color,
text_color=table_txt_color, text_size=table_txt_size)
table.cell(stats_table, 2, 7, text=
"TP 1: " + str.tostring(specific_tp_winrate("short", 0.5,
prob_stats_number)) + "%" + "\n" +
"TP 2: " + str.tostring(specific_tp_winrate("short", 0.8,
prob_stats_number)) + "%" + "\n" +
"TP 3: " + str.tostring(specific_tp_winrate("short", 1.3,
prob_stats_number)) + "%" + "\n" +
"TP 4: " + str.tostring(specific_tp_winrate("short", 2.1,
prob_stats_number)) + "%",
width=10, height=9, text_valign=text.align_center,
text_halign=text.align_center, bgcolor=table_txt_bg_color,
text_color=table_txt_color, text_size=table_txt_size)
table.cell(stats_table, 3, 7, text=
"TP 5: " + str.tostring(specific_tp_winrate("short", 3.4,
prob_stats_number)) + "%" + "\n" +
"TP 6: " + str.tostring(specific_tp_winrate("short", 5.5,
prob_stats_number)) + "%" + "\n" +
"TP 7: " + str.tostring(specific_tp_winrate("short", 8.9,
prob_stats_number)) + "%" + "\n" +
"TP 8: " + str.tostring(specific_tp_winrate("short", 14.4,
prob_stats_number)) + "%",
width=10, height=9, text_valign=text.align_center,
text_halign=text.align_center, bgcolor=table_txt_bg_color,
text_color=table_txt_color, text_size=table_txt_size)
// Average Data
table.cell(stats_table, 0, 8, text=
"Avg Max Profit: " + str.tostring(specific_avg_max_profit("long",
prob_stats_number)) + "%" + "\n" +
"Avg Drawdown: " + str.tostring(specific_avg_draw("long", prob_stats_number))
+ "%" + "\n" +
"Avg R/R Factor: " +
str.tostring(math.abs(math.round(specific_avg_max_profit("long", prob_stats_number)
/ specific_avg_draw("long", prob_stats_number),2))),
width=10, text_valign=text.align_center, text_halign=text.align_center,
bgcolor=table_txt_bg_color, text_color=table_txt_color, text_size=table_txt_size)
table.cell(stats_table, 1, 8, text="", width=10, height=5,
text_valign=text.align_center, text_halign=text.align_center,
bgcolor=table_txt_bg_color, text_color=table_txt_color, text_size=table_txt_size)
table.cell(stats_table, 2, 8, text=
"Avg Max Profit: " + str.tostring(specific_avg_max_profit("short",
prob_stats_number)) + "%" + "\n" +
"Avg Drawdown: " + str.tostring(specific_avg_draw("short", prob_stats_number))
+ "%" + "\n" +
"Avg R/R Factor: " +
str.tostring(math.abs(math.round(specific_avg_max_profit("short",
prob_stats_number) / specific_avg_draw("short", prob_stats_number),2))),
width=10, text_valign=text.align_center, text_halign=text.align_center,
bgcolor=table_txt_bg_color, text_color=table_txt_color, text_size=table_txt_size)
table.cell(stats_table, 3, 8, text="", width=10, height=5,
text_valign=text.align_center, text_halign=text.align_center,
bgcolor=table_txt_bg_color, text_color=table_txt_color, text_size=table_txt_size)
table.merge_cells(stats_table, 0,8,1,8)
table.merge_cells(stats_table, 2,8,3,8)
//
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------
table.merge_cells(stats_table, 0,10,3,10)
//
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------
// Cumulative Probabilities
//
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------
// Averaging Levels
plot(long_avg_plot_cond ? array.get(array_long_entries, pyramiding_counter_long +
1) : na, "Avg Order Long", color = color.rgb(72, 241, 241),
style=plot.style_circles, linewidth = 1)
plot(short_avg_plot_cond ? array.get(array_short_entries,pyramiding_counter_short +
1) : na, "Avg Order Short", color = color.rgb(72, 241, 241),
style=plot.style_circles, linewidth = 1)
plot(strategy.position_size > 0 and not long_avg_plot_cond ? long_stop_price : na,
"SL Long", color= color.red, style = plot.style_circles)
plot(strategy.position_size < 0 and not short_avg_plot_cond ? short_stop_price :
na, "SL Short", color=color.red, style=plot.style_circles)
// // BE
// plot(be_activated and be_is_active_long and strategy.position_size > 0 ? p_n :
na, "BE Long", color = color.orange, style = plot.style_circles, linewidth = 3)
// // plot(ts_activated and ts_plot_cond_short and not ts_achieved_long ?
ts_level_price_short : na, "BE Short", color = color.orange, style =
plot.style_circles, linewidth = 3)
// // TS
// plot(ts_activated and ts_plot_cond_long and not ts_achieved_long ?
ts_level_price_long : na, "TS Long", color = color.blue, style =
plot.style_circles, linewidth = 3)
// plot(ts_activated and ts_plot_cond_short and not ts_achieved_short ?
ts_level_price_short : na, "TS Short", color = color.blue, style =
plot.style_circles, linewidth = 3)
// TP Levels
plot(strategy.position_size != 0 ? current_tp1_level : na, title = "TP1",
style=plot.style_circles, color=color.new(color.green, 10), linewidth=1) // plot_4
--> 5° Plot
plot(strategy.position_size != 0 ? current_tp2_level : na, title = "TP2",
style=plot.style_circles, color=color.new(color.green, 10), linewidth=1)
plot(strategy.position_size != 0 ? current_tp3_level : na, title = "TP3",
style=plot.style_circles, color=color.new(color.green, 10), linewidth=1)
plot(strategy.position_size != 0 ? current_tp4_level : na, title = "TP4",
style=plot.style_circles, color=color.new(color.green, 10), linewidth=1)
plot(strategy.position_size != 0 ? current_tp5_level : na, title = "TP5",
style=plot.style_circles, color=color.new(color.green, 10), linewidth=1)
plot(strategy.position_size != 0 ? current_tp6_level : na, title = "TP6",
style=plot.style_circles, color=color.new(color.green, 10), linewidth=1) // plot_9
--> 10° Plot
plot(strategy.position_size != 0 ? current_tp7_level : na, title = "TP7",
style=plot.style_circles, color=color.new(color.green, 10), linewidth=1)
plot(strategy.position_size != 0 ? current_tp8_level : na, title = "TP8",
style=plot.style_circles, color=color.new(color.green, 10), linewidth=1)
// Background Color
backgroundColor = strategy.position_size > 0 ? color.new(color.green, 85) :
strategy.position_size < 0 ? color.new(color.red, 85) : na
bgcolor(backgroundColor)
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
/////
// TEST ALERT
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
/////
var string closed_long_alert = na
var string closed_short_alert = na
var string avg_long_alert = na
var string avg_short_alert = na
closed_alert_function(trade_type) =>
var string action_text = na
var string peak_string = na
var string final_message = na
final_message :=
"/b version: 1.0.0" +
"\nstrategy: " + asset +
"\n" +
"\n" +
"\n——— 🤖 " + uni_replace("BBScalper", false, true, false) + " 🤖 ———" +
"\n\n📋 " + uni_replace("Asset", false, true, false) + ": " + asset +
"\n🗃 " + uni_replace("Action", false, true, false) + ": " + action_text + "
Closed" +
"\n✍ " + uni_replace("Maximum Profit: " + peak_string + "%", false, true,
false)
avg_alert_function(trade_type) =>
var string action_text = na
var string peak_string = na
var string final_message = na
final_message :=
"/b version: 1.0.0" +
"\nstrategy: " + asset +
"\n" +
"\n" +
"\n——— 🤖 " + uni_replace("BBScalper", false, true, false) + " 🤖 ———" +
"\n\n📋 " + uni_replace("Asset", false, true, false) + ": " + asset +
"\n🗃 " + uni_replace("Action", false, true, false) + ": " + action_text + "
Averaged" +
"\n✍ " + uni_replace("Current Maximum Profit: " + peak_string + "%", false,
true, false) +
"\n✍ " + uni_replace("Current Avg Entry: " +
str.tostring(strategy.position_avg_price), false, true, false)
closed_long_alert := closed_alert_function("long")
closed_short_alert := closed_alert_function("short")
avg_long_alert := avg_alert_function("long")
avg_short_alert := avg_alert_function("short")