Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

The Strategy - Ichimoku Kinko Hyo and more

A Pine Script v5 strategy built on Lowest or Highest (TKlength), Crossover (close, KJ) and Crossunder (close, KJ). It has 12 order rules, 4 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade is 0.05 contracts and pays 0.075% commission. 75 settings; defaults include Position Entry-Direction Both, Repainting Allowed and Time Frame - 1st ENTRY SIGNAL Current.

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 The Strategy - Ichimoku Kinko Hyo and more repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 8 of 8 trades.
How did The Strategy - Ichimoku Kinko Hyo and more do on BTCUSDT 1D with default settings?
+10.29%
From 26 Jan 2024 to 21 Oct 2026, over 57 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
What alerts does The Strategy - Ichimoku Kinko Hyo and more have?
5
BybitAPI(BTCUSD) { continue(if=positionShort); market(position= 0); } BybitAPI(BTCUSD) { wait(0.5s); market(side=buy, amount=' + str.tostring(lot_size) + '); } \n #bot; BybitAPI(BTCUSD) { continue(if=positionLong); market(position= 0); } BybitAPI(BTCUSD) { wait(0.5s); market(side=sell, amount=' + str.tostring(lot_size) + '); } \n #bot; BybitAPI(BTCUSD) { market(position= 0 %p); } \n #bot; BybitAPI(BTCUSD) { market(position=' + str.tostring(av_tp_qty_var) + '%p); } \n #bot; and more.
Does The Strategy - Ichimoku Kinko Hyo and more run in Pine Script v6?
Yes
Same 57 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. The v6 script can be downloaded below.
Does The Strategy - Ichimoku Kinko Hyo and more use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.

BTCUSDT · 1D · default settings

  • position_avg_price
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$11,839$20,253Equity from $10,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots. 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. The live re-run is not offered here: the script requests BINANCE:BTCUSDT W, which this page cannot load in your browser.
Table drawn by the script, as it stood on the last bar
Unrealized Profit/Loss: 809.13
Net profit
+10.29%
$1,029.07
Buy and hold
+102.5%
same period
Closed trades
57
36 won · 21 lost
Profitable
63.2%
of closed trades
Profit factor
1.27
gross profit ÷ gross loss
Max drawdown
16.61%
−$1,726.41

One run with the author's default settings, $10,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

    ta.crossunder(rsi_f, 50) ignores the settings line 326

    Line 326 hard-codes 50 where line 375 uses “Exit ADX Threshold”. Changing those settings moves one band but not this one.

    ta.crossunder(rsi_f, 50)ta.crossunder(rsi_f, adx_thres_x)
  • Likely bug

    ta.crossunder(rsi_f_x, 50) ignores the settings line 333

    Line 333 hard-codes 50 where line 375 uses “Exit ADX Threshold”. Changing those settings moves one band but not this one.

    ta.crossunder(rsi_f_x, 50)ta.crossunder(rsi_f_x, adx_thres_x)
  • Likely bug

    ta.rising(trix_f, 1) ignores the settings line 242

    Line 242 hard-codes 1 where line 314 uses “MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.

    ta.rising(trix_f, 1)ta.rising(trix_f, slope_len)
  • Likely bug

    ta.rising(trix_f, 1) ignores the settings line 242

    Line 242 hard-codes 1 where line 314 uses “MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.

    ta.rising(trix_f, 1)ta.rising(trix_f, slope_len)
  • Likely bug

    ta.rising(trix_f, 1) ignores the settings line 244

    Line 244 hard-codes 1 where line 314 uses “MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.

    ta.rising(trix_f, 1)ta.rising(trix_f, slope_len)
  • Likely bug

    ta.rising(trix_x, 1) ignores the settings line 245

    Line 245 hard-codes 1 where line 314 uses “MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.

    ta.rising(trix_x, 1)ta.rising(trix_x, slope_len)
  • Likely bug

    ta.rising(trix_x, 1) ignores the settings line 245

    Line 245 hard-codes 1 where line 314 uses “MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.

    ta.rising(trix_x, 1)ta.rising(trix_x, slope_len)
  • Likely bug

    ta.rising(hma_f, 1) ignores the settings line 266

    Line 266 hard-codes 1 where line 314 uses “MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.

    ta.rising(hma_f, 1)ta.rising(hma_f, slope_len)
  • Likely bug

    ta.rising(hma_f, 1) ignores the settings line 266

    Line 266 hard-codes 1 where line 314 uses “MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.

    ta.rising(hma_f, 1)ta.rising(hma_f, slope_len)
  • Likely bug

    ta.rising(hma_f, 1) ignores the settings line 268

    Line 268 hard-codes 1 where line 314 uses “MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.

    ta.rising(hma_f, 1)ta.rising(hma_f, slope_len)
  • Likely bug

    ta.rising(hma_x, 1) ignores the settings line 269

    Line 269 hard-codes 1 where line 314 uses “MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.

    ta.rising(hma_x, 1)ta.rising(hma_x, slope_len)
  • Likely bug

    ta.rising(hma_x, 1) ignores the settings line 269

    Line 269 hard-codes 1 where line 314 uses “MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.

    ta.rising(hma_x, 1)ta.rising(hma_x, slope_len)
  • Likely bug

    ta.rising(alma, 1) ignores the settings line 301

    Line 301 hard-codes 1 where line 314 uses “MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.

    ta.rising(alma, 1)ta.rising(alma, slope_len)
  • Likely bug

    ta.rising(alma, 1) ignores the settings line 301

    Line 301 hard-codes 1 where line 314 uses “MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.

    ta.rising(alma, 1)ta.rising(alma, slope_len)
  • Likely bug

    ta.rising(alma, 1) ignores the settings line 304

    Line 304 hard-codes 1 where line 314 uses “MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.

    ta.rising(alma, 1)ta.rising(alma, slope_len)
  • Likely bug

    ta.rising(adx_s, 1) ignores the settings line 379

    Line 379 hard-codes 1 where line 314 uses “MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.

    ta.rising(adx_s, 1)ta.rising(adx_s, slope_len)
  • Likely bug

    ta.rising(f_hma(15), 1) ignores the settings line 547

    Line 547 hard-codes 1 where line 314 uses “MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.

    ta.rising(f_hma(15),1)ta.rising(f_hma(15), slope_len)
  • Likely bug

    ta.rising(ta.alma(close, 9, 0.85, 6), 1) ignores the settings line 549

    Line 549 hard-codes 1 where line 314 uses “MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.

    ta.rising(ta.alma(close, 9, 0.85, 6),1)ta.rising(ta.alma(close, 9, 0.85, 6), slope_len)
  • Likely bug

    ta.rising(macdLine, 1) ignores the settings line 551

    Line 551 hard-codes 1 where line 314 uses “MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.

    ta.rising(macdLine, 1)ta.rising(macdLine, slope_len)
  • Likely bug

    ta.falling(trix_f, 1) ignores the settings line 243

    Line 243 hard-codes 1 where line 316 uses “MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.

    ta.falling(trix_f, 1)ta.falling(trix_f, slope_len)
  • Likely bug

    ta.falling(trix_f, 1) ignores the settings line 243

    Line 243 hard-codes 1 where line 316 uses “MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.

    ta.falling(trix_f, 1)ta.falling(trix_f, slope_len)
  • Likely bug

    ta.falling(trix_x, 1) ignores the settings line 246

    Line 246 hard-codes 1 where line 316 uses “MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.

    ta.falling(trix_x, 1)ta.falling(trix_x, slope_len)
  • Likely bug

    ta.falling(trix_x, 1) ignores the settings line 246

    Line 246 hard-codes 1 where line 316 uses “MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.

    ta.falling(trix_x, 1)ta.falling(trix_x, slope_len)
  • Likely bug

    ta.falling(hma_f, 1) ignores the settings line 267

    Line 267 hard-codes 1 where line 316 uses “MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.

    ta.falling(hma_f, 1)ta.falling(hma_f, slope_len)
  • Likely bug

    ta.falling(hma_f, 1) ignores the settings line 267

    Line 267 hard-codes 1 where line 316 uses “MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.

    ta.falling(hma_f, 1)ta.falling(hma_f, slope_len)
  • Likely bug

    ta.falling(hma_x, 1) ignores the settings line 270

    Line 270 hard-codes 1 where line 316 uses “MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.

    ta.falling(hma_x, 1)ta.falling(hma_x, slope_len)
  • Likely bug

    ta.falling(hma_x, 1) ignores the settings line 270

    Line 270 hard-codes 1 where line 316 uses “MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.

    ta.falling(hma_x, 1)ta.falling(hma_x, slope_len)
  • Likely bug

    ta.falling(alma, 1) ignores the settings line 302

    Line 302 hard-codes 1 where line 316 uses “MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.

    ta.falling(alma, 1)ta.falling(alma, slope_len)
  • Likely bug

    ta.falling(alma, 1) ignores the settings line 302

    Line 302 hard-codes 1 where line 316 uses “MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.

    ta.falling(alma, 1)ta.falling(alma, slope_len)
  • Likely bug

    ta.pivothigh(high, 3, 0) ignores the settings line 284

    Line 284 hard-codes high where line 335 uses “Fractals Period” and 3 where line 335 uses “Fractals Period”. Changing those settings moves one band but not this one.

    ta.pivothigh(high, 3, 0)ta.pivothigh(fr_period, fr_period, 0)
  • Likely bug

    ta.pivothigh(high, 4, 1) ignores the settings line 284

    Line 284 hard-codes high where line 335 uses “Fractals Period” and 4 where line 335 uses “Fractals Period”. Changing those settings moves one band but not this one.

    ta.pivothigh(high, 4, 1)ta.pivothigh(fr_period, fr_period, 1)
  • Likely bug

    ta.pivothigh(high, 4, 1) ignores the settings line 284

    Line 284 hard-codes high where line 335 uses “Fractals Period” and 4 where line 335 uses “Fractals Period”. Changing those settings moves one band but not this one.

    ta.pivothigh(high, 4, 1)ta.pivothigh(fr_period, fr_period, 1)
  • Likely bug

    ta.pivothigh(2, 2) ignores the settings line 402

    Line 402 hard-codes 2 where line 335 uses “Fractals Period” and 2 where line 335 uses “Fractals Period”. Changing those settings moves one band but not this one.

    ta.pivothigh(2, 2)ta.pivothigh(fr_period, fr_period)
  • Likely bug

    ta.pivothigh(high, p_bar_sens_2, 0) ignores the settings line 508

    Line 508 hard-codes high where line 335 uses “Fractals Period”. Changing those settings moves one band but not this one.

    ta.pivothigh(high, p_bar_sens_2, 0)ta.pivothigh(fr_period, p_bar_sens_2, 0)
  • Likely bug

    ta.pivotlow(low, 3, 0) ignores the settings line 285

    Line 285 hard-codes low where line 336 uses “Fractals Period” and 3 where line 336 uses “Fractals Period”. Changing those settings moves one band but not this one.

    ta.pivotlow(low, 3, 0)ta.pivotlow(fr_period, fr_period, 0)
  • Likely bug

    ta.pivotlow(low, 4, 1) ignores the settings line 285

    Line 285 hard-codes low where line 336 uses “Fractals Period” and 4 where line 336 uses “Fractals Period”. Changing those settings moves one band but not this one.

    ta.pivotlow(low, 4, 1)ta.pivotlow(fr_period, fr_period, 1)
  • Likely bug

    ta.pivotlow(low, 4, 1) ignores the settings line 285

    Line 285 hard-codes low where line 336 uses “Fractals Period” and 4 where line 336 uses “Fractals Period”. Changing those settings moves one band but not this one.

    ta.pivotlow(low, 4, 1)ta.pivotlow(fr_period, fr_period, 1)
  • Likely bug

    ta.pivotlow(2, 2) ignores the settings line 403

    Line 403 hard-codes 2 where line 336 uses “Fractals Period” and 2 where line 336 uses “Fractals Period”. Changing those settings moves one band but not this one.

    ta.pivotlow(2, 2)ta.pivotlow(fr_period, fr_period)
  • Likely bug

    ta.pivotlow(low, p_bar_sens_2, 0) ignores the settings line 509

    Line 509 hard-codes low where line 336 uses “Fractals Period”. Changing those settings moves one band but not this one.

    ta.pivotlow(low, p_bar_sens_2, 0)ta.pivotlow(fr_period, p_bar_sens_2, 0)
  • Likely bug

    ta.alma(close, 9, 0.85, 6) ignores the settings line 549

    Line 549 hard-codes 9 where line 299 uses “ALMA Window Size” and 0.85 where line 299 uses “ALMA Offset” and 6 where line 299 uses “ALMA Sigma”. Changing those settings moves one band but not this one.

    ta.alma(close, 9, 0.85, 6)ta.alma(close, windowsize, offset, sigma)
  • Likely bug

    ta.valuewhen(up_fr, high[fr_period], 0) ignores the settings line 337

    Line 337 hard-codes 0 where line 348 uses “Exit Fractals - Past Fractal”. Changing those settings moves one band but not this one.

    ta.valuewhen(up_fr, high[fr_period], 0)ta.valuewhen(up_fr, high[fr_period], fr_past_x)
  • Likely bug

    ta.valuewhen(dn_fr, low[fr_period], 0) ignores the settings line 338

    Line 338 hard-codes 0 where line 348 uses “Exit Fractals - Past Fractal”. Changing those settings moves one band but not this one.

    ta.valuewhen(dn_fr, low[fr_period], 0)ta.valuewhen(dn_fr, low[fr_period], fr_past_x)
  • Likely bug

    ta.valuewhen(up_w_fr, high[2], 1) ignores the settings line 404

    Line 404 hard-codes 1 where line 348 uses “Exit Fractals - Past Fractal”. Changing those settings moves one band but not this one.

    ta.valuewhen(up_w_fr, high[2], 1)ta.valuewhen(up_w_fr, high[2], fr_past_x)
  • Likely bug

    ta.valuewhen(up_w_fr, high[2], 0) ignores the settings line 405

    Line 405 hard-codes 0 where line 348 uses “Exit Fractals - Past Fractal”. Changing those settings moves one band but not this one.

    ta.valuewhen(up_w_fr, high[2], 0)ta.valuewhen(up_w_fr, high[2], fr_past_x)
  • Likely bug

    ta.valuewhen(dn_w_fr, low[2], 1) ignores the settings line 406

    Line 406 hard-codes 1 where line 348 uses “Exit Fractals - Past Fractal”. Changing those settings moves one band but not this one.

    ta.valuewhen(dn_w_fr, low[2], 1)ta.valuewhen(dn_w_fr, low[2], fr_past_x)
  • Likely bug

    ta.valuewhen(dn_w_fr, low[2], 0) ignores the settings line 407

    Line 407 hard-codes 0 where line 348 uses “Exit Fractals - Past Fractal”. Changing those settings moves one band but not this one.

    ta.valuewhen(dn_w_fr, low[2], 0)ta.valuewhen(dn_w_fr, low[2], fr_past_x)
  • Likely bug

    ta.supertrend(2, 5) ignores the settings line 535

    Line 535 hard-codes 2 where line 354 uses “SuperTrend Multiplier” and 5 where line 354 uses “SuperTrend Length”. Changing those settings moves one band but not this one.

    ta.supertrend(2, 5)ta.supertrend(mult, len)
  • Likely bug

    ta.dmi(7, 7) ignores the settings line 534

    Line 534 hard-codes 7 where line 374 uses “Exit ADX Period” and 7 where line 374 uses “Exit ADX Smooth”. Changing those settings moves one band but not this one.

    ta.dmi(7, 7)ta.dmi(di_length_x, adx_smooth_x)
  • Likely bug

    ta.atr(1) ignores the settings line 543

    Line 543 hard-codes 1 where line 1162 uses “ATR Length”. Changing those settings moves one band but not this one.

    ta.atr(1)ta.atr(atr_l)
  • Check

    1 setting does nothing

    “General Description” is declared but never read.

  • Check

    No stop loss

    Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.

  • Note

    2 settings have no label

    In the settings dialog period_start (line 74), period_stop (line 75) show an empty name. The labels on this page come from the variable names.

  • Note

    No slippage

    Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
