Pine Script v4 · Strategy
Ruckard TradingLatino
A Pine Script v4 strategy built on Linreg or Highest or Lowest or SMA (lengthKC), Change (high) and RMA (tr, len). It has 10 order rules, 4 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade is one contract and pays 0.1% commission. 75 settings; defaults include (ADX) Smoothing {14} 14, (ADX) DI Length {14} 14 and (ADX) key level {23} 23.
Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.
- Does Ruckard TradingLatino repaint?
- Yes
- In a live replay, it did not match history on 3 of 73 trades.
- How did Ruckard TradingLatino do on BTCUSDT 1D with default settings?
- +64.58%
- From 26 Jan 2024 to 21 Oct 2026, over 240 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Ruckard TradingLatino be converted to Pine Script v5?
- No
- The automatic step from v4 to v5 changes the results, so no v5 download is offered; the edits are shown below.
- Does Ruckard TradingLatino use a stop loss?
- Yes
- strategy.exit sets a stop on line 2740, 2742.
- Does Ruckard TradingLatino run in Zeal Terminal?
- Yes
- It compiles in 751 ms and runs 1,000 bars in 7,480 ms, in the browser.
BTCUSDT · 1D · default settings
- Media movil azul {10}
- Media movil marrón {55}
- Main resistance TOP
- Main resistance BOTTOM
- new_trailing_take_profit_percentage_trigger_percent
- BUY
- BUY_tradinglatino_strategy_smilb_and_adx_long_advice
- BUY_tradinglatino_strategy_emas_long_advice
- BUY_price_next_to_ema55_buy_advice
- BUY_bottom_vpoc_n_bars_advice
- BUY_CLOSE
- BUY_CLOSE_tradinglatino_strategy_smilb_and_adx_short_advice
- BUY_CLOSE_tradinglatino_strategy_emas_short_advice
- BUY_CLOSE_bcolor_is_green
- BUY_CLOSE_stop_loss_not_worth_open_buy
- SELL
- Net profit
- +64.58%
- $645.84
- Buy and hold
- +102.5%
- same period
- Closed trades
- 240
- 103 won · 137 lost
- Profitable
- 42.9%
- of closed trades
- Profit factor
- 1.29
- gross profit ÷ gross loss
- Max drawdown
- 15.33%
- −$297.47
One run with the author's default settings, $1,000 starting capital, commission as the script sets it. A long position was still open at the last bar. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.
Review
What a careful reader of this script would point out, found by checking the source and the backtest.
-
Likely bug
highest(high, 5) ignores the settings line 2241
Line 2241 hard-codes 5 where line 2076 uses “(VP) Number of bars for VPVR VPOC {100}”. Changing those settings moves one band but not this one.
highest (high, 5)highest(high, vp_vpvr_vpoc_n_bars) -
Likely bug
highest(drawdown, 5) ignores the settings line 2243
Line 2243 hard-codes 5 where line 2076 uses “(VP) Number of bars for VPVR VPOC {100}”. Changing those settings moves one band but not this one.
highest (drawdown, 5)highest(drawdown, vp_vpvr_vpoc_n_bars) -
Likely bug
highest(inv_drawdown, 5) ignores the settings line 2260
Line 2260 hard-codes 5 where line 2076 uses “(VP) Number of bars for VPVR VPOC {100}”. Changing those settings moves one band but not this one.
highest (inv_drawdown, 5)highest(inv_drawdown, vp_vpvr_vpoc_n_bars) -
Likely bug
lowest(low, 5) ignores the settings line 2258
Line 2258 hard-codes 5 where line 2079 uses “(VP) Number of bars for VPVR VPOC {100}”. Changing those settings moves one band but not this one.
lowest (low, 5)lowest(low, vp_vpvr_vpoc_n_bars) -
Likely bug
ema(sell_dynamic_trailing_take_profit_trigger_tmp, 5) ignores the settings line 2245
Line 2245 hard-codes 5 where line 1453 uses “(EMAS) EMA10 - Length {10}”. Changing those settings moves one band but not this one.
ema (sell_dynamic_trailing_take_profit_trigger_tmp, 5)ema(sell_dynamic_trailing_take_profit_trigger_tmp, ema10_len) -
Likely bug
ema(buy_dynamic_trailing_take_profit_trigger_tmp, 5) ignores the settings line 2262
Line 2262 hard-codes 5 where line 1453 uses “(EMAS) EMA10 - Length {10}”. Changing those settings moves one band but not this one.
ema (buy_dynamic_trailing_take_profit_trigger_tmp, 5)ema(buy_dynamic_trailing_take_profit_trigger_tmp, ema10_len) -
Check
8 settings do nothing
“(ADX) key level {23}”, “(ADX) DI minimum percentage (%) {10.0}”, “(SQZMOM) Squeeze percentage zero {0.0}”, “(ADXSLOPE) ADX minimum steepness exit {45}”, “(TRAILING) Trailing Take Profit (%) {0.4}”, “(TRAILING) Trailing Take Profit Trigger (%) {0.8}”, “(TRAILING) Take profit percentage for dynamic Trailing Take Profit Trigger based on VPoC resistances (%) {20.0}”, “(VP) Avoid label price overlaps {False}” are declared but never read.
-
Note
Uses iff(), which v5 removed line 1437
iff() on line 1437, 1437, 1437. v5 writes it as the ternary c ? a : b.
-
Note
Uses transp =, which v5 removed line 1849
transp = on line 1849, 1850, 1851, 1852, 1853, 1854. v5 folds the transparency into the colour with color.new(c, transp).
Upgrade and export
Written in Pine Script v4. The upgrade to v5 takes 1 step, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.
- Upgrading to v5 renames max → math.max, min → math.min, floor → math.floor, cum → ta.cum, atan → math.atan, tostring → str.tostring, change → ta.change, rma → ta.rma, abs → math.abs, median → ta.median, sma → ta.sma, stdev → ta.stdev, linreg → ta.linreg, avg → math.avg, highest → ta.highest, lowest → ta.lowest, ema → ta.ema, security → request.security.
v4 → v5
DiffersTrades differ: 240 before, 247 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 1: //@version=4 → //@version=5
- Line 945: max → math.max
- Line 946: min → math.min
- Line 957: input(type = input.bool) → input.bool()
- Line 966: input(type = input.resolution) → input.timeframe()
- Line 987: input(type = input.float) → input.float()
103 more edits
- Line 988: input(type = input.float) → input.float()
- Line 989: input(type = input.float) → input.float()
- Line 990: input(type = input.float) → input.float()
- Line 991: input(type = input.float) → input.float()
- Line 1012: input(type = input.bool) → input.bool()
- Line 1030: input(type = input.bool) → input.bool()
- Line 1035: input(type = input.bool) → input.bool()
- Line 1036: input(type = input.bool) → input.bool()
- Line 1037: input(type = input.bool) → input.bool()
- Line 1039: input(type = input.bool) → input.bool()
- Line 1045: input(type = input.bool) → input.bool()
- Line 1141: floor → math.floor
- Line 1168: max → math.max
- Line 1168: max → math.max
- Line 1191: max → math.max
- Line 1191: max → math.max
- Line 1254: cum → ta.cum
- Line 1254: max → math.max
- Line 1256: max → math.max
- Line 1258: cum → ta.cum
- Line 1278: atan → math.atan
- Line 1289: tostring → str.tostring
- Line 1290: tostring → str.tostring
- Line 1382: change → ta.change
- Line 1383: change → ta.change
- Line 1384: rma → ta.rma
- Line 1384: tr → ta.tr
- Line 1385: rma → ta.rma
- Line 1386: rma → ta.rma
- Line 1391: rma → ta.rma
- Line 1391: abs → math.abs
- Line 1402: median → ta.median
- Line 1403: median → ta.median
- Line 1423: sma → ta.sma
- Line 1424: stdev → ta.stdev
- Line 1428: sma → ta.sma
- Line 1429: range is reserved in v5: renamed range_
- Line 1429: tr → ta.tr
- Line 1430: sma → ta.sma
- Line 1436: linreg → ta.linreg
- Line 1436: avg → math.avg
- Line 1436: avg → math.avg
- Line 1436: highest → ta.highest
- Line 1436: lowest → ta.lowest
- Line 1436: sma → ta.sma
- Line 1437: iff(c, a, b) → (c ? a : b)
- Line 1437: iff(c, a, b) → (c ? a : b)
- Line 1437: iff(c, a, b) → (c ? a : b)
- Line 1453: ema → ta.ema
- Line 1454: ema → ta.ema
- Line 1463: ema → ta.ema
- Line 1464: ema → ta.ema
- Line 1466: ema → ta.ema
- Line 1467: ema → ta.ema
- Line 1471: security → request.security
- Line 1472: security → request.security
- Line 1562: abs → math.abs
- Line 1563: abs → math.abs
- Line 1647: abs → math.abs
- Line 1648: abs → math.abs
- Line 1750: ema → ta.ema
- Line 1751: ema → ta.ema
- Line 1752: ema → ta.ema
- Line 1753: ema → ta.ema
- Line 1761: floor → math.floor
- Line 1763: security → request.security
- Line 1764: security → request.security
- Line 1849: transp = 50 → color.new(pricerange_background_colour, 50)
- Line 1850: transp = 50 → color.new(pricerange_background_colour, 50)
- Line 1851: transp = 50 → color.new(pricerange_background_colour, 50)
- Line 1852: transp = 50 → color.new(pricerange_background_colour, 50)
- Line 1853: transp = 50 → color.new(pricerange_background_colour, 50)
- Line 1854: transp = 50 → color.new(pricerange_background_colour, 50)
- Line 1948: tostring → str.tostring
- Line 1956: tostring → str.tostring
- Line 1960: tostring → str.tostring
- Line 1964: tostring → str.tostring
- Line 1964: tostring → str.tostring
- Line 1992: tostring → str.tostring
- Line 2001: tostring → str.tostring
- Line 2005: tostring → str.tostring
- Line 2009: tostring → str.tostring
- Line 2009: tostring → str.tostring
- Line 2062: highest → ta.highest
- Line 2063: lowest → ta.lowest
- Line 2067: max → math.max
- Line 2076: highest → ta.highest
- Line 2079: lowest → ta.lowest
- Line 2094: max → math.max
- Line 2103: max → math.max
- Line 2124: highest → ta.highest
- Line 2241: highest → ta.highest
- Line 2243: highest → ta.highest
- Line 2245: ema → ta.ema
- Line 2258: lowest → ta.lowest
- Line 2260: highest → ta.highest
- Line 2262: ema → ta.ema
- Line 2537: floor → math.floor
- Line 2545: floor → math.floor
- Line 2553: floor → math.floor
- Line 2620: floor → math.floor
- Line 2722: floor → math.floor
- Line 2726: floor → math.floor
-//@version=4+//@version=5//⋯DIVERGENCE_COLOUR_B = color.silver-hc = max(close, open)+hc = math.max(close, open)-lc = min(close, open)+lc = math.min(close, open)// ADX inputs⋯sqzmom_multKC = input(1.5, title="(SQZMOM) KC MultFactor {1.5}")-sqzmom_useTrueRange = input(true, title="(SQZMOM) Use TrueRange (KC) {True}", type=input.bool)+sqzmom_useTrueRange = input.bool(true, title="(SQZMOM) Use TrueRange (KC) {True}")sqzmom_zero = input(0.0, "(SQZMOM) Squeeze percentage zero {0.0}", minval=-100.0, maxval=100.0, step=0.01)⋯// Volume Profile inputs-vp_timeframe = input("1D",title="(VP) Volume Profile timeframe {1 day}",type=input.resolution)+vp_timeframe = input.timeframe("1D",title="(VP) Volume Profile timeframe {1 day}")vp_enable_custom_recent_n_bars = input(false, "(VP) Use number of bars (not VP timeframe)")⋯// Trailing Take Profit - Inputs-trailing_take_profit_percentage = input(0.4, "(TRAILING) Trailing Take Profit (%) {0.4}",minval=0,step=0.01,type=input.float) * 0.01+trailing_take_profit_percentage = input.float(0.4, "(TRAILING) Trailing Take Profit (%) {0.4}",minval=0,step=0.01) * 0.01-trailing_take_profit_percentage_trigger = input(0.8, "(TRAILING) Trailing Take Profit Trigger (%) {0.8}",minval=0,step=0.01,type=input.float) * 0.01+trailing_take_profit_percentage_trigger = input.float(0.8, "(TRAILING) Trailing Take Profit Trigger (%) {0.8}",minval=0,step=0.01) * 0.01-trailing_take_profit_percentage_from_drawdown = input(30.0, "(TRAILING) Drawdown percentage for dynamic Trailing Take Profit Trigger (%) {30.0}",minval=0,step=0.01,type=input.float) * 0.01+trailing_take_profit_percentage_from_drawdown = input.float(30.0, "(TRAILING) Drawdown percentage for dynamic Trailing Take Profit Trigger (%) {30.0}",minval=0,step=0.01) * 0.01-dynamic_trailing_take_profit_offset_percentage = input(45.0, "(TRAILING) Trailing Take Profit as a percentage of Trailing Take Profit Trigger (for dynamic TTP) (%) {45.0}",minval=0,step=0.01,type=input.float) * 0.01+dynamic_trailing_take_profit_offset_percentage = input.float(45.0, "(TRAILING) Trailing Take Profit as a percentage of Trailing Take Profit Trigger (for dynamic TTP) (%) {45.0}",minval=0,step=0.01) * 0.01-trailing_take_profit_percentage_resistances_strict_mode = input(20.0, "(TRAILING) Take profit percentage for dynamic Trailing Take Profit Trigger based on VPoC resistances (%) {20.0}",minval=0,step=0.01,type=input.float)+trailing_take_profit_percentage_resistances_strict_mode = input.float(20.0, "(TRAILING) Take profit percentage for dynamic Trailing Take Profit Trigger based on VPoC resistances (%) {20.0}",minval=0,step=0.01)enable_dynamic_trailing_take_profit = input(true, "(TRAILING) Enforce dynamic Trailing Take Profit {True}")⋯sl = true-enable_trailing_take_profit_percentage = input(true, title="(TRAILING) Enable Trailing Take Profit (%) {True}", type=input.bool)+enable_trailing_take_profit_percentage = input.bool(true, title="(TRAILING) Enable Trailing Take Profit (%) {True}")too_old_order_ignore_advice_on_buy_close = input(false, "(OLD) Ignore advice based on order being too old {False}")⋯pricerange_text_colour = color.white-price_is_in_range_print = input(false, title="(PRANGE) Print price is in range {False}", type=input.bool)+price_is_in_range_print = input.bool(false, title="(PRANGE) Print price is in range {False}")pricerange_periods_number = input(5, title="(PRANGE) Price range periods {5}")⋯// SQUEEZE MOMENTUM Desviation indicator - Inputs-enable_show_degrees = input(false, title="(SQZDIVER) Show degrees {False}", type=input.bool)+enable_show_degrees = input.bool(false, title="(SQZDIVER) Show degrees {False}")-enable_show_desviation_labels = input(false, title="(SQZDIVER) Show desviation labels {False}", type=input.bool)+enable_show_desviation_labels = input.bool(false, title="(SQZDIVER) Show desviation labels {False}")-enable_show_desviation_lines = input(false, title="(SQZDIVER) Show desviation lines {False}", type=input.bool)+enable_show_desviation_lines = input.bool(false, title="(SQZDIVER) Show desviation lines {False}")// VOLUME PROFILE indicator - Inputs-vp_enable_print_vpvr_vpoc_price = input(true, title="(VP) Print VPVR VPoc price {True}", type=input.bool)+vp_enable_print_vpvr_vpoc_price = input.bool(true, title="(VP) Print VPVR VPoc price {True}")vp_enable_avoid_overlap_mode = input(false, "(VP) Avoid label price overlaps {False}")⋯// Order comments based debug-enable_order_comment_debug = input(false, title="(DEBUG) Enable debug on order comments {False}", type=input.bool)+enable_order_comment_debug = input.bool(false, title="(DEBUG) Enable debug on order comments {False}")// Raw testing⋯ minutes-vp_recent_n_bars_based_on_resolution = int(floor(get_resolution_bar_minutes(vp_timeframe) / currentResInMinutes))+vp_recent_n_bars_based_on_resolution = int(math.floor(get_resolution_bar_minutes(vp_timeframe) / currentResInMinutes))vp_recent_n_bars = 0⋯ actual_high := row_high- val := val + volume[i] * (max(actual_high - actual_low, 1) / max((row_high - row_low) * VP_PRICE_LEVELS, 1) )+ val := val + volume[i] * (math.max(actual_high - actual_low, 1) / math.max((row_high - row_low) * VP_PRICE_LEVELS, 1) ) val⋯ actual_high := row_high- volume_ponderated := volume[i] * (max(actual_high - actual_low, 1) / max((row_high - row_low) * VP_PRICE_LEVELS, 1))+ volume_ponderated := volume[i] * (math.max(actual_high - actual_low, 1) / math.max((row_high - row_low) * VP_PRICE_LEVELS, 1)) total_volume := total_volume + volume_ponderated⋯// Linear regression - functions-lrp_Sum(src,p) => a = cum(src), a - a[max(p,0)]+lrp_Sum(src,p) => a = ta.cum(src), a - a[math.max(p,0)]lrp_Wma(src,p) => - mp = max(p,0)+ mp = math.max(p,0) denom = mp*(mp+1)/2- a = cum(src), (mp*a - lrp_Sum(a[1],p))/denom+ a = ta.cum(src), (mp*a - lrp_Sum(a[1],p))/denomlrp_getAandB(src, p) =>⋯ x_axis_slope=0- angle_radians = atan((slope-x_axis_slope)/(1+(slope*x_axis_slope)))+ angle_radians = math.atan((slope-x_axis_slope)/(1+(slope*x_axis_slope))) pi_number = 3.1415926535897⋯ if enable_show_degrees- line_smilb_angle_degrees := " (" + tostring(line_smilb_angle,"#.00") + ")"+ line_smilb_angle_degrees := " (" + str.tostring(line_smilb_angle,"#.00") + ")"- line_price_angle_degrees := " (" + tostring(line_price_angle,"#.00") + ")"+ line_price_angle_degrees := " (" + str.tostring(line_price_angle,"#.00") + ")" ⋯dirmov(len) =>- up = change(high)+ up = ta.change(high)- down = -change(low)+ down = -ta.change(low)- truerange = rma(tr, len)+ truerange = ta.rma(ta.tr, len)- plus = fixnan(100 * rma(up > down and up > 0 ? up : 0, len) / truerange)+ plus = fixnan(100 * ta.rma(up > down and up > 0 ? up : 0, len) / truerange)- minus = fixnan(100 * rma(down > up and down > 0 ? down : 0, len) / truerange)+ minus = fixnan(100 * ta.rma(down > up and down > 0 ? down : 0, len) / truerange) [plus, minus]⋯ sum = plus + minus- adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)+ adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen) [adx, plus, minus]⋯ is_in_range = true- hc_median = median (hc, pricerange_range_periods_number)+ hc_median = ta.median (hc, pricerange_range_periods_number)- lc_median = median (lc, pricerange_range_periods_number)+ lc_median = ta.median (lc, pricerange_range_periods_number) hc_maximum = hc_median * ((100 + pricerange_maximum_desviation_percent) / 100)⋯ source = close- basis = sma(source, length)+ basis = ta.sma(source, length)- dev = mult * stdev(source, length)+ dev = mult * ta.stdev(source, length) upperBB = basis + dev⋯ // Calculate KC- ma = sma(source, lengthKC)+ ma = ta.sma(source, lengthKC)- range = useTrueRange ? tr : (high - low)+ range_ = useTrueRange ? ta.tr : (high - low)- rangema = sma(range, lengthKC)+ rangema = ta.sma(range_, lengthKC) upperKC = ma + rangema * multKC⋯ noSqz = (sqzOn == false) and (sqzOff == false)- val = linreg(source - avg(avg(highest(high, lengthKC), lowest(low, lengthKC)),sma(close,lengthKC)), lengthKC,0)+ val = ta.linreg(source - math.avg(math.avg(ta.highest(high, lengthKC), ta.lowest(low, lengthKC)),ta.sma(close,lengthKC)), lengthKC,0)- bcolor = iff( val > 0, iff( val > nz(val[1]), color.lime, color.green), iff( val < nz(val[1]), color.red, color.maroon))+ bcolor = ( val > 0 ? ( val > nz(val[1]) ? color.lime : color.green) : ( val < nz(val[1]) ? color.red : color.maroon)) // TODO: Use string variables for colours so that final user can change the actual colour if he wants to.⋯fun_ema(ema10_len, ema10_src, ema55_len, ema55_src) =>- ema10_out = ema(ema10_src, ema10_len)+ ema10_out = ta.ema(ema10_src, ema10_len)- ema55_out = ema(ema55_src, ema55_len)+ ema55_out = ta.ema(ema55_src, ema55_len) [ema10_out, ema55_out]⋯ // Rely on default handling of na with default emas when we start- ema10_out := ema(ema10_src, ema10_len)+ ema10_out := ta.ema(ema10_src, ema10_len)- ema55_out := ema(ema55_src, ema55_len)+ ema55_out := ta.ema(ema55_src, ema55_len) else- ema10_out := ema(ema10_src[1], ema10_len)+ ema10_out := ta.ema(ema10_src[1], ema10_len)- ema55_out := ema(ema55_src[1], ema55_len)+ ema55_out := ta.ema(ema55_src[1], ema55_len) [ema10_out, ema55_out]⋯[ema10, ema55] = fun_ema(ema10_len, ema10_src, ema55_len, ema55_src)-[ema10_1d, ema55_1d] = security(syminfo.tickerid, fun_get_higher_timeframe(), fun_ema(ema10_len, ema10_src, ema55_len, ema55_src))+[ema10_1d, ema55_1d] = request.security(syminfo.tickerid, fun_get_higher_timeframe(), fun_ema(ema10_len, ema10_src, ema55_len, ema55_src))-bar_index_1d = security(syminfo.tickerid, fun_get_higher_timeframe(), bar_index)+bar_index_1d = request.security(syminfo.tickerid, fun_get_higher_timeframe(), bar_index)// EMAS printing⋯ smilb_is_light_green = (sqzmom_bcolor == color.lime)- smilb_sqz_percentage_greater_than_zero = (abs(sqz_percentage) > 0.5)+ smilb_sqz_percentage_greater_than_zero = (math.abs(sqz_percentage) > 0.5)- smilb_sqz_percentage_lesser_than_zero = (abs(sqz_percentage) > 0.5)+ smilb_sqz_percentage_lesser_than_zero = (math.abs(sqz_percentage) > 0.5) adx_positive_slope = fun_adx_positive_slope (adx_sig, adx_minimum_steepness_entry, adx_steepness_periods_number)⋯ smilb_is_light_green = (sqzmom_bcolor == color.lime)- smilb_sqz_percentage_greater_than_zero = (abs(sqz_percentage) > 0.5)+ smilb_sqz_percentage_greater_than_zero = (math.abs(sqz_percentage) > 0.5)- smilb_sqz_percentage_lesser_than_zero = (abs(sqz_percentage) > 0.5)+ smilb_sqz_percentage_lesser_than_zero = (math.abs(sqz_percentage) > 0.5) adx_positive_slope = fun_adx_positive_slope (adx_sig, adx_minimum_steepness_entry, adx_steepness_periods_number)⋯ // We make sure to use the previous day bar so that it's closed and confirmed- ema10_out_1 = ema(ema10_src[1], ema10_len)+ ema10_out_1 = ta.ema(ema10_src[1], ema10_len)- ema55_out_1 = ema(ema55_src[1], ema55_len)+ ema55_out_1 = ta.ema(ema55_src[1], ema55_len)- ema10_out_2 = ema(ema10_src[2], ema10_len)+ ema10_out_2 = ta.ema(ema10_src[2], ema10_len)- ema55_out_2 = ema(ema55_src[2], ema55_len)+ ema55_out_2 = ta.ema(ema55_src[2], ema55_len) bool are_equal = na⋯var higher_timeframe_confirmation_bars = 2-var bars_in_higher_timeframe = int(floor(get_resolution_bar_minutes(fun_get_higher_timeframe()) / currentResInMinutes)) // 1 day = 6 bars of 4h+var bars_in_higher_timeframe = int(math.floor(get_resolution_bar_minutes(fun_get_higher_timeframe()) / currentResInMinutes)) // 1 day = 6 bars of 4hvar higher_timeframe_oldest_bar_for_confirmation = (bars_in_higher_timeframe * higher_timeframe_confirmation_bars) - 1 // 6 -> 12 -> 11-long_advice_found = security(syminfo.tickerid, fun_get_higher_timeframe(), fun_ema_last_two_days_equal_to(ema10_len, ema10_src, ema55_len, ema55_src, true))+long_advice_found = request.security(syminfo.tickerid, fun_get_higher_timeframe(), fun_ema_last_two_days_equal_to(ema10_len, ema10_src, ema55_len, ema55_src, true))-short_advice_found = security(syminfo.tickerid, fun_get_higher_timeframe(), fun_ema_last_two_days_equal_to(ema10_len, ema10_src, ema55_len, ema55_src, false))+short_advice_found = request.security(syminfo.tickerid, fun_get_higher_timeframe(), fun_ema_last_two_days_equal_to(ema10_len, ema10_src, ema55_len, ema55_src, false))if ( na(tradinglatino_strategy_emas_long_advice[higher_timeframe_oldest_bar_for_confirmation]) or na(tradinglatino_strategy_emas_short_advice[higher_timeframe_oldest_bar_for_confirmation]) )⋯// Show Range - BEGIN-plotshape(series=price_is_in_range_R, title="RangeTitleR", style=shape.square, color=pricerange_background_colour, transp=50, text="R", textcolor=pricerange_text_colour, editable=false, location=location.bottom)+plotshape(series=price_is_in_range_R, title="RangeTitleR", style=shape.square, color=color.new(pricerange_background_colour, 50), text="R", textcolor=pricerange_text_colour, editable=false, location=location.bottom)-plotshape(series=price_is_in_range_A, title="RangeTitleA", style=shape.square, color=pricerange_background_colour, transp=50, text="A", textcolor=pricerange_text_colour, editable=false, location=location.bottom)+plotshape(series=price_is_in_range_A, title="RangeTitleA", style=shape.square, color=color.new(pricerange_background_colour, 50), text="A", textcolor=pricerange_text_colour, editable=false, location=location.bottom)-plotshape(series=price_is_in_range_N, title="RangeTitleN", style=shape.square, color=pricerange_background_colour, transp=50, text="N", textcolor=pricerange_text_colour, editable=false, location=location.bottom)+plotshape(series=price_is_in_range_N, title="RangeTitleN", style=shape.square, color=color.new(pricerange_background_colour, 50), text="N", textcolor=pricerange_text_colour, editable=false, location=location.bottom)-plotshape(series=price_is_in_range_G, title="RangeTitleG", style=shape.square, color=pricerange_background_colour, transp=50, text="G", textcolor=pricerange_text_colour, editable=false, location=location.bottom)+plotshape(series=price_is_in_range_G, title="RangeTitleG", style=shape.square, color=color.new(pricerange_background_colour, 50), text="G", textcolor=pricerange_text_colour, editable=false, location=location.bottom)-plotshape(series=price_is_in_range_E, title="RangeTitleE", style=shape.square, color=pricerange_background_colour, transp=50, text="E", textcolor=pricerange_text_colour, editable=false, location=location.bottom)+plotshape(series=price_is_in_range_E, title="RangeTitleE", style=shape.square, color=color.new(pricerange_background_colour, 50), text="E", textcolor=pricerange_text_colour, editable=false, location=location.bottom)-plotshape(series=price_is_in_range__, title="RangeTitle_", style=shape.square, color=pricerange_background_colour, transp=50, text="-", textcolor=pricerange_text_colour, editable=false, location=location.bottom)+plotshape(series=price_is_in_range__, title="RangeTitle_", style=shape.square, color=color.new(pricerange_background_colour, 50), text="-", textcolor=pricerange_text_colour, editable=false, location=location.bottom)// Show Range - END⋯ float entry_quantity_contracts_percent = (float_entry_quantity_contracts_usdt / float_current_capital) * 100.00- entry_quantity_contracts_percent_str = tostring(entry_quantity_contracts_percent, "0." + vp_get_resistances_price_decimal_digits_zero_string())+ entry_quantity_contracts_percent_str = str.tostring(entry_quantity_contracts_percent, "0." + vp_get_resistances_price_decimal_digits_zero_string()) // This is actually not needed because with pyramiding=0 it's impossible that an order is scaled (and thus modified)⋯ if sl- zignale_stop_loss_combo := zignaly_separator + zignaly_quote + "stopLossPercentage" + zignaly_quote + zignaly_equals + zignaly_quote + "-" + tostring((nz(constant_buy_SL) * 100), "0." + vp_get_resistances_price_decimal_digits_zero_string()) + zignaly_quote+ zignale_stop_loss_combo := zignaly_separator + zignaly_quote + "stopLossPercentage" + zignaly_quote + zignaly_equals + zignaly_quote + "-" + str.tostring((nz(constant_buy_SL) * 100), "0." + vp_get_resistances_price_decimal_digits_zero_string()) + zignaly_quote else⋯ if tp- zignale_take_profit_combo := zignaly_separator + zignaly_quote + "takeProfitPercentage1" + zignaly_quote + zignaly_equals + zignaly_quote + "" + tostring((TP * 100), "0." + vp_get_resistances_price_decimal_digits_zero_string()) + zignaly_quote+ zignale_take_profit_combo := zignaly_separator + zignaly_quote + "takeProfitPercentage1" + zignaly_quote + zignaly_equals + zignaly_quote + "" + str.tostring((TP * 100), "0." + vp_get_resistances_price_decimal_digits_zero_string()) + zignaly_quote else⋯ if enable_trailing_take_profit_percentage- zignale_trailing_take_profit_combo := zignaly_separator + zignaly_quote + "trailingStopDistancePercentage" + zignaly_quote + zignaly_equals + zignaly_quote + "-" + tostring((constant_trailing_take_profit_percentage * 100), "0." + vp_get_resistances_price_decimal_digits_zero_string()) + zignaly_quote + zignaly_separator + zignaly_quote + "trailingStopTriggerPercentage" + zignaly_quote + zignaly_equals + zignaly_quote + "" + tostring((constant_trailing_take_profit_percentage_trigger * 100), "0." + vp_get_resistances_price_decimal_digits_zero_string()) + zignaly_quote+ zignale_trailing_take_profit_combo := zignaly_separator + zignaly_quote + "trailingStopDistancePercentage" + zignaly_quote + zignaly_equals + zignaly_quote + "-" + str.tostring((constant_trailing_take_profit_percentage * 100), "0." + vp_get_resistances_price_decimal_digits_zero_string()) + zignaly_quote + zignaly_separator + zignaly_quote + "trailingStopTriggerPercentage" + zignaly_quote + zignaly_equals + zignaly_quote + "" + str.tostring((constant_trailing_take_profit_percentage_trigger * 100), "0." + vp_get_resistances_price_decimal_digits_zero_string()) + zignaly_quote else⋯ float entry_quantity_contracts_percent = (float_entry_quantity_contracts_usdt / float_current_capital) * 100.00- entry_quantity_contracts_percent_str = tostring(entry_quantity_contracts_percent, "0." + vp_get_resistances_price_decimal_digits_zero_string())+ entry_quantity_contracts_percent_str = str.tostring(entry_quantity_contracts_percent, "0." + vp_get_resistances_price_decimal_digits_zero_string()) // This is actually not needed because with pyramiding=0 it's impossible that an order is scaled (and thus modified)⋯ if sl- zignale_stop_loss_combo := zignaly_separator + zignaly_quote + "stopLossPercentage" + zignaly_quote + zignaly_equals + zignaly_quote + "" + tostring((nz(constant_sell_SL) * 100), "0." + vp_get_resistances_price_decimal_digits_zero_string()) + zignaly_quote+ zignale_stop_loss_combo := zignaly_separator + zignaly_quote + "stopLossPercentage" + zignaly_quote + zignaly_equals + zignaly_quote + "" + str.tostring((nz(constant_sell_SL) * 100), "0." + vp_get_resistances_price_decimal_digits_zero_string()) + zignaly_quote else⋯ if tp- zignale_take_profit_combo := zignaly_separator + zignaly_quote + "takeProfitPercentage1" + zignaly_quote + zignaly_equals + zignaly_quote + "-" + tostring((TP * 100), "0." + vp_get_resistances_price_decimal_digits_zero_string()) + zignaly_quote+ zignale_take_profit_combo := zignaly_separator + zignaly_quote + "takeProfitPercentage1" + zignaly_quote + zignaly_equals + zignaly_quote + "-" + str.tostring((TP * 100), "0." + vp_get_resistances_price_decimal_digits_zero_string()) + zignaly_quote else⋯ if enable_trailing_take_profit_percentage- zignale_trailing_take_profit_combo := zignaly_separator + zignaly_quote + "trailingStopDistancePercentage" + zignaly_quote + zignaly_equals + zignaly_quote + "" + tostring((constant_trailing_take_profit_percentage * 100), "0." + vp_get_resistances_price_decimal_digits_zero_string()) + zignaly_quote + zignaly_separator + zignaly_quote + "trailingStopTriggerPercentage" + zignaly_quote + zignaly_equals + zignaly_quote + "-" + tostring((constant_trailing_take_profit_percentage_trigger * 100), "0." + vp_get_resistances_price_decimal_digits_zero_string()) + zignaly_quote+ zignale_trailing_take_profit_combo := zignaly_separator + zignaly_quote + "trailingStopDistancePercentage" + zignaly_quote + zignaly_equals + zignaly_quote + "" + str.tostring((constant_trailing_take_profit_percentage * 100), "0." + vp_get_resistances_price_decimal_digits_zero_string()) + zignaly_quote + zignaly_separator + zignaly_quote + "trailingStopTriggerPercentage" + zignaly_quote + zignaly_equals + zignaly_quote + "-" + str.tostring((constant_trailing_take_profit_percentage_trigger * 100), "0." + vp_get_resistances_price_decimal_digits_zero_string()) + zignaly_quote else⋯// Recent VPoC - Value-vp_recent_high := highest(high, vp_recent_n_bars)+vp_recent_high := ta.highest(high, vp_recent_n_bars)-vp_recent_low := lowest(low, vp_recent_n_bars)+vp_recent_low := ta.lowest(low, vp_recent_n_bars)vp_recent_lvl_height = (vp_recent_high - vp_recent_low) / VP_PRICE_LEVELS⋯ vp_recent_lvl_value_tmp := vp_level_value_wrapper(vp_recent_lvl_height, vp_recent_low, vp_level_number, 0, vp_recent_n_bars)- vp_recent_highest_lvl_value := max(nz(vp_recent_highest_lvl_value), vp_recent_lvl_value_tmp)+ vp_recent_highest_lvl_value := math.max(nz(vp_recent_highest_lvl_value), vp_recent_lvl_value_tmp) if nz(vp_highest_recent_lvl_value) < vp_recent_highest_lvl_value⋯// vp_vpvr_recent_low := lowest(low, vp_vpvr_vpoc_n_bars)-vp_vpvr_recent_high_top := highest(high, vp_vpvr_vpoc_n_bars)+vp_vpvr_recent_high_top := ta.highest(high, vp_vpvr_vpoc_n_bars)vp_vpvr_recent_low_top := closevp_vpvr_recent_high_bottom := close-vp_vpvr_recent_low_bottom := lowest(low, vp_vpvr_vpoc_n_bars)+vp_vpvr_recent_low_bottom := ta.lowest(low, vp_vpvr_vpoc_n_bars)// vp_vpvr_recent_lvl_height = (vp_vpvr_recent_high - vp_vpvr_recent_low) / VP_PRICE_LEVELS⋯ vp_recent_lvl_value_tmp := vp_level_value_wrapper(vp_vpvr_recent_lvl_height_top, vp_vpvr_recent_low_top, vp_level_number, 0, vp_vpvr_vpoc_n_bars)- vp_vpvr_recent_highest_lvl_value := max(nz(vp_vpvr_recent_highest_lvl_value), vp_recent_lvl_value_tmp)+ vp_vpvr_recent_highest_lvl_value := math.max(nz(vp_vpvr_recent_highest_lvl_value), vp_recent_lvl_value_tmp) if nz(vp_vpvr_highest_recent_lvl_value) < vp_vpvr_recent_highest_lvl_value⋯ vp_recent_lvl_value_tmp := vp_level_value_wrapper(vp_vpvr_recent_lvl_height_bottom, vp_vpvr_recent_low_bottom, vp_level_number, 0, vp_vpvr_vpoc_n_bars)- vp_vpvr_recent_highest_lvl_value := max(nz(vp_vpvr_recent_highest_lvl_value), vp_recent_lvl_value_tmp)+ vp_vpvr_recent_highest_lvl_value := math.max(nz(vp_vpvr_recent_highest_lvl_value), vp_recent_lvl_value_tmp) if nz(vp_vpvr_highest_recent_lvl_value) < vp_vpvr_recent_highest_lvl_value⋯ bool lowest_higher_than_was_found = false- float lowest_higher_than = highest (pvp_recent_vpoc_price, pvp_bottom_vpoc_n_bars)+ float lowest_higher_than = ta.highest (pvp_recent_vpoc_price, pvp_bottom_vpoc_n_bars) for nbar = 0 to pvp_bottom_vpoc_n_bars⋯float new_trailing_take_profit_percentage = na-ath = highest (high, 5)+ath = ta.highest (high, 5)drawdown = 100 - ( low / ath ) * 100-maxdrawdown = highest (drawdown, 5)+maxdrawdown = ta.highest (drawdown, 5)sell_dynamic_trailing_take_profit_trigger_tmp = maxdrawdown * trailing_take_profit_percentage_from_drawdown-sell_dynamic_trailing_take_profit_trigger = ema (sell_dynamic_trailing_take_profit_trigger_tmp, 5)+sell_dynamic_trailing_take_profit_trigger = ta.ema (sell_dynamic_trailing_take_profit_trigger_tmp, 5)float ShortRatio = na⋯// plotchar(sell_dynamic_trailing_take_profit_trigger, "sell_dynamic_trailing_take_profit_trigger", "", location = location.top)-atl = lowest (low, 5)+atl = ta.lowest (low, 5)inv_drawdown = ( ( high / atl ) * 100 ) - 100-inv_maxdrawdown = highest (inv_drawdown, 5)+inv_maxdrawdown = ta.highest (inv_drawdown, 5)buy_dynamic_trailing_take_profit_trigger_tmp = inv_maxdrawdown * trailing_take_profit_percentage_from_drawdown-buy_dynamic_trailing_take_profit_trigger = ema (buy_dynamic_trailing_take_profit_trigger_tmp, 5)+buy_dynamic_trailing_take_profit_trigger = ta.ema (buy_dynamic_trailing_take_profit_trigger_tmp, 5)if enable_strict_mode and tradinglatino_strategy_emas_long_advice⋯bar_minutes_to_now = bar_index * bar_minutes-current_day := floor (bar_minutes_to_now / day_minutes)+current_day := math.floor (bar_minutes_to_now / day_minutes)// risk_management_maximum_loss_per_week⋯var week_minutes = get_resolution_bar_minutes('1W')-current_week := floor (bar_minutes_to_now / week_minutes)+current_week := math.floor (bar_minutes_to_now / week_minutes)// risk_management_maximum_loss_per_month⋯var month_minutes = get_resolution_bar_minutes('1M')-current_month := floor (bar_minutes_to_now / month_minutes)+current_month := math.floor (bar_minutes_to_now / month_minutes)float order_SL = na⋯// We assume the current price is current bar close-entry_quantity_contracts = (floor(((entry_quantity / close) * entry_quantity_contracts_reducer) * contract_multiplier) / contract_multiplier)+entry_quantity_contracts = (math.floor(((entry_quantity / close) * entry_quantity_contracts_reducer) * contract_multiplier) / contract_multiplier)entry_quantity_contracts_usdt = entry_quantity_contracts * (close)⋯buy_trailing_take_profit_offset_float = buy_tmp_ttp_top_value - buy_tmp_ttp_base_value-float buy_trailing_take_profit_offset_tick = floor (buy_trailing_take_profit_offset_float / syminfo.mintick)+float buy_trailing_take_profit_offset_tick = math.floor (buy_trailing_take_profit_offset_float / syminfo.mintick)sell_tmp_ttp_base_value = position_price * (1 - constant_trailing_take_profit_percentage_trigger)⋯sell_trailing_take_profit_offset_float = sell_tmp_ttp_base_value - sell_tmp_ttp_bottom_value-float sell_trailing_take_profit_offset_tick = floor (sell_trailing_take_profit_offset_float / syminfo.mintick)+float sell_trailing_take_profit_offset_tick = math.floor (sell_trailing_take_profit_offset_float / syminfo.mintick)if enable_trailing_take_profit_percentage⋯Clean v5
VerifiedSame 247 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 948: input() → input.int()
- Line 949: input() → input.int()
- Line 950: input() → input.int()
- Line 951: input() → input.float()
- Line 953: input() → input.int()
- Line 954: input() → input.float()
52 more edits
- Line 955: input() → input.int()
- Line 956: input() → input.float()
- Line 958: input() → input.float()
- Line 961: input() → input.int()
- Line 962: input() → input.source()
- Line 963: input() → input.int()
- Line 964: input() → input.source()
- Line 967: input() → input.bool()
- Line 968: input() → input.int()
- Line 969: input() → input.int()
- Line 970: input() → input.int()
- Line 971: input() → input.bool()
- Line 972: input() → input.int()
- Line 973: input() → input.int()
- Line 975: input() → input.int()
- Line 976: input() → input.int()
- Line 977: input() → input.int()
- Line 978: input() → input.int()
- Line 980: input() → input.float()
- Line 981: input() → input.float()
- Line 984: input() → input.float()
- Line 985: input() → input.float()
- Line 992: input() → input.bool()
- Line 994: input() → input.int()
- Line 995: input() → input.float()
- Line 996: input() → input.int()
- Line 997: input() → input.float()
- Line 998: input() → input.float()
- Line 999: input() → input.float()
- Line 1000: input() → input.float()
- Line 1002: input() → input.bool()
- Line 1003: input() → input.bool()
- Line 1004: input() → input.bool()
- Line 1005: input() → input.bool()
- Line 1006: input() → input.bool()
- Line 1007: input() → input.bool()
- Line 1008: input() → input.bool()
- Line 1013: input() → input.bool()
- Line 1014: input() → input.bool()
- Line 1021: input() → input.float()
- Line 1022: input() → input.float()
- Line 1023: input() → input.float()
- Line 1024: input() → input.float()
- Line 1026: input() → input.int()
- Line 1031: input() → input.int()
- Line 1032: input() → input.float()
- Line 1033: input() → input.float()
- Line 1040: input() → input.bool()
- Line 1047: input() → input.bool()
- Line 1048: input() → input.float()
- Line 1050: input() → input.bool()
- Line 1051: input() → input.bool()
⋯// ADX inputs-adx_adxlen = input(14, title="(ADX) Smoothing {14}")+adx_adxlen = input.int(14, title="(ADX) Smoothing {14}")-adx_dilen = input(14, title="(ADX) DI Length {14}")+adx_dilen = input.int(14, title="(ADX) DI Length {14}")-adx_keyLevel = input(23, title="(ADX) key level {23}")+adx_keyLevel = input.int(23, title="(ADX) key level {23}")-di_minimum_percentage = input(10.0, title="(ADX) DI minimum percentage (%) {10.0}", minval=0.0, step=0.01)+di_minimum_percentage = input.float(10.0, title="(ADX) DI minimum percentage (%) {10.0}", minval=0.0, step=0.01)// SMILB inputs-sqzmom_length = input(20, title="(SQZMOM) BB Length {20}")+sqzmom_length = input.int(20, title="(SQZMOM) BB Length {20}")-sqzmom_mult = input(2.0,title="(SQZMOM) BB MultFactor {2.0}")+sqzmom_mult = input.float(2.0,title="(SQZMOM) BB MultFactor {2.0}")-sqzmom_lengthKC=input(20, title="(SQZMOM) KC Length {20}")+sqzmom_lengthKC=input.int(20, title="(SQZMOM) KC Length {20}")-sqzmom_multKC = input(1.5, title="(SQZMOM) KC MultFactor {1.5}")+sqzmom_multKC = input.float(1.5, title="(SQZMOM) KC MultFactor {1.5}")sqzmom_useTrueRange = input.bool(true, title="(SQZMOM) Use TrueRange (KC) {True}")-sqzmom_zero = input(0.0, "(SQZMOM) Squeeze percentage zero {0.0}", minval=-100.0, maxval=100.0, step=0.01)+sqzmom_zero = input.float(0.0, "(SQZMOM) Squeeze percentage zero {0.0}", minval=-100.0, maxval=100.0, step=0.01)// EMAS inputsmarron_color=#800000-ema10_len = input(10, minval=1, title="(EMAS) EMA10 - Length {10}")+ema10_len = input.int(10, minval=1, title="(EMAS) EMA10 - Length {10}")-ema10_src = input(close, title="(EMAS) EMA10 - Source {close}")+ema10_src = input.source(close, title="(EMAS) EMA10 - Source {close}")-ema55_len = input(55, minval=1, title="(EMAS) EMA55 - Length {55}")+ema55_len = input.int(55, minval=1, title="(EMAS) EMA55 - Length {55}")-ema55_src = input(close, title="(EMAS) EMA55 - Source {close}")+ema55_src = input.source(close, title="(EMAS) EMA55 - Source {close}")// Volume Profile inputsvp_timeframe = input.timeframe("1D",title="(VP) Volume Profile timeframe {1 day}")-vp_enable_custom_recent_n_bars = input(false, "(VP) Use number of bars (not VP timeframe)")+vp_enable_custom_recent_n_bars = input.bool(false, "(VP) Use number of bars (not VP timeframe)")-vp_custom_recent_n_bars = input(100, "(VP) Number of bars {100}", minval=1, maxval=500)+vp_custom_recent_n_bars = input.int(100, "(VP) Number of bars {100}", minval=1, maxval=500)-vp_resistances_price_decimal_digits = input(2, "(VP) Resistances prices number of decimal digits {2}", minval=0, maxval=10, step=1)+vp_resistances_price_decimal_digits = input.int(2, "(VP) Resistances prices number of decimal digits {2}", minval=0, maxval=10, step=1)-vp_bottom_vpoc_n_bars = input(18, "(VP) Number of bars for bottom VPOC {18}", minval=1, maxval=500) // 18 bars 4h = 3 days+vp_bottom_vpoc_n_bars = input.int(18, "(VP) Number of bars for bottom VPOC {18}", minval=1, maxval=500) // 18 bars 4h = 3 days-vp_bottom_vpoc_ignore_advice = input(false, "(VP) Ignore VPOC bottom advice on long {False}")+vp_bottom_vpoc_ignore_advice = input.bool(false, "(VP) Ignore VPOC bottom advice on long {False}")-vp_vpvr_vpoc_n_bars = input(100, "(VP) Number of bars for VPVR VPOC {100}", minval=1, maxval=500)+vp_vpvr_vpoc_n_bars = input.int(100, "(VP) Number of bars for VPVR VPOC {100}", minval=1, maxval=500)-VP_PRICE_LEVELS = input(24, "(VP) Price levels {24}", minval=10, maxval=500)+VP_PRICE_LEVELS = input.int(24, "(VP) Price levels {24}", minval=10, maxval=500)// TradingLatino ADX Long based on slope and 23 value advice - Inputs-adx_23_value_for_strat = input(23, title="(ADXSLOPE) ADX cut {23}")+adx_23_value_for_strat = input.int(23, title="(ADXSLOPE) ADX cut {23}")-adx_minimum_steepness_entry = input(45, title="(ADXSLOPE) ADX minimum steepness entry {45}")+adx_minimum_steepness_entry = input.int(45, title="(ADXSLOPE) ADX minimum steepness entry {45}")-adx_minimum_steepness_exit = input(45, title="(ADXSLOPE) ADX minimum steepness exit {45}")+adx_minimum_steepness_exit = input.int(45, title="(ADXSLOPE) ADX minimum steepness exit {45}")-adx_steepness_periods_number = input(3, title="(ADXSLOPE) ADX steepness periods {3}")+adx_steepness_periods_number = input.int(3, title="(ADXSLOPE) ADX steepness periods {3}")// Next to EMA55 - Inputs-bounce_back_to_EMA55_percent = input(50.00, "(NEXTEMA55) EMA10 to EMA55 bounce back percentage {80}", minval=50, maxval=100, step=0.01)+bounce_back_to_EMA55_percent = input.float(50.00, "(NEXTEMA55) EMA10 to EMA55 bounce back percentage {80}", minval=50, maxval=100, step=0.01)-next_to_EMA55_percent = input(15.00, "(NEXTEMA55) Next to EMA55 percentage {15}", minval=0, maxval=50, step=0.01)+next_to_EMA55_percent = input.float(15.00, "(NEXTEMA55) Next to EMA55 percentage {15}", minval=0, maxval=50, step=0.01)// Stop Loss and Take Profit - Inputs// We make stop loss is always used and > 0, otherwise we would have a division per zero-SL = input(7.0, title="(STOPTAKE) Stop Loss % {7.0}", minval=0.01 ) / 100+SL = input.float(7.0, title="(STOPTAKE) Stop Loss % {7.0}", minval=0.01 ) / 100-TP = input(2.0, title="(STOPTAKE) Take Profit % {2.0}") / 100+TP = input.float(2.0, title="(STOPTAKE) Take Profit % {2.0}") / 100// Trailing Take Profit - Inputs⋯trailing_take_profit_percentage_resistances_strict_mode = input.float(20.0, "(TRAILING) Take profit percentage for dynamic Trailing Take Profit Trigger based on VPoC resistances (%) {20.0}",minval=0,step=0.01)-enable_dynamic_trailing_take_profit = input(true, "(TRAILING) Enforce dynamic Trailing Take Profit {True}")+enable_dynamic_trailing_take_profit = input.bool(true, "(TRAILING) Enforce dynamic Trailing Take Profit {True}")// Too old order - Inputs-too_old_bars_number = input(6, "(OLD) Number of bars to consider and order to be old {6}", minval=1, maxval=100, step=1)+too_old_bars_number = input.int(6, "(OLD) Number of bars to consider and order to be old {6}", minval=1, maxval=100, step=1)-too_old_minimum_loss_percent = input(0.8, "(OLD) Minimum loss percent to close an old order {0.8}", minval=0.01, maxval=100, step=0.01) / 100+too_old_minimum_loss_percent = input.float(0.8, "(OLD) Minimum loss percent to close an old order {0.8}", minval=0.01, maxval=100, step=0.01) / 100-too_recent_minutes_number = input(6, "(RECENT) Number of minutes to wait to open a new order after the previous one has been opened {6}", minval=1, maxval=100, step=1)+too_recent_minutes_number = input.int(6, "(RECENT) Number of minutes to wait to open a new order after the previous one has been opened {6}", minval=1, maxval=100, step=1)-dynamic_minimum_stop_loss = input(1.0, "(STOPTAKE) Minimum loss percent to be supported by VPVR VPoC {1.0}", minval=0.01, maxval=100, step=0.01) / 100+dynamic_minimum_stop_loss = input.float(1.0, "(STOPTAKE) Minimum loss percent to be supported by VPVR VPoC {1.0}", minval=0.01, maxval=100, step=0.01) / 100-dynamic_maximum_stop_loss = input(2.38, "(STOPTAKE) Maximum loss percent to be supported by VPVR VPoC {2.38}", minval=0.01, maxval=100, step=0.01) / 100+dynamic_maximum_stop_loss = input.float(2.38, "(STOPTAKE) Maximum loss percent to be supported by VPVR VPoC {2.38}", minval=0.01, maxval=100, step=0.01) / 100-Ratio = input(1.00, "(STOPTAKE) Win/Loss Ratio {1.00}", minval=0.01, maxval=100, step=0.01) // Ratio 1:1 it's '1'.+Ratio = input.float(1.00, "(STOPTAKE) Win/Loss Ratio {1.00}", minval=0.01, maxval=100, step=0.01) // Ratio 1:1 it's '1'.-exchange_order_fee_percent = input(0.04, "(EXCHANGE) Fees per order {0.04} (%)", minval=0.01, maxval=100, step=0.01)+exchange_order_fee_percent = input.float(0.04, "(EXCHANGE) Fees per order {0.04} (%)", minval=0.01, maxval=100, step=0.01)// MAIN TURN ON/OFF OPTIONS - Inputs-emas_ignore_advice = input(false, "(EMAS) Ignore advice based on emas {false}")+emas_ignore_advice = input.bool(false, "(EMAS) Ignore advice based on emas {false}")-emas_ignore_advice_on_buy_close = input(false, "(EMAS) Ignore advice based on emas (On closing long signal) {False}")+emas_ignore_advice_on_buy_close = input.bool(false, "(EMAS) Ignore advice based on emas (On closing long signal) {False}")-smilb_ignore_advice = input(false, "(SQZMOM) Ignore advice based on SQZMOM {false}")+smilb_ignore_advice = input.bool(false, "(SQZMOM) Ignore advice based on SQZMOM {false}")-sqzmom_percentage_zero_ignore_advice = input(true, "(SQZMOM) Ignore advice based squeeze percentage {True}")+sqzmom_percentage_zero_ignore_advice = input.bool(true, "(SQZMOM) Ignore advice based squeeze percentage {True}")-adx_positive_slope_ignore_advice = input(true, "(ADXSLOPE) Ignore advice based on ADX positive slope {true}")+adx_positive_slope_ignore_advice = input.bool(true, "(ADXSLOPE) Ignore advice based on ADX positive slope {true}")-adx_23_ignore_advice = input(true, "(ADXSLOPE) Ignore advice based on ADX cut (23) {true}")+adx_23_ignore_advice = input.bool(true, "(ADXSLOPE) Ignore advice based on ADX cut (23) {true}")-tp = input(false, "(STOPTAKE) Take Profit? {false}")+tp = input.bool(false, "(STOPTAKE) Take Profit? {false}")// sl = input(true, "(STOPTAKE) Stop Loss? {True}")⋯enable_trailing_take_profit_percentage = input.bool(true, title="(TRAILING) Enable Trailing Take Profit (%) {True}")-too_old_order_ignore_advice_on_buy_close = input(false, "(OLD) Ignore advice based on order being too old {False}")+too_old_order_ignore_advice_on_buy_close = input.bool(false, "(OLD) Ignore advice based on order being too old {False}")-enable_dynamic_stop_loss = input(true, "(STOPTAKE) Enforce dynamic stop loss up to maximum stop loss {True}")+enable_dynamic_stop_loss = input.bool(true, "(STOPTAKE) Enforce dynamic stop loss up to maximum stop loss {True}")// TradingLatino Strategy - Inputs⋯risk_management_type = input(_SCOMPOUND_, "(RISKM) Risk Management Type", options=[_SAFE_, _SCOMPOUND_, _UCOMPOUND_])-risk_management_maximum_loss_per_trade = input(1.0, title="(RISKM) Maximum loss per trade % {1.0}" ) / 100+risk_management_maximum_loss_per_trade = input.float(1.0, title="(RISKM) Maximum loss per trade % {1.0}" ) / 100-risk_management_maximum_loss_per_day = input(6.0, title="(RISKM) Maximum loss per day % {6.0}" ) / 100+risk_management_maximum_loss_per_day = input.float(6.0, title="(RISKM) Maximum loss per day % {6.0}" ) / 100-risk_management_maximum_loss_per_week = input(8.0, title="(RISKM) Maximum loss per week % {8.0}" ) / 100+risk_management_maximum_loss_per_week = input.float(8.0, title="(RISKM) Maximum loss per week % {8.0}" ) / 100-risk_management_maximum_loss_per_month = input(10.0, title="(RISKM) Maximum loss per month % {10.0}" ) / 100+risk_management_maximum_loss_per_month = input.float(10.0, title="(RISKM) Maximum loss per month % {10.0}" ) / 100// Decimal - Inputs-contract_maximum_decimal_number = input(3, title="(DECIMAL) Maximum number of decimal for contracts {3}",minval=0)+contract_maximum_decimal_number = input.int(3, title="(DECIMAL) Maximum number of decimal for contracts {3}",minval=0)// TradingLatino Price is in range - Inputs⋯price_is_in_range_print = input.bool(false, title="(PRANGE) Print price is in range {False}")-pricerange_periods_number = input(5, title="(PRANGE) Price range periods {5}")+pricerange_periods_number = input.int(5, title="(PRANGE) Price range periods {5}")-pricerange_maximum_desviation_percent = input(0.6, title="(PRANGE) Price range maximum desviation (%) {0.6} ( > 0 ) ")+pricerange_maximum_desviation_percent = input.float(0.6, title="(PRANGE) Price range maximum desviation (%) {0.6} ( > 0 ) ")-pricerange_minimum_desviation_percent = input(0.6, title="(PRANGE) Price range minimum desviation (%) {0.6} ( > 0 ) ")+pricerange_minimum_desviation_percent = input.float(0.6, title="(PRANGE) Price range minimum desviation (%) {0.6} ( > 0 ) ")// SQUEEZE MOMENTUM Desviation indicator - Inputs⋯vp_enable_print_vpvr_vpoc_price = input.bool(true, title="(VP) Print VPVR VPoc price {True}")-vp_enable_avoid_overlap_mode = input(false, "(VP) Avoid label price overlaps {False}")+vp_enable_avoid_overlap_mode = input.bool(false, "(VP) Avoid label price overlaps {False}")// Zignaly - Email (zignalye)⋯// Raw testing-enable_raw_testing = input(false, "(DEBUG) Enable raw testing {True}")+enable_raw_testing = input.bool(false, "(DEBUG) Enable raw testing {True}")-raw_testing_quantity = input(100.0, title="(DEBUG) Constant entry quantity for raw USDT testing {100.0}")+raw_testing_quantity = input.float(100.0, title="(DEBUG) Constant entry quantity for raw USDT testing {100.0}")// Plus or Neo mode-enable_plus_mode = input(false, "(PLUS MODE) Beyond original TradingLatino strategy (Experimental) {False}")+enable_plus_mode = input.bool(false, "(PLUS MODE) Beyond original TradingLatino strategy (Experimental) {False}")-enable_strict_mode = input(true, "(STRICT RISK) Even more strict risk management {True}")+enable_strict_mode = input.bool(true, "(STRICT RISK) Even more strict risk management {True}")// Dynamic Trailing Take Profit - Variables⋯Does it run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L1545:C4: a 'bool' cannot be 'na' in Pine Script v6 — declare it as true or false. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
-//@version=5+//@version=6//⋯Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| (ADX) Smoothing {14} | 14 | int | adx_sig di_plus di_minus |
| (ADX) DI Length {14} | 14 | int | adx_sig di_plus di_minus |
| (ADX) key level {23} | 23 | int | unused |
| (ADX) DI minimum percentage (%) {10.0} | 10.0 | float · min 0.0 · step 0.01 | unused |
| (SQZMOM) BB Length {20} | 20 | int | sqz_percentage sqzmom_val sqzmom_bcolor sqzmom_scolor |
| (SQZMOM) BB MultFactor {2.0} | 2.0 | float | sqz_percentage sqzmom_val sqzmom_bcolor sqzmom_scolor |
| (SQZMOM) KC Length {20} | 20 | int | sqz_percentage sqzmom_val sqzmom_bcolor sqzmom_scolor |
| (SQZMOM) KC MultFactor {1.5} | 1.5 | float | sqz_percentage sqzmom_val sqzmom_bcolor sqzmom_scolor |
| (SQZMOM) Use TrueRange (KC) {True} | true | bool | sqz_percentage sqzmom_val sqzmom_bcolor sqzmom_scolor |
| (SQZMOM) Squeeze percentage zero {0.0} | 0.0 | float · min -100.0 · max 100.0 · step 0.01 | unused |
| (EMAS) EMA10 - Length {10} | 10 | int · min 1 | ema10_out ema10 ema55 ema10_1d ema55_1d ema10_out_1 ema10_out_2 long_advice_found short_advice_found |
| (EMAS) EMA10 - Source {close} | close | source | ema10_out ema10 ema55 ema10_1d ema55_1d ema10_out_1 ema10_out_2 long_advice_found short_advice_found line 1461 |
| (EMAS) EMA55 - Length {55} | 55 | int · min 1 | ema55_out ema10 ema55 ema10_1d ema55_1d ema55_out_1 ema55_out_2 long_advice_found short_advice_found |
| (EMAS) EMA55 - Source {close} | close | source | ema55_out ema10 ema55 ema10_1d ema55_1d ema55_out_1 ema55_out_2 long_advice_found short_advice_found line 1461 |
| (VP) Volume Profile timeframe {1 day} | 1D | timeframe (written input.resolution) | vp_recent_n_bars_based_on_resolution |
| (VP) Use number of bars (not VP timeframe) | false | bool | line 1143 |
| (VP) Number of bars {100} | 100 | int · min 1 · max 500 | vp_recent_n_bars |
| (VP) Resistances prices number of decimal digits {2} | 2 | int · min 0 · max 10 · step 1 | line 1150 line 1151 |
| (VP) Number of bars for bottom VPOC {18} | 18 | int · min 1 · max 500 | vp_bottom_vpoc vp_top_vpoc |
| (VP) Ignore VPOC bottom advice on long {False} | false | bool | line 2318 line 2326 line 2343 line 2351 |
| (VP) Number of bars for VPVR VPOC {100} | 100 | int · min 1 · max 500 | vp_recent_lvl_value_tmp vp_vpvr_recent_high_top vp_vpvr_recent_low_bottom vp_recent_vpvr_vpoc_price_top vp_recent_vpvr_vpoc_price_bottom |
| (VP) Price levels {24} | 24 | int · min 10 · max 500 | volume_ponderated vp_recent_lvl_height vp_vpvr_recent_lvl_height_top vp_vpvr_recent_lvl_height_bottom val line 2065 line 2092 line 2101 |
| (ADXSLOPE) ADX cut {23} | 23 | int | adx_greater_than_23 tradinglatino_strategy_smilb_and_adx_long_advice tradinglatino_strategy_smilb_and_adx_short_advice |
| (ADXSLOPE) ADX minimum steepness entry {45} | 45 | int | adx_positive_slope adx_negative_slope tradinglatino_strategy_smilb_and_adx_long_advice tradinglatino_strategy_smilb_and_adx_short_advice line 1394 line 1396 |
| (ADXSLOPE) ADX minimum steepness exit {45} | 45 | int | unused |
| (ADXSLOPE) ADX steepness periods {3} | 3 | int | adx_positive_slope adx_negative_slope tradinglatino_strategy_smilb_and_adx_long_advice tradinglatino_strategy_smilb_and_adx_short_advice line 1394 line 1396 |
| (NEXTEMA55) EMA10 to EMA55 bounce back percentage {80} | 50.00 | float · min 50 · max 100 · step 0.01 | bounce_back_mode_buy_close_advice bounce_back_mode_sell_close_advice target_price_delta |
| (NEXTEMA55) Next to EMA55 percentage {15} | 15.00 | float · min 0 · max 50 · step 0.01 | target_price_delta price_next_to_ema55_buy_advice price_next_to_ema55_sell_advice |
| (STOPTAKE) Stop Loss % {7.0} | 7.0 | float · min 0.01 | new_buy_SL new_sell_SL buy_stop_loss_target sell_stop_loss_target |
| (STOPTAKE) Take Profit % {2.0} | 2.0 | float | zignale_take_profit_combo TP_B TP_S |
| (TRAILING) Trailing Take Profit (%) {0.4} | 0.4 | float · min 0 · step 0.01 | unused |
| (TRAILING) Trailing Take Profit Trigger (%) {0.8} | 0.8 | float · min 0 · step 0.01 | unused |
| (TRAILING) Drawdown percentage for dynamic Trailing Take Profit Trigger (%) {30.0} | 30.0 | float · min 0 · step 0.01 | sell_dynamic_trailing_take_profit_trigger_tmp buy_dynamic_trailing_take_profit_trigger_tmp |
| (TRAILING) Trailing Take Profit as a percentage of Trailing Take Profit Trigger (for dynamic TTP) (%) {45.0} | 45.0 | float · min 0 · step 0.01 | ShortRatio sell_dynamic_trailing_take_profit_offset LongRatio buy_dynamic_trailing_take_profit_offset |
| (TRAILING) Take profit percentage for dynamic Trailing Take Profit Trigger based on VPoC resistances (%) {20.0} | 20.0 | float · min 0 · step 0.01 | unused |
| (TRAILING) Enforce dynamic Trailing Take Profit {True} | true | bool | line 2276 |
| (OLD) Number of bars to consider and order to be old {6} | 6 | int · min 1 · max 100 · step 1 | is_too_old |
| (OLD) Minimum loss percent to close an old order {0.8} | 0.8 | float · min 0.01 · max 100 · step 0.01 | too_old_stop_loss |
| (RECENT) Number of minutes to wait to open a new order after the previous one has been opened {6} | 6 | int · min 1 · max 100 · step 1 | too_recent_minutes_number_ms |
| (STOPTAKE) Minimum loss percent to be supported by VPVR VPoC {1.0} | 1.0 | float · min 0.01 · max 100 · step 0.01 | new_buy_SL new_sell_SL line 2185 line 2211 |
| (STOPTAKE) Maximum loss percent to be supported by VPVR VPoC {2.38} | 2.38 | float · min 0.01 · max 100 · step 0.01 | line 2188 line 2214 |
| (STOPTAKE) Win/Loss Ratio {1.00} | 1.00 | float · min 0.01 · max 100 · step 0.01 | DesiredShortRatio DesiredLongRatio |
| (EXCHANGE) Fees per order {0.04} (%) | 0.04 | float · min 0.01 · max 100 · step 0.01 | ShortTargetPrice LongTargetPrice |
| (EMAS) Ignore advice based on emas {false} | false | bool | line 2316 line 2341 |
| (EMAS) Ignore advice based on emas (On closing long signal) {False} | false | bool | line 2385 line 2396 line 2422 line 2433 |
| (SQZMOM) Ignore advice based on SQZMOM {false} | false | bool | tradinglatino_strategy_smilb_and_adx_long_advice tradinglatino_strategy_smilb_and_adx_short_advice line 1569 line 1654 |
| (SQZMOM) Ignore advice based squeeze percentage {True} | true | bool | line 1570 line 1655 |
| (ADXSLOPE) Ignore advice based on ADX positive slope {true} | true | bool | tradinglatino_strategy_smilb_and_adx_long_advice tradinglatino_strategy_smilb_and_adx_short_advice line 1573 line 1580 line 1588 line 1595 line 1604 line 1611 line 1619 line 1626 line 1658 line 1665 line 1673 line 1680 line 1689 line 1696 line 1704 line 1711 |
| (ADXSLOPE) Ignore advice based on ADX cut (23) {true} | true | bool | tradinglatino_strategy_smilb_and_adx_long_advice tradinglatino_strategy_smilb_and_adx_short_advice line 1572 line 1587 line 1603 line 1618 line 1657 line 1672 line 1688 line 1703 |
| (STOPTAKE) Take Profit? {false} | false | bool | line 1959 line 2004 exit [SL/TP] |
| (TRAILING) Enable Trailing Take Profit (%) {True} | true | bool | line 1963 line 2008 line 2727 |
| (OLD) Ignore advice based on order being too old {False} | false | bool | line 2384 line 2421 |
| (STOPTAKE) Enforce dynamic stop loss up to maximum stop loss {True} | true | bool | line 2175 line 2334 line 2359 |
| (STRAT) Type Strategy | L_S | value · options [L_S, _L_, _S_] | line 2638 line 2655 line 2672 |
| (RISKM) Risk Management Type | _SCOMPOUND_ | value · options [_SAFE_, _SCOMPOUND_, _UCOMPOUND_] | line 2560 line 2564 line 2568 |
| (RISKM) Maximum loss per trade % {1.0} | 1.0 | float | tmp_entry_quantity |
| (RISKM) Maximum loss per day % {6.0} | 6.0 | float | line 2586 |
| (RISKM) Maximum loss per week % {8.0} | 8.0 | float | line 2598 |
| (RISKM) Maximum loss per month % {10.0} | 10.0 | float | line 2610 |
| (DECIMAL) Maximum number of decimal for contracts {3} | 3 | int · min 0 | contract_multiplier line 1108 line 1111 |
| (PRANGE) Print price is in range {False} | false | bool | price_is_in_range_R price_is_in_range_A price_is_in_range_N price_is_in_range_G price_is_in_range_E price_is_in_range__ |
| (PRANGE) Price range periods {5} | 5 | int | price_is_in_range |
| (PRANGE) Price range maximum desviation (%) {0.6} ( > 0 ) | 0.6 | float | hc_maximum hc_minimum lc_maximum lc_minimum price_is_in_range |
| (PRANGE) Price range minimum desviation (%) {0.6} ( > 0 ) | 0.6 | float | price_is_in_range |
| (SQZDIVER) Show degrees {False} | false | bool | line 1288 |
| (SQZDIVER) Show desviation labels {False} | false | bool | line 1924 line 1936 |
| (SQZDIVER) Show desviation lines {False} | false | bool | line 1916 line 1929 |
| (VP) Print VPVR VPoc price {True} | true | bool | line 2149 |
| (VP) Avoid label price overlaps {False} | false | bool | unused |
| (ZIG) Zignaly Alert Type {Email} | _ZIGNALYE_ | value · options [_ZIGNALYW_, _ZIGNALYE_] | line 1060 |
| (DEBUG) Enable debug on order comments {False} | false | bool | line 2038 |
| (DEBUG) Enable raw testing {True} | false | bool | line 2615 |
| (DEBUG) Constant entry quantity for raw USDT testing {100.0} | 100.0 | float | entry_quantity |
| (PLUS MODE) Beyond original TradingLatino strategy (Experimental) {False} | false | bool | line 1571 line 1602 line 1656 line 1687 line 2375 line 2412 |
| (STRICT RISK) Even more strict risk management {True} | true | bool | line 2179 line 2186 line 2205 line 2212 line 2248 line 2263 line 2297 line 2312 |
What it calculates
- Linreg / Highest / Lowest / SMA (
linreg,ta.linregin v5)source - avg(avg(highest(high, lengthKC), lowest(low, lengthKC)),sma(close,lengthKC)), lengthKC, 0val · line 1436 - Change (
change,ta.changein v5)highup · line 1382 - Change (
change,ta.changein v5)lowdown · line 1383 - RMA (
rma,ta.rmain v5)tr, lentruerange · line 1384 - RMA (
rma,ta.rmain v5)abs(plus - minus) / (sum == 0 ? 1 : sum), adxlenadx · line 1391 - Median (
median,ta.medianin v5)hc, pricerange_range_periods_numberhc_median · line 1402 - Median (
median,ta.medianin v5)lc, pricerange_range_periods_numberlc_median · line 1403 - SMA (
sma,ta.smain v5)source, lengthbasis · line 1423 - Stdev (
stdev,ta.stdevin v5)source, lengthdev · line 1424 - SMA (
sma,ta.smain v5)source, lengthKCma · line 1428 - SMA (
sma,ta.smain v5)range, lengthKCrangema · line 1430 - EMA (
ema,ta.emain v5)(EMAS) EMA10 - Source {close} (close), (EMAS) EMA10 - Length {10} (10)ema10_out · line 1463 - EMA (
ema,ta.emain v5)(EMAS) EMA55 - Source {close} (close), (EMAS) EMA55 - Length {55} (55)ema55_out · line 1464 - EMA (
ema,ta.emain v5)ema10_src[1], (EMAS) EMA10 - Length {10} (10)ema10_out_1 · line 1750 - EMA (
ema,ta.emain v5)ema55_src[1], (EMAS) EMA55 - Length {55} (55)ema55_out_1 · line 1751 - EMA (
ema,ta.emain v5)ema10_src[2], (EMAS) EMA10 - Length {10} (10)ema10_out_2 · line 1752 - EMA (
ema,ta.emain v5)ema55_src[2], (EMAS) EMA55 - Length {55} (55)ema55_out_2 · line 1753 - Highest (
highest,ta.highestin v5)high, vp_recent_n_barsvp_recent_high · line 2062 - Lowest (
lowest,ta.lowestin v5)low, vp_recent_n_barsvp_recent_low · line 2063 - Highest (
highest,ta.highestin v5)high, (VP) Number of bars for VPVR VPOC {100} (100)vp_vpvr_recent_high_top · line 2076 - Lowest (
lowest,ta.lowestin v5)low, (VP) Number of bars for VPVR VPOC {100} (100)vp_vpvr_recent_low_bottom · line 2079 - Highest (
highest,ta.highestin v5)pvp_recent_vpoc_price, pvp_bottom_vpoc_n_barslowest_higher_than · line 2124 - Highest (
highest,ta.highestin v5)high, 5ath · line 2241 - Highest (
highest,ta.highestin v5)drawdown, 5maxdrawdown · line 2243 - EMA (
ema,ta.emain v5)sell_dynamic_trailing_take_profit_trigger_tmp, 5sell_dynamic_trailing_take_profit_trigger · line 2245 - Lowest (
lowest,ta.lowestin v5)low, 5atl · line 2258 - Highest (
highest,ta.highestin v5)inv_drawdown, 5inv_maxdrawdown · line 2260 - EMA (
ema,ta.emain v5)buy_dynamic_trailing_take_profit_trigger_tmp, 5buy_dynamic_trailing_take_profit_trigger · line 2262
Signal flow
How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.
The script has 316 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open [B] long | BUY | On | 2643 |
| Close [B] | BUY_CLOSE | On | 2652 |
| Open [S] short | SELL | On | 2660 |
| Close [S] | SELL_CLOSE | On | 2669 |
| Open [B] long | BUY | On | 2688 |
| Close [B] | BUY_CLOSE | On | 2696 |
| Open [S] short | SELL | On | 2702 |
| Close [S] | SELL_CLOSE | On | 2710 |
| Exit [SL/TP] stop and limit | every bar | On | 2740 |
| Exit [SL/TP] stop and limit | every bar | On | 2742 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
Yes
The live replay did not match history.
- ClearHigher-timeframe data4 security call(s), none with lookahead on.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
- ClearOrder timingOrders fill at the next bar's open, after the signal bar has closed.
The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.
Other markets
The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | +64.6% | +102.5% | 240 | 43% | 1.29 | 15.3% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −10.9% | +5.5% | 119 | 30% | 0.83 | 20.3% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +57.6% | +9.8% | 235 | 39% | 1.26 | 13.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +8.4% | +8.4% | 154 | 36% | 1.09 | 11.5% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +117.2% | +16.7% | 212 | 41% | 1.50 | 14.2% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +7.8% | +21.5% | 155 | 43% | 1.08 | 21.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +54.7% | +148.3% | 230 | 41% | 1.25 | 16.1% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −1.8% | +17.1% | 138 | 37% | 0.98 | 13.1% | 8 May 2026 – 21 Oct 2026 |
Higher-timeframe data for request.security(): BINANCE:BTCUSDT 1W (Binance BTCUSDT 1w), fetched from Binance's public market data for each market.
Backtests are simulations on historical data and are not investment advice.
The trades
By market direction
| At entry, last 90 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 83 | 46% | $275.83 |
| Sideways market | 105 | 38% | −$33.81 |
| Falling market | 52 | 48% | $404.48 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
22.4%
The 95th percentile of the worst drawdown when the same 240 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 10.3% to 22.4%; the tick is what actually happened, 15.1%. Order luck alone moves it this much.
The first 150 of 240 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 28 Jan 2024 42,120.60 | 30 Jan 2024 43,443.70 | 2 | $16.09 |
| long | 31 Jan 2024 42,941.10 | 31 Jan 2024 42,511.70 | 0 | −$11.84 |
| long | 1 Feb 2024 42,580.00 | 1 Feb 2024 42,154.20 | 0 | −$11.74 |
| long | 3 Feb 2024 43,200.00 | 4 Feb 2024 42,546.80 | 1 | −$11.08 |
| long | 5 Feb 2024 42,582.90 | 5 Feb 2024 43,271.10 | 0 | $13.25 |
| long | 6 Feb 2024 42,708.70 | 7 Feb 2024 43,089.40 | 1 | $6.19 |
| long | 9 Feb 2024 45,288.70 | 9 Feb 2024 47,644.60 | 0 | $22.63 |
| long | 11 Feb 2024 47,751.10 | 13 Feb 2024 49,810.80 | 2 | $19.62 |
| long | 16 Feb 2024 51,880.00 | 17 Feb 2024 51,314.00 | 1 | −$12.05 |
| long | 18 Feb 2024 51,642.70 | 20 Feb 2024 52,386.90 | 2 | $6.40 |
| long | 22 Feb 2024 51,849.40 | 23 Feb 2024 50,625.00 | 1 | −$10.62 |
| long | 24 Feb 2024 50,744.20 | 25 Feb 2024 51,342.10 | 1 | $9.92 |
| long | 26 Feb 2024 51,728.90 | 26 Feb 2024 51,211.60 | 0 | −$11.78 |
| long | 1 Mar 2024 61,131.00 | 1 Mar 2024 62,613.00 | 0 | $17.66 |
| long | 3 Mar 2024 61,987.30 | 3 Mar 2024 61,367.40 | 0 | −$11.89 |
| long | 8 Mar 2024 66,823.20 | 8 Mar 2024 69,237.30 | 0 | $18.22 |
| long | 10 Mar 2024 68,313.30 | 10 Mar 2024 69,408.40 | 0 | $14.36 |
| long | 11 Mar 2024 68,955.90 | 11 Mar 2024 68,094.70 | 0 | −$11.98 |
| long | 14 Mar 2024 73,072.40 | 14 Mar 2024 71,333.30 | 0 | −$9.42 |
| long | 27 Mar 2024 69,988.00 | 27 Mar 2024 69,280.00 | 0 | −$11.86 |
| long | 28 Mar 2024 69,470.00 | 28 Mar 2024 70,869.70 | 0 | $11.33 |
| long | 30 Mar 2024 69,850.50 | 1 Apr 2024 70,809.30 | 2 | $9.82 |
| long | 2 Apr 2024 69,649.80 | 2 Apr 2024 68,062.90 | 0 | −$10.35 |
| long | 3 Apr 2024 65,464.00 | 3 Apr 2024 64,550.00 | 0 | −$11.48 |
| long | 4 Apr 2024 65,963.30 | 5 Apr 2024 68,464.90 | 1 | $14.20 |
| long | 7 Apr 2024 68,896.00 | 8 Apr 2024 71,957.10 | 1 | $20.44 |
| long | 10 Apr 2024 69,146.00 | 10 Apr 2024 68,210.00 | 0 | −$11.81 |
| long | 22 Apr 2024 64,941.20 | 23 Apr 2024 66,751.50 | 1 | $23.50 |
| long | 24 Apr 2024 66,414.00 | 24 Apr 2024 65,749.90 | 0 | −$12.74 |
| long | 27 Apr 2024 63,770.00 | 27 Apr 2024 63,132.30 | 0 | −$12.23 |
| long | 28 Apr 2024 63,462.00 | 29 Apr 2024 62,391.20 | 1 | −$10.77 |
| long | 5 May 2024 63,892.00 | 7 May 2024 62,541.00 | 2 | −$10.34 |
| long | 13 May 2024 61,484.00 | 14 May 2024 62,897.50 | 1 | $14.18 |
| long | 15 May 2024 61,577.50 | 16 May 2024 66,320.10 | 1 | $73.84 |
| long | 17 May 2024 65,235.20 | 18 May 2024 66,993.60 | 1 | $26.02 |
| long | 19 May 2024 66,915.20 | 19 May 2024 66,246.00 | 0 | −$12.84 |
| long | 20 May 2024 66,274.00 | 21 May 2024 71,514.10 | 1 | $81.64 |
| long | 22 May 2024 70,148.40 | 22 May 2024 69,162.90 | 0 | −$13.50 |
| long | 26 May 2024 69,290.60 | 26 May 2024 68,500.00 | 0 | −$13.93 |
| long | 10 Jun 2024 69,648.20 | 11 Jun 2024 68,951.70 | 1 | −$13.36 |
| long | 28 Jun 2024 61,706.50 | 28 Jun 2024 60,606.60 | 0 | −$12.22 |
| long | 30 Jun 2024 60,986.70 | 1 Jul 2024 62,631.00 | 1 | $27.37 |
| long | 2 Jul 2024 62,900.00 | 2 Jul 2024 62,271.00 | 0 | −$13.58 |
| long | 3 Jul 2024 62,135.50 | 3 Jul 2024 61,514.10 | 0 | −$13.41 |
| long | 4 Jul 2024 60,208.60 | 4 Jul 2024 59,400.00 | 0 | −$12.99 |
| long | 11 Jul 2024 57,725.90 | 11 Jul 2024 57,148.60 | 0 | −$13.15 |
| long | 12 Jul 2024 57,339.90 | 12 Jul 2024 56,766.50 | 0 | −$13.06 |
| long | 13 Jul 2024 57,889.10 | 15 Jul 2024 60,652.20 | 2 | $21.16 |
| long | 18 Jul 2024 64,088.00 | 18 Jul 2024 63,447.10 | 0 | −$13.06 |
| long | 19 Jul 2024 63,987.90 | 19 Jul 2024 66,886.00 | 0 | $38.74 |
| long | 21 Jul 2024 67,140.00 | 21 Jul 2024 66,222.40 | 0 | −$12.61 |
| long | 23 Jul 2024 67,532.00 | 23 Jul 2024 66,560.00 | 0 | −$12.17 |
| long | 24 Jul 2024 65,936.00 | 24 Jul 2024 65,276.60 | 0 | −$13.44 |
| long | 10 Aug 2024 60,838.00 | 11 Aug 2024 59,535.00 | 1 | −$11.39 |
| long | 12 Aug 2024 58,712.60 | 12 Aug 2024 58,125.40 | 0 | −$12.67 |
| long | 15 Aug 2024 58,683.40 | 15 Aug 2024 59,437.80 | 0 | $11.45 |
| long | 18 Aug 2024 59,492.00 | 18 Aug 2024 58,785.00 | 0 | −$12.38 |
| long | 19 Aug 2024 58,427.40 | 19 Aug 2024 57,843.10 | 0 | −$12.61 |
| long | 21 Aug 2024 59,013.80 | 21 Aug 2024 61,407.00 | 0 | $40.91 |
| long | 23 Aug 2024 60,375.80 | 23 Aug 2024 64,509.50 | 0 | $68.15 |
| long | 25 Aug 2024 64,157.00 | 26 Aug 2024 63,515.40 | 1 | −$13.85 |
| long | 11 Sep 2024 57,636.00 | 11 Sep 2024 56,386.40 | 0 | −$12.27 |
| long | 13 Sep 2024 58,132.30 | 14 Sep 2024 60,111.10 | 1 | $26.05 |
| long | 15 Sep 2024 59,993.00 | 15 Sep 2024 59,393.10 | 0 | −$13.67 |
| long | 16 Sep 2024 59,132.00 | 16 Sep 2024 58,540.70 | 0 | −$13.47 |
| long | 17 Sep 2024 58,214.00 | 17 Sep 2024 60,846.90 | 0 | $40.22 |
| long | 20 Sep 2024 62,948.00 | 23 Sep 2024 63,944.30 | 3 | $6.96 |
| long | 24 Sep 2024 63,340.00 | 25 Sep 2024 64,295.30 | 1 | $12.41 |
| long | 26 Sep 2024 63,152.00 | 26 Sep 2024 65,396.00 | 0 | $40.19 |
| long | 13 Oct 2024 63,206.20 | 13 Oct 2024 62,487.20 | 0 | −$14.36 |
| long | 14 Oct 2024 62,870.00 | 15 Oct 2024 65,969.60 | 1 | $44.56 |
| long | 17 Oct 2024 67,620.00 | 17 Oct 2024 66,750.50 | 0 | −$14.05 |
| long | 18 Oct 2024 67,421.80 | 18 Oct 2024 68,489.00 | 0 | $14.90 |
| long | 19 Oct 2024 68,428.00 | 21 Oct 2024 67,192.40 | 2 | −$13.71 |
| long | 22 Oct 2024 67,377.50 | 22 Oct 2024 66,703.70 | 0 | −$14.54 |
| long | 23 Oct 2024 67,426.00 | 23 Oct 2024 66,571.40 | 0 | −$13.84 |
| long | 8 Nov 2024 75,857.90 | 10 Nov 2024 80,646.60 | 2 | $37.06 |
| long | 15 Nov 2024 87,325.60 | 15 Nov 2024 91,237.50 | 0 | $52.27 |
| long | 17 Nov 2024 90,588.00 | 17 Nov 2024 89,681.00 | 0 | −$15.22 |
| long | 18 Nov 2024 89,856.00 | 18 Nov 2024 91,853.70 | 0 | $19.98 |
| long | 19 Nov 2024 90,464.10 | 19 Nov 2024 93,185.70 | 0 | $30.46 |
| long | 20 Nov 2024 92,310.80 | 22 Nov 2024 97,854.90 | 2 | $37.48 |
| long | 23 Nov 2024 98,892.00 | 24 Nov 2024 97,672.40 | 1 | −$9.91 |
| long | 13 Dec 2024 100,004.00 | 14 Dec 2024 101,194.00 | 1 | $13.84 |
| long | 15 Dec 2024 101,420.00 | 15 Dec 2024 104,539.00 | 0 | $37.86 |
| long | 18 Dec 2024 106,134.00 | 18 Dec 2024 105,072.00 | 0 | −$16.54 |
| long | 4 Jan 2025 98,174.20 | 7 Jan 2025 101,521.00 | 3 | $18.88 |
| long | 8 Jan 2025 96,954.60 | 8 Jan 2025 95,985.10 | 0 | −$16.27 |
| long | 15 Jan 2025 96,560.90 | 16 Jan 2025 99,599.90 | 1 | $17.06 |
| long | 19 Jan 2025 104,556.00 | 19 Jan 2025 102,278.00 | 0 | −$14.91 |
| long | 20 Jan 2025 101,332.00 | 20 Jan 2025 99,651.60 | 0 | −$15.05 |
| long | 23 Jan 2025 103,707.00 | 23 Jan 2025 102,670.00 | 0 | −$16.17 |
| long | 25 Jan 2025 104,871.00 | 26 Jan 2025 102,750.00 | 1 | −$13.97 |
| long | 27 Jan 2025 102,620.00 | 27 Jan 2025 101,594.00 | 0 | −$16.00 |
| long | 11 Feb 2025 97,430.80 | 11 Feb 2025 95,256.00 | 0 | −$14.21 |
| long | 14 Feb 2025 96,608.10 | 14 Feb 2025 97,949.60 | 0 | $10.32 |
| long | 15 Feb 2025 97,500.50 | 16 Feb 2025 96,252.80 | 1 | −$15.86 |
| long | 17 Feb 2025 96,118.10 | 18 Feb 2025 95,156.90 | 1 | −$16.13 |
| long | 20 Feb 2025 96,644.40 | 21 Feb 2025 98,493.20 | 1 | $13.23 |
| long | 22 Feb 2025 96,182.00 | 24 Feb 2025 94,871.90 | 2 | −$15.01 |
| long | 7 Mar 2025 89,931.90 | 7 Mar 2025 87,836.00 | 0 | −$13.64 |
| long | 14 Mar 2025 81,115.80 | 14 Mar 2025 84,570.00 | 0 | $36.17 |
| long | 16 Mar 2025 84,338.40 | 16 Mar 2025 83,495.00 | 0 | −$16.18 |
| long | 17 Mar 2025 82,574.50 | 17 Mar 2025 84,177.60 | 0 | $22.98 |
| long | 18 Mar 2025 84,010.00 | 18 Mar 2025 82,456.00 | 0 | −$13.76 |
| long | 21 Mar 2025 84,223.40 | 21 Mar 2025 83,381.10 | 0 | −$16.16 |
| long | 22 Mar 2025 84,088.80 | 24 Mar 2025 88,141.70 | 2 | $54.33 |
| long | 25 Mar 2025 87,498.20 | 28 Mar 2025 85,519.10 | 3 | −$15.06 |
| long | 29 Mar 2025 84,424.40 | 29 Mar 2025 83,585.00 | 0 | −$16.12 |
| long | 14 Apr 2025 83,760.00 | 14 Apr 2025 85,212.50 | 0 | $20.54 |
| long | 15 Apr 2025 84,591.60 | 15 Apr 2025 83,678.00 | 0 | −$16.23 |
| long | 16 Apr 2025 83,644.00 | 16 Apr 2025 84,913.30 | 0 | $17.61 |
| long | 17 Apr 2025 84,030.40 | 18 Apr 2025 84,844.00 | 1 | $9.67 |
| long | 19 Apr 2025 84,474.70 | 21 Apr 2025 87,873.50 | 2 | $51.62 |
| long | 24 Apr 2025 93,691.10 | 24 Apr 2025 91,935.40 | 0 | −$15.53 |
| long | 26 Apr 2025 94,638.70 | 28 Apr 2025 92,855.90 | 2 | −$15.76 |
| long | 11 May 2025 104,810.00 | 12 May 2025 104,118.00 | 1 | −$6.30 |
| long | 23 May 2025 111,696.00 | 23 May 2025 109,177.00 | 0 | −$13.70 |
| long | 11 Jun 2025 110,274.00 | 11 Jun 2025 108,331.00 | 0 | −$15.13 |
| long | 12 Jun 2025 108,645.00 | 12 Jun 2025 107,559.00 | 0 | −$15.63 |
| long | 13 Jun 2025 105,672.00 | 13 Jun 2025 104,615.00 | 0 | −$15.20 |
| long | 15 Jun 2025 105,415.00 | 16 Jun 2025 108,185.00 | 1 | $30.68 |
| long | 17 Jun 2025 106,795.00 | 17 Jun 2025 104,980.00 | 0 | −$14.18 |
| long | 18 Jun 2025 104,551.00 | 19 Jun 2025 104,887.00 | 1 | $1.39 |
| long | 25 Jun 2025 106,083.00 | 26 Jun 2025 107,204.00 | 1 | $8.17 |
| long | 27 Jun 2025 106,947.00 | 30 Jun 2025 108,040.00 | 3 | $10.53 |
| long | 1 Jul 2025 107,147.00 | 1 Jul 2025 106,075.00 | 0 | −$15.42 |
| long | 2 Jul 2025 105,681.00 | 2 Jul 2025 108,989.00 | 0 | $37.12 |
| long | 4 Jul 2025 109,585.00 | 4 Jul 2025 108,489.00 | 0 | −$15.77 |
| long | 5 Jul 2025 107,984.00 | 7 Jul 2025 108,943.00 | 2 | $8.90 |
| long | 8 Jul 2025 108,263.00 | 9 Jul 2025 111,240.00 | 1 | $33.10 |
| long | 12 Jul 2025 117,528.00 | 14 Jul 2025 121,862.00 | 2 | $24.57 |
| long | 15 Jul 2025 119,841.00 | 15 Jul 2025 118,643.00 | 0 | −$17.24 |
| long | 7 Aug 2025 114,992.00 | 8 Aug 2025 116,595.00 | 1 | $10.97 |
| long | 9 Aug 2025 116,675.00 | 11 Aug 2025 118,493.00 | 2 | $18.99 |
| long | 12 Aug 2025 118,686.00 | 14 Aug 2025 123,642.00 | 2 | $56.56 |
| long | 15 Aug 2025 118,295.00 | 15 Aug 2025 117,112.00 | 0 | −$17.02 |
| long | 16 Aug 2025 117,342.00 | 18 Aug 2025 116,169.00 | 2 | −$16.88 |
| long | 2 Sep 2025 109,237.00 | 4 Sep 2025 111,391.00 | 2 | $13.53 |
| long | 5 Sep 2025 110,731.00 | 5 Sep 2025 112,470.00 | 0 | $15.16 |
| long | 6 Sep 2025 110,660.00 | 8 Sep 2025 112,148.00 | 2 | $16.45 |
| long | 9 Sep 2025 112,065.00 | 13 Sep 2025 115,729.00 | 4 | $34.36 |
| long | 14 Sep 2025 115,918.00 | 15 Sep 2025 114,759.00 | 1 | −$18.07 |
| long | 16 Sep 2025 115,350.00 | 17 Sep 2025 116,478.00 | 1 | $11.65 |
| long | 18 Sep 2025 116,448.00 | 20 Sep 2025 115,632.00 | 2 | −$9.43 |
| long | 3 Oct 2025 120,529.00 | 3 Oct 2025 122,559.00 | 0 | $10.72 |
| long | 5 Oct 2025 122,391.00 | 5 Oct 2025 124,850.00 | 0 | $26.54 |
| long | 6 Oct 2025 123,482.00 | 6 Oct 2025 125,282.00 | 0 | $17.05 |
| long | 7 Oct 2025 124,659.00 | 7 Oct 2025 123,084.00 | 0 | −$18.22 |
| long | 8 Oct 2025 121,333.00 | 8 Oct 2025 123,346.00 | 0 | $22.99 |
Similar scripts
Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Ruckard TradingLatino this page | — | v4 strategy | +64.6% | 240 | 15.3% |
| VixFixLinReg-Strategy by Trendoscope | highest stdev sma lowest linreg | v4 strategy | −49.3% | 12 | 51.1% |
| Bagheri IG Ether by Bagheri_IG | ema highest lowest rma sma | v4 strategy | +0.0% | 3 | 0.0% |
| Bagheri IG Ether v2 by Bagheri_IG | ema highest lowest rma sma | v4 strategy | −0.0% | 2 | 0.0% |
| Crunchster's Turtle and Trend System by Crunchster1 | lowest highest ema stdev sma | v5 strategy | +18.0% | 31 | 16.7% |
| Multi MA MTF SandBox Strategy by dman103 | sma ema linreg highest lowest | v5 strategy | +17.4% | 48 | 9.5% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 751 ms | With a workaround 1,000 bars in 7,480 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report. PineTS runs Pine Script v5 and v6 only.
Source
Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.
//@version=4//strategy("Ruckard TradingLatino R348", shorttitle="R348TradingLatino", overlay=true, max_bars_back=5000, calc_on_order_fills=false, calc_on_every_tick=false, pyramiding=0, initial_capital=1000, slippage=1, commission_type=strategy.commission.percent, commission_value=0.1)// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// Current version: v20210421 ( R348 )// TradingView Public tags - BEGIN// Tag 1: tradinglatino// Tag 2: Volume Profile// Tag 3: Support and resistance// Tag 4: Average Directional Index (ADX)//// Tag 5: Momentum Indicator (MOM)// Tag 6: VPOC// Tag 7: VPVR// Tag 8: ema//// Tag 9: Divergence// Tag 10: Range// Tag 11: Linear Regression// Tag 12: zignaly// TradingView Public tags - END// Tradingview Public description - BEGIN// // This strategy tries to mimic TradingLatino strategy.// The current implementation is beta.// // Si hablas castellano o espanyol por favor consulta [B]MENSAJE EN CASTELLANO[/B] más abajo.// // It's aimed at BTCUSDT pair and 4h timeframe.//// [B]STRATEGY DEFAULT SETTINGS EXPLANATION[/B]// [list]// [*] max_bars_back=5000 : This is a random number of bars so that the strategy test lasts for one or two years// [*] calc_on_order_fills=false : To wait for the 4h closing is too much. Try to check if it's worth entering a position after closing one. I finally decided not to recheck if it's worth entering after an order is closed. So it is false.// [*] calc_on_every_tick=false// [*] pyramiding=0 : We only want one entry allowed in the same direction. And we don't want the order to scale by error.// [*] initial_capital=1000 : These are 1000 USDT. By using 1% maximum loss per trade and 7% as a default stop loss by using 1000 USDT at 12000 USDT per BTC price you would entry with around 142 USDT which are converted into: 0.010 BTC . The maximum number of decimal for contracts on this BTCUSDT market is 3 decimals. E.g. the minimum might be: 0.001 BTC . So, this minimal 1000 amount ensures us not to entry with less than 0.001 entries which might have happened when using 100 USDT as an initial capital.// [*] slippage=1 : Binance BTCUSDT mintick is: 0.01. Binance slippage: 0.1 % (Let's assume). TV has an integer slippage. It does not have a percentage based slippage. If we assume a 1000 initial capital, the recommended equity is 142 which at 11996 USDT per BTC price means: 0.011 BTC. The 0.1% slippage of: 0.011 BTC would be: 0.000011 . This is way smaller than the mintick. So our slippage is going to be 1. E.g. 1 (slippage) * 0.01 (mintick)// [*] commission_type=strategy.commission.percent and commission_value=0.1 : According to: binance . com / en / fee / schedule in VIP 0 level both maker and taker fees are: 0.1 %.// [/list]//// [B]BACKGROUND[/B]// Jaime Merino is a well known Youtuber focused on crypto trading// His channel TradingLatino// features monday to friday videos where he explains his strategy.// // [B]JAIME MERINO STANCE ON BOTS[/B]// Jaime Merino stance on bots (taken from memory out of a 2020 June video from him):// '~// You know. They can program you a bot and it might work.// But, there are some special situations that the bot would not be able to handle.// And, I, as a human, I would handle it. And the bot wouldn't do it.// ~'// // My long term target with this strategy script is add as many// special situations as I can to the script// so that it can match Jaime Merino behaviour even in non normal circumstances.// // My alternate target is learn Pine script// and enjoy programming with it.// // [B]WARNING[/B]// This script might be bigger than other TradingView scripts.// However, please, do not be confused because the current status is beta.// This script has not been tested with real money.// This is NOT an official strategy from Jaime Merino.// This is NOT an official strategy from TradingLatino . net .// // // [B]HOW IT WORKS[/B]// It basically uses ADX slope and LazyBear's Squeeze Momentum Indicator// to make its buy and sell decisions.// // Fast paced EMA being bigger than slow paced EMA// (on higher timeframe) advices going long.// // Fast paced EMA being smaller than slow paced EMA// (on higher timeframe) advices going short.// // It finally add many substrats that TradingLatino uses.// // [B]SETTINGS[/B]// [B]__ SETTINGS - Basics[/B]// [B]____ SETTINGS - Basics - ADX[/B]// [list]// [*] (ADX) Smoothing {14}// [*] (ADX) DI Length {14}// [*] (ADX) key level {23}// [*] (ADX) DI minimum percentage (%) {10.0}: Enforce a minimum DI percentage (DI+ over DI- or viceversa) to confirm long or short advice// [/list]// [B]____ SETTINGS - Basics - LazyBear Squeeze Momentum[/B]// [list]// [*] (SQZMOM) BB Length {20}// [*] (SQZMOM) BB MultFactor {2.0}// [*] (SQZMOM) KC Length {20}// [*] (SQZMOM) KC MultFactor {1.5}// [*] (SQZMOM) Use TrueRange (KC) {True}// [*] (SQZMOM) Squeeze percentage zero {0.0}: Zero value for the squeeze percentage (Bollinger and Keltner channels ratio).// [/list]// [B]____ SETTINGS - Basics - EMAs[/B]// [list]// [*] (EMAS) EMA10 - Length {10}// [*] (EMAS) EMA10 - Source {close}// [*] (EMAS) EMA55 - Length {55}// [*] (EMAS) EMA55 - Source {close}// [/list]// [B]____ SETTINGS - Volume Profile[/B]// Lowest and highest VPoC from last three days// is used to know if an entry has a support// // VPVR of last 100 4h bars// is also taken into account// // [list]// [*] (VP) Use number of bars (not VP timeframe): Uses 'Number of bars {100}' setting instead of 'Volume Profile timeframe' setting for calculating session VPoC// [*] (VP) Number of bars {100}: If 'Use number of bars (not VP timeframe)' is turned on this setting is used to calculate session VPoC.// [*] (VP) Volume Profile timeframe {1 day}: If 'Use number of bars (not VP timeframe)' is turned off this setting is used to calculate session VPoC.// [*] (VP) Resistances prices number of decimal digits [2]: Round Volume Profile bars label numbers so that they don't have so many decimals.// [*] (VP) Number of bars for bottom VPOC {18}: 18 bars equals 3 days in suggested timeframe of 4 hours. It's used to calculate lowest session VPoC from previous three days. It's also used as a top VPOC for sells.// [*] (VP) Ignore VPOC bottom advice on long {False}: If turned on it ignores bottom VPOC (or top VPOC on sells) when evaluating if a buy entry is worth it (just for the simple and now proven useless fact that the VPOC is below your entry).// [*] (VP) Number of bars for VPVR VPOC {100}: Number of bars to calculate the VPVR VPoC. We use 100 as Jaime once used. When the price bounces back to the EMA55 it might just bounce to this VPVR VPoC if its price it's lower than the EMA55 (Sells have inverse algorithm).// [*] (VP) Price levels {24}: Price levels for both VPVR VPoC and session VPoC// [/list]// [B]____ SETTINGS - ADX Slope[/B]// ADX Slope// help us to understand if ADX// has a positive slope, negative slope// or it is rather still.// // [list]// [*] (ADXSLOPE) ADX cut {23}: If ADX value is greater than this cut (23) then ADX has strength// [*] (ADXSLOPE) ADX minimum steepness entry {45}: ADX slope needs to be 45 degrees to be considered as a positive one.// [*] (ADXSLOPE) ADX minimum steepness exit {45}: ADX slope needs to be -45 degrees to be considered as a negative one.// [*] (ADXSLOPE) ADX steepness periods {3}: In order to avoid false detection the slope is calculated along 3 periods.// [/list]// [B]____ SETTINGS - Next to EMA55[/B]// [list]// [*] (NEXTEMA55) EMA10 to EMA55 bounce back percentage {80}: EMA10 might bounce back to EMA55 or maybe to 80% of its complete way to EMA55// [*] (NEXTEMA55) Next to EMA55 percentage {15}: How much next to the EMA55 you need to be to consider it's going to bounce back upwards again.// [/list]// // [B]____ SETTINGS - Stop Loss and Take Profit[/B]// You can set a default stop loss or a default take profit.// [list]// [*] (STOPTAKE) Stop Loss % {7.0}// [*] (STOPTAKE) Take Profit % {2.0}// [/list]// // [B]____ SETTINGS - Trailing Take Profit[/B]// You can customize the default trailing take profit values// [list]// [*] (TRAILING) Trailing Take Profit (%) {0.4}: Trailing take profit offset in percentage// [*] (TRAILING) Trailing Take Profit Trigger (%) {0.8}: When 0.8% of benefit is reached then activate the trailing take profit.// [*] (TRAILING) Drawdown percentage for dynamic Trailing Take Profit Trigger (%) {30.0}: Once drawdown has been calculated use 30% of it as Trailing Take Profit Trigger. [b]Note[/b]: This setting is only used when '(STRICT RISK) Even more strict risk management' setting is turned off.// [*] (TRAILING) Trailing Take Profit as a percentage of Trailing Take Profit Trigger (for dynamic TTP) (%) {45.0}: If dynamic TTP Trriger is 1% then dynamic TTP will be 0.45 % .// [*] (TRAILING) Take profit percentage for dynamic Trailing Take Profit Trigger based on VPoC resistances (%) {20.0}: Percentage of the distance between current price and next resistance to be used as Trailing Trake Profit Trigger. [b]Note[/b]: This setting is only used when '(STRICT RISK) Even more strict risk management' setting is turned on.// [*] (TRAILING) Enforce dynamic Trailing Take Profit {True}: When true the Trailing Take Profit is dynamic instead of using the static values.// [/list]// [B]____ SETTINGS - Old orders[/B]// You can customize the default old orders settings// [list]// [*] (OLD) Number of bars to consider and order to be old {6}: When to consider that an order is old.// [*] (OLD) Minimum loss percent to close an old order {0.8}: An old order should be closed if it's below 0.8 percent of losses.// [*] (RECENT) Number of minutes to wait to open a new order after the previous one has been opened {6}.// [/list]// [B]____ SETTINGS - Dynamic stop loss management[/B]// You can customize the default dynamic stop loss management settings// [list]// [*] (STOPTAKE) Minimum loss percent to be supported by VPVR VPoC {1.0}: An entry is ignored if the VPoC price it's too close to the current price. This settings let's you change how close is that.// [*] (STOPTAKE) Maximum loss percent to be supported by VPVR VPoC {2.38}: An entry is ignored if the VPoC price it's too far away from the current price. [b]Note[/b]: This setting is only used when '(STRICT RISK) Even more strict risk management' setting is turned on.// [*] (STOPTAKE) Win/Loss Ratio {1.00}: Set your exchange fees so that they are used on the actual ratio calculation.// [/list]// [B]____ SETTINGS - Exchange[/B]// [list]// [*] (EXCHANGE) Fees per order {0.04} (%): Set your desired Win/Loss Ratio. 1 means 1:1. 1.5 means 1.5:1 and so on.// [/list]// // [B]____ SETTINGS - MAIN TURN ON/OFF OPTIONS[/B]// [list]// [*] (EMAS) Ignore advice based on emas {false}.// [*] (EMAS) Ignore advice based on emas (On closing long signal) {False}: Ignore advice based on emas but only when deciding to close a buy entry.// [*] (SQZMOM) Ignore advice based on SQZMOM {false}: Ignores advice based on SQZMOM indicator.// [*] (SQZMOM) Ignore advice based squeeze percentage {True}: Whether to ignore or not advice based on squeeze percentage relative to squeeze percentage zero value.// [*] (ADXSLOPE) Ignore advice based on ADX positive slope {true}// [*] (ADXSLOPE) Ignore advice based on ADX cut (23) {true}// [*] (STOPTAKE) Take Profit? {false}: Enables simple Take Profit.// [*] (STOPTAKE) Stop Loss? {True}: Enables simple Stop Loss.// [*] (TRAILING) Enable Trailing Take Profit (%) {True}: Enables Trailing Take Profit.// [*] (OLD) Ignore advice based on order being too old {False}: When it's set to true it ignores the advice to close old orders which are losing.// [*] (STOPTAKE) Enforce dynamic stop loss up to maximum stop loss {True}: Change dinamically stop loss and its associated position size based to match the maximum expected stop loss according to the current VPVR VPoC. It also advises not to enter into positions which are not worth entering because of VPOC being too close.// [/list]// // [B]____ SETTINGS - Strategy mode[/B]// [list]// [*] (STRAT) Type Strategy: 'Long and Short', 'Long Only' or 'Short Only'. Default: 'Long and Short'.// [/list]// [B]____ SETTINGS - Risk Management [/B]// [list]// [*] (RISKM) Risk Management Type: 'Safe', 'Somewhat safe compound' or 'Unsafe compound'. '[b]Safe[/b]': Calculations are always done with the initial capital (1000) in mind. The maximum losses per trade/day/week/month are taken into account. '[b]Somewhat safe compound[/b]': Calculations are done with initial capital (1000) or a higher capital if it increases. The maximum losses per trade/day/week/month are taken into account. '[b]Unsafe compound[/b]': In each order all the current capital is gambled and only the default stop loss per order is taken into account. That means that the maximum losses per trade/day/week/month are not taken into account. [b]Default[/b]: 'Somewhat safe compound'.// [*] (RISKM) Maximum loss per trade % {1.0}.// [*] (RISKM) Maximum loss per day % {6.0}.// [*] (RISKM) Maximum loss per week % {8.0}.// [*] (RISKM) Maximum loss per month % {10.0}.// [/list]// [B]____ SETTINGS - Decimals [/B]// [list]// [*] (DECIMAL) Maximum number of decimal for contracts {3}: How small (3 decimals means 0.001) an entry position might be in your exchange.// [/list]// // [B]EXTRA 1 - PRICE IS IN RANGE indicator[/B]// [list]// [*] (PRANGE) Print price is in range {False}: Enable a bottom label that indicates if the price is in range or not.// [*] (PRANGE) Price range periods {5}: How many previous periods are used to calculate the medians// [*] (PRANGE) Price range maximum desviation (%) {0.6} ( > 0 ): Maximum positive desviation for range detection// [*] (PRANGE) Price range minimum desviation (%) {0.6} ( > 0 ): Mininum negative desviation for range detection// [/list]// // [B]EXTRA 2 - SQUEEZE MOMENTUM Desviation indicator[/B]// [list]// [*] (SQZDIVER) Show degrees {False}: Show degrees of each Squeeze Momentum Divergence lines to the x-axis.// [*] (SQZDIVER) Show desviation labels {False}: Whether to show or not desviation labels for the Squeeze Momentum Divergences.// [*] (SQZDIVER) Show desviation lines {False}: Whether to show or not desviation lines for the Squeeze Momentum Divergences.// [/list]// // [B]EXTRA 3 - VOLUME PROFILE indicator[/B]// WARNING: This indicator works not on current bar but on previous bar. So in the worst case it might be VP from 4 hours ago. Don't worry, inside the strategy calculus the correct values are used. It's just that I cannot show the most recent one in the chart.// [list]// [*] (VP) Print VPVR VPoc price {True}: Show VPVR VPoC price// [*] (VP) Avoid label price overlaps {False}: Avoid label prices to overlap on the chart.// [/list]//// [B]EXTRA 4 - ZIGNALY SUPPORT[/B]// [list]// [*] (ZIG) Zignaly Alert Type {Email}: 'Email', 'Webhook'. '[b]Email[/b]': Prepare alert_message variable content to be compatible with zignaly expected email content format. '[b]Webhook[/b]': Prepare alert_message variable content to be compatible with zignaly expected json content format.// [/list]//// [B]EXTRA 5 - DEBUG[/B]// [list]// [*] (DEBUG) Enable debug on order comments {False}: If set to true it prepares the order message to match the alert_message variable. It makes easier to debug what would have been sent by email or webhook on each of the times an order is triggered.// [*] (DEBUG) Enable raw testing {True} : If raw testing mode is enabled then every time 100 USDT is used as a bet. So that you can actually know if a change to the strategy is worth of it or not because money management does not take place.// [*] (DEBUG) Constant entry quantity for raw USDT testing {100.0}// [/list]// [B]EXTRA 6 - OTHER MODES[/B]// [list]// [*] (PLUS MODE) Beyond original TradingLatino strategy (Experimental) {False}: Tries to use even dark green in long advised entries. It does not give good results for Bitcoin but it might give better results for other securities.// [*] (STRICT RISK) Even more strict risk management {True}.// [/list]// // [B]HOW TO USE THIS STRATEGY[/B]// [list]// [*] BOT MODE: This is the default setting.// [*] PROPER VOLUME PROFILE VIEWING: Click on this strategy settings. Properties tab. Make sure Recalculate 'each time the order was run' is turned off.// [*] NEWBIE USER: (Check PROPER VOLUME PROFILE VIEWING above!) You might want to turn on the 'Print recent profile {False}' setting. Alternatively you can use my alternate realtime study: 'Resistances and supports based on simplified Volume Profile' but, be aware, it might consume one indicator.// [*] ADVANCED USER 1: Turn on the 'Print price is in range {False}' setting and help us to debug this subindicator. Also help us to figure out how to include this value in the strategy.// [*] ADVANCED USER 2: Turn on the all the (SQZDIVER) settings and help us to figure out how to include this value in the strategy.// [*] ADVANCED USER 3: (Check PROPER VOLUME PROFILE VIEWING above!) Turn on the 'Print recent profile {False}' setting and report any problem with it.// [*] JAIME MERINO: Just use the indicator as it comes by default. It should only show BUY signals, SELL signals and their associated closing signals. From time to time you might want to check 'ADVANCED USER 2' instructions to check that there's actually a divergence. Check also 'ADVANCED USER 1' instructions for your amusement.// [/list]// // // [B]EXTRA ADVICE[/B]// It's advised that you use this strategy in addition to these two other indicators:// * Squeeze Momentum Indicator [LazyBear]// * ADX// so that your chart matches as close as possible to TradingLatino chart.//// [B]ZIGNALY INTEGRATION[/B]// This strategy supports Zignaly email integration by default. It also supports Zignaly Webhook integration.// [B]ZIGNALY INTEGRATION - Email integration example[/B]// What you would write in your alert message:// ||{{strategy.order.alert_message}}||key=MYSECRETKEY||// [B]ZIGNALY INTEGRATION - Webhook integration example[/B]// What you would write in your alert message:// { {{strategy.order.alert_message}} , "key" : "MYSECRETKEY" }//// [b]CREDITS[/b]// I have reused and adapted some code from// 'Directional Movement Index + ADX & Keylevel Support' study// which it's from TradingView console user.// // I have reused and adapted some code from// '3ema' study// which it's from TradingView hunganhnguyen1193 user.// // I have reused and adapted some code from// 'Squeeze Momentum Indicator [LazyBear]' study// which it's from TradingView LazyBear user.// // I have reused and adapted some code from// 'Strategy Tester EMA-SMA-RSI-MACD' study// which it's from TradingView fikira user.// // I have reused and adapted some code from// 'Support Resistance MTF' study// which it's from TradingView LonesomeTheBlue user.// // I have reused and adapted some code from// 'TF Segmented Linear Regression' study// which it's from TradingView alexgrover user.// // I have reused and adapted some code from// "Poor man's volume profile" study// which it's from TradingView IldarAkhmetgaleev user.// // [B]FEEDBACK[/B]// Please check the strategy source code for more detailed information// where, among others, I explain all of the substrats// and if they are implemented or not.// // Q1. Did I understand wrong any of the Jaime substrats (which I have implemented)?// Q2. The strategy yields quite profit when we should long (EMA10 from 1d timeframe is higher than EMA55 from 1d timeframe.// Why the strategy yields much less profit when we should short (EMA10 from 1d timeframe is lower than EMA55 from 1d timeframe)?// Any idea if you need to do something else rather than just reverse what Jaime does when longing?// // [B]FREQUENTLY ASKED QUESTIONS[/B]// // FAQ1. Why are you giving this strategy for free?// TradingLatino and his fellow enthusiasts taught me this strategy. Now I'm giving back to them.// FAQ2. Seriously! Why are you giving this strategy for free?// I'm confident his strategy might be improved a lot. By keeping it to myself I would avoid other people contributions to improve it.// Now that everyone can contribute this is a win-win.// FAQ3. How can I connect this strategy to my Exchange account? // It seems that you can attach alerts to strategies.// You might want to combine it with a paying account which enable Webhook URLs to work.// I don't know how all of this works right now so I cannot give you advice on it.// You will have to do your own research on this subject. But, be careful. Automating trades, if not done properly,// might end on you automating losses.// FAQ4. I have just found that this strategy by default gives more than 3.97% of 'maximum series of losses'. That's unacceptable according to my risk management policy.// You might want to reduce default stop loss setting from 7% to something like 5% till you are ok with the 'maximum series of losses'.// FAQ5. Where can I learn more about your work on this strategy?// Check the source code. You might find unused strategies. Either because there's not a substantial increases on earnings. Or maybe because they have not been implemented yet.// FAQ6. How much leverage is applied in this strategy?// No leverage.// FAQ7. Any difference with original Jaime Merino strategy?// Most of the times Jaime defines an stop loss at the price entry. That's not the case here. The default stop loss is 7% (but, don't be confused it only means losing 1% of your investment thanks to risk management). There's also a trailing take profit that triggers at 2% profit with a 1% trailing.// FAQ8. Why this strategy return is so small?// The strategy should be improved a lot. And, well, backtesting in this platform is not guaranteed to return theoric results comparable to real-life returns. That's why I'm personally forward testing this strategy to verify it.// // // [B]MENSAJE EN CASTELLANO[/B]// En primer lugar se agradece feedback para mejorar la estrategia.//// Si eres un usuario avanzado y quieres colaborar en mejorar el script no dudes en comentar abajo.// Ten en cuenta que aunque toda esta descripción tenga que estar en inglés no es obligatorio que el comentario esté en inglés.// // [B]CHISTE - CASTELLANO[/B]// ¡Pero Jaime!// ¡400.000!// ¡Tu da mun!// Tradingview Public description - END// CREDITS - BEGIN// TradingLatino Youtube channel ( https://www.youtube.com/channel/UCLjSq1FapG5OgvHsDKinHdA )// where Jaime Merino explains bits of his strategy mostly every day.// ABCBITCOIN Youtube channel ( https://www.youtube.com/channel/UCB8HQYwzPeLXc6Dgxg2_mVQ )// where you can check many videos where the TradingLatino strategy is shown.// EMAS// Name: 3ema// User: hunganhnguyen1193// https://es.tradingview.com/script/aAtdQwcQ-3ema/// ADX// Name: Directional Movement Index + ADX & Keylevel Support// User: console// https://es.tradingview.com/script/38loM0lA-Directional-Movement-Index-ADX-Keylevel-Support/// LazyBear's Squeeze Momentum Indicator// Version sugerida por el de Pastebin 2014 09 29// Name: Squeeze Momentum Indicator [LazyBear]// User: LazyBear// https://www.tradingview.com/script/nqQ1DT5a-Squeeze-Momentum-Indicator-LazyBear/// https://pastebin.com/UCpcX8d7// Take profit and stop loss (and other) inputs// Name: Strategy Tester EMA-SMA-RSI-MACD// User: fikira// https://www.tradingview.com/script/akcty6VI-Strategy-Tester-EMA-SMA-RSI-MACD/// Get higher timeframe.period automatically// Name: Support Resistance MTF// User: LonesomeTheBlue// https://www.tradingview.com/script/E9l1xAQd-Support-Resistance-MTF/// Slope steepness// Name: TF Segmented Linear Regression// User: alexgrover// https://www.tradingview.com/script/FGvtpiFR-TF-Segmented-Linear-Regression///// https://www.mathwords.com/s/slope_of_a_line.htm// https://www.youtube.com/watch?v=JSEPDJfl8m8// Volume based resistances and supports// Name: Poor man's volume profile// User: IldarAkhmetgaleev// https://www.tradingview.com/script/IWdpl712-Poor-man-s-volume-profile/// CREDITS - END// SUB STRATEGIES - BEGIN// Sub strategy 1 (SS1): // Status: Implemented// SS1.1: https://www.youtube.com/watch?v=-QN9kFcUb3A (6m13s)// SS1.2: https://www.youtube.com/watch?v=objURdzcm00 (9m20s)//// 1d timeframe// Cruce: MediaMovilAzul mayor que MediaMovilMarron// Pendiente positiva// Direccionalidad de alcista del monitor// means:// Confirmamos tendencia alcista// The substrat one will help us on deciding// if we want to beat on 'tendencia alcista'// or if we want to beat on 'tendencia bajista'// Sub strategy 2 (SS2): https://www.youtube.com/watch?v=IwxDmHqmY8g// Status: TODO//// 8m12s// 12m15s// 13m32s// 4h timeframe// means:// Where not to buy// Conclusion: Detectar velas verdes gigantes seguidas de velas verdes rojas gigantes// Y dejar ¿7 periodos? antes de seguir con la estrategia// Sub strategy 3 (SS3): https://www.youtube.com/watch?v=hzK3W-aJlHc// Status: Done// // Ez Osaca comment (9th point)// Para entrar en long, hay que esperar la debilidad, es decir, // que el monitor cruce el punto cero, la parte baja del monitor cambie de dirección hacia arriba,// (SS3.ADX) y el adx se ponga con pendiente negativa.// Lo ideal es buscar esto en gráfico de1H.// En 4H también se puede hacer, pero hay que estar atento, ante un alza rápida del precio,// y proteger la entrada. El alza puede ser con rebote hacia abajo.// Sub strategy 4 (SS4): https://www.youtube.com/watch?v=hzK3W-aJlHc// Status: TODO//// SS4.1: Ez Osaca comment (3rd point)// ¿ hasta donde subirá el precio? No sabemos. ¿ Y el retroceso? Si.// Hasta la media móvil de 55 (7300) o POC (7100).// Esperar un patrón de debilidad.// Parte baja del monitor desarrollada ( cambiando hacia arriba), y Adx negativo.//// SS4.2: Ez Osaca comment (8th point)// Próximas 48 horas se desarrollará el monitor// bajando al punto cero, y adx con pendiente negativa.//// That means that if we detect a downwards trend// we can establish the SHORT take profit to the MediaMovilMarron value// (or randomly at 85% of the distance between the current price and expected MediaMovilMarron as a line).//// SS4.3// https://www.youtube.com/watch?v=b0aZKiGhpQE (v419)// 6m57s// Status: Implemented.//// The price falls just below or above the MediaMovilMarron and so you can// enter in long.// Please note that the current price is above the MediaMovilAzul and the 1d timeframe trend is upwards.//// So this should be used as an extra condition to// the usual pattern of waiting for dark-red on the sqz mom.//// SS4.4// https://www.youtube.com/watch?v=YSDQZ1m24Hw (v420)// 10m08s//// This is an example where you would expect the price to rebound// because it touches the MediaMovilMarron.//// But, however you need to ensure to see dark-red. The rebound.// So this is basically SS4.3 again with a different order.// Nice.//// SS4.5// https://www.youtube.com/watch?v=YSDQZ1m24Hw (v420)// 27m54s// Yet again the same explanation on where to buy when the price// rebounds on the MediaMovilMarron//// He also says that when the price is above the MediaMovilAzul// then the price is not getting higher.// So is it maybe a signal to sell?// Jaime Merino has never said to use price being above the MediaMovilAzul// as a signal to sell.//// Sub strategy 5 (SS5): https://www.youtube.com/watch?v=hzK3W-aJlHc// Status: Implemented//// Ez Osaca comment (5th point)// En btc buscamos tendencia en diario.// This is in favour of keeping long or short trend decision// based on 1d timeframe// I'm not sure this is absolutely a requisite while working// on 4h timeframe but it surely adds to this decision// Sub strategy 6 (SS6): https://www.youtube.com/watch?v=mwbDK_VZGLA// Status: Implemented//// Buy signal//// [5m28s - 6m02s - 6m50s - 9m24s]// Debilidad en el movimiento bajista// (SS6.ADX) Cuando la pendiente negativa del ADX rompe por el punto 23// hacia abajo//// 10m45s// En el momento en que el ADX rompe el punto 23// a partir de aquí se desencadena la señal de compra// porque la fuerza bajista que traía el precio finaliza// aunque en el dibujo no tengas todavía el cambio// de color de rojoclaro a rojooscuro//// This is the the same as substrat three and thus also as substrat one.//// TODO 1: tradinglatino_strategy_adx_long_advice should be reimplemented// so that it checks:// El ADX ha de tener pendiente negativa// El ADX es menor que 23// This is a very important TODO//// TODO 2: tradinglatino_strategy_smilb_long_advice should be reimplemented// so that it no longer checks the change from rojoclaro to rojooscuro// but that it only checks you having rojoclaro or rojooscuro// This is a very important TODO// Substrat six - TODO 1 has been implemented// Substrat six - TODO 2 has been implemented// Sub strategy 7 (SS7)// Status: Implemented but currently disabled//// We should save the BUY advice (LONG)// and wait for its confirmation// that it's when BUY and BUY[1] are both true// then we issue the actual BUY signal// This is a very important TODO// in order to avoid traps// Sub strategy 8 (SS8)// Status: Confusing ideas to discard// This is TODO// we need to check if the BUY_CLOSE signals make sense// somehow we need to close when adx is not greater than 23// but at the same time it does not make sense doing it always// I think it should only be triggered when being in darkgreen// or maybe when it's either lightgreen or darkgreen//// Maybe just refuse to buy on lightred even if it's confirmed by two// prebuy signals// and wait for the darkred colour// or maybe we need to set our stop losses correctly// and that's it// or maybe switch to 1h timeframe// or maybe do not use 1d timeframe for calculation and just use current timeframe// or maybe even better set up the take profit on the projected// MediaMovilMarron crossing the MediaMovilAzul// or something// or maybe trigger the BUY_CLOSE signal when the MediaMovilAzul// tiene una pendiente negativa// Sub strategy 9 (SS9)// Status: TODO as an optional feature//// Force EMAS from current timeperiod and EMAS from higher timeperiod to have both upwards trend// Sub strategy 10 (SS10)// Status: TODO as an optional feature//// Ignore or not emas from higher timeperiod and use emas from current timeperiod// Sub strategy 11 (SS11)// Status: Implemented//// Implement both long and short strategies// Sub strategy 12 (SS12)// Status: Implemented//// Short strategy should not switch to a long strategy// unless 10 periods have passed// and viceversa// Sub strategy 13 (SS13): // Status: Implemented// SS13: https://www.youtube.com/watch?v=objURdzcm00 (9m53s)// Long sell signal means changing from light green to dark green// and also adx slope being negative// Sub strategy 14 (SS14): // Status: Implemented// SS14: // If we are inside a price range then it's going to stay the same or dump down// SS14 updated.// Let's ignore price range alltogether// We will just print it and that's it// Sub strategy 15 (SS15): // Status: TODO// SS15: // Take into account resistances and supports// Sub strategy 16 (SS16): // Status: TODO// SS16: // Do not act (or close) on lightgreen if recent past was: lightgreen, darkgreen and now lightgreen appears again.// Idem with green colours that repeat or red colours that repeat in general// Sub strategy 17 (SS17): // Status: Wild idea// SS17: // Try to avoid operating on bank holidays// Close operations about 3 days (taking into account current timeframe) before them?// Sub strategy 18 (SS18): https://www.youtube.com/watch?v=OUSdjdYqErQ (v407)// Status: Discarded. We will just implement SS12 which it will achieve a similar result.// This is coming back to SS5.// 14m14s 14m44s//// How to confirm that main tendency has changed// from upwards to downwards movement// Condition 0: Daily timeframe// Condition 1: Price needs to be below FastEMA (10) and SlowEMA (55)// Condition 2: Price needs to be below an important Point of Control (PoC)// Condition 3: FastEMA (10) should cross downwards the SlowEMA (55) with strength// Condition 4: Detect a crossing like in 'Condition 3', rebounce back to SlowEMA (55) and then go downwards//// This substrategy should affect how tradinglatino_strategy_emas_short_advice and tradinglatino_strategy_emas_long_advice// are being calculated.// We should maybe even rename them to something like tradinglatino_strategy_higher_timeframe_short_advice and// tradinglatino_strategy_higher_timeframe_long_advice .// Sub strategy 19 (SS19)// Status: TODO//// As per SS18 we will need to find a way for describing that the 'Price' needs to be below FastEMA (10) and SlowEMA (55).// Maybe the highest value on the bar should be below the two of them////// Sub strategy 20 (SS20)// Status: Wild idea//// Use 1h timeframe so that we can act at 3h out of the current 4h candle// (We would use security function)// so that you don't need to wait for the total confirmation// of the candle and anticipate your decision//// Probably we should paint the 4h candles on our own// and ask the user to hide the 1h default candle painting from TradingView// Sub strategy 21 (SS21)// Status: TODO//// Instead of saying 'true' or 'false' to so many substrategy options// we might want to value them from 0 (ignore it) to 100 (Most agreement)// Then we can sum all of these substrategy weights// and have a threshold// Let's see an example// PRE_BUY := tradinglatino_strategy_smilb_and_adx_long_advice and tradinglatino_strategy_emas_long_advice// smilb_and_adx_long_advice_BUY_WEIGHT=80// emas_long_advice_advice_BUY_WEIGHT=70// Total weight (Two conditions) = 2 * 100 = 200// Random Threshold = Total weight / 2 = 100//// 80 + 70 = 150 > 100// So the condition should be true// However with a 151 threshold// the condition would be false//// This weights might be used// in the future in some Artificial Intelligence (A.I.)// training// Sub strategy 22 (SS22): https://www.youtube.com/watch?v=L3VJtKklU9I (v408)// Status: I want to implement it if it's not too difficult//// 13m10s// This would be an exception// And something a bot would have ignored// but not a human//// Do not take a long advice on upwards trend// if the entry price is about the same one// the one you last sold//// Wait for a downwards bounce to enter// Sub strategy 23 (SS23)// Status: Not sure if it will be actually needed// Detect pinbars to know when to bounce back// (Long strategy)// Sub strategy 24 (SS24)// // Status: Not sure if it will be actually needed// Zoom into 1h// https://www.youtube.com/watch?v=9pV9FMTPhrM (v414)//// 09m17s// Now we use 1h timeframe instead of 4h timeframe in order to search for buy entry points// Sub strategy 25 (SS25)//// Status: Need more confirmation// 1h timeframe// https://www.youtube.com/watch?v=9pV9FMTPhrM (v414)//// 12m17s 13m00s// If there is not downwards movement during// a range that lasts for (13 + 4) hours// then probably it's going upwards later on// Sub strategy 26 (SS26)//// Status: Need more confirmation// 1h timeframe// https://www.youtube.com/watch?v=9pV9FMTPhrM (v414)//// 13m55s// When the SQZ Momentum indicator reaches 0// then it's a good time to buy// because it might be going upwards// Sub strategy 27 (SS27): // Status: TODO// SS27: // This is a revisit on SS14.// We said that if we are inside a price range then it's going to stay the same or dump down//// https://www.youtube.com/watch?v=b0aZKiGhpQE// 8m00s//// Warning: 1h timeframe which we might never use// Warning: So maybe readapt later the price range based on median// settings.//// Please note than even if there was a former dark-red below it was ignored// Why?// Because there was a range (danger zone as Jaime Merino names it) above//// So we should be able to detect such ranges if we want to take advantage// of this fact//// We could use the candle body height to measure. If three of them have far lesser// body height than the detected range candles// then we are not longer in the range//// However right now the current range ( 28 Jul 20 -- 04:00 ) to ( 28 Jul 20 -- 20:00) on 1h timeframe. (Spain timezone).// is not detected by our median based range with the current settings:// * Price Range Periods: 5// * Price Range Maximum Desviation: 0.6// * Price Range Minimum Desviation: 0.6//// Maybe we need to rethink the range detection based on body heights as described above.// Sub strategy 28 (SS28): // Status: This is nonsense. I ignore it for the moment.// SS28:// https://www.youtube.com/watch?v=YSDQZ1m24Hw// 7m18s//// Apparently he waits till the ADX slope is positive// So he ignores the dark-red entries based on SQZMOM// because ADX is not yet positive// However, somehow he doesn't want to miss on ADX slope// being positive.// So he buys on some green even if the ADX slope is not// positive yet.// But this seems like a feeling he had and nothing// mathematic that we can convert into a substrategy.//// Probably our strategy would have detected the ADX slope// being positive because it just compares previous value// to current value.// I mean the ADX slope detector is much sensible than// an average person or Jaime would be.// Sub strategy 29 (SS29): // Status: TODO// SS29:// Per reading SS28 we might need to tweak the// (ADXSLOPE) ADX minimum steepness entry so that it's somewhat// similar to what a human would detect.// Check an actual example from:// https://www.youtube.com/watch?v=YSDQZ1m24Hw// 8m00s// in order to check it//// Although, warning, we know per SS28 that we should not// actually wait for such an steep slope// Sub strategy 30 (SS30): // Status: TODO// SS30:// We are not using adx_minimum_steepness_exit variable// Check why it's that.// Sub strategy 31 (SS31):// Status: Almost done// SS31// https://www.youtube.com/watch?v=YSDQZ1m24Hw (v420)// 11m11s//// Here we have some green colours on the SQM MOM// which were ignored by Jaime// But why did he decided to sell// Because in one of the last dark-green// He is seeing a divergence// He draws it in the chart//// So we might need to add support for divergences// and also somehow mathematically determine// if they are relevant or not//// According to my preliminar research// we could trigger a divergence when// the SQZMOM line is negative// and the main chart line is positive even// if it's barely over 0//// So, this might be another requisite before// selling.// So that do not sell even if you have a dark-green// SQZMOM wait for the divergence confirmation to happen//// We need more proofs from Jaime.// Because he usually says that he bases his// 'Sell now' trigger based exclusively on the// SQZMOM being dark-green//// So this substrategy might be implemented// as an additional feature// for more aggresive traders//// Update Status: We can print divergences.// Not sure how to use them yet.//// So no function has been implemented // to calculate is there's an// advice for selling a long position// from a divergence.// Sub strategy 32 (SS32):// Status: TODO// SS32//// https://www.youtube.com/watch?v=YSDQZ1m24Hw (v420)// 22:58//// 1d timeframe: Tendency. We already knew that.// 4h timeframe: We find entries for 48 or 72 hours.// 1h timeframe: 4h or 8h and you win//// So this substrategy might be implemented// as that entries created in 4h timeframe, do not have to last more// than 72 hours// (Assuming take profit or stop loss would not have kicked in yet.)//// Needs more thinking.// Sub strategy 33 (SS33):// Status: TODO// SS33//// https://www.youtube.com/watch?v=YSDQZ1m24Hw (v420)// 25:08//// In 1h you don't need the SQZMOM to reach zero.// If the ADX slope is positive you can bet// on the price being bigger//// Even if it's a dark-green.// Not only we need ADX slope being positive// but also direccionalidad//// I should learn how to calculate the direccionalidad// Maybe fuerza is ADX being bigger than 23// and direccionalidad is the ADX slope being positive// Sub strategy 34 (SS34):// Status: TODO// SS34//// https://www.youtube.com/watch?v=Fud2RdjOstg (v421)// 05:32// He is selling even if there was not a confirmation// with dark green//// 07:15// 08:40// 10:32// The volatility is getting smaller and smaller// and that it's a range that it's forming//// So the price might break// If we are in a 4h timeframe// we see the range// The price has not fallen down in 4h timeframe// So the short should not be down// 12:15// The price is stable in 4h timeframe// Sub strategy 35 (SS35):// Status: TODO// SS35// https://www.youtube.com/watch?v=Fud2RdjOstg (v421)// 13:49//// Warning: 1h timeframe//// Condition 1: Precio con mechazos a la alza (200, 300 dolares)// Condition 2: If dark green gets converted into light green// Condition 3: ADX slope becomes a positive one//// Then it's a buy signal// It's not always needed to touch zero point// Sub strategy 36 (SS36):// Status: TODO// SS36// https://www.youtube.com/watch?v=Fud2RdjOstg (v421)// 16:55//// 4h timeframe// Negative slope changes into Positive slope// And its direccionalidad alcista//// This is a buy signal// He says he managed to get it in the candle start// so we might need to zoom into 15 minutes to know// when to enter// Sub strategy 37 (SS37):// Status: TODO// SS37// So we need to integrate resistances and supports// from my other script// so that we can use its VPOC// in order to implement parts of// SS4.1 and SS18//// I will do it when I am more confident// on how this VPoC would be used//// As you can see SS18 is from Jaime Merino// but SS4.1 is not//// We should probably save the current VPOC price// when a buy signal is triggered//// That way we might use it in the future even// if it has dissapeared because of// more than one day has passed// Sub strategy 38 (SS38):// Status: Done// SS38// This has been explained by Jaime Merino many times// I have to find a video though.//// If the EMA10 in the current timeframe// is lower than the EMA55 in the current timeframe// then we should aim only at bouncing back to// the EMA55 price// and then the price goes down// We need a setting so that we can aim// e.g. at 80/100 of the EMA55 - EMA10 difference// Sub strategy 39 (SS39):// Status: Done// SS39// https://www.youtube.com/watch?v=1KBXRpKGNqg (v312)// 15m04s//// If VPoC (based on VPVR) is lower than the// MediaMovilMarron that means// the price is going to rebounce// to the VPoC//// It is not going to rebounce to the MediaMovilMarron// as it would have happened otherwise//// His VPoC based on VPVR has a range of 'n' 4h bars.// After counting them is 100 4h bars.// SUB STRATEGIES - ENDDIVERGENCE_COLOUR_A = color.whiteDIVERGENCE_COLOUR_B = color.silverhc = max(close, open)lc = min(close, open)// ADX inputsadx_adxlen = input(14, title="(ADX) Smoothing {14}")adx_dilen = input(14, title="(ADX) DI Length {14}")adx_keyLevel = input(23, title="(ADX) key level {23}")di_minimum_percentage = input(10.0, title="(ADX) DI minimum percentage (%) {10.0}", minval=0.0, step=0.01)// SMILB inputssqzmom_length = input(20, title="(SQZMOM) BB Length {20}")sqzmom_mult = input(2.0,title="(SQZMOM) BB MultFactor {2.0}")sqzmom_lengthKC=input(20, title="(SQZMOM) KC Length {20}")sqzmom_multKC = input(1.5, title="(SQZMOM) KC MultFactor {1.5}")sqzmom_useTrueRange = input(true, title="(SQZMOM) Use TrueRange (KC) {True}", type=input.bool)sqzmom_zero = input(0.0, "(SQZMOM) Squeeze percentage zero {0.0}", minval=-100.0, maxval=100.0, step=0.01)// EMAS inputsmarron_color=#800000ema10_len = input(10, minval=1, title="(EMAS) EMA10 - Length {10}")ema10_src = input(close, title="(EMAS) EMA10 - Source {close}")ema55_len = input(55, minval=1, title="(EMAS) EMA55 - Length {55}")ema55_src = input(close, title="(EMAS) EMA55 - Source {close}")// Volume Profile inputsvp_timeframe = input("1D",title="(VP) Volume Profile timeframe {1 day}",type=input.resolution)vp_enable_custom_recent_n_bars = input(false, "(VP) Use number of bars (not VP timeframe)")vp_custom_recent_n_bars = input(100, "(VP) Number of bars {100}", minval=1, maxval=500)vp_resistances_price_decimal_digits = input(2, "(VP) Resistances prices number of decimal digits {2}", minval=0, maxval=10, step=1)vp_bottom_vpoc_n_bars = input(18, "(VP) Number of bars for bottom VPOC {18}", minval=1, maxval=500) // 18 bars 4h = 3 daysvp_bottom_vpoc_ignore_advice = input(false, "(VP) Ignore VPOC bottom advice on long {False}")vp_vpvr_vpoc_n_bars = input(100, "(VP) Number of bars for VPVR VPOC {100}", minval=1, maxval=500)VP_PRICE_LEVELS = input(24, "(VP) Price levels {24}", minval=10, maxval=500)// TradingLatino ADX Long based on slope and 23 value advice - Inputsadx_23_value_for_strat = input(23, title="(ADXSLOPE) ADX cut {23}")adx_minimum_steepness_entry = input(45, title="(ADXSLOPE) ADX minimum steepness entry {45}")adx_minimum_steepness_exit = input(45, title="(ADXSLOPE) ADX minimum steepness exit {45}")adx_steepness_periods_number = input(3, title="(ADXSLOPE) ADX steepness periods {3}")// Next to EMA55 - Inputsbounce_back_to_EMA55_percent = input(50.00, "(NEXTEMA55) EMA10 to EMA55 bounce back percentage {80}", minval=50, maxval=100, step=0.01)next_to_EMA55_percent = input(15.00, "(NEXTEMA55) Next to EMA55 percentage {15}", minval=0, maxval=50, step=0.01)// Stop Loss and Take Profit - Inputs// We make stop loss is always used and > 0, otherwise we would have a division per zeroSL = input(7.0, title="(STOPTAKE) Stop Loss % {7.0}", minval=0.01 ) / 100TP = input(2.0, title="(STOPTAKE) Take Profit % {2.0}") / 100// Trailing Take Profit - Inputstrailing_take_profit_percentage = input(0.4, "(TRAILING) Trailing Take Profit (%) {0.4}",minval=0,step=0.01,type=input.float) * 0.01trailing_take_profit_percentage_trigger = input(0.8, "(TRAILING) Trailing Take Profit Trigger (%) {0.8}",minval=0,step=0.01,type=input.float) * 0.01trailing_take_profit_percentage_from_drawdown = input(30.0, "(TRAILING) Drawdown percentage for dynamic Trailing Take Profit Trigger (%) {30.0}",minval=0,step=0.01,type=input.float) * 0.01dynamic_trailing_take_profit_offset_percentage = input(45.0, "(TRAILING) Trailing Take Profit as a percentage of Trailing Take Profit Trigger (for dynamic TTP) (%) {45.0}",minval=0,step=0.01,type=input.float) * 0.01trailing_take_profit_percentage_resistances_strict_mode = input(20.0, "(TRAILING) Take profit percentage for dynamic Trailing Take Profit Trigger based on VPoC resistances (%) {20.0}",minval=0,step=0.01,type=input.float)enable_dynamic_trailing_take_profit = input(true, "(TRAILING) Enforce dynamic Trailing Take Profit {True}")// Too old order - Inputstoo_old_bars_number = input(6, "(OLD) Number of bars to consider and order to be old {6}", minval=1, maxval=100, step=1)too_old_minimum_loss_percent = input(0.8, "(OLD) Minimum loss percent to close an old order {0.8}", minval=0.01, maxval=100, step=0.01) / 100too_recent_minutes_number = input(6, "(RECENT) Number of minutes to wait to open a new order after the previous one has been opened {6}", minval=1, maxval=100, step=1)dynamic_minimum_stop_loss = input(1.0, "(STOPTAKE) Minimum loss percent to be supported by VPVR VPoC {1.0}", minval=0.01, maxval=100, step=0.01) / 100dynamic_maximum_stop_loss = input(2.38, "(STOPTAKE) Maximum loss percent to be supported by VPVR VPoC {2.38}", minval=0.01, maxval=100, step=0.01) / 100Ratio = input(1.00, "(STOPTAKE) Win/Loss Ratio {1.00}", minval=0.01, maxval=100, step=0.01) // Ratio 1:1 it's '1'.exchange_order_fee_percent = input(0.04, "(EXCHANGE) Fees per order {0.04} (%)", minval=0.01, maxval=100, step=0.01)// MAIN TURN ON/OFF OPTIONS - Inputsemas_ignore_advice = input(false, "(EMAS) Ignore advice based on emas {false}")emas_ignore_advice_on_buy_close = input(false, "(EMAS) Ignore advice based on emas (On closing long signal) {False}")smilb_ignore_advice = input(false, "(SQZMOM) Ignore advice based on SQZMOM {false}")sqzmom_percentage_zero_ignore_advice = input(true, "(SQZMOM) Ignore advice based squeeze percentage {True}")adx_positive_slope_ignore_advice = input(true, "(ADXSLOPE) Ignore advice based on ADX positive slope {true}")adx_23_ignore_advice = input(true, "(ADXSLOPE) Ignore advice based on ADX cut (23) {true}")tp = input(false, "(STOPTAKE) Take Profit? {false}")// sl = input(true, "(STOPTAKE) Stop Loss? {True}")// We make stop loss is always used and > 0, otherwise we would have a division per zerosl = trueenable_trailing_take_profit_percentage = input(true, title="(TRAILING) Enable Trailing Take Profit (%) {True}", type=input.bool)too_old_order_ignore_advice_on_buy_close = input(false, "(OLD) Ignore advice based on order being too old {False}")enable_dynamic_stop_loss = input(true, "(STOPTAKE) Enforce dynamic stop loss up to maximum stop loss {True}")// TradingLatino Strategy - InputsL_S = "Long and Short" , _L_ = "Long Only" , _S_ = "Short Only"Type = input(L_S, "(STRAT) Type Strategy", options=[L_S, _L_, _S_])// Risk Management - Inputs_SAFE_="Safe", _SCOMPOUND_="Somewhat safe compound", _UCOMPOUND_="Unsafe compound"risk_management_type = input(_SCOMPOUND_, "(RISKM) Risk Management Type", options=[_SAFE_, _SCOMPOUND_, _UCOMPOUND_])risk_management_maximum_loss_per_trade = input(1.0, title="(RISKM) Maximum loss per trade % {1.0}" ) / 100risk_management_maximum_loss_per_day = input(6.0, title="(RISKM) Maximum loss per day % {6.0}" ) / 100risk_management_maximum_loss_per_week = input(8.0, title="(RISKM) Maximum loss per week % {8.0}" ) / 100risk_management_maximum_loss_per_month = input(10.0, title="(RISKM) Maximum loss per month % {10.0}" ) / 100// Decimal - Inputscontract_maximum_decimal_number = input(3, title="(DECIMAL) Maximum number of decimal for contracts {3}",minval=0)// TradingLatino Price is in range - Inputspricerange_background_colour = color.yellowpricerange_text_colour = color.whiteprice_is_in_range_print = input(false, title="(PRANGE) Print price is in range {False}", type=input.bool)pricerange_periods_number = input(5, title="(PRANGE) Price range periods {5}")pricerange_maximum_desviation_percent = input(0.6, title="(PRANGE) Price range maximum desviation (%) {0.6} ( > 0 ) ")pricerange_minimum_desviation_percent = input(0.6, title="(PRANGE) Price range minimum desviation (%) {0.6} ( > 0 ) ")// SQUEEZE MOMENTUM Desviation indicator - Inputsenable_show_degrees = input(false, title="(SQZDIVER) Show degrees {False}", type=input.bool)enable_show_desviation_labels = input(false, title="(SQZDIVER) Show desviation labels {False}", type=input.bool)enable_show_desviation_lines = input(false, title="(SQZDIVER) Show desviation lines {False}", type=input.bool)// VOLUME PROFILE indicator - Inputsvp_enable_print_vpvr_vpoc_price = input(true, title="(VP) Print VPVR VPoc price {True}", type=input.bool)vp_enable_avoid_overlap_mode = input(false, "(VP) Avoid label price overlaps {False}")// Zignaly - Email (zignalye)_ZIGNALYE_="Email", _ZIGNALYW_="WebHook"zignaly_alert_type = input(_ZIGNALYE_, "(ZIG) Zignaly Alert Type {Email}", options=[_ZIGNALYW_, _ZIGNALYE_])// Order comments based debugenable_order_comment_debug = input(false, title="(DEBUG) Enable debug on order comments {False}", type=input.bool)// Raw testingenable_raw_testing = input(false, "(DEBUG) Enable raw testing {True}")raw_testing_quantity = input(100.0, title="(DEBUG) Constant entry quantity for raw USDT testing {100.0}")// Plus or Neo modeenable_plus_mode = input(false, "(PLUS MODE) Beyond original TradingLatino strategy (Experimental) {False}")enable_strict_mode = input(true, "(STRICT RISK) Even more strict risk management {True}")// Dynamic Trailing Take Profit - Variablesvar float constant_trailing_take_profit_percentage_trigger = navar float constant_trailing_take_profit_percentage = na// Zignalyexchange_tickerid = syminfo.basecurrency + syminfo.currencyvar string zignaly_separator = ","var string zignaly_quote = "\""var string zignaly_equals = "="if ( zignaly_alert_type == _ZIGNALYE_) zignaly_separator := "||" zignaly_quote := "" zignaly_equals := "="else zignaly_separator := "," zignaly_quote := "\"" zignaly_equals := ":"zignaly_common_alert_message = zignaly_quote + "exchange" + zignaly_quote + zignaly_equals + zignaly_quote + "binance" + zignaly_quote + zignaly_separator + zignaly_quote + "exchangeAccountType" + zignaly_quote + zignaly_equals + zignaly_quote + "futures" + zignaly_quote + zignaly_separator + zignaly_quote + "pair" + zignaly_quote + zignaly_equals + zignaly_quote + "" + exchange_tickerid + zignaly_quote + zignaly_separator + zignaly_quote + "leverage" + zignaly_quote + zignaly_equals + zignaly_quote + "1" + zignaly_quote// too old order variablesvar int buy_order_open_bar_index = navar int sell_order_open_bar_index = na// Dynamic stop loss variablesvar float buy_SL = navar float sell_SL = navar float new_buy_SL = navar float new_sell_SL = navar bool old_inside_a_buy_order = falsevar bool old_inside_a_sell_order = falsevar bool inside_a_buy_order = falsevar bool inside_a_sell_order = falseold_inside_a_buy_order := inside_a_buy_orderold_inside_a_sell_order := inside_a_sell_ordervar int last_order_open_bar_time = na// Handle recalculate after Stop Loss / Take Profit orderif (strategy.position_size == 0.0) inside_a_buy_order := false inside_a_sell_order := falseelse last_order_open_bar_time := time_closeVP_LAST_BLOCK_COLOR = color.grayVP_CURRENT_PRICE_LEVEL_COLOR = color.blueVP_SUPPORT_PRICE_LEVEL_COLOR = color.greenVP_RESISTANCE_PRICE_LEVEL_COLOR = color.redVP_VPOC_PRICE_LEVEL_COLOR = color.yellowint vp_current_price_level_number = naint vp_support_price_level_number = naint vp_resistance_price_level_number = naint vp_vpoc_price_level_number = na// int vp_vpvr_vpoc_price_level_number = naint vp_vpvr_vpoc_price_level_number_top = naint vp_vpvr_vpoc_price_level_number_bottom = navar string tmp_order_comment = navar string tmp_order_alert_message = navar int too_recent_minutes_number_ms = too_recent_minutes_number * 60 * 1000 // Convert minutes into milliseconds only once// Decimals - Functionsget_contract_multiplier(contract_maximum_decimal_number) => contract_multiplier = 1 if (contract_maximum_decimal_number == 0) contract_multiplier // Return 1 else for counter = 1 to contract_maximum_decimal_number contract_multiplier:= contract_multiplier * 10 contract_multiplier// —————————— PineCoders MTF Selection Framework functions// ————— Converts current "timeframe.multiplier" plus the TF into minutes of type float.f_resInMinutes() => _resInMinutes = timeframe.multiplier * ( timeframe.isseconds ? 1. / 60. : timeframe.isminutes ? 1. : timeframe.isdaily ? 1440. : timeframe.isweekly ? 10080. : timeframe.ismonthly ? 43800. : na) var currentResInMinutes = f_resInMinutes() // We need to calculate it only onceget_resolution_bar_minutes(resolution) => minutes = resolution == '1' ? (1 * 1) : resolution == '3' ? (3 * 1) : resolution == '5' ? (5 * 1) : resolution == '15' ? (15 * 1) : resolution == '30' ? (30 * 1) : resolution == '45' ? (45 * 1) : resolution == '60' ? (60 * 1) : resolution == '120' ? (2 * 60) : resolution == '180' ? (3 * 60) : resolution == '240' ? (4 * 60) : resolution == '1D' ? (24 * 60) : resolution == '1W' ? (7 * 24 * 60) : resolution == '1M' ? (4 * 7 * 24 * 60) : currentResInMinutes // Equal to current symbol minutesvp_recent_n_bars_based_on_resolution = int(floor(get_resolution_bar_minutes(vp_timeframe) / currentResInMinutes))vp_recent_n_bars = 0if vp_enable_custom_recent_n_bars vp_recent_n_bars := vp_custom_recent_n_barselse vp_recent_n_bars := vp_recent_n_bars_based_on_resolution// Volume Profile functionsvp_get_resistances_price_decimal_digits_zero_string () => zero_string = "" if not (vp_resistances_price_decimal_digits == 0) for digit = 1 to vp_resistances_price_decimal_digits zero_string := zero_string + "0" zero_stringvp_level_value(from_i, to_i, row_low, row_high) => float actual_low = na float actual_high = na val = 0.0 for i = from_i to to_i if low[i] < row_high and high[i] > row_low if low[i] > row_low actual_low := low[i] else actual_low := row_low // Should not happen if high[i] < row_high actual_high := high[i] else actual_high := row_high val := val + volume[i] * (max(actual_high - actual_low, 1) / max((row_high - row_low) * VP_PRICE_LEVELS, 1) ) valvp_level_price(from_i, to_i, row_low, row_high) => float actual_low = na float actual_high = na float volume_ponderated = 0.0 float price_ponderated = 0.0 float total_volume = 0.0 float price_ponderated_top_sum = 0.0 float return_price = 0.0 for i = from_i to to_i actual_high := row_high // Default value for the loop actual_low := row_low // Default values for the loop volume_ponderated := 0.0 // Default value for the loop if low[i] < row_high and high[i] > row_low if low[i] > row_low actual_low := low[i] else actual_low := row_low // Should not happen if high[i] < row_high actual_high := high[i] else actual_high := row_high volume_ponderated := volume[i] * (max(actual_high - actual_low, 1) / max((row_high - row_low) * VP_PRICE_LEVELS, 1)) total_volume := total_volume + volume_ponderated price_ponderated := ((actual_high + actual_low) / 2) price_ponderated_top_sum := price_ponderated_top_sum + (price_ponderated * volume_ponderated) if (total_volume != 0) return_price := price_ponderated_top_sum / total_volume else return_price := ((row_low + row_high ) / 2) return_pricevp_level_value_wrapper(vp_recent_lvl_height, vp_recent_low, vp_level_number, from_i, to_i) => recent_lvl_low = vp_recent_low + vp_recent_lvl_height * (0 + vp_level_number) recent_lvl_high = vp_recent_low + vp_recent_lvl_height * (1 + vp_level_number) recent_lvl_value = vp_level_value(0, to_i, recent_lvl_low, recent_lvl_high) recent_lvl_valuevp_level_price_wrapper(vp_recent_lvl_height, vp_recent_low, vp_level_number, vp_n_bars) => recent_lvl_low = vp_recent_low + vp_recent_lvl_height * (0 + vp_level_number) recent_lvl_high = vp_recent_low + vp_recent_lvl_height * (1 + vp_level_number) recent_lvl_price = vp_level_price(0, vp_n_bars, recent_lvl_low, recent_lvl_high) tick_based_lvl_price = 0.0// if (vp_enable_show_ticks and (syminfo.mintick > 0))// tick_based_lvl_price := floor(recent_lvl_price / syminfo.mintick) * syminfo.mintick// else // tick_based_lvl_price := recent_lvl_price tick_based_lvl_price := recent_lvl_price tick_based_lvl_price// Improved from:// Get higher timeframe.period automatically// Name: Support Resistance MTF// User: LonesomeTheBlue// https://www.tradingview.com/script/E9l1xAQd-Support-Resistance-MTF/// Timeframe period functionsfun_get_higher_timeframe() => Timeframe = timeframe.period if (timeframe.period == '1') Timeframe := '15' else if (timeframe.period == '3') Timeframe := '15' else if (timeframe.period == '5') Timeframe := '60' else if (timeframe.period == '15') Timeframe := '60' else if (timeframe.period == '30') Timeframe := '120' else if (timeframe.period == '45') Timeframe := '120' else if (timeframe.period == '60') Timeframe := '240' else if (timeframe.period == '120') Timeframe := '1D' else if (timeframe.period == '180') Timeframe := '1D' else if (timeframe.period == '240') Timeframe := '1D' else if (timeframe.period == 'D') Timeframe := '1W' else if (timeframe.period == 'W') Timeframe := '1M' else if (timeframe.period == 'M') Timeframe := '12M' Timeframe// Linear regression - functionslrp_Sum(src,p) => a = cum(src), a - a[max(p,0)]lrp_Wma(src,p) => mp = max(p,0) denom = mp*(mp+1)/2 a = cum(src), (mp*a - lrp_Sum(a[1],p))/denomlrp_getAandB(src, p) => a = lrp_Wma(src[1],p) b = lrp_Sum(src[1],p)/p A = 4*b-3*a B = 3*a-2*b [A,B]fun_linear_regression_points(src, periods_number) => k = 0 // Default value enforced [A,B] = lrp_getAandB(src, periods_number) line lr = na x1 = bar_index - periods_number + 1 y1 = A+k x2 = bar_index - 1 + 1 y2 = B+k [x1,y1,x2,y2]fun_line_slope(x1,y1,x2,y2) => (y2 - y1) / (x2 - x1)fun_slope_angle(slope) => x_axis_slope=0 angle_radians = atan((slope-x_axis_slope)/(1+(slope*x_axis_slope))) pi_number = 3.1415926535897 angle_degrees = (angle_radians * 180) / pi_number angle_degreesfun_divergence_symbol (line_smilb_angle, line_price_angle) => divergence_symbol = "" line_smilb_angle_symbol = "" line_price_angle_symbol = "" line_smilb_angle_degrees = "" line_price_angle_degrees = "" if enable_show_degrees line_smilb_angle_degrees := " (" + tostring(line_smilb_angle,"#.00") + ")" line_price_angle_degrees := " (" + tostring(line_price_angle,"#.00") + ")" if (line_smilb_angle > 0) line_smilb_angle_symbol := "/" else line_smilb_angle_symbol := "\\" if (line_price_angle > 0) line_price_angle_symbol := "/" else line_price_angle_symbol := "\\" line_smilb_angle_symbol := line_smilb_angle_symbol + line_smilb_angle_degrees line_price_angle_symbol := line_price_angle_symbol + line_price_angle_degrees divergence_symbol := line_price_angle_symbol + "\n" + line_smilb_angle_symbol divergence_symbolfun_set_current_section (red_smilb_section_a, green_smilb_section_b, red_smilb_section_b, green_smilb_section_a, smilb_is_green, smilb_is_red) => // Set correct section - BEGIN l_green_smilb_section_b = green_smilb_section_b l_red_smilb_section_b = red_smilb_section_b l_green_smilb_section_a = green_smilb_section_a l_red_smilb_section_a = red_smilb_section_a // Detect we enter into green section b if l_red_smilb_section_a[1] and smilb_is_green l_green_smilb_section_b := false l_red_smilb_section_b := false l_green_smilb_section_a := false l_red_smilb_section_a := false l_green_smilb_section_b := true // Detect we enter into red section b if l_green_smilb_section_b[1] and smilb_is_red l_green_smilb_section_b := false l_red_smilb_section_b := false l_green_smilb_section_a := false l_red_smilb_section_a := false l_red_smilb_section_b := true // Detect we enter into green section a if l_red_smilb_section_b[1] and smilb_is_green l_green_smilb_section_b := false l_red_smilb_section_b := false l_green_smilb_section_a := false l_red_smilb_section_a := false l_green_smilb_section_a := true // Detect we enter into red section a if l_green_smilb_section_a[1] and smilb_is_red l_green_smilb_section_b := false l_red_smilb_section_b := false l_green_smilb_section_a := false l_red_smilb_section_a := false l_red_smilb_section_a := true [l_green_smilb_section_b, l_red_smilb_section_b, l_green_smilb_section_a, l_red_smilb_section_a] // Set correct section - ENDfun_section_biggest_top(green_smilb_section, smilb_is_darker_green, smilb_is_light_green, green_maximum_smilb_section, green_maximum_price_section, green_maximum_section_index, new_green_divergence, sqzmom_val) => l_green_maximum_price_section = green_maximum_price_section l_green_maximum_smilb_section = green_maximum_smilb_section l_green_maximum_section_index = green_maximum_section_index l_new_green_divergence = new_green_divergence // Assuming we are in 'green section' let's obtain biggest top if green_smilb_section and smilb_is_darker_green and smilb_is_light_green[1] and (not na(smilb_is_light_green[1])) tmp_green_maximum_price_section = hc[1] // For top chart tmp_green_maximum_smilb_section = sqzmom_val[1] // Possible if for top chart // if tmp_green_maximum_price_section > nz(green_maximum_price_section_a) if tmp_green_maximum_smilb_section > nz(green_maximum_smilb_section) l_green_maximum_price_section := tmp_green_maximum_price_section l_green_maximum_smilb_section := tmp_green_maximum_smilb_section l_green_maximum_section_index := bar_index - 1 l_new_green_divergence := true [l_green_maximum_price_section, l_green_maximum_smilb_section, l_green_maximum_section_index, l_new_green_divergence]fun_meta_divergence_symbol (green_maximum_section_index_b,green_maximum_smilb_section_b,green_maximum_section_index_a,green_maximum_smilb_section_a, green_maximum_price_section_b, green_maximum_price_section_a) => line_smilb_slope_a = fun_line_slope(green_maximum_section_index_b,green_maximum_smilb_section_b,green_maximum_section_index_a,green_maximum_smilb_section_a) line_smilb_angle_a = fun_slope_angle(line_smilb_slope_a) line_price_slope_a = fun_line_slope(green_maximum_section_index_b,green_maximum_price_section_b,green_maximum_section_index_a,green_maximum_price_section_a) line_price_angle_a = fun_slope_angle(line_price_slope_a) green_divergence_label_a_text = fun_divergence_symbol (line_smilb_angle_a, line_price_angle_a)fun_steep_positive_slope(src, periods_number, minimum_steep_angle) => [x1,y1,x2,y2] = fun_linear_regression_points(src, periods_number) line_slope = fun_line_slope(x1,y1,x2,y2) line_angle = fun_slope_angle(line_slope) (line_angle > minimum_steep_angle)fun_steep_negative_slope(src, periods_number, minimum_steep_angle) => [x1,y1,x2,y2] = fun_linear_regression_points(src, periods_number) line_slope = fun_line_slope(x1,y1,x2,y2) line_angle = fun_slope_angle(line_slope) ( line_angle < (0 - minimum_steep_angle) )// ADX functionsdirmov(len) => up = change(high) down = -change(low) truerange = rma(tr, len) plus = fixnan(100 * rma(up > down and up > 0 ? up : 0, len) / truerange) minus = fixnan(100 * rma(down > up and down > 0 ? down : 0, len) / truerange) [plus, minus]adx(dilen, adxlen) => [plus, minus] = dirmov(dilen) sum = plus + minus adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen) [adx, plus, minus]fun_adx_positive_slope(adx_sig, adx_minimum_steepness_entry, adx_steepness_periods_number) => fun_steep_positive_slope(adx_sig, adx_steepness_periods_number, adx_minimum_steepness_entry)fun_adx_negative_slope(adx_sig, adx_minimum_steepness_entry, adx_steepness_periods_number) => fun_steep_negative_slope(adx_sig, adx_steepness_periods_number, adx_minimum_steepness_entry)// Price range - functionsfun_amount_within_limits(amount, maximum_amount, minimum_amount) => (amount > minimum_amount) and (amount < maximum_amount)fun_price_is_in_range(hc, lc, pricerange_maximum_desviation_percent, pricerange_minimum_desviation_percent, pricerange_range_periods_number) => is_in_range = true hc_median = median (hc, pricerange_range_periods_number) lc_median = median (lc, pricerange_range_periods_number) hc_maximum = hc_median * ((100 + pricerange_maximum_desviation_percent) / 100) hc_minimum = hc_median / ((100 + pricerange_maximum_desviation_percent) / 100) lc_maximum = lc_median * ((100 + pricerange_maximum_desviation_percent) / 100) lc_minimum = lc_median / ((100 + pricerange_maximum_desviation_percent) / 100) hc_within_limits = fun_amount_within_limits(hc, hc_maximum, hc_minimum) lc_within_limits = fun_amount_within_limits(lc, lc_maximum, lc_minimum) hc_within_limits and lc_within_limits// ADX values to be printed[adx_sig, di_plus, di_minus] = adx(adx_dilen, adx_adxlen)float di_percentage = naif (di_plus > di_minus) di_percentage := ((di_plus - di_minus) / di_minus) * 100else di_percentage := - ((di_minus - di_plus) / di_plus) * 100// SMILB functionssqzmom(length, mult, lengthKC, multKC, useTrueRange) => // Calculate BB source = close basis = sma(source, length) dev = mult * stdev(source, length) upperBB = basis + dev lowerBB = basis - dev // Calculate KC ma = sma(source, lengthKC) range = useTrueRange ? tr : (high - low) rangema = sma(range, lengthKC) upperKC = ma + rangema * multKC lowerKC = ma - rangema * multKC sqzOn = (lowerBB > lowerKC) and (upperBB < upperKC) sqzOff = (lowerBB < lowerKC) and (upperBB > upperKC) noSqz = (sqzOn == false) and (sqzOff == false) val = linreg(source - avg(avg(highest(high, lengthKC), lowest(low, lengthKC)),sma(close,lengthKC)), lengthKC,0) bcolor = iff( val > 0, iff( val > nz(val[1]), color.lime, color.green), iff( val < nz(val[1]), color.red, color.maroon)) // TODO: Use string variables for colours so that final user can change the actual colour if he wants to. scolor = noSqz ? color.blue : sqzOn ? color.black : color.gray sqzon_percentage = (((upperKC-upperBB)/upperKC)*100)*(0.5) + (((lowerBB-lowerKC)/lowerBB)*100)*(0.5) sqzoff_percentage = (((upperBB-upperKC)/upperBB)*100)*(0.5) + (((lowerKC-lowerBB)/lowerKC)*100)*(0.5) float sqz_percentage = na if sqzOn sqz_percentage := sqzon_percentage else if sqzOff sqz_percentage := - sqzoff_percentage [val, bcolor, scolor, sqz_percentage]// SMILB values to be printed[sqzmom_val, sqzmom_bcolor, sqzmom_scolor, sqz_percentage] = sqzmom(sqzmom_length, sqzmom_mult, sqzmom_lengthKC, sqzmom_multKC, sqzmom_useTrueRange)// EMAS functionsfun_ema(ema10_len, ema10_src, ema55_len, ema55_src) => ema10_out = ema(ema10_src, ema10_len) ema55_out = ema(ema55_src, ema55_len) [ema10_out, ema55_out]// EMAS functionsfun_ema_previous_bar(ema10_len, ema10_src, ema55_len, ema55_src) => // We make sure to use the previous day bar so that it's closed and confirmed float ema10_out = na float ema55_out = na if ( na(ema10_src) or na(ema55_src) or na(ema10_src[1]) or na(ema55_src[1]) ) // Rely on default handling of na with default emas when we start ema10_out := ema(ema10_src, ema10_len) ema55_out := ema(ema55_src, ema55_len) else ema10_out := ema(ema10_src[1], ema10_len) ema55_out := ema(ema55_src[1], ema55_len) [ema10_out, ema55_out]// EMAS values to be printed[ema10, ema55] = fun_ema(ema10_len, ema10_src, ema55_len, ema55_src)[ema10_1d, ema55_1d] = security(syminfo.tickerid, fun_get_higher_timeframe(), fun_ema(ema10_len, ema10_src, ema55_len, ema55_src))bar_index_1d = security(syminfo.tickerid, fun_get_higher_timeframe(), bar_index)// EMAS printingplot(ema10, color=color.blue, title="Media movil azul {10}")plot(ema55, color=marron_color, title="Media movil marrón {55}")// Bounce back to EMA55 - Functionsfun_get_bounce_back_mode_buy_close_advice (close, ema10, ema55, bounce_back_to_EMA55_percent, main_resistance_price) => target_price_delta = (ema55 - ema10) * (bounce_back_to_EMA55_percent/100) target_price = ema10 + target_price_delta // (SS39) // Use VPVR to bounce to // if VPVR is lower than the ema55 target // If VPoC is greater than the close price // then use it if it's also lower than our original // target price if (main_resistance_price > close) and (target_price > main_resistance_price) target_price := main_resistance_price if (close > target_price) true else falsefun_get_bounce_back_mode_sell_close_advice (close, ema10, ema55, bounce_back_to_EMA55_percent, main_resistance_price) => target_price_delta = (ema10 - ema55) * (bounce_back_to_EMA55_percent/100) target_price = ema10 - target_price_delta // (SS39) // Use VPVR to bounce to // if VPVR is lower than the ema55 target // If VPoC is smaller than the close price // then use it if it's also bigger than our original // target price if (main_resistance_price < close) and (target_price < main_resistance_price) target_price := main_resistance_price (close < target_price)// Next to EMA55 - Functionsfun_get_price_next_to_mediamovilmarron_buy_advice (price_to_compare, ema10, ema55, next_to_EMA55_percent) => target_price_delta = (ema10 - ema55) * (next_to_EMA55_percent/100) target_price = ema55 + target_price_delta (price_to_compare < target_price)fun_get_price_next_to_mediamovilmarron_sell_advice (price_to_compare, ema10, ema55, next_to_EMA55_percent) => target_price_delta = (ema55 - ema10) * (next_to_EMA55_percent/100) target_price = ema55 - target_price_delta (price_to_compare > target_price)// Too old orders functionsfun_get_too_old_order_buy_close_advice () => // Condition 1: The order is open // Condition 2: The order is long // Condition 3: Order age is bigger than the maximum setting // Returns boolean bool is_valid_open_buy_order = (strategy.position_size > 0) bool is_too_old = (bar_index >= (buy_order_open_bar_index + too_old_bars_number)) too_old_stop_loss = strategy.position_avg_price * (1 - too_old_minimum_loss_percent) bool is_losing_order = close < too_old_stop_loss too_old_order_buy_close_advice = is_valid_open_buy_order and is_too_old and is_losing_order too_old_order_buy_close_advicefun_get_too_old_order_sell_close_advice () => // Condition 1: The order is open // Condition 2: The order is short // Condition 3: Order age is bigger than the maximum setting // Returns boolean bool is_valid_open_sell_order = (strategy.position_size < 0) bool is_too_old = (bar_index >= (sell_order_open_bar_index + too_old_bars_number)) too_old_stop_loss = strategy.position_avg_price * (1 + too_old_minimum_loss_percent) bool is_losing_order = close > too_old_stop_loss too_old_order_buy_close_advice = is_valid_open_sell_order and is_too_old and is_losing_order too_old_order_buy_close_advice// Too recent orders functionsfun_get_too_recent_order_not_open_advice () => // Condition 1: The order was open // Condition 2: The order was long or short // Condition 3: Time since order was last open is smaller than minimum between orders // Returns boolean bool is_too_recent = ((time_close) <= (last_order_open_bar_time + too_recent_minutes_number_ms)) bool too_recent_order_buy_not_open_advice = na if (na(last_order_open_bar_time)) too_recent_order_buy_not_open_advice := false else too_recent_order_buy_not_open_advice := is_too_recent too_recent_order_buy_not_open_advice// TradingLatino SMILB-and-ADX Long Advice functionsfun_get_tl_smilb_and_adx_long_advice(sqzmom_bcolor, adx_23_value_for_strat, adx_sig, sqz_percentage, adx_23_ignore_advice, smilb_ignore_advice, adx_minimum_steepness_entry, adx_steepness_periods_number, adx_positive_slope_ignore_advice) => // (SS3.ADX): ADX needs a negative slope. // (SS6.ADX): ADX is lesser than 23. // (SS1): Monitor with upwards trend smilb_at_top = ( sqzmom_bcolor == color.lime) or ( sqzmom_bcolor == color.green) smilb_at_bottom = ( sqzmom_bcolor == color.red) or ( sqzmom_bcolor == color.maroon) smilb_is_darker_red = (sqzmom_bcolor == color.maroon) smilb_is_light_red = (sqzmom_bcolor == color.red) smilb_is_darker_green = (sqzmom_bcolor == color.green) smilb_is_light_green = (sqzmom_bcolor == color.lime) smilb_sqz_percentage_greater_than_zero = (abs(sqz_percentage) > 0.5) smilb_sqz_percentage_lesser_than_zero = (abs(sqz_percentage) > 0.5) adx_positive_slope = fun_adx_positive_slope (adx_sig, adx_minimum_steepness_entry, adx_steepness_periods_number) adx_negative_slope = fun_adx_negative_slope (adx_sig, adx_minimum_steepness_entry, adx_steepness_periods_number) adx_greater_than_23 = (adx_sig >= adx_23_value_for_strat) adx_lesser_than_23 = not (adx_greater_than_23) returned_advice = false if (not smilb_ignore_advice) if (not sqzmom_percentage_zero_ignore_advice) if (not enable_plus_mode) if (not adx_23_ignore_advice) if (not adx_positive_slope_ignore_advice) if (smilb_is_darker_red and adx_positive_slope and adx_greater_than_23 and smilb_sqz_percentage_greater_than_zero) or (smilb_is_light_green and adx_positive_slope and adx_greater_than_23 and smilb_sqz_percentage_greater_than_zero) returned_advice := true else if (smilb_is_darker_red and adx_greater_than_23 and smilb_sqz_percentage_greater_than_zero) or (smilb_is_light_green and adx_greater_than_23 and smilb_sqz_percentage_greater_than_zero) returned_advice := true else if (not adx_positive_slope_ignore_advice) if (smilb_is_darker_red and adx_positive_slope and smilb_sqz_percentage_greater_than_zero) or (smilb_is_light_green and adx_positive_slope and smilb_sqz_percentage_greater_than_zero) returned_advice := true else if (smilb_is_darker_red and smilb_sqz_percentage_greater_than_zero) or (smilb_is_light_green and smilb_sqz_percentage_greater_than_zero) returned_advice := true else if (not adx_23_ignore_advice) if (not adx_positive_slope_ignore_advice) if (smilb_is_darker_red and adx_positive_slope and adx_greater_than_23 and smilb_sqz_percentage_greater_than_zero) or (smilb_is_light_green and adx_positive_slope and adx_greater_than_23 and smilb_sqz_percentage_greater_than_zero) returned_advice := true else if (smilb_is_darker_red and adx_greater_than_23 and smilb_sqz_percentage_greater_than_zero) or (smilb_is_light_green and adx_greater_than_23 and smilb_sqz_percentage_greater_than_zero) returned_advice := true else if (not adx_positive_slope_ignore_advice) if (smilb_is_darker_red and adx_positive_slope and smilb_sqz_percentage_greater_than_zero) or (smilb_is_light_green and adx_positive_slope and smilb_sqz_percentage_greater_than_zero) returned_advice := true else if (smilb_is_darker_red and smilb_sqz_percentage_greater_than_zero) or (smilb_is_light_green and smilb_sqz_percentage_greater_than_zero) returned_advice := true else if (not enable_plus_mode) if (not adx_23_ignore_advice) if (not adx_positive_slope_ignore_advice) if (smilb_is_darker_red and adx_positive_slope and adx_greater_than_23) or (smilb_is_light_green and adx_positive_slope and adx_greater_than_23) returned_advice := true else if (smilb_is_darker_red and adx_greater_than_23) or (smilb_is_light_green and adx_greater_than_23) returned_advice := true else if (not adx_positive_slope_ignore_advice) if (smilb_is_darker_red and adx_positive_slope) or (smilb_is_light_green and adx_positive_slope) returned_advice := true else if (smilb_is_darker_red) or (smilb_is_light_green) returned_advice := true else if (not adx_23_ignore_advice) if (not adx_positive_slope_ignore_advice) if (smilb_is_darker_red and adx_positive_slope and adx_greater_than_23) or (smilb_is_light_green and adx_positive_slope and adx_greater_than_23) returned_advice := true else if (smilb_is_darker_red and adx_greater_than_23) or (smilb_is_light_green and adx_greater_than_23) returned_advice := true else if (not adx_positive_slope_ignore_advice) if (smilb_is_darker_red and adx_positive_slope) or (smilb_is_light_green and adx_positive_slope) returned_advice := true else if (smilb_is_darker_red) or (smilb_is_light_green) returned_advice := true else // Return false if SMILB was ignored because we cannot use a lonely ADX to advice a long position returned_advice := false returned_advice// TradingLatino SMILB-and-ADX SHORT Advice functionsfun_get_tl_smilb_and_adx_short_advice(sqzmom_bcolor, adx_23_value_for_strat, adx_sig, sqz_percentage, adx_23_ignore_advice, smilb_ignore_advice, adx_minimum_steepness_entry, adx_steepness_periods_number, adx_positive_slope_ignore_advice) => // (SS3.ADX): ADX needs a negative slope. (Inverse) // (SS6.ADX): ADX is lesser than 23. (Inverse) // (SS1): Monitor with downwards trend smilb_at_top = ( sqzmom_bcolor == color.lime) or ( sqzmom_bcolor == color.green) smilb_at_bottom = ( sqzmom_bcolor == color.red) or ( sqzmom_bcolor == color.maroon) smilb_is_darker_red = (sqzmom_bcolor == color.maroon) smilb_is_light_red = (sqzmom_bcolor == color.red) smilb_is_darker_green = (sqzmom_bcolor == color.green) smilb_is_light_green = (sqzmom_bcolor == color.lime) smilb_sqz_percentage_greater_than_zero = (abs(sqz_percentage) > 0.5) smilb_sqz_percentage_lesser_than_zero = (abs(sqz_percentage) > 0.5) adx_positive_slope = fun_adx_positive_slope (adx_sig, adx_minimum_steepness_entry, adx_steepness_periods_number) adx_negative_slope = fun_adx_negative_slope (adx_sig, adx_minimum_steepness_entry, adx_steepness_periods_number) adx_greater_than_23 = (adx_sig >= adx_23_value_for_strat) adx_lesser_than_23 = not (adx_greater_than_23) returned_advice = false if (not smilb_ignore_advice) if (not sqzmom_percentage_zero_ignore_advice) if (not enable_plus_mode) if (not adx_23_ignore_advice) if (not adx_positive_slope_ignore_advice) if (smilb_is_darker_green and adx_positive_slope and adx_greater_than_23 and smilb_sqz_percentage_lesser_than_zero) or (smilb_is_light_red and adx_positive_slope and adx_greater_than_23 and smilb_sqz_percentage_lesser_than_zero) returned_advice := true else if (smilb_is_darker_green and adx_greater_than_23 and smilb_sqz_percentage_lesser_than_zero) or (smilb_is_light_red and adx_greater_than_23 and smilb_sqz_percentage_lesser_than_zero) returned_advice := true else if (not adx_positive_slope_ignore_advice) if (smilb_is_darker_green and adx_positive_slope and smilb_sqz_percentage_lesser_than_zero) or (smilb_is_light_red and adx_positive_slope and smilb_sqz_percentage_lesser_than_zero) returned_advice := true else if (smilb_is_darker_green and smilb_sqz_percentage_lesser_than_zero) or (smilb_is_light_red and smilb_sqz_percentage_lesser_than_zero) returned_advice := true else if (not adx_23_ignore_advice) if (not adx_positive_slope_ignore_advice) if (smilb_is_darker_green and adx_positive_slope and adx_greater_than_23 and smilb_sqz_percentage_lesser_than_zero) or (smilb_is_light_red and adx_positive_slope and adx_greater_than_23 and smilb_sqz_percentage_lesser_than_zero) returned_advice := true else if (smilb_is_darker_green and adx_greater_than_23 and smilb_sqz_percentage_lesser_than_zero) or (smilb_is_light_red and adx_greater_than_23 and smilb_sqz_percentage_lesser_than_zero) returned_advice := true else if (not adx_positive_slope_ignore_advice) if (smilb_is_darker_green and adx_positive_slope and smilb_sqz_percentage_lesser_than_zero) or (smilb_is_light_red and adx_positive_slope and smilb_sqz_percentage_lesser_than_zero) returned_advice := true else if (smilb_is_darker_green and smilb_sqz_percentage_lesser_than_zero) or (smilb_is_light_red and smilb_sqz_percentage_lesser_than_zero) returned_advice := true else if (not enable_plus_mode) if (not adx_23_ignore_advice) if (not adx_positive_slope_ignore_advice) if (smilb_is_darker_green and adx_positive_slope and adx_greater_than_23) or (smilb_is_light_red and adx_positive_slope and adx_greater_than_23) returned_advice := true else if (smilb_is_darker_green and adx_greater_than_23) or (smilb_is_light_red and adx_greater_than_23) returned_advice := true else if (not adx_positive_slope_ignore_advice) if (smilb_is_darker_green and adx_positive_slope) or (smilb_is_light_red and adx_positive_slope) returned_advice := true else if (smilb_is_darker_green) or (smilb_is_light_red) returned_advice := true else if (not adx_23_ignore_advice) if (not adx_positive_slope_ignore_advice) if (smilb_is_darker_green and adx_positive_slope and adx_greater_than_23) or (smilb_is_light_red and adx_positive_slope and adx_greater_than_23) returned_advice := true else if (smilb_is_darker_green and adx_greater_than_23) or (smilb_is_light_red and adx_greater_than_23) returned_advice := true else if (not adx_positive_slope_ignore_advice) if (smilb_is_darker_green and adx_positive_slope) or (smilb_is_light_red and adx_positive_slope) returned_advice := true else if (smilb_is_darker_green) or (smilb_is_light_red) returned_advice := true else // Return false if SMILB was ignored because we cannot use a lonely ADX to advice a long position returned_advice := false returned_advice// TradingLatino EMAS Long Advice functionsfun_get_tl_emas_long_advice(ema10_1d, ema10, ema55_1d, ema55) => (ema10_1d > ema55_1d)// TradingLatino EMAS SHORT Advice functionsfun_get_tl_emas_short_advice(ema10_1d, ema10, ema55_1d, ema55) => (ema10_1d < ema55_1d)fun_all_values_equal_to (pseries, number_of_bars, bool_value) => bool are_equal = true for bar = 0 to number_of_bars if (not(pseries[bar] == bool_value)) are_equal := false break are_equal// TradingLatino ADX SHORT advice - Inputs// TODOvar bool tradinglatino_strategy_emas_long_advice = navar bool tradinglatino_strategy_emas_short_advice = na// // TradingLatino EMAS Long advicenew_tradinglatino_strategy_emas_long_advice = fun_get_tl_emas_long_advice(ema10_1d, ema10, ema55_1d, ema55)// // // TradingLatino EMAS SHORT advicenew_tradinglatino_strategy_emas_short_advice = fun_get_tl_emas_short_advice(ema10_1d, ema10, ema55_1d, ema55)// // // (SS12)// // 2 days in a row = 12 bars of 4h .// // We use var to instance them only once because these values are always constant// fun_ema_last_two_days_equal_to(ema10_len, ema10_src, ema55_len, ema55_src, bool_value) => // We make sure to use the previous day bar so that it's closed and confirmed ema10_out_1 = ema(ema10_src[1], ema10_len) ema55_out_1 = ema(ema55_src[1], ema55_len) ema10_out_2 = ema(ema10_src[2], ema10_len) ema55_out_2 = ema(ema55_src[2], ema55_len) bool are_equal = na if (bool_value) are_equal := (ema10_out_1 > ema55_out_1) and (ema10_out_2 > ema55_out_2) else are_equal := (ema10_out_1 < ema55_out_1) and (ema10_out_2 < ema55_out_2) are_equalvar higher_timeframe_confirmation_bars = 2var bars_in_higher_timeframe = int(floor(get_resolution_bar_minutes(fun_get_higher_timeframe()) / currentResInMinutes)) // 1 day = 6 bars of 4hvar higher_timeframe_oldest_bar_for_confirmation = (bars_in_higher_timeframe * higher_timeframe_confirmation_bars) - 1 // 6 -> 12 -> 11long_advice_found = security(syminfo.tickerid, fun_get_higher_timeframe(), fun_ema_last_two_days_equal_to(ema10_len, ema10_src, ema55_len, ema55_src, true))short_advice_found = security(syminfo.tickerid, fun_get_higher_timeframe(), fun_ema_last_two_days_equal_to(ema10_len, ema10_src, ema55_len, ema55_src, false))if ( na(tradinglatino_strategy_emas_long_advice[higher_timeframe_oldest_bar_for_confirmation]) or na(tradinglatino_strategy_emas_short_advice[higher_timeframe_oldest_bar_for_confirmation]) ) tradinglatino_strategy_emas_long_advice := new_tradinglatino_strategy_emas_long_advice tradinglatino_strategy_emas_short_advice := new_tradinglatino_strategy_emas_short_adviceelse if (long_advice_found and (bar_index_1d[1] != bar_index_1d[0])) tradinglatino_strategy_emas_long_advice := true tradinglatino_strategy_emas_short_advice := falseelse if (short_advice_found and (bar_index_1d[1] != bar_index_1d[0])) tradinglatino_strategy_emas_short_advice := true tradinglatino_strategy_emas_long_advice := false// Take into account DI - TODO: Make it optional// tradinglatino_strategy_emas_long_advice := tradinglatino_strategy_emas_long_advice and ((di_plus > di_minus) and (di_percentage > di_minimum_percentage))// tradinglatino_strategy_emas_short_advice := tradinglatino_strategy_emas_short_advice and ((di_plus <= di_minus) and (di_percentage < (- di_minimum_percentage)))// if ((sqzmom_bcolor == color.maroon) or (sqzmom_bcolor == color.lime)) and (di_plus > di_minus) and (di_percentage > di_minimum_percentage)// tradinglatino_strategy_emas_long_advice := true// tradinglatino_strategy_emas_short_advice := false// else if ((sqzmom_bcolor == color.red) or (sqzmom_bcolor == color.green)) and (di_plus <= di_minus) and (di_percentage < (- di_minimum_percentage) )// tradinglatino_strategy_emas_long_advice := false// tradinglatino_strategy_emas_short_advice := true// else// tradinglatino_strategy_emas_long_advice := false// tradinglatino_strategy_emas_short_advice := false// TradingLatino SMILB-and-ADX Long advicetradinglatino_strategy_smilb_and_adx_long_advice = fun_get_tl_smilb_and_adx_long_advice(sqzmom_bcolor, adx_23_value_for_strat, adx_sig, sqz_percentage, adx_23_ignore_advice, smilb_ignore_advice, adx_minimum_steepness_entry, adx_steepness_periods_number, adx_positive_slope_ignore_advice)// TradingLatino SMILB-and-ADX SHORT advicetradinglatino_strategy_smilb_and_adx_short_advice = fun_get_tl_smilb_and_adx_short_advice(sqzmom_bcolor, adx_23_value_for_strat, adx_sig, sqz_percentage, adx_23_ignore_advice, smilb_ignore_advice, adx_minimum_steepness_entry, adx_steepness_periods_number, adx_positive_slope_ignore_advice)// Price is in rangeprice_is_in_range = fun_price_is_in_range(hc, lc, pricerange_maximum_desviation_percent, pricerange_minimum_desviation_percent, pricerange_periods_number)// if (price_is_in_range and (not (price_is_in_range[1])))// label.new(bar_index, high, text="Range Detected", style=label.style_label_lower_right, color=color.purple, textcolor=color.white)// // if ((not price_is_in_range) and (price_is_in_range[1]))// label.new(bar_index, high, text="Range not detected", style=label.style_label_lower_left, color=color.navy, textcolor=color.white)range_string_loop_by_char(global_char_number, reset) => range_string_length = 6 // 'RANGE-' char_number = global_char_number if reset char_number := 1 else char_number := char_number + 1 if (char_number == (range_string_length + 1)) char_number := 1 return_char = (char_number == 1) ? 'R' : (char_number == 2) ? 'A' : (char_number == 3) ? 'N' : (char_number == 4) ? 'G' : (char_number == 5) ? 'E' : (char_number == 6) ? '-' : 'Notreturned' return_charrange_string_loop_by_number(global_char_number, reset) => range_string_length = 6 // 'RANGE-' char_number = global_char_number if reset char_number := 1 else char_number := char_number + 1 if (char_number == (range_string_length + 1)) char_number := 1 return_char = (char_number == 1) ? 'R' : (char_number == 2) ? 'A' : (char_number == 3) ? 'N' : (char_number == 4) ? 'G' : (char_number == 5) ? 'E' : (char_number == 6) ? '-' : 'Notreturned' char_number// Loop range string by char preparation - BEGINvar range_char = 'S'var range_char_number = 1if (price_is_in_range) if (not (price_is_in_range[1])) // RFE to TradingView: Please let me assign ( := ) a function array result to two variables // as you already can with ( = ). range_char := range_string_loop_by_char(range_char_number,true) range_char_number := range_string_loop_by_number(range_char_number,true) else range_char := range_string_loop_by_char(range_char_number,false) range_char_number := range_string_loop_by_number(range_char_number,false)price_is_in_range_R = ( price_is_in_range and (range_char=="R") ) and price_is_in_range_printprice_is_in_range_A = ( price_is_in_range and (range_char=="A") ) and price_is_in_range_printprice_is_in_range_N = ( price_is_in_range and (range_char=="N") ) and price_is_in_range_printprice_is_in_range_G = ( price_is_in_range and (range_char=="G") ) and price_is_in_range_printprice_is_in_range_E = ( price_is_in_range and (range_char=="E") ) and price_is_in_range_printprice_is_in_range__ = ( price_is_in_range and (range_char=="-") ) and price_is_in_range_print// Loop range string by char preparation - END// Show Range - BEGINplotshape(series=price_is_in_range_R, title="RangeTitleR", style=shape.square, color=pricerange_background_colour, transp=50, text="R", textcolor=pricerange_text_colour, editable=false, location=location.bottom)plotshape(series=price_is_in_range_A, title="RangeTitleA", style=shape.square, color=pricerange_background_colour, transp=50, text="A", textcolor=pricerange_text_colour, editable=false, location=location.bottom)plotshape(series=price_is_in_range_N, title="RangeTitleN", style=shape.square, color=pricerange_background_colour, transp=50, text="N", textcolor=pricerange_text_colour, editable=false, location=location.bottom)plotshape(series=price_is_in_range_G, title="RangeTitleG", style=shape.square, color=pricerange_background_colour, transp=50, text="G", textcolor=pricerange_text_colour, editable=false, location=location.bottom)plotshape(series=price_is_in_range_E, title="RangeTitleE", style=shape.square, color=pricerange_background_colour, transp=50, text="E", textcolor=pricerange_text_colour, editable=false, location=location.bottom)plotshape(series=price_is_in_range__, title="RangeTitle_", style=shape.square, color=pricerange_background_colour, transp=50, text="-", textcolor=pricerange_text_colour, editable=false, location=location.bottom)// Show Range - END// Print Divergences - BEGIN// Order of sections: GREEN-A, RED-A, GREEN-B, RED-B and then again GREEN-A,...smilb_is_darker_red = (sqzmom_bcolor == color.maroon)smilb_is_light_red = (sqzmom_bcolor == color.red)smilb_is_darker_green = (sqzmom_bcolor == color.green)smilb_is_light_green = (sqzmom_bcolor == color.lime)smilb_is_green = smilb_is_darker_green or smilb_is_light_greensmilb_is_red = smilb_is_darker_red or smilb_is_light_redvar bool green_smilb_section_a = navar bool green_smilb_section_b = navar bool red_smilb_section_a = navar bool red_smilb_section_b = navar float maximum_green = navar float green_maximum_price_section_a = navar float green_maximum_price_section_b = navar float green_maximum_smilb_section_a = navar float green_maximum_smilb_section_b = navar int green_maximum_section_index_a = navar int green_maximum_section_index_b = nabool new_green_divergence_a = falsebool new_green_divergence_b = falsevar line green_divergence_line_a = navar line green_divergence_line_b = navar label green_divergence_label_a = navar label green_divergence_label_b = nafloat dibujar_divergencia = 0// Let's start with section aif barstate.isfirst if smilb_is_red red_smilb_section_a := true else green_smilb_section_a := true[tmp_green_smilb_section_b, tmp_red_smilb_section_b, tmp_green_smilb_section_a, tmp_red_smilb_section_a] = fun_set_current_section (red_smilb_section_a, green_smilb_section_b, red_smilb_section_b, green_smilb_section_a, smilb_is_green, smilb_is_red)green_smilb_section_b := tmp_green_smilb_section_bred_smilb_section_b := tmp_red_smilb_section_bgreen_smilb_section_a := tmp_green_smilb_section_ared_smilb_section_a := tmp_red_smilb_section_a// Reset green_maximum_smilb_section_a when entering a new green_section_aif green_smilb_section_a and smilb_is_red[1] and (not na(smilb_is_red[1])) green_maximum_smilb_section_a := na green_maximum_price_section_a := na// Reset green_maximum_smilb_section_b when entering a new green_section_bif green_smilb_section_b and smilb_is_red[1] and (not na(smilb_is_red[1])) green_maximum_smilb_section_b := na green_maximum_price_section_b := na// Assuming we are in 'green section a' let's obtain biggest top[tmpa_green_maximum_price_section, tmpa_green_maximum_smilb_section, tmpa_green_maximum_section_index, tmpa_new_green_divergence] = fun_section_biggest_top(green_smilb_section_a, smilb_is_darker_green, smilb_is_light_green, green_maximum_smilb_section_a, green_maximum_price_section_a, green_maximum_section_index_a, new_green_divergence_a, sqzmom_val)green_maximum_price_section_a := tmpa_green_maximum_price_sectiongreen_maximum_smilb_section_a := tmpa_green_maximum_smilb_sectiongreen_maximum_section_index_a := tmpa_green_maximum_section_indexnew_green_divergence_a := tmpa_new_green_divergence// Assuming we are in 'green section b' let's obtain biggest top[tmpb_green_maximum_price_section, tmpb_green_maximum_smilb_section, tmpb_green_maximum_section_index, tmpb_new_green_divergence] = fun_section_biggest_top(green_smilb_section_b, smilb_is_darker_green, smilb_is_light_green, green_maximum_smilb_section_b, green_maximum_price_section_b, green_maximum_section_index_b, new_green_divergence_b, sqzmom_val)green_maximum_price_section_b := tmpb_green_maximum_price_sectiongreen_maximum_smilb_section_b := tmpb_green_maximum_smilb_sectiongreen_maximum_section_index_b := tmpb_green_maximum_section_indexnew_green_divergence_b := tmpb_new_green_divergence// Plot divergence on 'green section a'if green_smilb_section_a and new_green_divergence_a and not (na(green_maximum_smilb_section_b)) line.delete(green_divergence_line_a) if enable_show_desviation_lines green_divergence_line_a := line.new(green_maximum_section_index_b, green_maximum_price_section_b, green_maximum_section_index_a, green_maximum_price_section_a, width=2, xloc = xloc.bar_index, color=DIVERGENCE_COLOUR_A, style=line.style_dotted) // Possible line for bottom chart // green_divergence_line_a := line.new(green_maximum_section_index_b, green_maximum_smilb_section_b, green_maximum_section_index_a, green_maximum_smilb_section_a, width=2, xloc = xloc.bar_index, color=DIVERGENCE_COLOUR_A, style=line.style_dotted) green_divergence_label_a_text = fun_meta_divergence_symbol (green_maximum_section_index_b,green_maximum_smilb_section_b,green_maximum_section_index_a,green_maximum_smilb_section_a, green_maximum_price_section_b, green_maximum_price_section_a) label.delete(green_divergence_label_a) if enable_show_desviation_labels green_divergence_label_a := label.new(x=green_maximum_section_index_a, y=green_maximum_price_section_a, text=green_divergence_label_a_text, xloc=xloc.bar_index, yloc=yloc.price)// Plot divergence on 'green section b'if green_smilb_section_b and new_green_divergence_b and not (na(green_maximum_smilb_section_a)) line.delete(green_divergence_line_b) if enable_show_desviation_lines green_divergence_line_b := line.new(green_maximum_section_index_a, green_maximum_price_section_a, green_maximum_section_index_b, green_maximum_price_section_b, width=2, xloc = xloc.bar_index, color=DIVERGENCE_COLOUR_B, style=line.style_dotted) // Possible line for bottom chart // green_divergence_line_b := line.new(green_maximum_section_index_a, green_maximum_smilb_section_a, green_maximum_section_index_b, green_maximum_smilb_section_b, width=2, xloc = xloc.bar_index, color=DIVERGENCE_COLOUR_B, style=line.style_dotted) green_divergence_label_b_text = fun_meta_divergence_symbol (green_maximum_section_index_a,green_maximum_smilb_section_a,green_maximum_section_index_b,green_maximum_smilb_section_b, green_maximum_price_section_a, green_maximum_price_section_b) label.delete(green_divergence_label_b) if enable_show_desviation_labels green_divergence_label_b := label.new(x=green_maximum_section_index_b, y=green_maximum_price_section_b, text=green_divergence_label_b_text, xloc=xloc.bar_index, yloc=yloc.price)// Print Divergences - END// Zignalye - Functions - BEGINget_zignaly_long_alert_message(entry_quantity_contracts_usdt, current_capital) => var string zignale_stop_loss_combo = "" var string zignale_take_profit_combo = "" var string zignale_trailing_take_profit_combo = "" zignaly_long_common_alert_message = zignaly_quote + "type" + zignaly_quote + zignaly_equals + zignaly_quote + "entry" + zignaly_quote + zignaly_separator + zignaly_quote + "side" + zignaly_quote + zignaly_equals + zignaly_quote + "long" + zignaly_quote + zignaly_separator + zignaly_quote + "orderType" + zignaly_quote + zignaly_equals + zignaly_quote + "market" + zignaly_quote + zignaly_separator + zignaly_quote + "signalId" + zignaly_quote + zignaly_equals + zignaly_quote + "LONG-" + exchange_tickerid + zignaly_quote float float_entry_quantity_contracts_usdt = entry_quantity_contracts_usdt float float_current_capital = current_capital float entry_quantity_contracts_percent = (float_entry_quantity_contracts_usdt / float_current_capital) * 100.00 entry_quantity_contracts_percent_str = tostring(entry_quantity_contracts_percent, "0." + vp_get_resistances_price_decimal_digits_zero_string()) // This is actually not needed because with pyramiding=0 it's impossible that an order is scaled (and thus modified) float constant_buy_SL = na if (old_inside_a_buy_order and inside_a_buy_order) constant_buy_SL := buy_SL else constant_buy_SL := new_buy_SL if sl zignale_stop_loss_combo := zignaly_separator + zignaly_quote + "stopLossPercentage" + zignaly_quote + zignaly_equals + zignaly_quote + "-" + tostring((nz(constant_buy_SL) * 100), "0." + vp_get_resistances_price_decimal_digits_zero_string()) + zignaly_quote else zignale_stop_loss_combo := "" if tp zignale_take_profit_combo := zignaly_separator + zignaly_quote + "takeProfitPercentage1" + zignaly_quote + zignaly_equals + zignaly_quote + "" + tostring((TP * 100), "0." + vp_get_resistances_price_decimal_digits_zero_string()) + zignaly_quote else zignale_take_profit_combo := "" if enable_trailing_take_profit_percentage zignale_trailing_take_profit_combo := zignaly_separator + zignaly_quote + "trailingStopDistancePercentage" + zignaly_quote + zignaly_equals + zignaly_quote + "-" + tostring((constant_trailing_take_profit_percentage * 100), "0." + vp_get_resistances_price_decimal_digits_zero_string()) + zignaly_quote + zignaly_separator + zignaly_quote + "trailingStopTriggerPercentage" + zignaly_quote + zignaly_equals + zignaly_quote + "" + tostring((constant_trailing_take_profit_percentage_trigger * 100), "0." + vp_get_resistances_price_decimal_digits_zero_string()) + zignaly_quote else zignale_trailing_take_profit_combo := "" var string message = "" message := zignaly_common_alert_message + zignaly_separator + zignaly_long_common_alert_message + zignaly_separator + zignaly_quote + "positionSizePercentage" + zignaly_quote + zignaly_equals + zignaly_quote + "" + entry_quantity_contracts_percent_str + zignaly_quote + zignale_stop_loss_combo + zignale_take_profit_combo + zignale_trailing_take_profit_combo messageget_zignaly_long_close_alert_message() => zignaly_long_close_common_alert_message = zignaly_quote + "type" + zignaly_quote + zignaly_equals + zignaly_quote + "exit" + zignaly_quote + zignaly_separator + zignaly_quote + "side" + zignaly_quote + zignaly_equals + zignaly_quote + "long" + zignaly_quote + zignaly_separator + zignaly_quote + "orderType" + zignaly_quote + zignaly_equals + zignaly_quote + "market" + zignaly_quote + zignaly_separator + zignaly_quote + "signalId" + zignaly_quote + zignaly_equals + zignaly_quote + "LONG-" + exchange_tickerid + zignaly_quote var string message = "" message := zignaly_common_alert_message + zignaly_separator + zignaly_long_close_common_alert_message messageget_zignaly_short_alert_message(entry_quantity_contracts_usdt, current_capital) => var string zignale_stop_loss_combo = "" var string zignale_take_profit_combo = "" var string zignale_trailing_take_profit_combo = "" zignaly_short_common_alert_message = zignaly_quote + "type" + zignaly_quote + zignaly_equals + zignaly_quote + "entry" + zignaly_quote + zignaly_separator + zignaly_quote + "side" + zignaly_quote + zignaly_equals + zignaly_quote + "short" + zignaly_quote + zignaly_separator + zignaly_quote + "orderType" + zignaly_quote + zignaly_equals + zignaly_quote + "market" + zignaly_quote + zignaly_separator + zignaly_quote + "signalId" + zignaly_quote + zignaly_equals + zignaly_quote + "SHORT-" + exchange_tickerid + zignaly_quote float float_entry_quantity_contracts_usdt = entry_quantity_contracts_usdt float float_current_capital = current_capital float entry_quantity_contracts_percent = (float_entry_quantity_contracts_usdt / float_current_capital) * 100.00 entry_quantity_contracts_percent_str = tostring(entry_quantity_contracts_percent, "0." + vp_get_resistances_price_decimal_digits_zero_string()) // This is actually not needed because with pyramiding=0 it's impossible that an order is scaled (and thus modified) float constant_sell_SL = na if (old_inside_a_sell_order and inside_a_sell_order) constant_sell_SL := sell_SL else constant_sell_SL := new_sell_SL if sl zignale_stop_loss_combo := zignaly_separator + zignaly_quote + "stopLossPercentage" + zignaly_quote + zignaly_equals + zignaly_quote + "" + tostring((nz(constant_sell_SL) * 100), "0." + vp_get_resistances_price_decimal_digits_zero_string()) + zignaly_quote else zignale_stop_loss_combo := "" if tp zignale_take_profit_combo := zignaly_separator + zignaly_quote + "takeProfitPercentage1" + zignaly_quote + zignaly_equals + zignaly_quote + "-" + tostring((TP * 100), "0." + vp_get_resistances_price_decimal_digits_zero_string()) + zignaly_quote else zignale_take_profit_combo := "" if enable_trailing_take_profit_percentage zignale_trailing_take_profit_combo := zignaly_separator + zignaly_quote + "trailingStopDistancePercentage" + zignaly_quote + zignaly_equals + zignaly_quote + "" + tostring((constant_trailing_take_profit_percentage * 100), "0." + vp_get_resistances_price_decimal_digits_zero_string()) + zignaly_quote + zignaly_separator + zignaly_quote + "trailingStopTriggerPercentage" + zignaly_quote + zignaly_equals + zignaly_quote + "-" + tostring((constant_trailing_take_profit_percentage_trigger * 100), "0." + vp_get_resistances_price_decimal_digits_zero_string()) + zignaly_quote else zignale_trailing_take_profit_combo := "" var string message = "" message := zignaly_common_alert_message + zignaly_separator + zignaly_short_common_alert_message + zignaly_separator + zignaly_quote + "positionSizePercentage" + zignaly_quote + zignaly_equals + zignaly_quote + "" + entry_quantity_contracts_percent_str + zignaly_quote + zignale_stop_loss_combo + zignale_take_profit_combo + zignale_trailing_take_profit_combo messageget_zignaly_short_close_alert_message() => zignaly_short_close_common_alert_message = zignaly_quote + "type" + zignaly_quote + zignaly_equals + zignaly_quote + "exit" + zignaly_quote + zignaly_separator + zignaly_quote + "side" + zignaly_quote + zignaly_equals + zignaly_quote + "short" + zignaly_quote + zignaly_separator + zignaly_quote + "orderType" + zignaly_quote + zignaly_equals + zignaly_quote + "market" + zignaly_quote + zignaly_separator + zignaly_quote + "signalId" + zignaly_quote + zignaly_equals + zignaly_quote + "SHORT-" + exchange_tickerid + zignaly_quote var string message = "" message := zignaly_common_alert_message + zignaly_separator + zignaly_short_close_common_alert_message message// Zignalye - Functions - END// Order comment - Functions - BEGINget_order_comment(typeOrder, side, alert_message) => // TODO: Add descriptive comments // typeOrder="entry" or typeOrder="close" // side: true means long ; false means short ; We can use strategy.long or strategy.short as true and false aliases // alert_message var string l_order_comment = "" if (enable_order_comment_debug) l_order_comment := alert_message else // TODO: Use human explanations instead of default order comment value (na) l_order_comment := na l_order_comment // Order comment - Functions - END// Volume Profile variablesfloat vp_recent_high = nafloat vp_recent_low = nafloat vp_recent_highest_lvl_value = nafloat vp_highest_recent_lvl_value = nafloat vp_vpvr_highest_recent_lvl_value = nafloat vp_recent_lvl_value_tmp = nafloat vp_vpvr_recent_highest_lvl_value = na// float vp_vpvr_recent_high = na// float vp_vpvr_recent_low = nafloat vp_vpvr_recent_high_top = nafloat vp_vpvr_recent_low_top = nafloat vp_vpvr_recent_high_bottom = nafloat vp_vpvr_recent_low_bottom = na// Recent VPoC - Valuevp_recent_high := highest(high, vp_recent_n_bars)vp_recent_low := lowest(low, vp_recent_n_bars)vp_recent_lvl_height = (vp_recent_high - vp_recent_low) / VP_PRICE_LEVELSfor vp_level_number = 0 to (VP_PRICE_LEVELS - 1) vp_recent_lvl_value_tmp := vp_level_value_wrapper(vp_recent_lvl_height, vp_recent_low, vp_level_number, 0, vp_recent_n_bars) vp_recent_highest_lvl_value := max(nz(vp_recent_highest_lvl_value), vp_recent_lvl_value_tmp) if nz(vp_highest_recent_lvl_value) < vp_recent_highest_lvl_value vp_highest_recent_lvl_value := vp_recent_highest_lvl_value vp_vpoc_price_level_number := vp_level_number// Recent VPoC - Pricevp_recent_vpoc_price = (vp_level_price_wrapper(vp_recent_lvl_height, vp_recent_low, vp_vpoc_price_level_number, vp_recent_n_bars))// VPVR VPoC - Value// vp_vpvr_recent_high := highest(high, vp_vpvr_vpoc_n_bars)// vp_vpvr_recent_low := lowest(low, vp_vpvr_vpoc_n_bars)vp_vpvr_recent_high_top := highest(high, vp_vpvr_vpoc_n_bars)vp_vpvr_recent_low_top := closevp_vpvr_recent_high_bottom := closevp_vpvr_recent_low_bottom := lowest(low, vp_vpvr_vpoc_n_bars)// vp_vpvr_recent_lvl_height = (vp_vpvr_recent_high - vp_vpvr_recent_low) / VP_PRICE_LEVELSvp_vpvr_recent_lvl_height_top = (vp_vpvr_recent_high_top - vp_vpvr_recent_low_top) / VP_PRICE_LEVELSvp_vpvr_recent_lvl_height_bottom = (vp_vpvr_recent_high_top - vp_vpvr_recent_low_top) / VP_PRICE_LEVELS// for vp_level_number = 0 to (VP_PRICE_LEVELS - 1)// vp_recent_lvl_value_tmp := vp_level_value_wrapper(vp_vpvr_recent_lvl_height, vp_vpvr_recent_low, vp_level_number, 0, vp_vpvr_vpoc_n_bars)// vp_vpvr_recent_highest_lvl_value := max(nz(vp_vpvr_recent_highest_lvl_value), vp_recent_lvl_value_tmp)// if nz(vp_vpvr_highest_recent_lvl_value) < vp_vpvr_recent_highest_lvl_value// vp_vpvr_highest_recent_lvl_value := vp_vpvr_recent_highest_lvl_value// vp_vpvr_vpoc_price_level_number := vp_level_numbervp_vpvr_highest_recent_lvl_value := navp_vpvr_recent_highest_lvl_value := navp_vpvr_vpoc_price_level_number_top := nafor vp_level_number = 0 to (VP_PRICE_LEVELS - 1) vp_recent_lvl_value_tmp := vp_level_value_wrapper(vp_vpvr_recent_lvl_height_top, vp_vpvr_recent_low_top, vp_level_number, 0, vp_vpvr_vpoc_n_bars) vp_vpvr_recent_highest_lvl_value := max(nz(vp_vpvr_recent_highest_lvl_value), vp_recent_lvl_value_tmp) if nz(vp_vpvr_highest_recent_lvl_value) < vp_vpvr_recent_highest_lvl_value vp_vpvr_highest_recent_lvl_value := vp_vpvr_recent_highest_lvl_value vp_vpvr_vpoc_price_level_number_top := vp_level_numbervp_vpvr_highest_recent_lvl_value := navp_vpvr_recent_highest_lvl_value := navp_vpvr_vpoc_price_level_number_bottom := nafor vp_level_number = 0 to (VP_PRICE_LEVELS - 1) vp_recent_lvl_value_tmp := vp_level_value_wrapper(vp_vpvr_recent_lvl_height_bottom, vp_vpvr_recent_low_bottom, vp_level_number, 0, vp_vpvr_vpoc_n_bars) vp_vpvr_recent_highest_lvl_value := max(nz(vp_vpvr_recent_highest_lvl_value), vp_recent_lvl_value_tmp) if nz(vp_vpvr_highest_recent_lvl_value) < vp_vpvr_recent_highest_lvl_value vp_vpvr_highest_recent_lvl_value := vp_vpvr_recent_highest_lvl_value vp_vpvr_vpoc_price_level_number_bottom := vp_level_number// VPVR VPoC - Pricevp_recent_vpvr_vpoc_price_top = (vp_level_price_wrapper(vp_vpvr_recent_lvl_height_top, vp_vpvr_recent_low_top, vp_vpvr_vpoc_price_level_number_top, vp_vpvr_vpoc_n_bars))vp_recent_vpvr_vpoc_price_bottom = (vp_level_price_wrapper(vp_vpvr_recent_lvl_height_bottom, vp_vpvr_recent_low_bottom, vp_vpvr_vpoc_price_level_number_bottom, vp_vpvr_vpoc_n_bars))// vp_bottom_vpoc = lowest(vp_recent_vpoc_price, vp_bottom_vpoc_n_bars)// vp_top_vpoc = highest(vp_recent_vpoc_price, vp_bottom_vpoc_n_bars)fun_highest_lower_than(pvp_recent_vpoc_price, pclose, pvp_bottom_vpoc_n_bars) => float highest_lower_than = 0.0 for nbar = 0 to pvp_bottom_vpoc_n_bars if (pvp_recent_vpoc_price[nbar] < pclose) and (pvp_recent_vpoc_price[nbar] > highest_lower_than) highest_lower_than := pvp_recent_vpoc_price[nbar] // Workaround for limit scenarios if (highest_lower_than == 0.0) highest_lower_than := pclose highest_lower_than fun_lowest_higher_than(pvp_recent_vpoc_price, pclose, pvp_bottom_vpoc_n_bars) => bool lowest_higher_than_was_found = false float lowest_higher_than = highest (pvp_recent_vpoc_price, pvp_bottom_vpoc_n_bars) for nbar = 0 to pvp_bottom_vpoc_n_bars if (pvp_recent_vpoc_price[nbar] > pclose) and (pvp_recent_vpoc_price[nbar] < lowest_higher_than) lowest_higher_than_was_found := true lowest_higher_than := pvp_recent_vpoc_price[nbar] // Workaround for limit scenarios if (not lowest_higher_than_was_found) lowest_higher_than := pclose lowest_higher_thanvp_bottom_vpoc = fun_highest_lower_than(vp_recent_vpoc_price, low, vp_bottom_vpoc_n_bars)vp_top_vpoc = fun_lowest_higher_than(vp_recent_vpoc_price, high, vp_bottom_vpoc_n_bars)float main_resistance_price = namain_resistance_price := vp_recent_vpvr_vpoc_price_top// if (tradinglatino_strategy_emas_long_advice)// main_resistance_price := vp_recent_vpvr_vpoc_price_bottom// else// main_resistance_price := vp_recent_vpvr_vpoc_price_topif (tradinglatino_strategy_emas_long_advice) main_resistance_price := vp_bottom_vpocelse main_resistance_price := vp_top_vpoc// Main resistance - Printfloat main_resistance_price_print = nafloat vp_top_vpoc_print = nafloat vp_bottom_vpoc_print = naif vp_enable_print_vpvr_vpoc_price main_resistance_price_print := main_resistance_price vp_top_vpoc_print := vp_top_vpoc vp_bottom_vpoc_print := vp_bottom_vpocelse main_resistance_price_print := na vp_top_vpoc_print := na vp_bottom_vpoc_print := na // plot(main_resistance_price_print, color=color.yellow, title="Main resistance")// plot(vp_recent_vpvr_vpoc_price_top, color=color.yellow, style=plot.style_stepline, title="Main resistance TOP")// plot(vp_recent_vpvr_vpoc_price_bottom, color=color.yellow, style=plot.style_stepline, title="Main resistance BOTTOM")plot(vp_top_vpoc_print, color=color.yellow, style=plot.style_stepline, title="Main resistance TOP")plot(vp_bottom_vpoc_print, color=color.yellow, style=plot.style_stepline, title="Main resistance BOTTOM")// plot(vp_recent_vpoc_price, color=color.lime, style=plot.style_stepline, title="Daily VPoC")// Dynamic stop loss handling// SL: This is the original stop loss with a default value of: 0.07var bool stop_loss_not_worth_open_sell = navar bool stop_loss_not_worth_open_buy = na// Calculations on the bar which enters the order need to use close because position_avg_price is not yet defined.float position_price = naif (inside_a_sell_order or inside_a_buy_order) position_price := strategy.position_avg_priceelse position_price := close// Let's calculate new_buy_SL and new_sell_SL but do not use them yet.if enable_dynamic_stop_loss if (position_price > main_resistance_price) float buy_stop_loss_target = position_price * (1 - SL) if (buy_stop_loss_target > main_resistance_price) if enable_strict_mode new_buy_SL := na stop_loss_not_worth_open_buy := true else new_buy_SL := SL // Just use original stop loss stop_loss_not_worth_open_buy := false else if ( ( position_price / main_resistance_price ) >= (1 + dynamic_minimum_stop_loss) ) if enable_strict_mode new_buy_SL := 1 - (main_resistance_price / position_price) if new_buy_SL >= dynamic_maximum_stop_loss // Bigger than 2% we don't trade new_buy_SL := na stop_loss_not_worth_open_buy := true else stop_loss_not_worth_open_buy := false else new_buy_SL := 1 - (main_resistance_price / position_price) stop_loss_not_worth_open_buy := false else new_buy_SL := dynamic_minimum_stop_loss // Ensure a minimum stop loss is used stop_loss_not_worth_open_buy := false new_sell_SL := na stop_loss_not_worth_open_sell := true // stop_loss_not_worth_open_buy := false else if (position_price < main_resistance_price) float sell_stop_loss_target = position_price * (1 + SL) if (sell_stop_loss_target < main_resistance_price) if enable_strict_mode new_sell_SL := na stop_loss_not_worth_open_sell := true else new_sell_SL := SL // Just use original stop loss stop_loss_not_worth_open_sell := false else if ( ( main_resistance_price / position_price ) >= (1 + dynamic_minimum_stop_loss) ) if enable_strict_mode new_sell_SL := (main_resistance_price / position_price) - 1 if new_sell_SL >= dynamic_maximum_stop_loss // Bigger than 2% we don't trade new_sell_SL := na stop_loss_not_worth_open_sell := true else stop_loss_not_worth_open_sell := false else new_sell_SL := (main_resistance_price / position_price) - 1 stop_loss_not_worth_open_sell := false else new_sell_SL := dynamic_minimum_stop_loss // Ensure a minimum stop loss is used stop_loss_not_worth_open_sell := false new_buy_SL := na stop_loss_not_worth_open_buy := true // stop_loss_not_worth_open_sell := false else // Both buy and sell are too close to the VPoC. We refuse to buy or sell. stop_loss_not_worth_open_buy := true stop_loss_not_worth_open_sell := true new_buy_SL := na new_sell_SL := naelse stop_loss_not_worth_open_buy := false stop_loss_not_worth_open_sell := false new_buy_SL := SL new_sell_SL := SL// Dynamic Trailing Take Profitfloat new_trailing_take_profit_percentage_trigger = nafloat new_trailing_take_profit_percentage = naath = highest (high, 5)drawdown = 100 - ( low / ath ) * 100maxdrawdown = highest (drawdown, 5)sell_dynamic_trailing_take_profit_trigger_tmp = maxdrawdown * trailing_take_profit_percentage_from_drawdownsell_dynamic_trailing_take_profit_trigger = ema (sell_dynamic_trailing_take_profit_trigger_tmp, 5)float ShortRatio = nafloat DesiredShortRatio = naif enable_strict_mode and tradinglatino_strategy_emas_short_advice // sell_dynamic_trailing_take_profit_trigger := (trailing_take_profit_percentage_resistances_strict_mode / close) * (close - vp_bottom_vpoc) // Old strategy that targetted VPoCs DesiredShortRatio := Ratio * ((1 + new_sell_SL) / 1) // Make ratio compared to Stop Loss ShortRatio := DesiredShortRatio * (1 + (dynamic_trailing_take_profit_offset_percentage/100.0)) // Assume worst case scenario ShortTargetPrice = close * ( ( (100 / ShortRatio) - exchange_order_fee_percent) / ( 100 + exchange_order_fee_percent ) ) sell_dynamic_trailing_take_profit_trigger := (1 - (ShortTargetPrice / close)) * 100.0 sell_dynamic_trailing_take_profit_offset = sell_dynamic_trailing_take_profit_trigger * dynamic_trailing_take_profit_offset_percentage// plotchar(sell_dynamic_trailing_take_profit_trigger, "sell_dynamic_trailing_take_profit_trigger", "", location = location.top)atl = lowest (low, 5)inv_drawdown = ( ( high / atl ) * 100 ) - 100inv_maxdrawdown = highest (inv_drawdown, 5)buy_dynamic_trailing_take_profit_trigger_tmp = inv_maxdrawdown * trailing_take_profit_percentage_from_drawdownbuy_dynamic_trailing_take_profit_trigger = ema (buy_dynamic_trailing_take_profit_trigger_tmp, 5)if enable_strict_mode and tradinglatino_strategy_emas_long_advice // buy_dynamic_trailing_take_profit_trigger := (trailing_take_profit_percentage_resistances_strict_mode / close) * (vp_top_vpoc - close) // Old strategy that targetted VPoCs DesiredLongRatio = Ratio * ((1 + new_buy_SL) / 1) // Make ratio compared to Stop Loss LongRatio = DesiredLongRatio * (1 + (dynamic_trailing_take_profit_offset_percentage/100.0)) // Assume worst case scenario LongTargetPrice = close * ( ((LongRatio * 100) + exchange_order_fee_percent) / (100 - exchange_order_fee_percent)) buy_dynamic_trailing_take_profit_trigger := ((LongTargetPrice / close) - 1) * 100.0 buy_dynamic_trailing_take_profit_offset = buy_dynamic_trailing_take_profit_trigger * dynamic_trailing_take_profit_offset_percentage// plotchar(buy_dynamic_trailing_take_profit_trigger, "buy_dynamic_trailing_take_profit_trigger", "", location = location.top)// trailing_take_profit_percentage = input(0.4, "(TRAILING) Trailing Take Profit (%) {0.4}",minval=0,step=0.01,type=input.float) * 0.01// trailing_take_profit_percentage_trigger = input(0.8, "(TRAILING) Trailing Take Profit Trigger (%) {0.8}",minval=0,step=0.01,type=input.float) * 0.01// enable_dynamic_trailing_take_profit = input(true, "(TRAILING) Enforce dynamic Trailing Take Profit {True}")if enable_dynamic_trailing_take_profit if (tradinglatino_strategy_emas_long_advice) new_trailing_take_profit_percentage_trigger := buy_dynamic_trailing_take_profit_trigger * 0.01 new_trailing_take_profit_percentage := buy_dynamic_trailing_take_profit_offset * 0.01 else new_trailing_take_profit_percentage_trigger := sell_dynamic_trailing_take_profit_trigger * 0.01 new_trailing_take_profit_percentage := sell_dynamic_trailing_take_profit_offset * 0.01plotchar(new_trailing_take_profit_percentage_trigger * 100.0, "new_trailing_take_profit_percentage_trigger_percent", "", location = location.top)// plotchar(new_trailing_take_profit_percentage * 100.0, "new_trailing_take_profit_percentage_percent", "", location = location.top)// plotchar(ShortRatio, "ShortRatio", "", location = location.top)// plotchar(DesiredShortRatio, "DesiredShortRatio", "", location = location.top)//plotchar(new_sell_SL, "new_sell_SL", "", location = location.top)// INTERNAL NOTE: N_017 file references to draw a rectangle might be useful// when programming resistances and supports later// (SS38)// Try to bounce back to EMA55// Normal or bounce back modebuy_normal_mode = ema10 > ema55sell_normal_mode = not (buy_normal_mode) // Also known as buy_bounce_back_modebounce_back_mode_buy_close_advice = fun_get_bounce_back_mode_buy_close_advice (close, ema10, ema55, bounce_back_to_EMA55_percent, main_resistance_price)bounce_back_mode_sell_close_advice = fun_get_bounce_back_mode_sell_close_advice (close, ema10, ema55, bounce_back_to_EMA55_percent, main_resistance_price)if enable_strict_mode bounce_back_mode_buy_close_advice := false bounce_back_mode_sell_close_advice := falsetoo_old_order_buy_close_advice = fun_get_too_old_order_buy_close_advice ()too_old_order_sell_close_advice = fun_get_too_old_order_sell_close_advice ()too_recent_order_not_open_advice = fun_get_too_recent_order_not_open_advice ()// SS4.3// Wait for the price to fall just below or above the MediaMovilMarron and so you can// enter in long.price_next_to_ema55_buy_advice = fun_get_price_next_to_mediamovilmarron_buy_advice (hc, ema10, ema55, next_to_EMA55_percent)price_next_to_ema55_sell_advice = fun_get_price_next_to_mediamovilmarron_sell_advice (lc, ema10, ema55, next_to_EMA55_percent)bottom_vpoc_n_bars_advice = hc > vp_bottom_vpoctop_vpoc_n_bars_advice = lc < vp_top_vpoc// Show Final advice// If we are in strict mode we only want the advice from Smilb and ADXif enable_strict_mode buy_normal_mode := false sell_normal_mode := falsePRE_BUY = falseif (emas_ignore_advice) if buy_normal_mode if vp_bottom_vpoc_ignore_advice PRE_BUY := (tradinglatino_strategy_smilb_and_adx_long_advice) or price_next_to_ema55_buy_advice else PRE_BUY := (tradinglatino_strategy_smilb_and_adx_long_advice) or price_next_to_ema55_buy_advice or bottom_vpoc_n_bars_advice else PRE_BUY := tradinglatino_strategy_smilb_and_adx_long_adviceelse if buy_normal_mode if vp_bottom_vpoc_ignore_advice PRE_BUY := tradinglatino_strategy_emas_long_advice and (tradinglatino_strategy_smilb_and_adx_long_advice or price_next_to_ema55_buy_advice) else PRE_BUY := tradinglatino_strategy_emas_long_advice and (tradinglatino_strategy_smilb_and_adx_long_advice or price_next_to_ema55_buy_advice or bottom_vpoc_n_bars_advice) else PRE_BUY := tradinglatino_strategy_emas_long_advice and (tradinglatino_strategy_smilb_and_adx_long_advice)BUY = PRE_BUY[1] and PRE_BUY// Do not confirm the buy entryif (enable_dynamic_stop_loss and stop_loss_not_worth_open_buy) BUY := falseelse BUY := PRE_BUY // Default behaviourif (too_recent_order_not_open_advice) BUY := falsePRE_SELL = falseif (emas_ignore_advice) if sell_normal_mode if vp_bottom_vpoc_ignore_advice // It uses the long bool variable on purpose PRE_SELL := (tradinglatino_strategy_smilb_and_adx_short_advice) or price_next_to_ema55_sell_advice else PRE_SELL := (tradinglatino_strategy_smilb_and_adx_short_advice) or price_next_to_ema55_sell_advice or top_vpoc_n_bars_advice else PRE_SELL := tradinglatino_strategy_smilb_and_adx_short_adviceelse if sell_normal_mode if vp_bottom_vpoc_ignore_advice // It uses the long bool variable on purpose PRE_SELL := tradinglatino_strategy_emas_short_advice and (tradinglatino_strategy_smilb_and_adx_short_advice or price_next_to_ema55_sell_advice) else PRE_SELL := tradinglatino_strategy_emas_short_advice and (tradinglatino_strategy_smilb_and_adx_short_advice or price_next_to_ema55_sell_advice or top_vpoc_n_bars_advice) else PRE_SELL := tradinglatino_strategy_emas_short_advice and (tradinglatino_strategy_smilb_and_adx_short_advice)SELL = PRE_SELL[1] and PRE_SELL// Do not confirm the sell entryif (enable_dynamic_stop_loss and stop_loss_not_worth_open_sell) SELL := falseelse SELL := PRE_SELL // Default behaviourif (too_recent_order_not_open_advice) SELL := falseBUY_CLOSE = true// (SS13)// Long sell signal means changing from light green to dark green// (SS14)// If we are inside a price range then it's going to stay the same or dump down// (SS14. Updated)// Let's ignore price range alltogether// We will just print it and that's itbool sqzmom_bcolor_buy_close_advice = nabool new_tradinglatino_strategy_smilb_and_adx_short_advice = naif enable_plus_mode sqzmom_bcolor_buy_close_advice := false new_tradinglatino_strategy_smilb_and_adx_short_advice := falseelse // TODO: sqzmom_bcolor_buy_close_advice being dependent on di_plus should be optional. // sqzmom_bcolor_buy_close_advice := (sqzmom_bcolor == color.green) and ((di_plus <= di_minus) and (di_percentage < (- di_minimum_percentage))) //new_tradinglatino_strategy_smilb_and_adx_short_advice := tradinglatino_strategy_smilb_and_adx_short_advice and ((di_plus <= di_minus) and (di_percentage < (- di_minimum_percentage))) sqzmom_bcolor_buy_close_advice := (sqzmom_bcolor == color.green) new_tradinglatino_strategy_smilb_and_adx_short_advice := tradinglatino_strategy_smilb_and_adx_short_adviceif (too_old_order_ignore_advice_on_buy_close) if (emas_ignore_advice_on_buy_close) if buy_normal_mode BUY_CLOSE := new_tradinglatino_strategy_smilb_and_adx_short_advice or sqzmom_bcolor_buy_close_advice else BUY_CLOSE := new_tradinglatino_strategy_smilb_and_adx_short_advice or sqzmom_bcolor_buy_close_advice or bounce_back_mode_buy_close_advice else if buy_normal_mode BUY_CLOSE := new_tradinglatino_strategy_smilb_and_adx_short_advice or tradinglatino_strategy_emas_short_advice or sqzmom_bcolor_buy_close_advice else BUY_CLOSE := new_tradinglatino_strategy_smilb_and_adx_short_advice or tradinglatino_strategy_emas_short_advice or sqzmom_bcolor_buy_close_advice or bounce_back_mode_buy_close_adviceelse if (emas_ignore_advice_on_buy_close) if buy_normal_mode BUY_CLOSE := new_tradinglatino_strategy_smilb_and_adx_short_advice or sqzmom_bcolor_buy_close_advice or too_old_order_buy_close_advice else BUY_CLOSE := new_tradinglatino_strategy_smilb_and_adx_short_advice or sqzmom_bcolor_buy_close_advice or bounce_back_mode_buy_close_advice or too_old_order_buy_close_advice else if buy_normal_mode BUY_CLOSE := new_tradinglatino_strategy_smilb_and_adx_short_advice or tradinglatino_strategy_emas_short_advice or sqzmom_bcolor_buy_close_advice or too_old_order_buy_close_advice else BUY_CLOSE := new_tradinglatino_strategy_smilb_and_adx_short_advice or tradinglatino_strategy_emas_short_advice or sqzmom_bcolor_buy_close_advice or bounce_back_mode_buy_close_advice or too_old_order_buy_close_advice// Let's make sure BUY does not trigger if BUY_CLOSE would tell us to close the BUYif BUY_CLOSE BUY := falseSELL_CLOSE = truebool sqzmom_bcolor_sell_close_advice = nabool new_tradinglatino_strategy_smilb_and_adx_long_advice = naif enable_plus_mode sqzmom_bcolor_sell_close_advice := false new_tradinglatino_strategy_smilb_and_adx_long_advice := falseelse // TODO: sqzmom_bcolor_sell_close_advice being dependent on di_plus should be optional. // sqzmom_bcolor_sell_close_advice := (sqzmom_bcolor == color.maroon) and ((di_plus > di_minus) and (di_percentage > di_minimum_percentage)) // new_tradinglatino_strategy_smilb_and_adx_long_advice := tradinglatino_strategy_smilb_and_adx_long_advice and ((di_plus > di_minus) and (di_percentage > di_minimum_percentage)) sqzmom_bcolor_sell_close_advice := (sqzmom_bcolor == color.maroon) new_tradinglatino_strategy_smilb_and_adx_long_advice := tradinglatino_strategy_smilb_and_adx_long_adviceif (too_old_order_ignore_advice_on_buy_close) if (emas_ignore_advice_on_buy_close) // It uses the long bool variable on purpose if sell_normal_mode SELL_CLOSE := new_tradinglatino_strategy_smilb_and_adx_long_advice or sqzmom_bcolor_sell_close_advice else SELL_CLOSE := new_tradinglatino_strategy_smilb_and_adx_long_advice or sqzmom_bcolor_sell_close_advice or bounce_back_mode_sell_close_advice else if sell_normal_mode SELL_CLOSE := new_tradinglatino_strategy_smilb_and_adx_long_advice or tradinglatino_strategy_emas_long_advice or sqzmom_bcolor_sell_close_advice else SELL_CLOSE := new_tradinglatino_strategy_smilb_and_adx_long_advice or tradinglatino_strategy_emas_long_advice or sqzmom_bcolor_sell_close_advice or bounce_back_mode_sell_close_adviceelse if (emas_ignore_advice_on_buy_close) // It uses the long bool variable on purpose if sell_normal_mode SELL_CLOSE := new_tradinglatino_strategy_smilb_and_adx_long_advice or sqzmom_bcolor_sell_close_advice or too_old_order_sell_close_advice else SELL_CLOSE := new_tradinglatino_strategy_smilb_and_adx_long_advice or sqzmom_bcolor_sell_close_advice or bounce_back_mode_sell_close_advice or too_old_order_sell_close_advice else if sell_normal_mode SELL_CLOSE := new_tradinglatino_strategy_smilb_and_adx_long_advice or tradinglatino_strategy_emas_long_advice or sqzmom_bcolor_sell_close_advice or too_old_order_sell_close_advice else SELL_CLOSE := new_tradinglatino_strategy_smilb_and_adx_long_advice or tradinglatino_strategy_emas_long_advice or sqzmom_bcolor_sell_close_advice or bounce_back_mode_sell_close_advice or too_old_order_sell_close_advice// Let's make sure SELL does not trigger if SELL_CLOSE would tell us to close the SELLif SELL_CLOSE SELL := false// Debug strategy variables - BEGINplotchar(BUY, "BUY", "", location = location.top)plotchar(new_tradinglatino_strategy_smilb_and_adx_long_advice, "BUY_tradinglatino_strategy_smilb_and_adx_long_advice", "", location = location.top)plotchar(tradinglatino_strategy_emas_long_advice, "BUY_tradinglatino_strategy_emas_long_advice", "", location = location.top)plotchar(price_next_to_ema55_buy_advice, "BUY_price_next_to_ema55_buy_advice", "", location = location.top)plotchar(bottom_vpoc_n_bars_advice, "BUY_bottom_vpoc_n_bars_advice", "", location = location.top)plotchar(BUY_CLOSE, "BUY_CLOSE", "", location = location.top)plotchar(tradinglatino_strategy_smilb_and_adx_short_advice, "BUY_CLOSE_tradinglatino_strategy_smilb_and_adx_short_advice", "", location = location.top)plotchar(tradinglatino_strategy_emas_short_advice, "BUY_CLOSE_tradinglatino_strategy_emas_short_advice", "", location = location.top)plotchar((sqzmom_bcolor == color.green), "BUY_CLOSE_bcolor_is_green", "", location = location.top)plotchar(buy_normal_mode, "BUY_CLOSE_normal_mode", "", location = location.top)plotchar(bounce_back_mode_buy_close_advice, "BUY_CLOSE_bounce_back_mode_advice", "", location = location.top)plotchar(too_old_order_buy_close_advice, "BUY_CLOSE_too_old_order_buy_close_advice", "", location = location.top)plotchar(stop_loss_not_worth_open_buy, "BUY_CLOSE_stop_loss_not_worth_open_buy", "", location = location.top)plotchar(SELL, "SELL", "", location = location.top)plotchar(tradinglatino_strategy_smilb_and_adx_short_advice, "SELL_tradinglatino_strategy_smilb_and_adx_short_advice", "", location = location.top)plotchar(tradinglatino_strategy_emas_short_advice, "SELL_tradinglatino_strategy_emas_short_advice", "", location = location.top)plotchar(price_next_to_ema55_sell_advice, "SELL_price_next_to_ema55_sell_advice", "", location = location.top)plotchar(top_vpoc_n_bars_advice, "SELL_top_vpoc_n_bars_advice", "", location = location.top)plotchar(SELL_CLOSE, "SELL_CLOSE", "", location = location.top)plotchar(new_tradinglatino_strategy_smilb_and_adx_long_advice, "SELL_CLOSE_tradinglatino_strategy_smilb_and_adx_long_advice", "", location = location.top)plotchar(tradinglatino_strategy_emas_long_advice, "SELL_CLOSE_tradinglatino_strategy_emas_long_advice", "", location = location.top)plotchar((sqzmom_bcolor == color.maroon), "SELL_CLOSE_bcolor_is_maroon", "", location = location.top)plotchar(sell_normal_mode, "SELL_CLOSE_normal_mode", "", location = location.top)plotchar(bounce_back_mode_sell_close_advice, "SELL_CLOSE_bounce_back_mode_advice", "", location = location.top)plotchar(too_old_order_sell_close_advice, "SELL_CLOSE_too_old_order_sell_close_advice", "", location = location.top)plotchar(stop_loss_not_worth_open_sell, "SELL_CLOSE_stop_loss_not_worth_open_sell", "", location = location.top)plotchar(too_recent_order_not_open_advice, "too_recent_order_not_open_advice", "", location = location.top)plotchar(main_resistance_price, "main_resistance_price", "", location = location.top)// plotchar(PRE_BUY, "PRE_BUY", "", location = location.top)//// plotchar(tradinglatino_strategy_emas_short_advice, "BUY_CLOSE_tradinglatino_strategy_emas_short_advice", "", location = location.top)// plotchar((sqzmom_bcolor == color.green), "BUY_CLOSE_sqmom_bcolor equals green", "", location = location.top)// plotchar(buy_normal_mode, "BUY_CLOSE_normal_mode", "", location = location.top)// plotchar(bounce_back_mode_buy_close_advice, "BUY_CLOSE_bounce_back_mode_advice", "", location = location.top)// plotchar(vp_recent_vpvr_vpoc_price, "BUY_CLOSE_vp_recent_vpvr_vpoc_price", "", location = location.top)// // plotchar(ema10_1d, "ema10_1d", "", location = location.top)// plotchar(ema55_1d, "ema55_1d", "", location = location.top)// // plotchar(price_is_in_range, "price_is_in_range", "", location = location.top)// // plotchar(adx_sig, "Current ADX", "", location = location.top)// Debug strategy variables - END// Dynamic Trailing Take Profit being constant during an order logic// if ((old_inside_a_buy_order and inside_a_buy_order) or (old_inside_a_sell_order and inside_a_sell_order))// constant_trailing_take_profit_percentage_trigger := trailing_take_profit_percentage_trigger// constant_trailing_take_profit_percentage := trailing_take_profit_percentage// else// constant_trailing_take_profit_percentage_trigger := new_trailing_take_profit_percentage_trigger// constant_trailing_take_profit_percentage := new_trailing_take_profit_percentageif (not ((old_inside_a_buy_order and inside_a_buy_order) or (old_inside_a_sell_order and inside_a_sell_order))) constant_trailing_take_profit_percentage_trigger := new_trailing_take_profit_percentage_trigger constant_trailing_take_profit_percentage := new_trailing_take_profit_percentage// Custom take profit and stop lossTP_B = position_price * (1 + TP)TP_S = position_price * (1 - TP)float SL_B = nafloat SL_S = na// enable_dynamic_stop_loss being true or false is handle with the same piece of code// I'm not sure that pyramiding=0 ensures that an exit order is scaled (and thus modified) so let's keep this herefloat constant_buy_SL = naif (old_inside_a_buy_order and inside_a_buy_order) constant_buy_SL := buy_SLelse constant_buy_SL := new_buy_SL// I'm not sure that pyramiding=0 ensures that an exit order is scaled (and thus modified) so let's keep this herefloat constant_sell_SL = naif (old_inside_a_sell_order and inside_a_sell_order) constant_sell_SL := sell_SLelse constant_sell_SL := new_sell_SLif na(constant_buy_SL) SL_B := naelse SL_B := position_price * (1 - constant_buy_SL)if na(constant_sell_SL) SL_S := naelse SL_S := position_price * (1 + constant_sell_SL)float entry_quantity = nafloat current_capital = strategy.initial_capital + strategy.netprofit// risk_management_maximum_loss_per_dayvar float current_day_entry_quantity = nacurrent_day_entry_quantity := navar current_day_loss = 0.0var current_day_capital = 0.0var current_day = 0var day_minutes = get_resolution_bar_minutes('1D')var bar_minutes = get_resolution_bar_minutes(timeframe.period)bar_minutes_to_now = bar_index * bar_minutescurrent_day := floor (bar_minutes_to_now / day_minutes)// risk_management_maximum_loss_per_weekvar float current_week_entry_quantity = nacurrent_week_entry_quantity := navar current_week_loss = 0.0var current_week_capital = 0.0var current_week = 0var week_minutes = get_resolution_bar_minutes('1W')current_week := floor (bar_minutes_to_now / week_minutes)// risk_management_maximum_loss_per_monthvar float current_month_entry_quantity = nacurrent_month_entry_quantity := navar current_month_loss = 0.0var current_month_capital = 0.0var current_month = 0var month_minutes = get_resolution_bar_minutes('1M')current_month := floor (bar_minutes_to_now / month_minutes)float order_SL = naif BUY order_SL := constant_buy_SLelse order_SL := constant_sell_SLfloat tmp_entry_quantity = naif (risk_management_type == _SAFE_) // Safe means we stick to the original initial capital // to enforce our risk management policy tmp_entry_quantity := (strategy.initial_capital * risk_management_maximum_loss_per_trade) / order_SLelse if (risk_management_type == _SCOMPOUND_) // Safe compound means that we are gambling everything we have // but we try to follow risk management rules tmp_entry_quantity:= (current_capital * risk_management_maximum_loss_per_trade) / order_SLelse if (risk_management_type == _UCOMPOUND_) // Unsafe compound means that we are gambling always everything we have tmp_entry_quantity := current_capitalif (tmp_entry_quantity > current_capital) // Avoid being stuck when numbers don't match entry_quantity := current_capitalelse entry_quantity := tmp_entry_quantity// DAYif (current_day[1] != current_day) current_day_loss := 0.0 current_day_capital := current_capitalelse if (current_capital < current_day_capital) current_day_loss := current_day_capital - current_capital else current_day_loss := 0.0 tmp_current_day_loss_perone = current_day_loss / current_day_capital if (tmp_current_day_loss_perone >= risk_management_maximum_loss_per_day) current_day_entry_quantity:= 0.0 // Avoid entering a position// WEEKif (current_week[1] != current_week) current_week_loss := 0.0 current_week_capital := current_capitalelse if (current_capital < current_week_capital) current_week_loss := current_week_capital - current_capital else current_week_loss := 0.0 tmp_current_week_loss_perone = current_week_loss / current_week_capital if (tmp_current_week_loss_perone >= risk_management_maximum_loss_per_week) current_week_entry_quantity:= 0.0 // Avoid entering a position// MONTHif (current_month[1] != current_month) current_month_loss := 0.0 current_month_capital := current_capitalelse if (current_capital < current_month_capital) current_month_loss := current_month_capital - current_capital else current_month_loss := 0.0 tmp_current_month_loss_perone = current_month_loss / current_month_capital if (tmp_current_month_loss_perone >= risk_management_maximum_loss_per_month) current_month_entry_quantity:= 0.0 // Avoid entering a position// Avoid to enter a position overall logicif ( (not na(current_day_entry_quantity)) or (not na(current_week_entry_quantity)) or (not na(current_month_entry_quantity)) ) entry_quantity:= 0.0if enable_raw_testing entry_quantity:= raw_testing_quantityfloat entry_quantity_contracts_reducer = 0.99contract_multiplier = get_contract_multiplier(contract_maximum_decimal_number)// We assume the current price is current bar closeentry_quantity_contracts = (floor(((entry_quantity / close) * entry_quantity_contracts_reducer) * contract_multiplier) / contract_multiplier)entry_quantity_contracts_usdt = entry_quantity_contracts * (close)plotchar(strategy.initial_capital, "strategy.initial_capital", "", location = location.top)plotchar(strategy.netprofit, "strategy.netprofit", "", location = location.top)plotchar(entry_quantity, "entry_quantity", "", location = location.top)// plotchar((contract_multiplier), "contract_multiplier", "", location = location.top)// plotchar(entry_quantity_contracts_reducer, "entry_quantity_contracts_reducer", "", location = location.top)plotchar(current_day_loss, "current_day_loss", "", location = location.top)plotchar(((current_day_loss / current_day_capital) * 100 ), "current_day_loss_percent", "", location = location.top)plotchar(current_day_capital, "current_day_capital", "", location = location.top)plotchar(current_week_capital, "current_week_capital", "", location = location.top)plotchar(current_month_capital, "current_month_capital", "", location = location.top)plotchar(current_capital, "current_capital", "", location = location.top)plotchar(current_week_loss, "current_week_loss", "", location = location.top)plotchar(((current_week_loss / current_week_capital) * 100 ), "current_week_loss_percent", "", location = location.top)plotchar(current_month_loss, "current_month_loss", "", location = location.top)plotchar(((current_month_loss / current_month_capital) * 100 ), "current_month_loss_percent", "", location = location.top)var float tmp_position_before_opening_order = naif (Type == _L_) if BUY tmp_position_before_opening_order := strategy.position_avg_price tmp_order_alert_message := get_zignaly_long_alert_message(entry_quantity_contracts_usdt, current_capital) tmp_order_comment := get_order_comment("entry", strategy.long, tmp_order_alert_message) strategy.entry("[B]", strategy.long, qty=entry_quantity_contracts, alert_message=tmp_order_alert_message, comment=tmp_order_comment) if (na(tmp_position_before_opening_order)) // bar_index should only be saved when there is no order opened buy_order_open_bar_index := bar_index + 1 if (not inside_a_buy_order) buy_SL := new_buy_SL inside_a_buy_order := true 0 // Workaround for making every if branch to return the same type of value else if BUY_CLOSE tmp_order_comment := get_order_comment("close", strategy.long, get_zignaly_long_close_alert_message()) strategy.close("[B]", alert_message=get_zignaly_long_close_alert_message(), comment=tmp_order_comment) inside_a_buy_order := false 0 // Workaround for making every if branch to return the same type of valueif (Type == _S_) if SELL tmp_position_before_opening_order := strategy.position_avg_price tmp_order_alert_message := get_zignaly_short_alert_message(entry_quantity_contracts_usdt, current_capital) tmp_order_comment := get_order_comment("entry", strategy.short, tmp_order_alert_message) strategy.entry("[S]", strategy.short, qty=entry_quantity_contracts, alert_message=tmp_order_alert_message, comment=tmp_order_comment) if (na(tmp_position_before_opening_order)) // bar_index should only be saved when there is no order opened sell_order_open_bar_index := bar_index + 1 if (not inside_a_sell_order) sell_SL := new_sell_SL inside_a_sell_order := true 0 // Workaround for making every if branch to return the same type of value else if SELL_CLOSE tmp_order_comment := get_order_comment("close", strategy.short, get_zignaly_short_close_alert_message()) strategy.close("[S]", alert_message=get_zignaly_short_close_alert_message(), comment=tmp_order_comment) inside_a_sell_order := false 0 // Workaround for making every if branch to return the same type of valueif (Type == L_S)// Asumption: Above we have:// if BUY_CLOSE// BUY := false// if SELL_CLOSE// SELL := false // BUY and SELL cannot be true at the same time // Anyways we will take it into account if (BUY == true) and (SELL == true) BUY := true SELL := false SELL_CLOSE := true if BUY tmp_position_before_opening_order := strategy.position_avg_price tmp_order_alert_message := get_zignaly_long_alert_message(entry_quantity_contracts_usdt, current_capital) tmp_order_comment := get_order_comment("entry", strategy.long, tmp_order_alert_message) strategy.entry("[B]", strategy.long, qty=entry_quantity_contracts, alert_message=tmp_order_alert_message, comment=tmp_order_comment) if (na(tmp_position_before_opening_order)) // bar_index should only be saved when there is no order opened buy_order_open_bar_index := bar_index + 1 if (not inside_a_buy_order) buy_SL := new_buy_SL inside_a_buy_order := true if BUY_CLOSE tmp_order_comment := get_order_comment("close", strategy.long, get_zignaly_long_close_alert_message()) strategy.close("[B]", alert_message=get_zignaly_long_close_alert_message(), comment=tmp_order_comment) inside_a_buy_order := false if SELL tmp_position_before_opening_order := strategy.position_avg_price tmp_order_alert_message := get_zignaly_short_alert_message(entry_quantity_contracts_usdt, current_capital) tmp_order_comment := get_order_comment("entry", strategy.short, tmp_order_alert_message) strategy.entry("[S]", strategy.short, qty=entry_quantity_contracts, alert_message=tmp_order_alert_message, comment=tmp_order_comment) if (na(tmp_position_before_opening_order)) // bar_index should only be saved when there is no order opened sell_order_open_bar_index := bar_index + 1 if (not inside_a_sell_order) sell_SL := new_sell_SL inside_a_sell_order := true if SELL_CLOSE tmp_order_comment := get_order_comment("close", strategy.short, get_zignaly_short_close_alert_message()) strategy.close("[S]", alert_message=get_zignaly_short_close_alert_message(), comment=tmp_order_comment) inside_a_sell_order := falsefloat buy_trailing_take_profit_price = nafloat buy_trailing_take_profit_points = nafloat buy_trailing_take_profit_offset = nafloat sell_trailing_take_profit_price = nafloat sell_trailing_take_profit_points = nafloat sell_trailing_take_profit_offset = na// Calculate trailing_take_profit_offset based on tick unitsbuy_tmp_ttp_base_value = position_price * (1 + constant_trailing_take_profit_percentage_trigger)buy_tmp_ttp_top_value = buy_tmp_ttp_base_value * (1 + constant_trailing_take_profit_percentage)buy_trailing_take_profit_offset_float = buy_tmp_ttp_top_value - buy_tmp_ttp_base_valuefloat buy_trailing_take_profit_offset_tick = floor (buy_trailing_take_profit_offset_float / syminfo.mintick)sell_tmp_ttp_base_value = position_price * (1 - constant_trailing_take_profit_percentage_trigger)sell_tmp_ttp_bottom_value = sell_tmp_ttp_base_value * (1 - constant_trailing_take_profit_percentage)sell_trailing_take_profit_offset_float = sell_tmp_ttp_base_value - sell_tmp_ttp_bottom_valuefloat sell_trailing_take_profit_offset_tick = floor (sell_trailing_take_profit_offset_float / syminfo.mintick)if enable_trailing_take_profit_percentage buy_trailing_take_profit_price := position_price * (1 + constant_trailing_take_profit_percentage_trigger) buy_trailing_take_profit_offset := buy_trailing_take_profit_offset_tick sell_trailing_take_profit_price := position_price * (1 - constant_trailing_take_profit_percentage_trigger) sell_trailing_take_profit_offset := sell_trailing_take_profit_offset_tickelse buy_trailing_take_profit_price := na buy_trailing_take_profit_offset := na sell_trailing_take_profit_price := na sell_trailing_take_profit_offset := na// This might trigger additional close orders than needed in zignaly// Better close an existing order twice than regreting zignaly not having closed it.tmp_order_comment := get_order_comment("close", strategy.long, get_zignaly_long_close_alert_message())strategy.exit("[SL/TP]", "[B]", stop= sl ? SL_B : na, limit= tp ? TP_B : na, trail_price= buy_trailing_take_profit_price, trail_offset = buy_trailing_take_profit_offset, alert_message=get_zignaly_long_close_alert_message(), comment=tmp_order_comment)tmp_order_comment := get_order_comment("close", strategy.short, get_zignaly_short_close_alert_message())strategy.exit("[SL/TP]", "[S]", stop= sl ? SL_S : na, limit= tp ? TP_S : na, trail_price= sell_trailing_take_profit_price, trail_offset = sell_trailing_take_profit_offset, alert_message=get_zignaly_short_close_alert_message(), comment=tmp_order_comment)// Dynamic stop loss management Debug variables - BEGINplotchar(strategy.position_avg_price, "strategy.position_avg_price", "", location = location.top)plotchar(strategy.position_size, "strategy.position_size", "", location = location.top)plotchar(position_price, "position_price", "", location = location.top)plotchar(buy_SL * 100.0, "BUY_buy_SL_percent", "", location = location.top)plotchar(new_buy_SL * 100.0, "BUY_new_buy_SL_percent", "", location = location.top)plotchar(sell_SL * 100.0, "SELL_sell_SL_percent", "", location = location.top)plotchar(new_sell_SL * 100.0, "SELL_new_sell_SL_percent", "", location = location.top)// plotchar(SL_B, "SL_B", "", location = location.top)// plotchar(SL_S, "SL_S", "", location = location.top)plotchar(constant_buy_SL * 100.0, "constant_buy_SL_percent", "", location = location.top)plotchar(constant_sell_SL * 100.0, "constant_sell_SL_percent", "", location = location.top)// Dynamic stop loss management Debug variables - END// Debug - Angles - BEGIN// [gx1,gy1,gx2,gy2] = fun_linear_regression_points(adx_sig, adx_steepness_periods_number)// gline_slope = fun_line_slope(gx1,gy1,gx2,gy2)// gline_angle = fun_slope_angle(gline_slope)// // // plotchar(gline_angle, "gline_angle", "", location = location.top)// plotchar(adx_minimum_steepness_entry, "adx_minimum_steepness_entry", "", location = location.top)// Debug - Angles - END