General DescriptionThis script offers you the opportunity to backtest many signals and filters to compare the results. Make yourself familiar with the signals and the options and become creative ... At least you will be able to see what and on what circumstances works or not. Note the \'KISS\' principle and that \'context\' matters. The key feature of technical analysis is that every market participant is an interface to the world or market-environment and all market relevant information is visible in the chart. The default values are suitable for Bitcoin on ByBit (one tick = 0.5). Deselect \'Signal Labels\' at strategy properties -> Style to avoid signal label strings.falseboolunused
Position Entry-DirectionLong= long entries only, Short= short entries only, Both= long and short entries are possible.Bothstring · options ['Both', 'Long', 'Short']long short both
RepaintingIf repainting "Not allowed" is selected, then signals from higher time frames have a lag of an additional bar from the higher time frame but you trade what you have backtested. Otherwise singals can occure multiple times as long as the higher time frame bar is not closed but the first signal of these possible multiple signals is much earlier.Allowedstring · options ['Not allowed', 'Allowed']entry_filter_buy_1 entry_filter_buy_11 entry_filter_sell_1 entry_filter_sell_11 entry_filter_buy_2 entry_filter_buy_22 entry_filter_sell_2 entry_filter_sell_22 exit_filter_buy_1 exit_filter_sig_buy_11 exit_filter_sell_1 exit_filter_sig_sell_11 exit_filter_buy_2 exit_filter_sig_buy_22 exit_filter_sell_2 exit_filter_sig_sell_22 opt_sig_buy_1 opt_sig_buy_11 opt_sig_sell_1 opt_sig_sell_11 opt_sig_buy_2 opt_sig_buy_22 opt_sig_sell_2 opt_sig_sell_22 line 716
Plot Info PanelInfo panel for current unrealized profit or loss for the open positiontrueboolline 148
Plot Position Avarage Price Line.This plots the position avarage price line.trueboolposition_avg_price
Pyramiding ModeIf disabled: as long as the signal is valid a new trade can be opened on each bar (more filter sensitive). If not \'Both\' as direction is selected, the opposite signal closes the current position. If enabled: a new trade is opened with every signal. Use Properties -> Pyramiding to increase the maximum amount of orders.falseboolkijun_buy kumo_buy kumo_flip_buy chikou_X_price_buy chikou_X_kumo_buy price_X_tenkan_buy tenkan_X_kumo_buy tenkan_X_kijun_buy kijun_sell kumo_sell kumo_flip_sell chikou_X_price_sell chikou_X_kumo_sell price_X_tenkan_sell tenkan_X_kumo_sell tenkan_X_kijun_sell rsi_f_buy rsi_f_sell fr_upx fr_dnx sup_buy sup_sell psar_buy psar_sell long_1 short_1 long_2 short_2 sma_buy sma_sell buy_up_line sell_dn_line long_c short_c long_pic short_pic entry os_b close os_b close os_b entry os_s close os_s close os_s line 1201 line 1205 line 1208 line 1218 line 1220 line 1222 line 1230 line 1234 line 1237 line 1238 line 1240 line 1241
entry signals:
Time Frame - 1st ENTRY SIGNALChoose always a higher time frame than the current. Lower time frames than the current may result in false values.Currentstring · options ['Current', '5m', '10m', '15m', '30m', '1H', '2H', '3H', '4H', '6H', '12H', 'D', '3D', 'W', 'M']opt_sig_buy_1 opt_sig_sell_1
Time Frame - 2nd ENTRY SIGNALChoose always a higher time frame than the current. Lower time frames than the current may result in false values.Currentstring · options ['Current', '5m', '10m', '15m', '30m', '1H', '2H', '3H', '4H', '6H', '12H', 'D', '3D', 'W', 'M']opt_sig_buy_2 opt_sig_sell_2
--- 1st ENTRY SIGNAL ---Various entry signals. 1st ENTRY SIGNAL and 2nd ENTRY SIGNAL are OR connected.Price X Kumo sigstring · options ['---', 'Fractals trend lines sig (no tf filter)', 'Segments sig (no tf filter)', 'DMI ADX classic sig', 'DMI ADX mod sig', 'DMI ADX-slope sig', 'EMA1 x EMA2 sig', 'TRIX slope sig', 'ALMA slope sig', 'MACD(fast) slope sig', 'HMA slope sig', 'Grid - reentry sig (no tf filter)', 'Grid - counter trend sig (no tf filter)', 'Pin bar sig', 'Inside bar sig', 'Outside bar sig', 'Sandwich bar sig', 'Bar breakout 1 sig', 'Bar breakout 2 sig', 'Higher-low/lower-high bar sig', 'Entry on every bar-open sig', 'Fractals sig', 'Reverse fractal sig', 'SMA sig', 'RSI50 sig', 'Parabolic SAR sig', 'SuperTrend sig', 'Price X Kijun sig', 'Price X Kumo sig', 'Kumo flip sig', 'Chikou X price sig', 'Chikou X Kumo sig', 'Price X Tenkan sig', 'Tenkan X Kumo sig', 'Tenkan X Kijun sig', 'CB/CS sig (no tf filter)', 'IB/IS sig (no tf filter)', 'B1/S1 sig', 'B2/S2 sig']entry_opt_sig_buy_1 entry_opt_sig_sell_1 opt_sig_buy_11 opt_sig_sell_11
--- 2nd ENTRY SIGNAL --- (Enable Pyramiding Mode)Various entry signals. Signal 1 and signal 2 are OR connected. Works with pyramiding mode only---string · options ['---', 'Fractals trend lines sig (no tf filter)', 'Segments sig (no tf filter)', 'DMI ADX classic sig', 'DMI ADX mod sig', 'DMI ADX-slope sig', 'EMA1 x EMA2 sig', 'TRIX slope sig', 'ALMA slope sig', 'MACD(fast) slope sig', 'HMA slope sig', 'Grid - reentry sig (no tf filter)', 'Grid - counter trend sig (no tf filter)', 'Pin bar sig', 'Inside bar sig', 'Outside bar sig', 'Sandwich bar sig', 'Bar breakout 1 sig', 'Bar breakout 2 sig', 'Higher-low/lower-high bar sig', 'Entry on every bar-open sig', 'Fractals sig', 'Reverse fractal sig', 'SMA sig', 'RSI50 sig', 'Parabolic SAR sig', 'SuperTrend sig', 'Price X Kijun sig', 'Price X Kumo sig', 'Kumo flip sig', 'Chikou X price sig', 'Chikou X Kumo sig', 'Price X Tenkan sig', 'Tenkan X Kumo sig', 'Tenkan X Kijun sig', 'CB/CS sig (no tf filter)', 'IB/IS sig (no tf filter)', 'B1/S1 sig', 'B2/S2 sig']entry_opt_sig_buy_2 entry_opt_sig_sell_2 opt_sig_buy_22 opt_sig_sell_22
Entry filters:
Time Frame - Entry Filter 1The time frame for the 1st ENTRY SIGNAL filter. Choose always a higher time frame than the current. Lower time frames than the current may result in false values.Currentstring · options ['Current', '5m', '10m', '15m', '30m', '1H', '2H', '3H', '4H', '6H', '12H', 'D', '3D', 'W', 'M']entry_filter_buy_1 entry_filter_sell_1
Time Frame - Entry Filter 2The time frame for the 2st ENTRY SIGNAL filter. Choose always a higher time frame than the current. Lower time frames than the current may result in false values.Currentstring · options ['Current', '5m', '10m', '15m', '30m', '1H', '2H', '3H', '4H', '6H', '12H', 'D', '3D', 'W', 'M']entry_filter_buy_2 entry_filter_sell_2
Entry Filter 1Various entry filter signals. Entry filter 1 and Entry filter 2 are AND connected.---string · options ['---', 'Fractals trend lines filter (no tf filter)', 'Bar breakout 1 filter', 'Bar breakout 2 filter', 'SMA filter', 'MACD filter', 'EMA1 x EMA2 filter', 'RSI Stochastic filter', 'TRIX slope filter', 'ALMA slope filter','HMA slope filter', 'MACD(fast) slope filter', 'RSI50 filter', 'Segments filter (no tf filter)', 'Reverse fractal filter', 'Fractals filter', 'SuperTrend filter', 'Parabolic SAR filter', 'ADX Threshold filter', 'DMI filter', 'Price X Kumo filter', 'Price X Kijun filter', 'Kumo flip filter', 'Price filtered Kumo flip filter (no tf filter)', 'Chikou X price filter', 'Chikou X Kumo filter', 'Price X Tenkan filter', 'Tenkan X Kumo filter', 'Tenkan X Kijun filter', 'B1/S1 sig', 'B2/S2 sig', 'IB/IS sig (no tf filter)']entry_filter_sig_buy_1 entry_filter_sig_sell_1 entry_filter_buy_11 entry_filter_sell_11
Entry Filter 2Various entry filter signals. Filter 1 and filter 2 are AND connected.---string · options ['---', 'Fractals trend lines filter (no tf filter)', 'Bar breakout 1 filter', 'Bar breakout 2 filter', 'SMA filter', 'MACD filter', 'EMA1 x EMA2 filter', 'RSI Stochastic filter', 'TRIX slope filter', 'ALMA slope filter','HMA slope filter', 'MACD(fast) slope filter', 'RSI50 filter', 'Segments filter (no tf filter)', 'Reverse fractal filter', 'Fractals filter', 'SuperTrend filter', 'Parabolic SAR filter', 'ADX Threshold filter', 'DMI filter', 'Price X Kumo filter', 'Price X Kijun filter', 'Kumo flip filter', 'Price filtered Kumo flip filter (no tf filter)', 'Chikou X price filter', 'Chikou X Kumo filter', 'Price X Tenkan filter', 'Tenkan X Kumo filter', 'Tenkan X Kijun filter', 'B1/S1 sig', 'B2/S2 sig', 'IB/IS sig (no tf filter)']entry_filter_sig_buy_2 entry_filter_sig_sell_2 entry_filter_buy_22 entry_filter_sell_22
exit filters:
Time Frame - Exit Filter 1Choose always a higher time frame than the current. Lower time frames than the current may result in false values.Currentstring · options ['Current', '5m', '10m', '15m', '30m', '1H', '2H', '3H', '4H', '6H', '12H', 'D', '3D', 'W', 'M']exit_filter_buy_1 exit_filter_sell_1
Time Frame - Exit Filter 2Choose always a higher time frame than the current. Lower time frames than the current may result in false values.Currentstring · options ['Current', '5m', '10m', '15m', '30m', '1H', '2H', '3H', '4H', '6H', '12H', 'D', '3D', 'W', 'M']exit_filter_buy_2 exit_filter_sell_2
Exit Filter 1Some exit filter signals. Exit filter 1 and Exit filter 2 are OR connected.---string · options ['---', 'Reverse bar exit', 'Reverse fractal exit', 'Bar breakout 2 exit', 'SMA exit', 'MACD exit', 'MACD(fast) slope exit', 'RSI50 exit', 'RSI Stochastic exit', 'TRIX slope exit', 'HMA slope exit', 'EMA1 x EMA2 exit', 'Fractals exit', 'SuperTrend exit', 'Parabolic SAR exit', 'ADX Threshold exit', 'Cloud exit', 'Kijun exit', 'IB/IS exit (no tf filter)']exit_filter_sig_buy_1 exit_filter_sig_sell_1 exit_filter_sig_buy_11 exit_filter_sig_sell_11
Exit Filter 2Some exit filter signals. Exit filter 1 and Exit filter 2 are OR connected.---string · options ['---', 'Reverse bar exit', 'Reverse fractal exit', 'Bar breakout 2 exit', 'SMA exit', 'MACD exit', 'MACD(fast) slope exit', 'RSI50 exit', 'RSI Stochastic exit', 'TRIX slope exit', 'HMA slope exit', 'EMA1 x EMA2 exit', 'Fractals exit', 'SuperTrend exit', 'Parabolic SAR exit', 'ADX Threshold exit', 'Cloud exit', 'Kijun exit', 'IB/IS exit (no tf filter)']exit_filter_sig_buy_2 exit_filter_sig_sell_2 exit_filter_sig_buy_22 exit_filter_sig_sell_22
Live trading Parameter (does not affect backtesting):
Lot SizeAlertatron lot size string for Bybit exchange. Affects live trading only.300int · min 1 · step 100alert
Grid parameter:
Grid Gap - Base CurrencyThe minimum trigger-gap between two trades in case of a selected grid signal.500float · min 1 · step 50re_grid
Define the backtest period or start of trend:
Period start (no label in the script)Backtest period start.timestamp('13 Mar 2020 00:00 +0000')timeline 154
Period stop (no label in the script)Backtest period end.timestamp('31 Dec 2120 00:00 +0000')timeline 154
Take profit based on average position price:
Enable take Profit - Average Position Price ProfitProfit taking condition: current price >= average position price of positions + ATRtrueboolclose os_b close os_s line 1210 line 1224 line 1246 line 1247
Take Average Position Price Profit - Quantity Of Position (Percent)Reduction of the current position in percent.10float · min 1 · max 100 · step 5av_tp_qty_var close os_b close os_s
ATR LengthATR length for profit and step calculation50int · min 0 · step 5atr_sec
ATR Time FrameATR time frame for profit and step calculationWstring · options ['60', '120', '240', '480', '960', 'D', '3D', 'W', 'M']atr_sec
ATR FactorATR factor to increase/decrease ATR for profit and step calculation1float · min 0 · step 0.1atr_calc
Stop loss based on average position price:
Enable Stop Loss - Average Position Price LossStop loss condition: current price <= average position price of positions - \'Stop average-entry loss...\' AND current price <= average position price of positions - \'Stop loss step...\'trueboolclose os_b close os_s line 1213 line 1226 line 1250 line 1251
Stop Average Position Price Loss - Quantity Of Position (Percent)Reduction of the current position in percent.50float · min 0 · max 100 · step 5av_sl_qty_var close os_b close os_s
ATR LengthATR length for loss and step calculation50int · min 0 · step 5atr_sec_l
ATR Time FrameATR time frame for loss and step calculationWstring · options ['60', '120', '240', '480', '960', 'D', '3D', 'W', 'M']atr_sec_l
ATR FactorATR factor to increase/decrease ATR for loss and step calculation1float · min 0 · step 0.1atr_calc_l
Confluence signal offsets:
CB/CS Signal OffsetDecreasing this parameter increases the sensitivity of the signal.2float · min -6 · max 9 · step 1long_c short_c
IB/IS Signal OffsetDecreasing this parameter increases the sensitivity of the signal.0float · min -5 · max 4 · step 1long_pic short_pic
Shared filter and entry signal parameters:
Segment Max Bars10int · min 0 · step 1line 452 line 457 line 462 line 476 line 481 line 486
Pin Bar Sensitivity 1Condition: candle wick > candle body * \'Pin bar sensitivity\' . The smaller the factor, the more wicks are detected as part of a pin bar.0.6float · step 0.02pin_up_def pin_dn_def
Pin Bar Sensitivity 2Condition: high/low >< last two high/low\'.1int · min 1 · step 1pivot_up pivot_dn
Fractals Period2int · min 1up_fr dn_fr fractal_up_v fractal_dn_v
RSI Period14int · min 1rsi_f
SMA Period50int · min 1 · step 5sma_buy sma_sell sma_buy_f sma_sell_f
SuperTrend Multiplier3float · min 1 · step 0.2SuperTrend Dir
SuperTrend Length6int · min 1SuperTrend Dir
ADX DI Length10int · min 1diplus_s diminus_s adx_s
ADX Smooth10int · min 1diplus_s diminus_s adx_s
ADX Threshold25int · min 1 · step 2adx_above_thres long_2 short_2
ALMA Window Size9int · min 1 · step 1alma
ALMA Offset0.85float · min 0 · step 0.05alma
ALMA Sigma6float · min 1 · step 1alma
MACD MacdlLine Slope LenthMACD\'s fast line1int · min 1macd_slope_up_e macd_slope_dn_e macd_slope_up_f
HMA Length100int · min 1 · step 5hma_f
EMA1 Length10int · min 1 · step 2ema1_f
EMA2 Length20int · min 1 · step 2ema2_f
RSI-Stoch K-lineRSI Stochastic\'s fast line3int · min 1k_f
RSI-Stoch D-lineRSI Stochastic\'s slow line3int · min 1d_f
RSI-Stoch Stochastic Length14int · min 1k_f
RSI-Stoch RSI Length14int · min 1rsi_rs_f
TRIX Length10int · min 1trix_f
Exit filter Parameters:
Exit Fractals - Period2int · min 1up_fr_x dn_fr_x fractal_up_v_x fractal_dn_v_x
Exit Fractals - Past Fractal0int · min 0fractal_up_v_x fractal_dn_v_x
Exit RSI Period14int · min 1rsi_f_x
Exit SMA Period50int · min 1 · step 5sma_buy_x sma_sell_x
Exit SuperTrend Multiplier2float · min 1SuperTrend_x Dir_x
Exit SuperTrend Length5int · min 1SuperTrend_x Dir_x
Exit ADX Period10int · min 1diplus_f_x diminus_f_X adx_f_x
Exit ADX Smooth10int · min 1diplus_f_x diminus_f_X adx_f_x
Exit ADX Threshold25int · min 1 · step 2adx_thres_f_x
Exit MACD MacdlLine Slope LenthMACD\'s fast line1int · min 1macd_slope_up_x macd_slope_dn_x
Exit HMA Length100int · min 1 · step 5hma_x
Exit EMA1 Length10int · min 1 · step 2ema1_x
Exit EMA2 Length20int · min 1 · step 2ema2_x
Exit RSI-Stoch K-lineRSI Stochastic\'s fast line3int · min 1k_x
Exit RSI-Stoch D-lineRSI Stochastic\'s slow line3int · min 1d_x
Exit RSI-Stoch Stochastic Length14int · min 1k_x
Exit RSI-Stoch RSI Length14int · min 1rsi_rs_x
Exit TRIX Length10int · min 1trix_x

What it calculates

  • Lowest / HighestTKlengthTK · line 162
  • Lowest / HighestKJlengthKJ · line 163
  • Lowest / HighestSBlengthSB · line 165
  • Crossoverclose, KJkijun_buy · line 179
  • Crossoverclose, kumo_highkumo_buy · line 180
  • CrossoverSA, SBkumo_flip_buy · line 181
  • CrossoverCS, high[26 - 1]chikou_X_price_buy · line 182
  • CrossoverCS, kumo_high[26 - 1]chikou_X_kumo_buy · line 183
  • Crossoverclose, TKprice_X_tenkan_buy · line 184
  • CrossoverTK, kumo_hightenkan_X_kumo_buy · line 185
  • CrossoverTK, KJtenkan_X_kijun_buy · line 186
  • Crossunderclose, KJkijun_sell · line 187
  • Crossunderclose, kumo_lowkumo_sell · line 188
  • CrossunderSA, SBkumo_flip_sell · line 189
  • CrossunderCS, low[26 - 1]chikou_X_price_sell · line 190
  • CrossunderCS, kumo_low[26 - 1]chikou_X_kumo_sell · line 191
  • Crossunderclose, TKprice_X_tenkan_sell · line 192
  • CrossunderTK, kumo_lowtenkan_X_kumo_sell · line 193
  • CrossunderTK, KJtenkan_X_kijun_sell · line 194
  • Crossoverhigh, KJkijun_buy_x · line 215
  • Crossunderlow, KJkijun_sell_x · line 216
  • Crossoverhigh, kumo_highkumo_buy_x · line 217
  • Crossunderlow, kumo_lowkumo_sell_x · line 218
  • Risingtrix_f, 1trix_slo_up_f · line 244
  • RSIclose, RSI-Stoch RSI Length (14)rsi_rs_f · line 249
  • SMA / Stochta.stoch(rsi_rs_f, rsi_rs_f, rsi_rs_f, stoch_length_f), RSI-Stoch K-line (3)k_f · line 250
  • SMAk_f, RSI-Stoch D-line (3)d_f · line 251
  • RSIclose, Exit RSI-Stoch RSI Length (14)rsi_rs_x · line 256
  • SMA / Stochta.stoch(rsi_rs_x, rsi_rs_x, rsi_rs_x, stoch_length_x), Exit RSI-Stoch K-line (3)k_x · line 257
  • SMAk_x, Exit RSI-Stoch D-line (3)d_x · line 258
  • Risinghma_f, 1hma_up_f · line 268
  • Crossoverema1_f, ema2_fema_1x2_buy_s · line 293
  • Crossunderema1_f, ema2_fema_1x2_sell_s · line 294
  • Crossoverema1_x, ema2_xema_1x2_buy_x · line 296
  • Crossunderema1_x, ema2_xema_1x2_sell_x · line 297
  • ALMAclose, ALMA Window Size (9), ALMA Offset (0.85), ALMA Sigma (6)alma · line 299
  • Risingalma, 1alma_slo_up_f · line 304
  • MACDclose, 12, 26, 9macdLine_f · line 306
  • MACDclose, 12, 26, 9signalLine_f · line 306
  • MACDclose, 12, 26, 9histLine_f · line 306
  • CrossovermacdLine_f, signalLine_fmacd_buy_x · line 311
  • CrossundermacdLine_f, signalLine_fmacd_sell_x · line 312
  • RisingmacdLine_f, MACD MacdlLine Slope Lenth (1)macd_slope_up_f · line 318
  • Crossoverrsi_f, 50rsi_f_buy · line 325
  • Crossunderrsi_f, 50rsi_f_sell · line 326
  • Crossoverrsi_f_x, 50rsi_f_buy_x · line 332
  • Crossunderrsi_f_x, 50rsi_f_sell_x · line 333
  • PivothighFractals Period (2), Fractals Period (2)up_fr · line 335
  • PivotlowFractals Period (2), Fractals Period (2)dn_fr · line 336
  • Valuewhenup_fr, high[fr_period], 0fractal_up_v · line 337
  • Valuewhendn_fr, low[fr_period], 0fractal_dn_v · line 338
  • Crossoverhigh, fractal_up_vfr_upx · line 340
  • Crossunderlow, fractal_dn_vfr_dnx · line 341
  • PivothighExit Fractals - Period (2), Exit Fractals - Period (2)up_fr_x · line 346
  • PivotlowExit Fractals - Period (2), Exit Fractals - Period (2)dn_fr_x · line 347
  • Valuewhenup_fr_x, high[fr_period_x], Exit Fractals - Past Fractal (0)fractal_up_v_x · line 348
  • Valuewhendn_fr_x, low[fr_period_x], Exit Fractals - Past Fractal (0)fractal_dn_v_x · line 349
  • Crossoverhigh, fractal_up_v_xfr_upx_x · line 350
  • Crossunderlow, fractal_dn_v_xfr_dnx_x · line 351
  • SupertrendSuperTrend Multiplier (3), SuperTrend Length (6)SuperTrend · line 354
  • SupertrendSuperTrend Multiplier (3), SuperTrend Length (6)Dir · line 354
  • Crossoverhigh, SuperTrendsup_buy · line 355
  • Crossunderlow, SuperTrendsup_sell · line 356
  • SupertrendExit SuperTrend Multiplier (2), Exit SuperTrend Length (5)SuperTrend_x · line 361
  • SupertrendExit SuperTrend Multiplier (2), Exit SuperTrend Length (5)Dir_x · line 361
  • Crossoverhigh, SuperTrend_xsup_buy_x · line 362
  • Crossunderlow, SuperTrend_xsup_sell_x · line 363
  • Crossover / SARhigh, ta.sar(start, inc, max)[0]psar_buy · line 365
  • Crossunder / SARlow, ta.sar(start, inc, max)[0]psar_sell · line 366
  • Crossover / SARhigh, ta.sar(start, inc, max)[0]psar_buy_x · line 370
  • Crossunder / SARlow, ta.sar(start, inc, max)[0]psar_sell_x · line 371
  • DMIExit ADX Period (10), Exit ADX Smooth (10)diplus_f_x · line 374
  • DMIExit ADX Period (10), Exit ADX Smooth (10)diminus_f_X · line 374
  • DMIExit ADX Period (10), Exit ADX Smooth (10)adx_f_x · line 374
  • Crossunderadx_f_x, Exit ADX Threshold (25)adx_thres_f_x · line 375
  • DMIADX DI Length (10), ADX Smooth (10)diplus_s · line 377
  • DMIADX DI Length (10), ADX Smooth (10)diminus_s · line 377
  • DMIADX DI Length (10), ADX Smooth (10)adx_s · line 377
  • Risingadx_s, 1adx_slope_up · line 379
  • Crossoverdiplus_s, diminus_slong_1 · line 384
  • Crossunderdiplus_s, diminus_sshort_1 · line 385
  • Crossoverdiplus_s, diminus_slong_2 · line 386
  • Crossunderdiplus_s, diminus_sshort_2 · line 387
  • Crossoverclose[1], f_sma(ma_period)sma_buy · line 393
  • Crossunderclose[1], f_sma(ma_period)sma_sell · line 394
  • Crossoverclose[1], f_sma(ma_period_x)sma_buy_x · line 399
  • Crossunderclose[1], f_sma(ma_period_x)sma_sell_x · line 400
  • Pivothigh2, 2up_w_fr · line 402
  • Pivotlow2, 2dn_w_fr · line 403
  • Valuewhenup_w_fr, high[2], 1y1_frup_1 · line 404
  • Valuewhenup_w_fr, high[2], 0y0_frup_0 · line 405
  • Valuewhendn_w_fr, low[2], 1y1_frdn_1 · line 406
  • Valuewhendn_w_fr, low[2], 0y0_frdn_0 · line 407
  • Crossoverhigh, y_up_lvlbuy_up_line · line 439
  • Crossunderlow, y_dn_lvlsell_dn_line · line 440
  • Pivothighhigh, Pin Bar Sensitivity 2 (1), 0pivot_up · line 508
  • Pivotlowlow, Pin Bar Sensitivity 2 (1), 0pivot_dn · line 509
  • MACDclose, 12, 26, 9macdLine · line 532
  • MACDclose, 12, 26, 9signalLine · line 532
  • MACDclose, 12, 26, 9histLine · line 532
  • DMI7, 7diplus · line 534
  • DMI7, 7diminus · line 534
  • DMI7, 7adx · line 534
  • Supertrend2, 5superTrend · line 535
  • Supertrend2, 5dir · line 535
  • Changehlc3sv · line 537
  • EMAsv, 34kvo · line 538
  • EMAkvo, 13sig · line 539
  • ATR1STR · line 543
  • Risingf_hma(15), 1hma_slo_up · line 547
  • Rising / ALMAta.alma(close, 9, 0.85, 6), 1alma_slo_up · line 549
  • RisingmacdLine, 1macd_slo_up · line 551
  • Crossoverbs_conf_sig, (long_short_trig + trig_gap_cbcs)long_c · line 650
  • Crossunderbs_conf_sig, (long_short_trig - trig_gap_cbcs)short_c · line 651
  • Crossoverbs_pic_sig, pic_l_s_trig + trig_gap_ibislong_pic · line 711
  • Crossunderbs_pic_sig, pic_l_s_trig - trig_gap_ibisshort_pic · line 712
  • ATRATR Length (50) · chosen by ATR Time Frameatr_sec · line 1162
  • ATRATR Length (50) · chosen by ATR Time Frameatr_sec_l · line 1171

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 344 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.

Order rules

OrderFires whenBy defaultLine
Open os_b longentry_long_1On1200
Open os_b longone_side_pyr and entry_long_2On1202
Close os_bnot both and not one_side_pyr ? exit_long_2 : exit_long_1On1206
Close os_bnot both and one_side_pyr ? exit_long_1 and not exit_long_1[1] : naOn1209
Close os_bav_tp_en and av_profit_lOn1211
Close os_bsl_en and sl_t_lOn1214
Open os_s shortentry_short_1On1217
Open os_s shortone_side_pyr and entry_short_2On1219
Close os_snot both and not one_side_pyr ? exit_short_2 : exit_short_1On1221
Close os_snot both and one_side_pyr ? exit_short_1 and not exit_short_1[1] : naOn1223
Close os_sav_tp_en and av_profit_sOn1225
Close os_ssl_en and sl_t_sOn1227

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Alerts

AlertCallMessageLine
(no title)alertBybitAPI(BTCUSD) { continue(if=positionShort); market(position= 0); } BybitAPI(BTCUSD) { wait(0.5s); market(side=buy, amount=' + str.tostring(lot_size) + '); } \n #bot1231
(no title)alertBybitAPI(BTCUSD) { continue(if=positionLong); market(position= 0); } BybitAPI(BTCUSD) { wait(0.5s); market(side=sell, amount=' + str.tostring(lot_size) + '); } \n #bot1235
(no title)alertBybitAPI(BTCUSD) { market(position= 0 %p); } \n #bot1243
(no title)alertBybitAPI(BTCUSD) { market(position=' + str.tostring(av_tp_qty_var) + '%p); } \n #bot1249
(no title)alertBybitAPI(BTCUSD) { market(position=' + str.tostring(av_sl_qty_var) + '%p); } \n #bot1253

Does it repaint?

No

No repainting patterns in the source, and the live replay matched history.

8/8trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • ClearHigher-timeframe data3 request.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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D+10.3%+102.5%5763%1.2716.6%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+5.2%+5.5%2250%1.535.1%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+0.9%+9.8%4367%1.460.8%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.0%+8.4%3023%0.990.4%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.0%+16.7%4955%1.020.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%2035%2.030.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.3%+148.3%5576%2.520.1%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.1%+17.1%3421%0.420.1%8 May 2026 – 21 Oct 2026

Higher-timeframe data for request.security(): BINANCE:BTCUSDT W (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 barsTradesWonP&L
Rising market1547%−$785.90
Sideways market3969%$1,232.77
Falling market367%$584.16

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

17.1%

The 95th percentile of the worst drawdown when the same 57 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 7.5% to 17.1%; the tick is what actually happened, 15.8%. Order luck alone moves it this much.

0%20%
All 57 trades
SideEntryExitBarsP&L
long12 Apr 2024 70,006.2014 Apr 2024 63,924.502−$154.55
long12 Apr 2024 70,006.2018 Apr 2024 61,277.406−$110.34
long12 Apr 2024 70,006.201 May 2024 60,672.0019−$58.95
long12 Apr 2024 70,006.201 May 2024 60,672.0019−$58.95
short1 May 2024 60,672.0018 May 2024 67,024.0017−$322.39
long18 May 2024 67,024.0021 May 2024 71,446.603$21.59
long18 May 2024 67,024.0022 Jun 2024 64,143.6035−$134.05
short22 Jun 2024 64,143.606 Jul 2024 56,628.8014$37.12
short22 Jun 2024 64,143.6020 Jul 2024 66,660.0028−$117.66
long20 Jul 2024 66,660.003 Aug 2024 61,498.3014−$131.44
long20 Jul 2024 66,660.005 Aug 2024 58,161.0016−$214.82
short5 Aug 2024 58,161.0024 Aug 2024 64,037.2019−$149.20
short5 Aug 2024 58,161.0014 Sep 2024 60,498.0040−$60.65
long14 Sep 2024 60,498.0016 Sep 2024 59,132.002−$72.79
short16 Sep 2024 59,132.0018 Sep 2024 60,314.002−$63.58
long18 Sep 2024 60,314.0015 Oct 2024 66,084.0027$28.38
long18 Sep 2024 60,314.0030 Oct 2024 72,736.4042$55.45
long18 Sep 2024 60,314.007 Nov 2024 75,572.0050$61.38
long18 Sep 2024 60,314.0011 Nov 2024 80,370.0054$72.72
long18 Sep 2024 60,314.0012 Nov 2024 88,648.0055$92.58
long18 Sep 2024 60,314.0021 Nov 2024 94,286.6064$99.96
long18 Sep 2024 60,314.006 Dec 2024 96,945.6079$97.02
long18 Sep 2024 60,314.0016 Dec 2024 104,464.0089$105.29
long18 Sep 2024 60,314.0016 Jan 2025 100,497.00120$86.23
long18 Sep 2024 60,314.0021 Jan 2025 102,260.00125$81.02
long18 Sep 2024 60,314.003 Feb 2025 97,700.60138$649.73
short3 Feb 2025 97,700.604 Feb 2025 101,329.001−$188.86
long4 Feb 2025 101,329.005 Feb 2025 97,763.101−$185.73
short5 Feb 2025 97,763.1026 Feb 2025 88,680.4021$44.71
short5 Feb 2025 97,763.101 Mar 2025 84,349.9024$59.74
short5 Feb 2025 97,763.104 Mar 2025 86,221.2027$46.19
short5 Feb 2025 97,763.1011 Mar 2025 78,595.9034$69.38
short5 Feb 2025 97,763.107 Apr 2025 78,430.0061$62.99
short5 Feb 2025 97,763.1023 Apr 2025 93,443.0077$123.32
long23 Apr 2025 93,443.009 May 2025 103,262.0016$48.36
long23 Apr 2025 93,443.0022 May 2025 109,644.0029$72.22
long23 Apr 2025 93,443.0010 Jun 2025 110,263.0048$67.50
long23 Apr 2025 93,443.0030 Jun 2025 108,357.0068$53.81
long23 Apr 2025 93,443.0011 Jul 2025 116,010.0079$73.52
long23 Apr 2025 93,443.0014 Aug 2025 123,306.00113$87.69
long23 Apr 2025 93,443.0026 Aug 2025 110,112.00125$438.87
short26 Aug 2025 110,112.0019 Sep 2025 117,074.0024−$356.60
long19 Sep 2025 117,074.0023 Sep 2025 112,651.004−$229.74
short23 Sep 2025 112,651.002 Oct 2025 118,595.009−$305.87
long2 Oct 2025 118,595.0011 Oct 2025 112,774.009−$299.70
short11 Oct 2025 112,774.005 Nov 2025 101,497.0025$55.58
short11 Oct 2025 112,774.0017 Nov 2025 94,261.4037$82.61
short11 Oct 2025 112,774.0021 Nov 2025 86,637.2041$105.25
short11 Oct 2025 112,774.0015 Jan 2026 96,951.8096$571.00
long15 Jan 2026 96,951.8026 Jan 2026 86,670.4011−$520.96
short26 Jan 2026 86,670.406 Feb 2026 62,909.9011$118.24
short26 Jan 2026 86,670.4016 Apr 2026 74,810.0080$528.27
long16 Apr 2026 74,810.001 Jun 2026 73,674.4046−$62.35
short1 Jun 2026 73,674.4026 Jun 2026 59,794.6025$68.90
short1 Jun 2026 73,674.4019 Aug 2026 64,725.4079$398.03
long19 Aug 2026 64,725.4022 Aug 2026 78,338.003$67.53
long19 Aug 2026 64,725.4022 Sep 2026 86,620.0034$98.01

Similar scripts

Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.

ScriptSharesTypeNetTradesMax drawdown
The Strategy - Ichimoku Kinko Hyo and more this page—v5 strategy+10.3%5716.6%
Grid Tool by ramsay09lowest rising falling pivothigh pivotlow valuewhen alma macd rsi supertrend dmiv5 strategyNo trades on this market
VXD Supercycle by Vvaz_supertrend ema sma pivothigh pivotlow valuewhen highest lowest rsiv5 strategydoes not run in Zeal Terminal
supertrend with multiple filter strategy by mathlabelsupertrend sma highest lowest macd ema atr stoch pivothigh pivotlow rsiv5 strategydoes not run in Zeal Terminal
X48 - Strategy - MA Type Cross + TPSL - Future&Spot - V.2 by X4815162342ema rsi sma highest lowest pivothigh pivotlow valuewhenv5 strategydoes not run in Zeal Terminal
-Backtesting System by HALDROalma dmi rising falling highest lowest rsi atrv5 strategy+1.2%22.6%

Upgrade and export

Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.

  • No v6-only features. v6 is not needed to run this script.

Clean v5

Verified

Nothing to change.

Does it run in Pine Script v6?

Yes

Same 57 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. It differs from the v5 version by 1 edit.

Download the v6 script

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/-//@version=5+//@version=6strategy(title='The Strategy - Ichimoku Kinko Hyo and more', shorttitle='Strategy', overlay=true, initial_capital=10000, pyramiding=1, default_qty_type=strategy.fixed, default_qty_value=0.05, currency=currency.USD, ⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 400 msWith a workaround 1,000 bars in 790 msNot measured
PineTSNot testedNot testedNot 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.

Source

Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0///@version=5strategy(title='The Strategy - Ichimoku Kinko Hyo and more', shorttitle='Strategy', overlay=true, initial_capital=10000, pyramiding=1, default_qty_type=strategy.fixed, default_qty_value=0.05, currency=currency.USD,              commission_type=strategy.commission.percent, commission_value=0.075, margin_long=0, margin_short=0)//-------------------------------------------------------------------- inputs ---------------------------------------------------------------general_info        = input.bool(title='General Description', defval=false,                      tooltip='This script offers you the opportunity to backtest many signals and filters to compare the results.  Make yourself familiar with the signals and the options and become creative ...                       At least you will be able to see what and on what circumstances works or not. Note the \'KISS\' principle and that \'context\' matters.                       The key feature of technical analysis is that every market participant is an interface to the world or market-environment and all market relevant information is visible in the chart.                       The default values are suitable for Bitcoin on ByBit (one tick = 0.5). Deselect \'Signal Labels\' at strategy properties -> Style to avoid signal label strings.')entry_type          = input.string('Both', title='Position Entry-Direction', options=['Both', 'Long', 'Short'],                      tooltip='Long= long entries only, Short= short entries only, Both= long and short entries are possible.')repaint             = input.string('Allowed', title='Repainting', options=['Not allowed', 'Allowed'],                      tooltip='If repainting "Not allowed" is selected, then signals from higher time frames have a lag of an additional bar from the higher time frame but you trade what you have backtested.                       Otherwise singals can occure multiple times as long as the higher time frame bar is not closed but the first signal of these possible multiple signals is much earlier.')panel               = input.bool(true, title='Plot Info Panel', tooltip='Info panel for current unrealized profit or loss for the open position')plot_avg_price      = input.bool(true, title='Plot Position Avarage Price Line.',                      tooltip='This plots the position avarage price line.')one_side_pyr        = input.bool(title='Pyramiding Mode', defval=false,                      tooltip='If disabled: as long as the signal is valid a new trade can be opened on each bar (more filter sensitive). If not \'Both\' as direction is selected,                       the opposite signal closes the current position. If enabled: a new trade is opened with every signal. Use Properties -> Pyramiding to increase the maximum amount of orders.')htf_entr_opt_1      = input.string('Current', title='Time Frame - 1st ENTRY SIGNAL', options=['Current', '5m', '10m', '15m', '30m', '1H', '2H', '3H', '4H', '6H', '12H', 'D', '3D', 'W', 'M'],                      tooltip='Choose always a higher time frame than the current. Lower time frames than the current may result in false values.', group='entry signals:')htf_entr_opt_2      = input.string('Current', title='Time Frame - 2nd ENTRY SIGNAL', options=['Current', '5m', '10m', '15m', '30m', '1H', '2H', '3H', '4H', '6H', '12H', 'D', '3D', 'W', 'M'],                      tooltip='Choose always a higher time frame than the current. Lower time frames than the current may result in false values.', group='entry signals:')X_opt               = input.string('Price X Kumo sig', title='--- 1st ENTRY SIGNAL ---', options=['---', 'Fractals trend lines sig (no tf filter)', 'Segments sig (no tf filter)',                      'DMI ADX classic sig', 'DMI ADX mod sig', 'DMI ADX-slope sig', 'EMA1 x EMA2 sig', 'TRIX slope sig', 'ALMA slope sig', 'MACD(fast) slope sig', 'HMA slope sig',                      'Grid - reentry sig (no tf filter)', 'Grid - counter trend sig (no tf filter)', 'Pin bar sig', 'Inside bar sig', 'Outside bar sig', 'Sandwich bar sig', 'Bar breakout 1 sig', 'Bar breakout 2 sig',                      'Higher-low/lower-high bar sig', 'Entry on every bar-open sig', 'Fractals sig', 'Reverse fractal sig', 'SMA sig',                      'RSI50 sig', 'Parabolic SAR sig', 'SuperTrend sig', 'Price X Kijun sig', 'Price X Kumo sig', 'Kumo flip sig',                      'Chikou X price sig', 'Chikou X Kumo sig', 'Price X Tenkan sig', 'Tenkan X Kumo sig', 'Tenkan X Kijun sig', 'CB/CS sig (no tf filter)', 'IB/IS sig (no tf filter)', 'B1/S1 sig', 'B2/S2 sig'],                      tooltip='Various entry signals. 1st ENTRY SIGNAL and 2nd ENTRY SIGNAL are OR connected.', group='entry signals:')X_opt_2             = input.string('---', title='--- 2nd ENTRY SIGNAL --- (Enable Pyramiding Mode)', options=['---', 'Fractals trend lines sig (no tf filter)', 'Segments sig (no tf filter)',                      'DMI ADX classic sig', 'DMI ADX mod sig', 'DMI ADX-slope sig', 'EMA1 x EMA2 sig', 'TRIX slope sig', 'ALMA slope sig', 'MACD(fast) slope sig', 'HMA slope sig',                       'Grid - reentry sig (no tf filter)', 'Grid - counter trend sig (no tf filter)', 'Pin bar sig', 'Inside bar sig', 'Outside bar sig', 'Sandwich bar sig', 'Bar breakout 1 sig', 'Bar breakout 2 sig',                      'Higher-low/lower-high bar sig', 'Entry on every bar-open sig', 'Fractals sig', 'Reverse fractal sig', 'SMA sig',                      'RSI50 sig', 'Parabolic SAR sig', 'SuperTrend sig', 'Price X Kijun sig', 'Price X Kumo sig', 'Kumo flip sig',                      'Chikou X price sig', 'Chikou X Kumo sig', 'Price X Tenkan sig', 'Tenkan X Kumo sig', 'Tenkan X Kijun sig', 'CB/CS sig (no tf filter)', 'IB/IS sig (no tf filter)', 'B1/S1 sig', 'B2/S2 sig'],                      tooltip='Various entry signals. Signal 1 and signal 2 are OR connected. Works with pyramiding mode only', group='entry signals:')htf_filt_opt_1      = input.string('Current', title='Time Frame - Entry Filter 1', options=['Current', '5m', '10m', '15m', '30m', '1H', '2H', '3H', '4H', '6H', '12H', 'D', '3D', 'W', 'M'],                      tooltip='The time frame for the 1st ENTRY SIGNAL filter. Choose always a higher time frame than the current. Lower time frames than the current may result in false values.', group='Entry filters:')htf_filt_opt_2      = input.string('Current', title='Time Frame - Entry Filter 2', options=['Current', '5m', '10m', '15m', '30m', '1H', '2H', '3H', '4H', '6H', '12H', 'D', '3D', 'W', 'M'],                      tooltip='The time frame for the 2st ENTRY SIGNAL filter. Choose always a higher time frame than the current. Lower time frames than the current may result in false values.', group='Entry filters:')entry_f_1           = input.string('---', title='Entry Filter 1', options=['---', 'Fractals trend lines filter (no tf filter)', 'Bar breakout 1 filter', 'Bar breakout 2 filter', 'SMA filter', 'MACD filter',                      'EMA1 x EMA2 filter', 'RSI Stochastic filter', 'TRIX slope filter', 'ALMA slope filter','HMA slope filter',                       'MACD(fast) slope filter', 'RSI50 filter', 'Segments filter (no tf filter)', 'Reverse fractal filter', 'Fractals filter',                      'SuperTrend filter', 'Parabolic SAR filter', 'ADX Threshold filter', 'DMI filter', 'Price X Kumo filter', 'Price X Kijun filter', 'Kumo flip filter', 'Price filtered Kumo flip filter (no tf filter)',                      'Chikou X price filter', 'Chikou X Kumo filter', 'Price X Tenkan filter', 'Tenkan X Kumo filter', 'Tenkan X Kijun filter', 'B1/S1 sig', 'B2/S2 sig', 'IB/IS sig (no tf filter)'], group='Entry filters:',                      tooltip='Various entry filter signals. Entry filter 1 and Entry filter 2 are AND connected.')entry_f_2           = input.string('---', title='Entry Filter 2', options=['---', 'Fractals trend lines filter (no tf filter)', 'Bar breakout 1 filter', 'Bar breakout 2 filter', 'SMA filter', 'MACD filter',                      'EMA1 x EMA2 filter', 'RSI Stochastic filter', 'TRIX slope filter', 'ALMA slope filter','HMA slope filter',                       'MACD(fast) slope filter', 'RSI50 filter', 'Segments filter (no tf filter)', 'Reverse fractal filter', 'Fractals filter',                     'SuperTrend filter', 'Parabolic SAR filter', 'ADX Threshold filter', 'DMI filter', 'Price X Kumo filter', 'Price X Kijun filter', 'Kumo flip filter', 'Price filtered Kumo flip filter (no tf filter)',                      'Chikou X price filter', 'Chikou X Kumo filter', 'Price X Tenkan filter', 'Tenkan X Kumo filter', 'Tenkan X Kijun filter', 'B1/S1 sig', 'B2/S2 sig', 'IB/IS sig (no tf filter)'], group='Entry filters:',                      tooltip='Various entry filter signals. Filter 1 and filter 2 are AND connected.')htf_exit_opt_1      = input.string('Current', title='Time Frame - Exit Filter 1', options=['Current', '5m', '10m', '15m', '30m', '1H', '2H', '3H', '4H', '6H', '12H', 'D', '3D', 'W', 'M'],                      tooltip='Choose always a higher time frame than the current. Lower time frames than the current may result in false values.', group='exit filters:')htf_exit_opt_2      = input.string('Current', title='Time Frame - Exit Filter 2', options=['Current', '5m', '10m', '15m', '30m', '1H', '2H', '3H', '4H', '6H', '12H', 'D', '3D', 'W', 'M'],                      tooltip='Choose always a higher time frame than the current. Lower time frames than the current may result in false values.', group='exit filters:')exit_f_1            = input.string('---', title='Exit Filter 1', options=['---', 'Reverse bar exit', 'Reverse fractal exit', 'Bar breakout 2 exit', 'SMA exit', 'MACD exit', 'MACD(fast) slope exit',  'RSI50 exit',                      'RSI Stochastic exit', 'TRIX slope exit',                      'HMA slope exit', 'EMA1 x EMA2 exit', 'Fractals exit', 'SuperTrend exit', 'Parabolic SAR exit', 'ADX Threshold exit', 'Cloud exit', 'Kijun exit', 'IB/IS exit (no tf filter)'], group='exit filters:',                      tooltip='Some exit filter signals. Exit filter 1 and Exit filter 2 are OR connected.')exit_f_2            = input.string('---', title='Exit Filter 2', options=['---', 'Reverse bar exit', 'Reverse fractal exit', 'Bar breakout 2 exit', 'SMA exit', 'MACD exit', 'MACD(fast) slope exit', 'RSI50 exit',                      'RSI Stochastic exit', 'TRIX slope exit',                      'HMA slope exit', 'EMA1 x EMA2 exit', 'Fractals exit', 'SuperTrend exit', 'Parabolic SAR exit', 'ADX Threshold exit', 'Cloud exit', 'Kijun exit', 'IB/IS exit (no tf filter)'], group='exit filters:',                      tooltip='Some exit filter signals. Exit filter 1 and Exit filter 2 are OR connected.')//------------------------ lot size for live trading --------------------------//Alertatron lot size on Bybitlot_size            = input.int(300, title='Lot Size', minval=1, step=100,                      tooltip='Alertatron lot size string for Bybit exchange. Affects live trading only.', group='Live trading Parameter (does not affect backtesting):')grid_gap            = input.float(500, title='Grid Gap - Base Currency', minval=1, step=50, group='Grid parameter:', tooltip='The minimum trigger-gap between two trades in case of a selected grid signal.')//------------------------ Backtest periode inputs ----------------------------period_start        = input.time(title='', inline='start_timestamp', defval=timestamp('13 Mar 2020 00:00 +0000'), group='Define the backtest period or start of trend:', tooltip='Backtest period start.')period_stop         = input.time(title='', inline='end_timestamp', defval=timestamp('31 Dec 2120 00:00 +0000'), group='Define the backtest period or start of trend:', tooltip='Backtest period end.')//---------------------- take profit inputs -----------------------------av_tp_en            = input.bool(title='Enable take Profit - Average Position Price Profit', defval=true, group='Take profit based on average position price:', tooltip='Profit taking condition:                      current price >= average position price of positions + ATR')av_tp_qty           = input.float(10, title='Take Average Position Price Profit - Quantity Of Position (Percent)', minval=1, step=5, maxval=100, group='Take profit based on average position price:',                      tooltip='Reduction of the current position in percent.')atr_l               = input.int(50, title='ATR Length', minval=0, step=5, group='Take profit based on average position price:',                      tooltip='ATR length for profit and step calculation')atr_tf              = input.string('W', title='ATR Time Frame', options=['60', '120', '240', '480', '960', 'D', '3D', 'W', 'M'], group='Take profit based on average position price:',                      tooltip='ATR time frame for profit and step calculation')atr_fact            = input.float(1, title='ATR Factor', minval=0, step=0.1, group='Take profit based on average position price:',                      tooltip='ATR factor to increase/decrease ATR for profit and step calculation')//---------------------- stop loss inputs --------------------------sl_en               = input.bool(title='Enable Stop Loss - Average Position Price Loss', defval=true, group='Stop loss based on average position price:',                      tooltip='Stop loss condition: current price <= average position price of positions - \'Stop average-entry loss...\' AND current price <= average position price of positions -                      \'Stop loss step...\'')av_sl_qty           = input.float(50, title='Stop Average Position Price Loss - Quantity Of Position (Percent)', minval=0, step=5, maxval=100, group='Stop loss based on average position price:',                      tooltip='Reduction of the current position in percent.')atr_l_l             = input.int(50, title='ATR Length', minval=0, step=5, group='Stop loss based on average position price:', tooltip='ATR length for loss and step calculation')atr_tf_l            = input.string('W', title='ATR Time Frame', options=['60', '120', '240', '480', '960', 'D', '3D', 'W', 'M'], group='Stop loss based on average position price:',                      tooltip='ATR time frame for loss and step calculation')atr_fact_l          = input.float(1, title='ATR Factor', minval=0, step=0.1, group='Stop loss based on average position price:', tooltip='ATR factor to increase/decrease ATR for loss and step calculation')//------------------------ Signal inputs CB/CS and IB/IS ---------------------------trig_gap_cbcs       = input.float(2, title='CB/CS Signal Offset', minval=-6, maxval=9, step=1, group='Confluence signal offsets:', tooltip='Decreasing this parameter increases the sensitivity of the signal.')trig_gap_ibis       = input.float(0, title='IB/IS Signal Offset', minval=-5, maxval=4, step=1, group='Confluence signal offsets:', tooltip='Decreasing this parameter increases the sensitivity of the signal.')//----------------------- entry signals and filters -----------------------sb                  = input.int(10, title='Segment Max Bars', minval=0, step=1, group='Shared filter and entry signal parameters:')p_bar_sens_1        = input.float(0.6, title='Pin Bar Sensitivity 1', step=0.02, tooltip='Condition: candle wick > candle body * \'Pin bar sensitivity\' .                       The smaller the factor, the more wicks are detected as part of a pin bar.', group='Shared filter and entry signal parameters:')p_bar_sens_2        = input.int(1, title='Pin Bar Sensitivity 2', step=1, minval=1, tooltip='Condition: high/low >< last two high/low\'.', group='Shared filter and entry signal parameters:')fr_period           = input.int(2, title='Fractals Period', minval=1, group='Shared filter and entry signal parameters:')rsi_period          = input.int(14, title='RSI Period', minval=1, group='Shared filter and entry signal parameters:')ma_period           = input.int(50, title='SMA Period', minval=1, step=5, group='Shared filter and entry signal parameters:')mult                = input.float(3, title='SuperTrend Multiplier', minval=1, step=0.2, group='Shared filter and entry signal parameters:')len                 = input.int(6, title='SuperTrend Length', minval=1, group='Shared filter and entry signal parameters:')start               = 0.02  //input(0.02, title= "PSAR Start (Filter/Entry)", minval= 0)inc                 = 0.02  //input(0.02, title= "PSAR Increment (Filter/Entry)", minval= 0)max                 = 0.2  //input(.2, title= "PSAR Maximum (Filter/Entry)", minval= 0)di_length_s         = input.int(10, title='ADX DI Length', minval=1, group='Shared filter and entry signal parameters:')adx_smooth_s        = input.int(10, title='ADX Smooth', minval=1, group='Shared filter and entry signal parameters:')adx_thres_s         = input.int(25, title='ADX Threshold', step=2, minval=1, group='Shared filter and entry signal parameters:')windowsize          = input.int(9, title="ALMA Window Size", minval=1, step=1, group='Shared filter and entry signal parameters:', tooltip='')offset              = input.float(0.85, title="ALMA Offset", minval=0, step=0.05, group='Shared filter and entry signal parameters:', tooltip='')sigma               = input.float(6, title="ALMA Sigma", minval=1, step=1, group='Shared filter and entry signal parameters:', tooltip='')slope_len           = input.int(1, minval=1, title='MACD MacdlLine Slope Lenth', tooltip='MACD\'s fast line', group='Shared filter and entry signal parameters:')hma_len_f           = input.int(100, minval=1, step=5, title='HMA Length', group='Shared filter and entry signal parameters:')ema1_len_f          = input.int(10, minval=1, step=2, title='EMA1 Length', group='Shared filter and entry signal parameters:')ema2_len_f          = input.int(20, minval=1, step=2, title='EMA2 Length', group='Shared filter and entry signal parameters:')k_smoo_f            = input.int(3, title='RSI-Stoch K-line', minval=1, tooltip='RSI Stochastic\'s fast line', group='Shared filter and entry signal parameters:')d_smoo_f            = input.int(3, title='RSI-Stoch D-line', minval=1, tooltip='RSI Stochastic\'s slow line', group='Shared filter and entry signal parameters:')stoch_length_f      = input.int(14, title='RSI-Stoch Stochastic Length', minval=1, group='Shared filter and entry signal parameters:')rsi_length_sto_f    = input.int(14, title='RSI-Stoch RSI Length', minval=1, group='Shared filter and entry signal parameters:')trix_len_f          = input.int(10, title="TRIX Length", minval=1, group='Shared filter and entry signal parameters:')// exit filtersfr_period_x         = input.int(2, title='Exit Fractals - Period', minval=1, group='Exit filter Parameters:')fr_past_x           = input.int(0, title='Exit Fractals - Past Fractal', minval=0, group='Exit filter Parameters:')rsi_period_x        = input.int(14, title='Exit RSI Period', minval=1, group='Exit filter Parameters:')ma_period_x         = input.int(50, title='Exit SMA Period', step=5, minval=1, group='Exit filter Parameters:')mult_x              = input.float(2, title='Exit SuperTrend Multiplier', minval=1, group='Exit filter Parameters:')len_x               = input.int(5, title='Exit SuperTrend Length', minval=1, group='Exit filter Parameters:')di_length_x         = input.int(10, title='Exit ADX Period', minval=1, group='Exit filter Parameters:')adx_smooth_x        = input.int(10, title='Exit ADX Smooth', minval=1, group='Exit filter Parameters:')adx_thres_x         = input.int(25, title='Exit ADX Threshold', step=2, minval=1, group='Exit filter Parameters:')slope_len_x         = input.int(1, title='Exit MACD MacdlLine Slope Lenth', minval=1, tooltip='MACD\'s fast line', group='Exit filter Parameters:')hma_len_x           = input.int(100, minval=1, step=5, title='Exit HMA Length', group='Exit filter Parameters:')ema1_len_x          = input.int(10, title='Exit EMA1 Length', minval=1, step=2, group='Exit filter Parameters:')ema2_len_x          = input.int(20, title='Exit EMA2 Length', minval=1, step=2, group='Exit filter Parameters:')k_smoo_x            = input.int(3, title='Exit RSI-Stoch K-line', minval=1, tooltip='RSI Stochastic\'s fast line', group='Exit filter Parameters:')d_smoo_x            = input.int(3, title='Exit RSI-Stoch D-line', minval=1, tooltip='RSI Stochastic\'s slow line', group='Exit filter Parameters:')stoch_length_x      = input.int(14, title='Exit RSI-Stoch Stochastic Length', minval=1, group='Exit filter Parameters:')rsi_length_sto_x    = input.int(14, title='Exit RSI-Stoch RSI Length', minval=1, group='Exit filter Parameters:')trix_len_x          = input.int(10, title="Exit TRIX Length", minval=1, group='Exit filter Parameters:')//--------------- Current unrealized profit or loss for the open position -------------------if panel    var info_panel = table.new(position = position.bottom_left, columns = 1, rows = 1, bgcolor=color.new(color.blue, 92), frame_width=1, border_width=1)    text1   = "Unrealized Profit/Loss:\n" + str.tostring(strategy.openprofit, "#.00")    table.cell(table_id=info_panel, column=0, row=0, text=text1, text_size= size.normal, text_color=color.new(color.silver, 0))//----------------------- Backtest periode --------------------------------backtest_period() =>    time >= period_start and time <= period_stop ? true : false//-------------------- Ichimoku --------------------TKlength            = 9  //input(9, "Tenkan-sen length", minval= 1)KJlength            = 26  //input(26, "Kijun-sen length", minval= 1)CSHSlength          = 26  //input(26, "Chikouspan length/horizontal shift", minval= 1)SBlength            = 52  //input(52, "SenkouspanB length", minval= 1)SAlength            = 26  //input(26, "SenkouspanA length", minval= 1)// calculationTK                  = math.avg(ta.lowest(TKlength), ta.highest(TKlength))KJ                  = math.avg(ta.lowest(KJlength), ta.highest(KJlength))CS                  = closeSB                  = math.avg(ta.lowest(SBlength), ta.highest(SBlength))SA                  = math.avg(TK, KJ)kumo_high           = math.max(SA[CSHSlength - 1], SB[CSHSlength - 1])kumo_low            = math.min(SA[CSHSlength - 1], SB[CSHSlength - 1])//--------------------------------------------------------------------------------- Filters and entry signals -----------------------------------------------------------------------------------//---------------------- Ichimoku filter ------------------------var bool tkkj_x = trueif ta.crossover(TK, KJ) and TK > kumo_high and KJ > kumo_high    tkkj_x := true    tkkj_xif ta.crossunder(TK, KJ) and TK < kumo_low and KJ < kumo_low    tkkj_x := false    tkkj_x//Ichimoku entry signalskijun_buy                           = one_side_pyr ? ta.crossover(close, KJ) : close > KJkumo_buy                            = one_side_pyr ? ta.crossover(close, kumo_high) : close > kumo_highkumo_flip_buy                       = one_side_pyr ? ta.crossover(SA, SB) : SA > SBchikou_X_price_buy                  = one_side_pyr ? ta.crossover(CS, high[26 - 1]) : CS > high[26 - 1]chikou_X_kumo_buy                   = one_side_pyr ? ta.crossover(CS, kumo_high[26 - 1]) : CS > kumo_high[26 - 1]price_X_tenkan_buy                  = one_side_pyr ? ta.crossover(close, TK) : close > TKtenkan_X_kumo_buy                   = one_side_pyr ? ta.crossover(TK, kumo_high) : TK > kumo_hightenkan_X_kijun_buy                  = one_side_pyr ? ta.crossover(TK, KJ) : TK > KJkijun_sell                          = one_side_pyr ? ta.crossunder(close, KJ) : close < KJkumo_sell                           = one_side_pyr ? ta.crossunder(close, kumo_low) : close < kumo_lowkumo_flip_sell                      = one_side_pyr ? ta.crossunder(SA, SB) : SA < SBchikou_X_price_sell                 = one_side_pyr ? ta.crossunder(CS, low[26 - 1]) : CS < low[26 - 1]chikou_X_kumo_sell                  = one_side_pyr ? ta.crossunder(CS, kumo_low[26 - 1]) : CS < kumo_low[26 - 1]price_X_tenkan_sell                 = one_side_pyr ? ta.crossunder(close, TK) : close < TKtenkan_X_kumo_sell                  = one_side_pyr ? ta.crossunder(TK, kumo_low) : TK < kumo_lowtenkan_X_kijun_sell                 = one_side_pyr ? ta.crossunder(TK, KJ) : TK < KJ// Ichimoku filterskijun_buy_f                         = close > KJkumo_buy_f                          = close > kumo_highkumo_flip_buy_f                     = SA > SBchikou_X_price_buy_f                = CS > high[26 - 1]chikou_X_kumo_buy_f                 = CS > kumo_high[26 - 1]price_X_tenkan_buy_f                = close > TKtenkan_X_kumo_buy_f                 = TK > kumo_hightenkan_X_kijun_buy_f                = TK > KJkumo_filtered_tenkan_X_kijun_buy_f  = tkkj_x and TK > kumo_high and KJ > kumo_high and TK > KJkijun_sell_f                        = close < KJkumo_sell_f                         = close < kumo_lowkumo_flip_sell_f                    = SA < SBchikou_X_price_sell_f               = CS < low[26 - 1]chikou_X_kumo_sell_f                = CS < kumo_low[26 - 1]price_X_tenkan_sell_f               = close < TKtenkan_X_kumo_sell_f                = TK < kumo_lowtenkan_X_kijun_sell_f               = TK < KJkumo_filtered_tenkan_X_kijun_sell_f = not tkkj_x and TK < kumo_low and KJ < kumo_low and TK < KJ// Ichimoku exitskijun_buy_x                         = ta.crossover(high, KJ)kijun_sell_x                        = ta.crossunder(low, KJ)kumo_buy_x                          = ta.crossover(high, kumo_high)kumo_sell_x                         = ta.crossunder(low, kumo_low)//----------------------- bar signals -----------------------//entry signalbar_sig_1_buy                       = close > high[1]                           // bar breakout signal 1bar_sig_1_sell                      = close < low[1]//filterbar_sig_1_buy_f                     = close > high[1]                           // bar breakout signal 1 - filterbar_sig_1_sell_f                    = close < low[1]//entrybar_sig_2_buy                       = high > high[1]                            // bar breakout signal 2bar_sig_2_sell                      = low < low[1]//filterbar_sig_2_buy_f                     = high > high[1]                            // bar breakout signal 2 - filterbar_sig_2_sell_f                    = low < low[1]rev_bar_sig_buy                     = close > open                              // reverse bar exitrev_bar_sig_sell                    = close < openhllh_buy                            = low > low[1]                              // higher-low/lower-high bar sighllh_sell                           = high < high[1]open_buy                            = close != 0                                // entry on every open bar sigopen_sell                           = close != 0//-------------------------- trix --------------------------f_trix(_trix_len)                   => 10000 * ta.change(ta.ema(ta.ema(ta.ema(math.log(close), _trix_len), _trix_len), _trix_len))trix_f                              = f_trix(trix_len_f)trix_x                              = f_trix(trix_len_x)trix_buy_s                          = ta.rising(trix_f, 1) and not ta.rising(trix_f, 1)[1] //one_side_pyr ? ta.rising(trix_f, 1) and not ta.rising(trix_f, 1)[1] : ta.rising(trix_f, 1) trix_sell_s                         = ta.falling(trix_f, 1) and not ta.falling(trix_f, 1)[1] //one_side_pyr ? ta.falling(trix_f, 1) and not ta.falling(trix_f, 1)[1] : ta.falling(trix_f, 1) trix_slo_up_f                       = ta.rising(trix_f, 1) trix_slo_up_x                       = ta.rising(trix_x, 1) and not ta.rising(trix_x, 1)[1]trix_slo_dn_x                       = ta.falling(trix_x, 1) and not ta.falling(trix_x, 1)[1]//----------------------- rsi stochastic ----------------------------//filterrsi_rs_f                            = ta.rsi(close, rsi_length_sto_f)k_f                                 = ta.sma(ta.stoch(rsi_rs_f, rsi_rs_f, rsi_rs_f, stoch_length_f), k_smoo_f)d_f                                 = ta.sma(k_f, d_smoo_f)//signalkd_mom_up_f                         = k_f > 20 and d_f > 20 and not(k_f < d_f and k_f < 80 and d_f < 80)kd_mom_dn_f                         = k_f < 80 and d_f < 80 and not(k_f > d_f and k_f > 80 and d_f > 80)//exitrsi_rs_x                            = ta.rsi(close, rsi_length_sto_x)k_x                                 = ta.sma(ta.stoch(rsi_rs_x, rsi_rs_x, rsi_rs_x, stoch_length_x), k_smoo_x)d_x                                 = ta.sma(k_x, d_smoo_x)//signalkd_mom_up_x                         = k_x > 20 and d_x > 20 and not(k_x < d_x and k_x < 80 and d_x < 80)kd_mom_dn_x                         = k_x < 80 and d_x < 80 and not(k_x > d_x and k_x > 80 and d_x > 80)//------------------------- hma ----------------------------f_hma(_hma_len)                     => ta.hma(close, _hma_len)  hma_f                               = f_hma(hma_len_f)                                                                                      // entry filterhma_x                               = f_hma(hma_len_x)                                                                                      // exit hma_up_e                            = ta.rising(hma_f, 1) and not ta.rising(hma_f, 1)[1] //one_side_pyr ? ta.rising(hma_f, 1) and not ta.rising(hma_f, 1)[1] : ta.rising(hma_f, 1)          // entry signalhma_dn_e                            = ta.falling(hma_f, 1) and not ta.falling(hma_f, 1)[1] //one_side_pyr ? ta.falling(hma_f, 1) and not ta.falling(hma_f, 1)[1] : ta.falling(hma_f, 1) hma_up_f                            = ta.rising(hma_f, 1)              // entry filterhma_up_x                            = ta.rising(hma_x, 1) and not ta.rising(hma_x, 1)[1]                                                    // exit hma_dn_x                            = ta.falling(hma_x, 1) and not ta.falling(hma_x, 1)[1] //------------------------ grid --------------------------re_grid = 0.re_grid := nz(high > re_grid[1] + grid_gap or low < re_grid[1] - grid_gap ? close : re_grid[1])grid_ct_buy         = re_grid < re_grid[1]grid_ct_sell        = re_grid > re_grid[1]grid_re_buy         = re_grid > re_grid[1]grid_re_sell        = re_grid < re_grid[1]//plot(re_grid,"Plot", color= color.yellow, linewidth= 2)//---------------------- reverse fractal signal and filter --------------------------up_bar      = close[0] > open[0]dn_bar      = close[0] < open[0]hl          = low[0] > low[1]lh          = high[0] < high[1]rev_up_fr_sell = ta.pivothigh(high, 3, 0) and dn_bar and up_bar[1] or ta.pivothigh(high, 4, 1) and dn_bar and up_bar[1] or ta.pivothigh(high, 4, 1) and lh and up_bar and up_bar[1]rev_dn_fr_buy = ta.pivotlow(low, 3, 0) and up_bar and dn_bar[1] or ta.pivotlow(low, 4, 1) and up_bar and dn_bar[1] or ta.pivotlow(low, 4, 1) and hl and dn_bar and dn_bar[1]//------------------------- ema1 x ema2 ------------------------f_ema(_ema_len) =>  ta.ema(close, _ema_len)                     // ma function definitionf_sma(_sma_len) =>  ta.sma(close, _sma_len)                     // ma function definitionema1_f                              = f_ema(ema1_len_f)ema2_f                              = f_ema(ema2_len_f)ema1_x                              = f_ema(ema1_len_x)ema2_x                              = f_ema(ema2_len_x)ema_1x2_buy_s                       = ta.crossover(ema1_f, ema2_f)ema_1x2_sell_s                      = ta.crossunder(ema1_f, ema2_f)ema_1x2_buy_f                       = ema1_f > ema2_fema_1x2_buy_x                       = ta.crossover(ema1_x, ema2_x)ema_1x2_sell_x                      = ta.crossunder(ema1_x, ema2_x)//--------------------- ALMA ------------------------alma                                = ta.alma(close, windowsize, offset, sigma)//entry signalsalma_slo_up_e                       = ta.rising(alma, 1) and not ta.rising(alma, 1)[1] //one_side_pyr ? ta.rising(alma, 1) and not ta.rising(alma, 1)[1] : ta.rising(alma, 1) alma_slo_dn_e                       = ta.falling(alma, 1) and not ta.falling(alma, 1)[1] //one_side_pyr ? ta.falling(alma, 1) and not ta.falling(alma, 1)[1] : ta.falling(alma, 1) //filtersalma_slo_up_f                       = ta.rising(alma, 1)  //----------------------- macd filter and macd slope-----------------------[macdLine_f, signalLine_f, histLine_f]  = ta.macd(close, 12, 26, 9)//filtersmacd_buy                                = macdLine_f > signalLine_fmacd_sell                               = macdLine_f < signalLine_f//exitmacd_buy_x                              = ta.crossover(macdLine_f, signalLine_f)macd_sell_x                             = ta.crossunder(macdLine_f, signalLine_f)//macd fast line slopemacd_slope_up_e                         = ta.rising(macdLine_f, slope_len) and not ta.rising(macdLine_f, slope_len)[1]                                         //one_side_pyr ? ta.rising(macdLine_f, slope_len) and not ta.rising(macdLine_f, slope_len)[1] : ta.rising(macdLine_f, slope_len)                    // entrymacd_slope_dn_e                         = ta.falling(macdLine_f, slope_len) and not ta.falling(macdLine_f, slope_len)[1]                                         //one_side_pyr ? ta.falling(macdLine_f, slope_len) and not ta.falling(macdLine_f, slope_len)[1] : ta.falling(macdLine_f, slope_len)macd_slope_up_f                         = ta.rising(macdLine_f, slope_len)                                                                                                                  // filtermacd_slope_up_x                         = ta.rising(macdLine_f, slope_len_x) and not ta.rising(macdLine_f, slope_len_x)[1]                                                                  // exitmacd_slope_dn_x                         = ta.falling(macdLine_f, slope_len_x) and not ta.falling(macdLine_f, slope_len_x)[1]//---------------------- rsi filter and entry signal------------------------f_rsi(_rsi_period)           => ta.rsi(close, _rsi_period)//entryrsi_f           = f_rsi(rsi_period)rsi_f_buy       = one_side_pyr ? ta.crossover(rsi_f, 50) : rsi_f > 50rsi_f_sell      = one_side_pyr ? ta.crossunder(rsi_f, 50) : rsi_f < 50//filtersrsi_f_buy_f     = rsi_f > 50rsi_f_sell_f    = rsi_f < 50//exitrsi_f_x         = f_rsi(rsi_period_x)rsi_f_buy_x     = ta.crossover(rsi_f_x, 50)rsi_f_sell_x    = ta.crossunder(rsi_f_x, 50)//---------------- Bill Williams Fractals (filter and entry signal) -----------------up_fr           = ta.pivothigh(fr_period, fr_period)dn_fr           = ta.pivotlow(fr_period, fr_period)fractal_up_v    = ta.valuewhen(up_fr, high[fr_period], 0)fractal_dn_v    = ta.valuewhen(dn_fr, low[fr_period], 0)//entry signalfr_upx          = one_side_pyr ? ta.crossover(high, fractal_up_v) : high > fractal_up_v fr_dnx          = one_side_pyr ? ta.crossunder(low, fractal_dn_v) : low < fractal_dn_v//filtersfr_upx_f        = high > fractal_up_vfr_dnx_f        = low < fractal_dn_v//exitup_fr_x         = ta.pivothigh(fr_period_x, fr_period_x)dn_fr_x         = ta.pivotlow(fr_period_x, fr_period_x)fractal_up_v_x  = ta.valuewhen(up_fr_x, high[fr_period_x], fr_past_x)fractal_dn_v_x  = ta.valuewhen(dn_fr_x, low[fr_period_x], fr_past_x)fr_upx_x        = ta.crossover(high, fractal_up_v_x)fr_dnx_x        = ta.crossunder(low, fractal_dn_v_x)//-------------------- SuperTrend filter and entry signal ---------------------//entry[SuperTrend, Dir]       = ta.supertrend(mult, len)sup_buy                 = one_side_pyr ? ta.crossover(high, SuperTrend) : high > SuperTrendsup_sell                = one_side_pyr ? ta.crossunder(low, SuperTrend) : low < SuperTrend//filterssup_buy_f               = high > SuperTrendsup_sell_f              = low < SuperTrend//exit[SuperTrend_x, Dir_x]   = ta.supertrend(mult_x, len_x)sup_buy_x               = ta.crossover(high, SuperTrend_x)sup_sell_x              = ta.crossunder(low, SuperTrend_x)//----------------- Parabolic SAR Signal (pb/ps) and filter -------------------psar_buy                = one_side_pyr ? ta.crossover(high, ta.sar(start, inc, max)[0]) : high > ta.sar(start, inc, max)[0]psar_sell               = one_side_pyr ? ta.crossunder(low, ta.sar(start, inc, max)[0]) : low < ta.sar(start, inc, max)[0]//filterspsar_buy_f              = high > ta.sar(start, inc, max)[0]psar_sell_f             = low < ta.sar(start, inc, max)[0]psar_buy_x              = ta.crossover(high, ta.sar(start, inc, max)[0])psar_sell_x             = ta.crossunder(low, ta.sar(start, inc, max)[0])//-------------------------- DMI ADX entry sig and filter ---------------------------//exit[diplus_f_x, diminus_f_X, adx_f_x]      = ta.dmi(di_length_x, adx_smooth_x)adx_thres_f_x                           = ta.crossunder(adx_f_x, adx_thres_x)//dmi and adx signal 1/2/3 and filters[diplus_s, diminus_s, adx_s]            = ta.dmi(di_length_s, adx_smooth_s)adx_above_thres                         = adx_s > adx_thres_sadx_slope_up                            = ta.rising(adx_s, 1)//entry filterlong_e      = diplus_s > diminus_sshort_e     = diplus_s < diminus_s//entrylong_1      = one_side_pyr ? ta.crossover(diplus_s, diminus_s) and adx_s < diplus_s and adx_s > diminus_s : diplus_s > diminus_s and adx_s < diplus_s and adx_s > diminus_sshort_1     = one_side_pyr ? ta.crossunder(diplus_s, diminus_s) and adx_s > diplus_s and adx_s < diminus_s : diplus_s < diminus_s and adx_s > diplus_s and adx_s < diminus_slong_2      = one_side_pyr ? ta.crossover(diplus_s, diminus_s) and adx_s > adx_thres_s : diplus_s > diminus_s and adx_above_thresshort_2     = one_side_pyr ? ta.crossunder(diplus_s, diminus_s) and adx_s > adx_thres_s : diplus_s < diminus_s and adx_above_thres//dmi adx-slope signaladx_up_c    = adx_slope_up and diplus_s > diminus_s and not (adx_slope_up and diplus_s > diminus_s)[1]                      adx_dn_c    = adx_slope_up and diplus_s < diminus_s and not (adx_slope_up and diplus_s < diminus_s)[1]//-------------------------- SMA50 filter and entry---------------------------//entrysma_buy     = one_side_pyr ? ta.crossover(close[1], f_sma(ma_period)) : close[2] > f_sma(ma_period)sma_sell    = one_side_pyr ? ta.crossunder(close[1], f_sma(ma_period)) : close[2] < f_sma(ma_period)//filterssma_buy_f   = close[2] > f_sma(ma_period)sma_sell_f  = close[2] < f_sma(ma_period)//exitsma_buy_x   = ta.crossover(close[1], f_sma(ma_period_x))sma_sell_x  = ta.crossunder(close[1], f_sma(ma_period_x))//---------------- williams fractals trend lines -----------------up_w_fr         = ta.pivothigh(2, 2)dn_w_fr         = ta.pivotlow(2, 2)y1_frup_1       = ta.valuewhen(up_w_fr, high[2], 1)y0_frup_0       = ta.valuewhen(up_w_fr, high[2], 0)y1_frdn_1       = ta.valuewhen(dn_w_fr, low[2], 1)y0_frdn_0       = ta.valuewhen(dn_w_fr, low[2], 0)// bar-id loops to get x1 and x2 for line.new()xup0 = 2for i = 1 to 35 by 1    if high[i + 2] >= high[i + 3] and high[i + 2] > high[i + 4] and high[i + 2] > high[i + 1] and high[i + 2] >= high[i + 0]        break    xup0 := xup0 + 1    xup0xup1 = xup0for i = xup1 to 50 by 1    if high[i + 2] >= high[i + 3] and high[i + 2] > high[i + 4] and high[i + 2] > high[i + 1] and high[i + 2] >= high[i + 0]        break    xup1 := xup1 + 1    xup1xdn0 = 2for i = 1 to 35 by 1    if low[i + 2] <= low[i + 3] and low[i + 2] < low[i + 4] and low[i + 2] < low[i + 1] and low[i + 2] <= low[i + 0]        break    xdn0 := xdn0 + 1    xdn0xdn1 = xdn0for i = xdn1 to 50 by 1    if low[i + 2] <= low[i + 3] and low[i + 2] < low[i + 4] and low[i + 2] < low[i + 1] and low[i + 2] <= low[i + 0]        break    xdn1 := xdn1 + 1    xdn1// y-linebreak values for upper_line and lower_liney_up_lvl        = (y0_frup_0 - y1_frup_1) / (xup1 + 2 - xup0) * xup0 + y0_frup_0  // y = slope * x0 + y0y_dn_lvl        = (y0_frdn_0 - y1_frdn_1) / (xdn1 + 2 - xdn0) * xdn0 + y0_frdn_0// entry//frup_buy        = ta.crossover(high, y0_frup_0)//frdn_sell       = ta.crossunder(low, y0_frdn_0)buy_up_line     = one_side_pyr ? ta.crossover(high, y_up_lvl) : high > y_up_lvl// or frup_buysell_dn_line    = one_side_pyr ? ta.crossunder(low, y_dn_lvl) : low < y_dn_lvl// or frdn_sell//--------------------------- Segments signal ----------------------------count1_l                    = 0count2_l                    = 0segment_1_stat_l            = falsesegment_2_stat_l            = falsesegment_3_stat_l            = falsehigher_low                  = low > low[1]var line segment_low_1_l    = navar line segment_low_2_l    = navar line segment_low_3_l    = na// long segmentsfor i = 0 to sb by 1    count1_l := count1_l + 1    if low[1] > low[i + 2] and higher_low        segment_1_stat_l := true        breakfor i = count1_l to sb + count1_l by 1    count2_l := count2_l + 1    if low[1 + count1_l] > low[i + 2] and segment_1_stat_l        segment_2_stat_l := true        breakfor i = count2_l to sb + count2_l by 1    if low[1 + count1_l + count2_l] > low[i + 2 + count1_l] and segment_2_stat_l        segment_3_stat_l := true        break// short segmentscount1_s                    = 0count2_s                    = 0segment_1_stat_s            = falsesegment_2_stat_s            = falsesegment_3_stat_s            = falselower_high                  = high < high[1]var line segment_high_1     = navar line segment_high_2     = navar line segment_high_3     = nafor i = 0 to sb by 1    count1_s := count1_s + 1    if high[1] < high[i + 2] and lower_high        segment_1_stat_s := true        breakfor i = count1_s to sb + count1_s by 1    count2_s := count2_s + 1    if high[1 + count1_s] < high[i + 2] and segment_1_stat_s        segment_2_stat_s := true        breakfor i = count2_s to sb + count2_s by 1    if high[1 + count1_s + count2_s] < high[i + 2 + count1_s] and segment_2_stat_s        segment_3_stat_s := true        break// segments signalsseg_stat_l                  = segment_1_stat_l and segment_2_stat_l and segment_3_stat_lseg_stat_s                  = segment_1_stat_s and segment_2_stat_s and segment_3_stat_s//entrysegments_buy                = high > high[1] and seg_stat_l[1]segments_sell               = low < low[1] and seg_stat_s[1]//filterssegments_buy_f              = high > high[1] and seg_stat_l[1]segments_sell_f             = low < low[1] and seg_stat_s[1]//----------------------- i-o-s-p signals ------------------------i_bar_buy           = high[1] < high[2] and low[1] > low[2] and close > high[1]i_bar_sell          = high[1] < high[2] and low[1] > low[2] and close < low[1]o_bar_buy           = high[1] > high[2] and low[1] < low[2] and high > high[1]o_bar_sell          = high[1] > high[2] and low[1] < low[2] and low < low[1]s_bar_buy           = high[2] < high[3] and low[2] > low[3] and high[1] > high[2] and low[1] < low[2] and high > high[1]s_bar_sell          = high[2] < high[3] and low[2] > low[3] and high[1] > high[2] and low[1] < low[2] and low < low[1]//pinbarcandle_body         = math.abs(open - close)pivot_up            = ta.pivothigh(high, p_bar_sens_2, 0)pivot_dn            = ta.pivotlow(low, p_bar_sens_2, 0)up_wick             = close > open ? high - close : high - opendn_wick             = close > open ? open - low : close - lowpin_up_def          = high - open > p_bar_sens_1 * candle_body and close < open or high - close > p_bar_sens_1 * candle_body and close > openpin_dn_def          = open - low > p_bar_sens_1 * candle_body and close > open or close - low > p_bar_sens_1 * candle_body and close < openp_bar_sell          = pin_up_def and pivot_up and up_wick > dn_wickp_bar_buy           = pin_dn_def and pivot_dn and up_wick < dn_wick//----------------- Ichimoku Signal B1/S1 -----------------buy_strong_B1       = TK >= KJ and high > kumo_high and CS > high[26 - 1] and CS > kumo_high[26 - 1] and SA > SBsell_strong_S1      = TK <= KJ and low < kumo_low and CS < low[26 - 1] and CS < kumo_low[26 - 1] and SA < SB//----------------- Ichimoku Signal B2/S2 -----------------buy_strong_B2       = TK >= KJ and high > kumo_high and CS > high[26 - 1]sell_strong_S2      = TK <= KJ and low < kumo_low and CS < low[26 - 1]//---------------------------- Confluence Signal CB/CS ----------------------------long_short_trig     = 10  //input(9, type= input.float, title= "Confluence signal trigger Level", step= 0.2)//Indicators// masma1                                = f_sma(50)sma2                                = f_sma(200)ema1                                = f_ema(50)ema2                                = f_ema(200)ema_c                               = f_ema(21)sma_c                               = f_sma(20)[macdLine, signalLine, histLine]    = ta.macd(close, 12, 26, 9)rsi                                 = f_rsi(14)[diplus, diminus, adx]              = ta.dmi(7, 7)[superTrend, dir]                   = ta.supertrend(2, 5)//Klinger Oszillatorsv                                  = ta.change(hlc3) >= 0 ? volume : -volumekvo                                 = ta.ema(sv, 34) - ta.ema(sv, 55)sig                                 = ta.ema(kvo, 13)//Vortex IndicatorVMP                                 = math.sum(math.abs(high - low[1]), 14)VMM                                 = math.sum(math.abs(low - high[1]), 14)STR                                 = math.sum(ta.atr(1), 14)VIP                                 = VMP / STRVIM                                 = VMM / STR//HMA slopehma_slo_up                          = ta.rising(f_hma(15),1)//ALMA slopealma_slo_up                         = ta.rising(ta.alma(close, 9, 0.85, 6),1)//MACD slopemacd_slo_up                         = ta.rising(macdLine, 1)//Signalsvar float sem_sig_w                 = navar float sma_sig_w                 = navar float ema_sig_w                 = navar float p_kj_sig_w                = navar float tk_kj_sig_w               = navar float B1_S1_sig_w               = navar float B2_S2_sig_w               = navar float psar_sig_w                = navar float frac_sig_w                = navar float macd_sig_w                = navar float rsi_sig_w                 = navar float p_tk_sig_w                = navar float dmi_sig_w                 = navar float klin_sig_w                = navar float vort_sig_w                = navar float sup_sig_w                 = navar float hma_sig_w                 = navar float alma_sig_w                = navar float macd_s_sig_w              = naif ema_c > sma_c    sem_sig_w := 1else if ema_c < sma_c    sem_sig_w := 0if sma1 > sma2    sma_sig_w := 1else if sma1 < sma2    sma_sig_w := 0if ema1 > ema2    ema_sig_w := 1else if ema1 < ema2    ema_sig_w := 0if high > KJ    p_kj_sig_w := 1else if low < KJ    p_kj_sig_w := 0if TK > KJ    tk_kj_sig_w := 1else if TK < KJ    tk_kj_sig_w := 0if buy_strong_B1    B1_S1_sig_w := 1else if sell_strong_S1    B1_S1_sig_w := 0if buy_strong_B2    B2_S2_sig_w := 1else if sell_strong_S2    B2_S2_sig_w := 0if high >= ta.sar(start, inc, max)[0]    psar_sig_w := 1else if low <= ta.sar(start, inc, max)[0]    psar_sig_w := 0if high > fractal_up_v    frac_sig_w := 1else if low < fractal_dn_v    frac_sig_w := 0if macdLine > signalLine    macd_sig_w := 1else if macdLine < signalLine    macd_sig_w := 0if rsi > 50    rsi_sig_w := 1else if rsi < 50    rsi_sig_w := 0if high > TK    p_tk_sig_w := 1else if low < TK    p_tk_sig_w := 0if diplus > diminus    dmi_sig_w := 1else if diplus < diminus    dmi_sig_w := 0if sig > 0    klin_sig_w := 1else if sig < 0    klin_sig_w := 0if VIP > VIM    vort_sig_w := 1else if VIP < VIM    vort_sig_w := 0if high > superTrend    sup_sig_w := 1else if low < superTrend    sup_sig_w := 0if hma_slo_up    hma_sig_w := 2else if not hma_slo_up    hma_sig_w := -1if alma_slo_up    alma_sig_w := 2else if not alma_slo_up    alma_sig_w := -1if macd_slo_up    macd_s_sig_w := 1else if not macd_slo_up    macd_s_sig_w := 0bs_conf_sig             = sma_sig_w + ema_sig_w + p_kj_sig_w + tk_kj_sig_w + B1_S1_sig_w + B2_S2_sig_w + psar_sig_w + frac_sig_w + macd_sig_w + rsi_sig_w + dmi_sig_w + klin_sig_w + vort_sig_w + sup_sig_w +                          p_tk_sig_w + sem_sig_w + hma_sig_w + alma_sig_w + macd_s_sig_wlong_c                  = one_side_pyr ? ta.crossover(bs_conf_sig, (long_short_trig + trig_gap_cbcs)) : bs_conf_sig > (long_short_trig + trig_gap_cbcs)                         //with +- signal is more stableshort_c                 = one_side_pyr ? ta.crossunder(bs_conf_sig, (long_short_trig - trig_gap_cbcs)) : bs_conf_sig < (long_short_trig - trig_gap_cbcs)//---------------------------- Pure Ichimoku Confluence Signal IB/IS ----------------------------pic_l_s_trig            = 5  //input(4, type= input.float, title= "Ichimoku confluence signal trigger Level", step= 0.1)//Signalsvar float tkkh_sig_w    = navar float csh_sig_w     = navar float cskh_sig_w    = navar float pkj_sig_w     = navar float ptk_sig_w     = navar float tkkj_sig_w    = navar float sasb_sig_w    = navar float ckh_sig_w     = navar float cskj_sig_w    = navar float cstk_sig_w    = navar float kjcl_sig_w    = naif TK > kumo_high    tkkh_sig_w := 1else if TK < kumo_low    tkkh_sig_w := 0if CS > high[26 - 1]    csh_sig_w := 1else if CS < low[26 - 1]    csh_sig_w := 0if CS > kumo_high[26 - 1]    cskh_sig_w := 1else if CS < kumo_low[26 - 1]    cskh_sig_w := 0if high > TK    ptk_sig_w := 1else if low < TK    ptk_sig_w := 0if high > KJ    pkj_sig_w := 1else if low < KJ    pkj_sig_w := 0if TK > KJ    tkkj_sig_w := 1else if TK < KJ    tkkj_sig_w := 0if SA > SB    sasb_sig_w := 1else if SA < SB    sasb_sig_w := 0if high > kumo_high    ckh_sig_w := 1else if low < kumo_low    ckh_sig_w := 0if CS > KJ[26 - 1]    cskj_sig_w := 1else if CS < KJ[26 - 1]    cskj_sig_w := 0if CS > TK[26 - 1]    cstk_sig_w := 1else if CS < TK[26 - 1]    cstk_sig_w := 0if KJ > kumo_high    kjcl_sig_w := 1else if KJ < kumo_high    kjcl_sig_w := 0bs_pic_sig          = tkkh_sig_w + csh_sig_w + cskh_sig_w + ptk_sig_w + pkj_sig_w + tkkj_sig_w + sasb_sig_w + ckh_sig_w   +   cskj_sig_w + cstk_sig_w + kjcl_sig_wlong_pic            = one_side_pyr ? ta.crossover(bs_pic_sig, pic_l_s_trig + trig_gap_ibis) : bs_pic_sig > pic_l_s_trig + trig_gap_ibisshort_pic           = one_side_pyr ? ta.crossunder(bs_pic_sig, pic_l_s_trig - trig_gap_ibis) : bs_pic_sig < pic_l_s_trig - trig_gap_ibislong_pic_x          = long_pic and not long_pic[1]short_pic_x         = short_pic and not short_pic[1]//-------------------------------------------------------------------- entry filters -------------------------------------------------------------------f_secureSecurity(_symbol, _res, _src) => request.security(_symbol, _res, _src[repaint == 'Allowed' ? 0 : 1])                 // no repainting - taken from PineCoders     entry_filter_sig_buy_1      = entry_f_1 == '---' ? true :                              entry_f_1 == 'TRIX slope filter' ? trix_slo_up_f :                             entry_f_1 == 'RSI Stochastic filter' ? kd_mom_up_f :                              entry_f_1 == 'EMA1 x EMA2 filter' ? ema_1x2_buy_f :                              entry_f_1 == 'HMA slope filter' ? hma_up_f :                              entry_f_1 == 'MACD(fast) slope filter' ? macd_slope_up_f :                              entry_f_1 == 'MACD filter' ? macd_buy :                              entry_f_1 == 'RSI50 filter' ? rsi_f_buy_f :                              entry_f_1 == 'Fractals filter' ? fr_upx_f :                              entry_f_1 == 'SuperTrend filter' ? sup_buy_f :                              entry_f_1 == 'Parabolic SAR filter' ? psar_buy_f :                              entry_f_1 == 'SMA filter' ? sma_buy_f :                              entry_f_1 == 'ADX Threshold filter' ? adx_above_thres :                              entry_f_1 == 'DMI filter' ? long_e :                              entry_f_1 == 'Bar breakout 1 filter' ? bar_sig_1_buy_f :                              entry_f_1 == 'Bar breakout 2 filter' ? bar_sig_2_buy_f :                              entry_f_1 == 'Reverse fractal filter' ? rev_dn_fr_buy :                              entry_f_1 == 'ALMA slope filter' ? alma_slo_up_f :                              entry_f_1 == 'Price X Kumo filter' ? kumo_buy_f :                              entry_f_1 == 'Price X Kijun filter' ? kijun_buy_f :                              entry_f_1 == 'Kumo flip filter' ? kumo_flip_buy_f :                              entry_f_1 == 'Chikou X price filter' ? chikou_X_price_buy_f :                              entry_f_1 == 'Chikou X Kumo filter' ? chikou_X_kumo_buy_f :                              entry_f_1 == 'Price X Tenkan filter' ? price_X_tenkan_buy_f :                              entry_f_1 == 'Tenkan X Kumo filter' ? tenkan_X_kumo_buy_f :                              entry_f_1 == 'Tenkan X Kijun filter' ? tenkan_X_kijun_buy_f :                              entry_f_1 == 'B1/S1 sig' ? buy_strong_B1 :                              entry_f_1 == 'B2/S2 sig' ? buy_strong_B2 : trueentry_filter_sig_sell_1     = entry_f_1 == '---' ? true :                              entry_f_1 == 'TRIX slope filter' ? not trix_slo_up_f :                             entry_f_1 == 'RSI Stochastic filter' ? kd_mom_dn_f :                              entry_f_1 == 'EMA1 x EMA2 filter' ? not ema_1x2_buy_f :                              entry_f_1 == 'HMA slope filter' ? not hma_up_f :                              entry_f_1 == 'MACD(fast) slope filter' ? not macd_slope_up_f :                              entry_f_1 == 'MACD filter' ? macd_sell :                              entry_f_1 == 'RSI50 filter' ? rsi_f_sell_f :                              entry_f_1 == 'Fractals filter' ? fr_dnx_f :                              entry_f_1 == 'SuperTrend filter' ? sup_sell_f :                              entry_f_1 == 'Parabolic SAR filter' ? psar_sell_f :                              entry_f_1 == 'SMA filter' ? sma_sell_f :                              entry_f_1 == 'ADX Threshold filter' ? adx_above_thres :                              entry_f_1 == 'DMI filter' ? short_e :                              entry_f_1 == 'Bar breakout 1 filter' ? bar_sig_1_sell_f :                              entry_f_1 == 'Bar breakout 2 filter' ? bar_sig_2_sell_f :                              entry_f_1 == 'Reverse fractal filter' ? rev_up_fr_sell :                              entry_f_1 == 'ALMA slope filter' ? not alma_slo_up_f :                              entry_f_1 == 'Price X Kumo filter' ? kumo_sell_f :                              entry_f_1 == 'Price X Kijun filter' ? kijun_sell_f :                              entry_f_1 == 'Kumo flip filter' ? kumo_flip_sell_f :                              entry_f_1 == 'Chikou X price filter' ? chikou_X_price_sell_f :                              entry_f_1 == 'Chikou X Kumo filter' ? chikou_X_kumo_sell_f :                              entry_f_1 == 'Price X Tenkan filter' ? price_X_tenkan_sell_f :                              entry_f_1 == 'Tenkan X Kumo filter' ? tenkan_X_kumo_sell_f :                              entry_f_1 == 'Tenkan X Kijun filter' ? tenkan_X_kijun_sell_f :                              entry_f_1 == 'B1/S1 sig' ? sell_strong_S1 :                              entry_f_1 == 'B2/S2 sig' ? sell_strong_S2 : trueentry_filter_sig_buy_2      = entry_f_2 == '---' ? true :                              entry_f_2 == 'TRIX slope filter' ? trix_slo_up_f :                             entry_f_2 == 'RSI Stochastic filter' ? kd_mom_up_f :                              entry_f_2 == 'EMA1 x EMA2 filter' ? ema_1x2_buy_f :                              entry_f_2 == 'HMA slope filter' ? hma_up_f :                              entry_f_2 == 'MACD(fast) slope filter' ? macd_slope_up_f :                              entry_f_2 == 'MACD filter' ? macd_buy :                              entry_f_2 == 'RSI50 filter' ? rsi_f_buy_f :                             entry_f_2 == 'Fractals filter' ? fr_upx_f :                              entry_f_2 == 'SuperTrend filter' ? sup_buy_f :                              entry_f_2 == 'Parabolic SAR filter' ? psar_buy_f :                              entry_f_2 == 'SMA filter' ? sma_buy_f :                              entry_f_2 == 'ADX Threshold filter' ? adx_above_thres :                              entry_f_2 == 'DMI filter' ? long_e :                              entry_f_2 == 'Bar breakout 1 filter' ? bar_sig_1_buy_f :                              entry_f_2 == 'Bar breakout 2 filter' ? bar_sig_2_buy_f :                              entry_f_2 == 'Reverse fractal filter' ? rev_dn_fr_buy :                              entry_f_2 == 'ALMA slope filter' ? alma_slo_up_f :                              entry_f_2 == 'Price X Kumo filter' ? kumo_buy_f :                              entry_f_2 == 'Price X Kijun filter' ? kijun_buy_f :                              entry_f_2 == 'Kumo flip filter' ? kumo_flip_buy_f :                              entry_f_2 == 'Chikou X price filter' ? chikou_X_price_buy_f :                              entry_f_2 == 'Chikou X Kumo filter' ? chikou_X_kumo_buy_f :                              entry_f_2 == 'Price X Tenkan filter' ? price_X_tenkan_buy_f :                              entry_f_2 == 'Tenkan X Kumo filter' ? tenkan_X_kumo_buy_f :                              entry_f_2 == 'Tenkan X Kijun filter' ? tenkan_X_kijun_buy_f :                              entry_f_2 == 'B1/S1 sig' ? buy_strong_B1 :                              entry_f_2 == 'B2/S2 sig' ? buy_strong_B2 : trueentry_filter_sig_sell_2     = entry_f_2 == '---' ? true :                              entry_f_2 == 'TRIX slope filter' ? not trix_slo_up_f :                             entry_f_2 == 'RSI Stochastic filter' ? kd_mom_dn_f :                              entry_f_2 == 'EMA1 x EMA2 filter' ? not ema_1x2_buy_f :                              entry_f_2 == 'HMA slope filter' ? not hma_up_f :                              entry_f_2 == 'MACD(fast) slope filter' ? not macd_slope_up_f :                              entry_f_2 == 'MACD filter' ? macd_sell :                              entry_f_2 == 'RSI50 filter' ? rsi_f_sell_f :                              entry_f_2 == 'Fractals filter' ? fr_dnx_f :                              entry_f_2 == 'SuperTrend filter' ? sup_sell_f :                              entry_f_2 == 'Parabolic SAR filter' ? psar_sell_f :                              entry_f_2 == 'SMA filter' ? sma_sell_f :                              entry_f_2 == 'ADX Threshold filter' ? adx_above_thres :                              entry_f_2 == 'DMI filter' ? long_e :                              entry_f_2 == 'Bar breakout 1 filter' ? bar_sig_1_sell_f :                              entry_f_2 == 'Bar breakout 2 filter' ? bar_sig_2_sell_f :                              entry_f_2 == 'Reverse fractal filter' ? rev_up_fr_sell :                              entry_f_2 == 'ALMA slope filter' ? not alma_slo_up_f :                              entry_f_2 == 'Price X Kumo filter' ? kumo_sell_f :                              entry_f_2 == 'Price X Kijun filter' ? kijun_sell_f :                              entry_f_2 == 'Kumo flip filter' ? kumo_flip_sell_f :                              entry_f_2 == 'Chikou X price filter' ? chikou_X_price_sell_f :                              entry_f_2 == 'Chikou X Kumo filter' ? chikou_X_kumo_sell_f :                              entry_f_2 == 'Price X Tenkan filter' ? price_X_tenkan_sell_f :                              entry_f_2 == 'Tenkan X Kumo filter' ? tenkan_X_kumo_sell_f :                              entry_f_2 == 'Tenkan X Kijun filter' ? tenkan_X_kijun_sell_f :                              entry_f_2 == 'B1/S1 sig' ? sell_strong_S1 :                              entry_f_2 == 'B2/S2 sig' ? sell_strong_S2 : true//entry buy filter 1 optionsentry_filter_buy_1          = htf_filt_opt_1 == 'Current' ? entry_filter_sig_buy_1[repaint == 'Allowed' ? 0 : 1] :                              f_secureSecurity(syminfo.tickerid,                              htf_filt_opt_1 == '5m' ? '5' : htf_filt_opt_1 == '10m' ? '10' : htf_filt_opt_1 == '15m' ? '15' :                              htf_filt_opt_1 == '30m' ? '30' : htf_filt_opt_1 == '1H' ? '60' : htf_filt_opt_1 == '2H' ? '120' : htf_filt_opt_1 == '3H' ? '180' : htf_filt_opt_1 == '4H' ? '240' :                              htf_filt_opt_1 == '6H' ? '360' : htf_filt_opt_1 == '12H' ? '720' : htf_filt_opt_1 == 'D' ? 'D' : htf_filt_opt_1 == '3D' ? '3D' : htf_filt_opt_1 == 'W' ? 'W' : htf_filt_opt_1 == 'M' ? 'M' : na,                              entry_filter_sig_buy_1)entry_filter_buy_11         = entry_f_1 == 'Segments filter (no tf filter)' ? segments_buy :                              entry_f_1 == 'IB/IS sig (no tf filter)' ? long_pic[repaint == 'Allowed' ? 0 : 1] :                             entry_f_1 == 'Fractals trend lines filter (no tf filter)' ? buy_up_line  : true//entry sell filter 1 optionsentry_filter_sell_1         = htf_filt_opt_1 == 'Current' ? entry_filter_sig_sell_1[repaint == 'Allowed' ? 0 : 1] :                              f_secureSecurity(syminfo.tickerid,                              htf_filt_opt_1 == '5m' ? '5' : htf_filt_opt_1 == '10m' ? '10' : htf_filt_opt_1 == '15m' ? '15' :                              htf_filt_opt_1 == '30m' ? '30' : htf_filt_opt_1 == '1H' ? '60' : htf_filt_opt_1 == '2H' ? '120' : htf_filt_opt_1 == '3H' ? '180' : htf_filt_opt_1 == '4H' ? '240' :                              htf_filt_opt_1 == '6H' ? '360' : htf_filt_opt_1 == '12H' ? '720' : htf_filt_opt_1 == 'D' ? 'D' : htf_filt_opt_1 == '3D' ? '3D' : htf_filt_opt_1 == 'W' ? 'W' : htf_filt_opt_1 == 'M' ? 'M' : na,                              entry_filter_sig_sell_1)entry_filter_sell_11        = entry_f_1 == 'Segments filter (no tf filter)' ? segments_sell :                              entry_f_1 == 'IB/IS sig (no tf filter)' ? short_pic[repaint == 'Allowed' ? 0 : 1] :                             entry_f_1 == 'Fractals trend lines filter (no tf filter)' ? sell_dn_line : true//entry buy filter 2 optionsentry_filter_buy_2          = htf_filt_opt_2 == 'Current' ? entry_filter_sig_buy_2[repaint == 'Allowed' ? 0 : 1] :                              f_secureSecurity(syminfo.tickerid,                              htf_filt_opt_2 == '5m' ? '5' : htf_filt_opt_2 == '10m' ? '10' : htf_filt_opt_2 == '15m' ? '15' :                              htf_filt_opt_2 == '30m' ? '30' : htf_filt_opt_2 == '1H' ? '60' : htf_filt_opt_2 == '2H' ? '120' : htf_filt_opt_2 == '3H' ? '180' : htf_filt_opt_2 == '4H' ? '240' :                              htf_filt_opt_2 == '6H' ? '360' : htf_filt_opt_2 == '12H' ? '720' : htf_filt_opt_2 == 'D' ? 'D' : htf_filt_opt_2 == '3D' ? '3D' : htf_filt_opt_2 == 'W' ? 'W' : htf_filt_opt_2 == 'M' ? 'M' : na,                              entry_filter_sig_buy_2)entry_filter_buy_22         = entry_f_2 == 'Fractals trend lines filter (no tf filter)' ? buy_up_line :                              entry_f_2 == 'Segments filter (no tf filter)' ? segments_buy :                              entry_f_2 == 'IB/IS sig (no tf filter)' ? long_pic[repaint == 'Allowed' ? 0 : 1] : true//entry sell filter 2 optionsentry_filter_sell_2         = htf_filt_opt_2 == 'Current' ? entry_filter_sig_sell_2[repaint == 'Allowed' ? 0 : 1] :                              f_secureSecurity(syminfo.tickerid,                              htf_filt_opt_2 == '5m' ? '5' : htf_filt_opt_2 == '10m' ? '10' : htf_filt_opt_2 == '15m' ? '15' :                              htf_filt_opt_2 == '30m' ? '30' : htf_filt_opt_2 == '1H' ? '60' : htf_filt_opt_2 == '2H' ? '120' : htf_filt_opt_2 == '3H' ? '180' : htf_filt_opt_2 == '4H' ? '240' :                              htf_filt_opt_2 == '6H' ? '360' : htf_filt_opt_2 == '12H' ? '720' : htf_filt_opt_2 == 'D' ? 'D' : htf_filt_opt_2 == '3D' ? '3D' : htf_filt_opt_2 == 'W' ? 'W' : htf_filt_opt_2 == 'M' ? 'M' : na,                              entry_filter_sig_sell_2)entry_filter_sell_22        = entry_f_2 == 'Fractals trend lines filter (no tf filter)' ? sell_dn_line :                              entry_f_2 == 'Segments filter (no tf filter)' ? segments_sell :                              entry_f_2 == 'IB/IS sig (no tf filter)' ? short_pic[repaint == 'Allowed' ? 0 : 1] : true//-------------------------------------------------------------------- exit filters -----------------------------------------------------------------------exit_filter_sig_buy_1       = exit_f_1 == '---' ? false :                              exit_f_1 == 'TRIX slope exit' ? trix_slo_up_x :                              exit_f_1 == 'RSI Stochastic exit' ? kd_mom_up_x :                              exit_f_1 == 'EMA1 x EMA2 exit' ? ema_1x2_buy_x :                              exit_f_1 == 'HMA slope exit' ? hma_up_x :                              exit_f_1 == 'Reverse bar exit' ? rev_bar_sig_buy :                              exit_f_1 == 'Reverse fractal exit' ? rev_dn_fr_buy :                              exit_f_1 == 'Bar breakout 2 exit' ? bar_sig_2_buy :                              exit_f_1 == 'MACD(fast) slope exit' ? macd_slope_up_x :                              exit_f_1 == 'MACD exit' ? macd_buy_x :                              exit_f_1 == 'RSI50 exit' ? rsi_f_buy_x :                              exit_f_1 == 'Fractals exit' ? fr_upx_x :                              exit_f_1 == 'SuperTrend exit' ? sup_buy_x :                              exit_f_1 == 'Parabolic SAR exit' ? psar_buy_x :                              exit_f_1 == 'SMA exit' ? sma_buy_x :                              exit_f_1 == 'ADX Threshold exit' ? adx_thres_f_x :                              exit_f_1 == 'Cloud exit' ? kumo_buy_x :                              exit_f_1 == 'Kijun exit' ? kijun_buy_x : falseexit_filter_sig_sell_1      = exit_f_1 == '---' ? false :                              exit_f_1 == 'TRIX slope exit' ? trix_slo_dn_x :                             exit_f_1 == 'RSI Stochastic exit' ? kd_mom_dn_x :                              exit_f_1 == 'EMA1 x EMA2 exit' ? ema_1x2_sell_x :                              exit_f_1 == 'HMA slope exit' ? hma_dn_x :                              exit_f_1 == 'Reverse bar exit' ? rev_bar_sig_sell :                              exit_f_1 == 'Reverse fractal exit' ? rev_up_fr_sell :                              exit_f_1 == 'Bar breakout 2 exit' ? bar_sig_2_sell :                              exit_f_1 == 'MACD(fast) slope exit' ? macd_slope_dn_x :                              exit_f_1 == 'MACD exit' ? macd_sell_x :                              exit_f_1 == 'RSI50 exit' ? rsi_f_sell_x :                              exit_f_1 == 'Fractals exit' ? fr_dnx_x :                              exit_f_1 == 'SuperTrend exit' ? sup_sell_x :                              exit_f_1 == 'Parabolic SAR exit' ? psar_sell_x :                             exit_f_1 == 'SMA exit' ? sma_sell_x :                              exit_f_1 == 'ADX Threshold exit' ? adx_thres_f_x :                              exit_f_1 == 'Cloud exit' ? kumo_sell_x :                              exit_f_1 == 'Kijun exit' ? kijun_sell_x : falseexit_filter_sig_buy_2       = exit_f_2 == '---' ? false :                              exit_f_2 == 'TRIX slope exit' ? trix_slo_up_x :                             exit_f_2 == 'RSI Stochastic exit' ? kd_mom_up_x :                              exit_f_2 == 'EMA1 x EMA2 exit' ? ema_1x2_buy_x :                              exit_f_2 == 'HMA slope exit' ? hma_up_x :                              exit_f_2 == 'Reverse bar exit' ? rev_bar_sig_buy :                              exit_f_2 == 'Reverse fractal exit' ? rev_dn_fr_buy :                              exit_f_2 == 'Bar breakout 2 exit' ? bar_sig_2_buy :                              exit_f_2 == 'MACD(fast) slope exit' ? macd_slope_up_x :                              exit_f_2 == 'MACD exit' ? macd_buy_x :                              exit_f_2 == 'RSI50 exit' ? rsi_f_buy_x :                              exit_f_2 == 'Fractals exit' ? fr_upx_x :                              exit_f_2 == 'SuperTrend exit' ? sup_buy_x :                              exit_f_2 == 'Parabolic SAR exit' ? psar_buy_x :                              exit_f_2 == 'SMA exit' ? sma_buy_x :                              exit_f_2 == 'ADX Threshold exit' ? adx_thres_f_x :                              exit_f_2 == 'Cloud exit' ? kumo_buy_x :                              exit_f_2 == 'Kijun exit' ? kijun_buy_x : falseexit_filter_sig_sell_2      = exit_f_2 == '---' ? false :                              exit_f_2 == 'TRIX slope exit' ? trix_slo_dn_x :                             exit_f_2 == 'RSI Stochastic exit' ? kd_mom_dn_x :                              exit_f_2 == 'EMA1 x EMA2 exit' ? ema_1x2_sell_x :                              exit_f_2 == 'HMA slope exit' ? hma_dn_x :                              exit_f_2 == 'Reverse bar exit' ? rev_bar_sig_sell :                              exit_f_2 == 'Reverse fractal exit' ? rev_up_fr_sell :                              exit_f_2 == 'Bar breakout 2 exit' ? bar_sig_2_sell :                              exit_f_2 == 'MACD(fast) slope exit' ? macd_slope_dn_x :                              exit_f_2 == 'MACD exit' ? macd_sell_x :                              exit_f_2 == 'RSI50 exit' ? rsi_f_sell_x :                              exit_f_2 == 'Fractals exit' ? fr_dnx_x :                              exit_f_2 == 'SuperTrend exit' ? sup_sell_x :                              exit_f_2 == 'Parabolic SAR exit' ? psar_sell_x :                              exit_f_2 == 'SMA exit' ? sma_sell_x :                              exit_f_2 == 'ADX Threshold exit' ? adx_thres_f_x :                              exit_f_2 == 'Cloud exit' ? kumo_sell_x :                              exit_f_2 == 'Kijun exit' ? kijun_sell_x : false//short exit buy filter 1 optionsexit_filter_buy_1           = htf_exit_opt_1 == 'Current' ? exit_filter_sig_buy_1[repaint == 'Allowed' ? 0 : 1] :                              f_secureSecurity(syminfo.tickerid,                              htf_exit_opt_1 == '5m' ? '5' : htf_exit_opt_1 == '10m' ? '10' : htf_exit_opt_1 == '15m' ? '15' :                              htf_exit_opt_1 == '30m' ? '30' : htf_exit_opt_1 == '1H' ? '60' : htf_exit_opt_1 == '2H' ? '120' : htf_exit_opt_1 == '3H' ? '180' : htf_exit_opt_1 == '4H' ? '240' :                              htf_exit_opt_1 == '6H' ? '360' : htf_exit_opt_1 == '12H' ? '720' : htf_exit_opt_1 == 'D' ? 'D' : htf_exit_opt_1 == '3D' ? '3D' : htf_exit_opt_1 == 'W' ? 'W' :                              htf_exit_opt_1 == 'M' ? 'M' : na, exit_filter_sig_buy_1)exit_filter_sig_buy_11      = exit_f_1 == 'IB/IS exit (no tf filter)' ? long_pic_x[repaint == 'Allowed' ? 0 : 1] : false//long exit sell filter 1 optionsexit_filter_sell_1          = htf_exit_opt_1 == 'Current' ? exit_filter_sig_sell_1[repaint == 'Allowed' ? 0 : 1] :                              f_secureSecurity(syminfo.tickerid,                              htf_exit_opt_1 == '5m' ? '5' : htf_exit_opt_1 == '10m' ? '10' : htf_exit_opt_1 == '15m' ? '15' :                              htf_exit_opt_1 == '30m' ? '30' : htf_exit_opt_1 == '1H' ? '60' : htf_exit_opt_1 == '2H' ? '120' : htf_exit_opt_1 == '3H' ? '180' : htf_exit_opt_1 == '4H' ? '240' :                              htf_exit_opt_1 == '6H' ? '360' : htf_exit_opt_1 == '12H' ? '720' : htf_exit_opt_1 == 'D' ? 'D' : htf_exit_opt_1 == '3D' ? '3D' : htf_exit_opt_1 == 'W' ? 'W' :                              htf_exit_opt_1 == 'M' ? 'M' : na, exit_filter_sig_sell_1)exit_filter_sig_sell_11     = exit_f_1 == 'IB/IS exit (no tf filter)' ? short_pic_x[repaint == 'Allowed' ? 0 : 1] : false//short exit buy filter 2 optionsexit_filter_buy_2           = htf_exit_opt_2 == 'Current' ? exit_filter_sig_buy_2[repaint == 'Allowed' ? 0 : 1] :                              f_secureSecurity(syminfo.tickerid,                              htf_exit_opt_2 == '5m' ? '5' : htf_exit_opt_2 == '10m' ? '10' : htf_exit_opt_2 == '15m' ? '15' :                             htf_exit_opt_2 == '30m' ? '30' : htf_exit_opt_2 == '1H' ? '60' : htf_exit_opt_2 == '2H' ? '120' : htf_exit_opt_2 == '3H' ? '180' : htf_exit_opt_2 == '4H' ? '240' :                              htf_exit_opt_2 == '6H' ? '360' : htf_exit_opt_2 == '12H' ? '720' : htf_exit_opt_2 == 'D' ? 'D' : htf_exit_opt_2 == '3D' ? '3D' : htf_exit_opt_2 == 'W' ? 'W' :                              htf_exit_opt_2 == 'M' ? 'M' : na, exit_filter_sig_buy_2)exit_filter_sig_buy_22      = exit_f_2 == 'IB/IS exit (no tf filter)' ? long_pic_x[repaint == 'Allowed' ? 0 : 1] : false//long exit sell filter 2 optionsexit_filter_sell_2          = htf_exit_opt_2 == 'Current' ? exit_filter_sig_sell_2[repaint == 'Allowed' ? 0 : 1] :                              f_secureSecurity(syminfo.tickerid,                              htf_exit_opt_2 == '5m' ? '5' : htf_exit_opt_2 == '10m' ? '10' : htf_exit_opt_2 == '15m' ? '15' :                              htf_exit_opt_2 == '30m' ? '30' : htf_exit_opt_2 == '1H' ? '60' : htf_exit_opt_2 == '2H' ? '120' : htf_exit_opt_2 == '3H' ? '180' : htf_exit_opt_2 == '4H' ? '240' :                              htf_exit_opt_2 == '6H' ? '360' : htf_exit_opt_2 == '12H' ? '720' : htf_exit_opt_2 == 'D' ? 'D' : htf_exit_opt_2 == '3D' ? '3D' : htf_exit_opt_2 == 'W' ? 'W' :                              htf_exit_opt_2 == 'M' ? 'M' : na, exit_filter_sig_sell_2)exit_filter_sig_sell_22     = exit_f_2 == 'IB/IS exit (no tf filter)' ? short_pic_x[repaint == 'Allowed' ? 0 : 1] : false//---------------------------------------------------------------------- entry signals -------------------------------------------------------------------entry_opt_sig_buy_1         = X_opt == '---' ? na :                              X_opt == 'TRIX slope sig' ? trix_buy_s :                              X_opt == 'EMA1 x EMA2 sig' ? ema_1x2_buy_s :                              X_opt == 'HMA slope sig' ? hma_up_e :                              X_opt == 'DMI ADX-slope sig' ? adx_up_c :                              X_opt == 'DMI ADX mod sig' ? long_1 :                              X_opt == 'DMI ADX classic sig' ? long_2 :                              X_opt == 'Pin bar sig' ? p_bar_buy :                              X_opt == 'Inside bar sig' ? i_bar_buy :                              X_opt == 'Outside bar sig' ? o_bar_buy :                              X_opt == 'Sandwich bar sig' ? s_bar_buy :                              X_opt == 'Bar breakout 1 sig' ? bar_sig_1_buy :                              X_opt == 'Bar breakout 2 sig' ? bar_sig_2_buy :                              X_opt == 'Higher-low/lower-high bar sig' ? hllh_buy :                              X_opt == 'Entry on every bar-open sig' ? open_buy :                              X_opt == 'SMA sig' ? sma_buy :                              X_opt == 'Fractals sig' ? fr_upx :                              X_opt == 'Reverse fractal sig' ? rev_dn_fr_buy :                              X_opt == 'MACD(fast) slope sig' ? macd_slope_up_e :                              X_opt == 'RSI50 sig' ? rsi_f_buy :                              X_opt == 'Parabolic SAR sig' ? psar_buy :                              X_opt == 'ALMA slope sig' ? alma_slo_up_e :                              X_opt == 'SuperTrend sig' ? sup_buy :                              X_opt == 'Price X Kijun sig' ? kijun_buy :                              X_opt == 'Price X Kumo sig' ? kumo_buy :                              X_opt == 'Kumo flip sig' ? kumo_flip_buy :                              X_opt == 'Chikou X price sig' ? chikou_X_price_buy :                              X_opt == 'Chikou X Kumo sig' ? chikou_X_kumo_buy :                              X_opt == 'Price X Tenkan sig' ? price_X_tenkan_buy :                              X_opt == 'Tenkan X Kumo sig' ? tenkan_X_kumo_buy :                              X_opt == 'Tenkan X Kijun sig' ? tenkan_X_kijun_buy :                              X_opt == 'B1/S1 sig' ? buy_strong_B1 :                              X_opt == 'B2/S2 sig' ? buy_strong_B2 : naentry_opt_sig_sell_1        = X_opt == '---' ? na :                              X_opt == 'TRIX slope sig' ? trix_sell_s :                             X_opt == 'EMA1 x EMA2 sig' ? ema_1x2_sell_s :                              X_opt == 'HMA slope sig' ? hma_dn_e :                              X_opt == 'DMI ADX-slope sig' ? adx_dn_c :                              X_opt == 'DMI ADX mod sig' ? short_1 :                              X_opt == 'DMI ADX classic sig' ? short_2 :                              X_opt == 'Pin bar sig' ? p_bar_sell :                              X_opt == 'Inside bar sig' ? i_bar_sell :                              X_opt == 'Outside bar sig' ? o_bar_sell :                              X_opt == 'Sandwich bar sig' ? s_bar_sell :                              X_opt == 'Bar breakout 1 sig' ? bar_sig_1_sell :                              X_opt == 'Bar breakout 2 sig' ? bar_sig_2_sell :                              X_opt == 'Higher-low/lower-high bar sig' ? hllh_sell :                              X_opt == 'Entry on every bar-open sig' ? open_sell :                              X_opt == 'SMA sig' ? sma_sell :                              X_opt == 'Fractals sig' ? fr_dnx :                              X_opt == 'Reverse fractal sig' ? rev_up_fr_sell :                              X_opt == 'MACD(fast) slope sig' ? macd_slope_dn_e :                              X_opt == 'RSI50 sig' ? rsi_f_sell :                              X_opt == 'Parabolic SAR sig' ? psar_sell :                              X_opt == 'ALMA slope sig' ? alma_slo_dn_e :                              X_opt == 'SuperTrend sig' ? sup_sell :                              X_opt == 'Price X Kijun sig' ? kijun_sell :                              X_opt == 'Price X Kumo sig' ? kumo_sell :                              X_opt == 'Kumo flip sig' ? kumo_flip_sell :                              X_opt == 'Chikou X price sig' ? chikou_X_price_sell :                              X_opt == 'Chikou X Kumo sig' ? chikou_X_kumo_sell :                              X_opt == 'Price X Tenkan sig' ? price_X_tenkan_sell :                              X_opt == 'Tenkan X Kumo sig' ? tenkan_X_kumo_sell :                              X_opt == 'Tenkan X Kijun sig' ? tenkan_X_kijun_sell :                              X_opt == 'B1/S1 sig' ? sell_strong_S1 :                              X_opt == 'B2/S2 sig' ? sell_strong_S2 : naentry_opt_sig_buy_2         = X_opt_2 == '---' ? na :                              X_opt_2 == 'TRIX slope sig' ? trix_buy_s :                             X_opt_2 == 'EMA1 x EMA2 sig' ? ema_1x2_buy_s :                              X_opt_2 == 'HMA slope sig' ? hma_up_e :                              X_opt_2 == 'DMI ADX-slope sig' ? adx_up_c :                              X_opt_2 == 'DMI ADX mod sig' ? long_1 :                              X_opt_2 == 'DMI ADX classic sig' ? long_2 :                              X_opt_2 == 'Pin bar sig' ? p_bar_buy :                              X_opt_2 == 'Inside bar sig' ? i_bar_buy :                              X_opt_2 == 'Outside bar sig' ? o_bar_buy :                              X_opt_2 == 'Sandwich bar sig' ? s_bar_buy :                              X_opt_2 == 'Bar breakout 1 sig' ? bar_sig_1_buy :                              X_opt_2 == 'Bar breakout 2 sig' ? bar_sig_2_buy :                              X_opt_2 == 'Higher-low/lower-high bar sig' ? hllh_buy :                              X_opt_2 == 'Entry on every bar-open sig' ? open_buy :                              X_opt_2 == 'SMA sig' ? sma_buy :                              X_opt_2 == 'Fractals sig' ? fr_upx :                              X_opt_2 == 'Reverse fractal sig' ? rev_dn_fr_buy :                              X_opt_2 == 'MACD(fast) slope sig' ? macd_slope_up_e :                              X_opt_2 == 'RSI50 sig' ? rsi_f_buy :                              X_opt_2 == 'Parabolic SAR sig' ? psar_buy :                              X_opt_2 == 'ALMA slope sig' ? alma_slo_up_e :                              X_opt_2 == 'SuperTrend sig' ? sup_buy :                              X_opt_2 == 'Price X Kijun sig' ? kijun_buy :                              X_opt_2 == 'Price X Kumo sig' ? kumo_buy :                              X_opt_2 == 'Kumo flip sig' ? kumo_flip_buy :                              X_opt_2 == 'Chikou X price sig' ? chikou_X_price_buy :                              X_opt_2 == 'Chikou X Kumo sig' ? chikou_X_kumo_buy :                              X_opt_2 == 'Price X Tenkan sig' ? price_X_tenkan_buy :                              X_opt_2 == 'Tenkan X Kumo sig' ? tenkan_X_kumo_buy :                              X_opt_2 == 'Tenkan X Kijun sig' ? tenkan_X_kijun_buy :                              X_opt_2 == 'B1/S1 sig' ? buy_strong_B1 :                              X_opt_2 == 'B2/S2 sig' ? buy_strong_B2 : naentry_opt_sig_sell_2        = X_opt_2 == '---' ? na :                              X_opt_2 == 'TRIX slope sig' ? trix_sell_s :                             X_opt_2 == 'EMA1 x EMA2 sig' ? ema_1x2_sell_s :                              X_opt_2 == 'HMA slope sig' ? hma_dn_e :                              X_opt_2 == 'DMI ADX-slope sig' ? adx_dn_c :                              X_opt_2 == 'DMI ADX mod sig' ? short_1 :                              X_opt_2 == 'DMI ADX classic sig' ? short_2 :                              X_opt_2 == 'Pin bar sig' ? p_bar_sell :                              X_opt_2 == 'Inside bar sig' ? i_bar_sell :                              X_opt_2 == 'Outside bar sig' ? o_bar_sell :                              X_opt_2 == 'Sandwich bar sig' ? s_bar_sell :                              X_opt_2 == 'Bar breakout 1 sig' ? bar_sig_1_sell :                              X_opt_2 == 'Bar breakout 2 sig' ? bar_sig_2_sell :                             X_opt_2 == 'Higher-low/lower-high bar sig' ? hllh_sell :                              X_opt_2 == 'Entry on every bar-open sig' ? open_sell :                              X_opt_2 == 'SMA sig' ? sma_sell :                              X_opt_2 == 'Fractals sig' ? fr_dnx :                              X_opt_2 == 'Reverse fractal sig' ? rev_up_fr_sell :                              X_opt_2 == 'MACD(fast) slope sig' ? macd_slope_dn_e :                              X_opt_2 == 'RSI50 sig' ? rsi_f_sell :                              X_opt_2 == 'Parabolic SAR sig' ? psar_sell :                              X_opt_2 == 'ALMA slope sig' ? alma_slo_dn_e :                              X_opt_2 == 'SuperTrend sig' ? sup_sell :                              X_opt_2 == 'Price X Kijun sig' ? kijun_sell :                              X_opt_2 == 'Price X Kumo sig' ? kumo_sell :                              X_opt_2 == 'Kumo flip sig' ? kumo_flip_sell :                              X_opt_2 == 'Chikou X price sig' ? chikou_X_price_sell :                              X_opt_2 == 'Chikou X Kumo sig' ? chikou_X_kumo_sell :                              X_opt_2 == 'Price X Tenkan sig' ? price_X_tenkan_sell :                              X_opt_2 == 'Tenkan X Kumo sig' ? tenkan_X_kumo_sell :                              X_opt_2 == 'Tenkan X Kijun sig' ? tenkan_X_kijun_sell :                              X_opt_2 == 'B1/S1 sig' ? sell_strong_S1 :                              X_opt_2 == 'B2/S2 sig' ? sell_strong_S2 : na// buy signal options 1opt_sig_buy_1               = htf_entr_opt_1 == 'Current' ? entry_opt_sig_buy_1[repaint == 'Allowed' ? 0 : 1] :                              f_secureSecurity(syminfo.tickerid,                              htf_entr_opt_1 == '5m' ? '5' : htf_entr_opt_1 == '10m' ? '10' : htf_entr_opt_1 == '15m' ? '15' :                              htf_entr_opt_1 == '30m' ? '30' : htf_entr_opt_1 == '1H' ? '60' : htf_entr_opt_1 == '2H' ? '120' : htf_entr_opt_1 == '3H' ? '180' : htf_entr_opt_1 == '4H' ? '240' :                              htf_entr_opt_1 == '6H' ? '360' : htf_entr_opt_1 == '12H' ? '720' : htf_entr_opt_1 == 'D' ? 'D' : htf_entr_opt_1 == '3D' ? '3D' : htf_entr_opt_1 == 'W' ? 'W' :                              htf_entr_opt_1 == 'M' ? 'M' : na, entry_opt_sig_buy_1)opt_sig_buy_11              = X_opt == 'Grid - counter trend sig (no tf filter)' ? grid_ct_buy :                              X_opt == 'Grid - reentry sig (no tf filter)' ? grid_re_buy :                              X_opt == 'Fractals trend lines sig (no tf filter)' ? buy_up_line :                              X_opt == 'Segments sig (no tf filter)' ? segments_buy :                              X_opt == 'CB/CS sig (no tf filter)' ? long_c[repaint == 'Allowed' ? 0 : 1] :                              X_opt == 'IB/IS sig (no tf filter)' ? long_pic[repaint == 'Allowed' ? 0 : 1] : na// sell signal options 1opt_sig_sell_1              = htf_entr_opt_1 == 'Current' ? entry_opt_sig_sell_1[repaint == 'Allowed' ? 0 : 1] :                              f_secureSecurity(syminfo.tickerid,                              htf_entr_opt_1 == '5m' ? '5' : htf_entr_opt_1 == '10m' ? '10' : htf_entr_opt_1 == '15m' ? '15' :                              htf_entr_opt_1 == '30m' ? '30' : htf_entr_opt_1 == '1H' ? '60' : htf_entr_opt_1 == '2H' ? '120' : htf_entr_opt_1 == '3H' ? '180' : htf_entr_opt_1 == '4H' ? '240' :                              htf_entr_opt_1 == '6H' ? '360' : htf_entr_opt_1 == '12H' ? '720' : htf_entr_opt_1 == 'D' ? 'D' : htf_entr_opt_1 == '3D' ? '3D' : htf_entr_opt_1 == 'W' ? 'W' :                              htf_entr_opt_1 == 'M' ? 'M' : na, entry_opt_sig_sell_1)opt_sig_sell_11             = X_opt == 'Grid - counter trend sig (no tf filter)' ? grid_ct_sell :                              X_opt == 'Grid - reentry sig (no tf filter)' ? grid_re_sell :                              X_opt == 'Fractals trend lines sig (no tf filter)' ? sell_dn_line :                              X_opt == 'Segments sig (no tf filter)' ? segments_sell :                              X_opt == 'CB/CS sig (no tf filter)' ? short_c[repaint == 'Allowed' ? 0 : 1] :                              X_opt == 'IB/IS sig (no tf filter)' ? short_pic[repaint == 'Allowed' ? 0 : 1] : na// buy signal options 2opt_sig_buy_2               = htf_entr_opt_2 == 'Current' ? entry_opt_sig_buy_2[repaint == 'Allowed' ? 0 : 1] :                              f_secureSecurity(syminfo.tickerid,                              htf_entr_opt_2 == '5m' ? '5' : htf_entr_opt_2 == '10m' ? '10' : htf_entr_opt_2 == '15m' ? '15' :                              htf_entr_opt_2 == '30m' ? '30' : htf_entr_opt_2 == '1H' ? '60' : htf_entr_opt_2 == '2H' ? '120' : htf_entr_opt_2 == '3H' ? '180' : htf_entr_opt_2 == '4H' ? '240' :                              htf_entr_opt_2 == '6H' ? '360' : htf_entr_opt_2 == '12H' ? '720' : htf_entr_opt_2 == 'D' ? 'D' : htf_entr_opt_2 == '3D' ? '3D' : htf_entr_opt_2 == 'W' ? 'W' :                              htf_entr_opt_2 == 'M' ? 'M' : na, entry_opt_sig_buy_2)opt_sig_buy_22              = X_opt_2 == 'Grid - counter trend sig (no tf filter)' ? grid_ct_buy :                              X_opt_2 == 'Grid - reentry sig (no tf filter)' ? grid_re_buy :                              X_opt_2 == 'Fractals trend lines sig (no tf filter)' ? buy_up_line :                              X_opt_2 == 'Segments sig (no tf filter)' ? segments_buy :                              X_opt_2 == 'CB/CS sig (no pyr, no tf filter)' ? long_c[repaint == 'Allowed' ? 0 : 1] :                              X_opt_2 == 'IB/IS sig (no pyr, no tf filter)' ? long_pic[repaint == 'Allowed' ? 0 : 1] : na// sell signal options 2opt_sig_sell_2              = htf_entr_opt_2 == 'Current' ? entry_opt_sig_sell_2[repaint == 'Allowed' ? 0 : 1] :                              f_secureSecurity(syminfo.tickerid,                              htf_entr_opt_2 == '5m' ? '5' : htf_entr_opt_2 == '10m' ? '10' : htf_entr_opt_2 == '15m' ? '15' :                              htf_entr_opt_2 == '30m' ? '30' : htf_entr_opt_2 == '1H' ? '60' : htf_entr_opt_2 == '2H' ? '120' : htf_entr_opt_2 == '3H' ? '180' : htf_entr_opt_2 == '4H' ? '240' :                              htf_entr_opt_2 == '6H' ? '360' : htf_entr_opt_2 == '12H' ? '720' : htf_entr_opt_2 == 'D' ? 'D' : htf_entr_opt_2 == '3D' ? '3D' : htf_entr_opt_2 == 'W' ? 'W' :                              htf_entr_opt_2 == 'M' ? 'M' : na, entry_opt_sig_sell_2)opt_sig_sell_22             = X_opt_2 == 'Grid - counter trend sig (no tf filter)' ? grid_ct_sell :                              X_opt_2 == 'Grid - reentry sig (no tf filter)' ? grid_re_sell :                              X_opt_2 == 'Fractals trend lines sig (no tf filter)' ? sell_dn_line :                              X_opt_2 == 'Segments sig (no tf filter)' ? segments_sell :                              X_opt_2 == 'CB/CS sig (no tf filter)' ? short_c[repaint == 'Allowed' ? 0 : 1] :                              X_opt_2 == 'IB/IS sig (no tf filter)' ? short_pic[repaint == 'Allowed' ? 0 : 1] : na//---------------------------------------------------- Take profit, stop loss and trailing price --------------------------------------------------------//take profit of average position priceatr_sec                     = request.security(syminfo.tickerid, atr_tf, ta.atr(atr_l))atr_calc                    = atr_sec * atr_facttp_step = 0.tp_step := nz(high > tp_step[1] + atr_calc or low < tp_step[1] - atr_calc ? close : tp_step[1])tp_step_l                   = tp_step > tp_step[1]tp_step_s                   = tp_step < tp_step[1]av_profit_l                 = close - strategy.position_avg_price > atr_calc and tp_step_lav_profit_s                 = strategy.position_avg_price - close > atr_calc and tp_step_s//stop loss of average position priceatr_sec_l                   = request.security(syminfo.tickerid, atr_tf_l, ta.atr(atr_l_l))atr_calc_l                  = atr_sec_l * atr_fact_lsl_step = 0.sl_step := nz(high > sl_step[1] + atr_calc_l or low < sl_step[1] - atr_calc_l ? close : sl_step[1])sl_step_l                   = sl_step < sl_step[1]sl_step_s                   = sl_step > sl_step[1]sl_t_l                      = strategy.position_avg_price - close > atr_calc_l and sl_step_lsl_t_s                      = close - strategy.position_avg_price > atr_calc_l and sl_step_s//average position price lineplot(plot_avg_price ? strategy.position_avg_price : na, linewidth=1, color=color.new(color.blue, 30), title='position_avg_price')//---------------------------------------------------------------- strategy entry / exit -----------------------------------------------------------------long                        = entry_type != 'Short'                 // long or bothshort                       = entry_type != 'Long'                  // short or bothboth                        = entry_type == 'Both'                  // both//exit filterexit_long_1                 = exit_filter_sell_1 or exit_filter_sell_2 or exit_filter_sig_sell_11 or exit_filter_sig_sell_22exit_short_1                = exit_filter_buy_1 or exit_filter_buy_2 or exit_filter_sig_buy_11 or exit_filter_sig_buy_22//opposite signal as exit signalexit_long_2                 = opt_sig_sell_1 or opt_sig_sell_2 or opt_sig_sell_11 or opt_sig_sell_22exit_short_2                = opt_sig_buy_1 or opt_sig_buy_2 or opt_sig_buy_11 or opt_sig_buy_22//long entry conditions for the 1st and the 2nd entry signalentry_long_1                = (opt_sig_buy_11 or opt_sig_buy_1) and entry_filter_buy_1 and entry_filter_buy_2 and entry_filter_buy_11 and entry_filter_buy_22 and not exit_long_1entry_long_2                = (opt_sig_buy_22 or opt_sig_buy_2) and entry_filter_buy_1 and entry_filter_buy_2 and entry_filter_buy_11 and entry_filter_buy_22 and not exit_long_1//short entry conditions for the 1st and the 2nd entry signalentry_short_1               = (opt_sig_sell_11 or opt_sig_sell_1) and entry_filter_sell_1 and entry_filter_sell_2 and entry_filter_sell_11 and entry_filter_sell_22 and not exit_short_1entry_short_2               = (opt_sig_sell_22 or opt_sig_sell_2) and entry_filter_sell_1 and entry_filter_sell_2 and entry_filter_sell_11 and entry_filter_sell_22 and not exit_short_1if backtest_period()    if long        if entry_long_1            strategy.entry('os_b', strategy.long)                                                                               // 1st entry signal         if one_side_pyr and entry_long_2            strategy.entry('os_b', strategy.long)                                                                               // 2nd entry signal when in pyramiding mode                        if not both and not one_side_pyr ? exit_long_2 : exit_long_1            strategy.close('os_b')                                                                                              // opposite signal or exit-filter signal exit                 if not both and one_side_pyr ? exit_long_1 and not exit_long_1[1] : na            strategy.close('os_b')                                                                                              // exit-filter exit         if av_tp_en and av_profit_l            strategy.close('os_b', qty_percent= av_tp_qty)                                                                      // average take profit                if sl_en and sl_t_l            strategy.close('os_b', qty_percent= av_sl_qty)                                                                      // average stop loss    if short        if entry_short_1            strategy.entry('os_s', strategy.short)         if one_side_pyr and entry_short_2            strategy.entry('os_s', strategy.short)        if not both and not one_side_pyr ? exit_short_2 : exit_short_1            strategy.close('os_s')        if not both and one_side_pyr ? exit_short_1 and not exit_short_1[1] : na            strategy.close('os_s')        if av_tp_en and av_profit_s            strategy.close('os_s', qty_percent= av_tp_qty)        if sl_en and sl_t_s            strategy.close('os_s', qty_percent= av_sl_qty) //alert messages - same conditions like strategy....() - live tradingif  long and entry_long_1 or      long and (one_side_pyr ? entry_long_2 : na)    alert(message= 'BybitAPI(BTCUSD) { continue(if=positionShort); market(position= 0); } BybitAPI(BTCUSD) { wait(0.5s); market(side=buy, amount=' + str.tostring(lot_size) + '); } \n #bot',      freq= alert.freq_once_per_bar)if  short and entry_short_1 or      short and (one_side_pyr ? entry_short_2 : na)    alert(message= 'BybitAPI(BTCUSD) { continue(if=positionLong); market(position= 0); } BybitAPI(BTCUSD) { wait(0.5s); market(side=sell, amount=' + str.tostring(lot_size) + '); } \n #bot',      freq= alert.freq_once_per_bar)if  long and (not both and not one_side_pyr ? exit_long_2 : exit_long_1) or        long and (not both and one_side_pyr ? exit_long_1 and not exit_long_1[1] : na) or         short and (not both and not one_side_pyr ? exit_short_2 : exit_short_1) or         short and (not both and one_side_pyr ? exit_short_1 and not exit_short_1[1] : na)        alert(message= 'BybitAPI(BTCUSD) { market(position= 0 %p); } \n #bot', freq= alert.freq_once_per_bar)var float av_tp_qty_var     = 100 - av_tp_qty                                                                                                                           // calc because of alertatron syntax stringvar float av_sl_qty_var     = 100 - av_sl_qtyif  long and (av_tp_en ? av_profit_l : na) or     short and (av_tp_en ? av_profit_s : na)        alert(message= 'BybitAPI(BTCUSD) { market(position=' + str.tostring(av_tp_qty_var) + '%p); } \n #bot', freq= alert.freq_once_per_bar)if  long and (sl_en ? sl_t_l : na) or     short and (sl_en ? sl_t_s : na)        alert(message= 'BybitAPI(BTCUSD) { market(position=' + str.tostring(av_sl_qty_var) + '%p); } \n #bot', freq= alert.freq_once_per_bar)