Pine Script v5 · Strategy
Grid Tool
A Pine Script v5 strategy built on Lowest or Highest (TKlength), Crossover (high, KJ) and Crossunder (low, KJ). It has 22 order rules, 8 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.01 contracts and pays 0.075% commission. 105 settings; defaults include Trade Direction Long, Repainting Allowed and Strategy Switch/Trigger Level 0.
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 Grid Tool repaint?
- Yes
- At least one pattern in the source can repaint: intrabar recalculation.
- How did Grid Tool do on BTCUSDT 1D with default settings?
- Not measured
- It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its code limits trading to a date window, which can leave this period out. It closed no trades on the other markets either. A backtest, not investment advice.
- What alerts does Grid Tool have?
- 14
- BybitAPI(BTCUSD) { continue(if=positionShort); market(position= 0); } BybitAPI(BTCUSD) { wait(0.5s); market(side=buy, amount=' + str.tostring(pos_qty_lv) + '); } \n #bot; BybitAPI(BTCUSD) { continue(if=positionShort); market(position= 0); } BybitAPI(BTCUSD) { wait(0.5s); market(side=buy, amount=' + str.tostring(pos_qty_lv) + '); } \n #bot; BybitAPI(BTCUSD) { continue(if=positionLong); market(position= 0); } BybitAPI(BTCUSD) { wait(0.5s); market(side=sell, amount=' + str.tostring(pos_qty_lv) + '); } \n #bot; BybitAPI(BTCUSD) { continue(if=positionLong); market(position= 0); } BybitAPI(BTCUSD) { wait(0.5s); market(side=sell, amount=' + str.tostring(pos_qty_lv) + '); } \n #bot; and more.
- Does Grid Tool run in Pine Script v6?
- Not tested
- Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download.
- Does Grid Tool use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
BTCUSDT · 1D · default settings
- Winning trade
- Losing trade
- Equity
- Buy and hold
Needs BINANCE:BTCUSDT NaN data, not available: "NaN" is not a timeframe the engine reads Values that depend on it are empty on this chart.
| Position Size: .0000 |
| Unrealized Profit/Loss: .00 |
- Net profit
- 0.00%
- $0.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 0
- 0 won · 0 lost
- Profitable
- 0.0%
- of closed trades
- Profit factor
- —
- gross profit ÷ gross loss
- Max drawdown
- 0.00%
- $0.00
One run with the author's default settings, $10,000 starting capital, commission as the script sets it. 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_x, 50) ignores the settings line 474
Line 474 hard-codes 50 where line 525 uses “Exit DMI 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 341
Line 341 hard-codes 1 where line 460 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 342
Line 342 hard-codes 1 where line 460 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 342
Line 342 hard-codes 1 where line 460 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 342
Line 342 hard-codes 1 where line 460 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 347
Line 347 hard-codes 1 where line 460 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 349
Line 349 hard-codes 1 where line 460 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 349
Line 349 hard-codes 1 where line 460 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 349
Line 349 hard-codes 1 where line 460 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_f, 1) ignores the settings line 446
Line 446 hard-codes 1 where line 460 uses “MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.
ta.rising(alma_f, 1)ta.rising(alma_f, slope_len) -
Likely bug
ta.rising(alma_x, 1) ignores the settings line 449
Line 449 hard-codes 1 where line 460 uses “MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.
ta.rising(alma_x, 1)ta.rising(alma_x, slope_len) -
Likely bug
ta.rising(alma_x, 1) ignores the settings line 449
Line 449 hard-codes 1 where line 460 uses “MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.
ta.rising(alma_x, 1)ta.rising(alma_x, slope_len) -
Likely bug
ta.rising(alma_x, 1) ignores the settings line 449
Line 449 hard-codes 1 where line 460 uses “MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.
ta.rising(alma_x, 1)ta.rising(alma_x, slope_len) -
Likely bug
ta.rising(adx_s, 1) ignores the settings line 522
Line 522 hard-codes 1 where line 460 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.falling(trix_x, 1) ignores the settings line 343
Line 343 hard-codes 1 where line 462 uses “Exit 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_x) -
Likely bug
ta.falling(trix_x, 1) ignores the settings line 343
Line 343 hard-codes 1 where line 462 uses “Exit 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_x) -
Likely bug
ta.falling(trix_x, 1) ignores the settings line 343
Line 343 hard-codes 1 where line 462 uses “Exit 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_x) -
Likely bug
ta.falling(hma_f, 1) ignores the settings line 348
Line 348 hard-codes 1 where line 462 uses “Exit 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_x) -
Likely bug
ta.falling(hma_x, 1) ignores the settings line 350
Line 350 hard-codes 1 where line 462 uses “Exit 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_x) -
Likely bug
ta.falling(hma_x, 1) ignores the settings line 350
Line 350 hard-codes 1 where line 462 uses “Exit 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_x) -
Likely bug
ta.falling(hma_x, 1) ignores the settings line 350
Line 350 hard-codes 1 where line 462 uses “Exit 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_x) -
Likely bug
ta.falling(alma_x, 1) ignores the settings line 450
Line 450 hard-codes 1 where line 462 uses “Exit MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.
ta.falling(alma_x, 1)ta.falling(alma_x, slope_len_x) -
Likely bug
ta.falling(alma_x, 1) ignores the settings line 450
Line 450 hard-codes 1 where line 462 uses “Exit MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.
ta.falling(alma_x, 1)ta.falling(alma_x, slope_len_x) -
Likely bug
ta.falling(alma_x, 1) ignores the settings line 450
Line 450 hard-codes 1 where line 462 uses “Exit MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.
ta.falling(alma_x, 1)ta.falling(alma_x, slope_len_x) -
Likely bug
ta.falling(adx_x, 1) ignores the settings line 528
Line 528 hard-codes 1 where line 462 uses “Exit MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.
ta.falling(adx_x, 1)ta.falling(adx_x, slope_len_x) -
Likely bug
ta.falling(adx_x, 1) ignores the settings line 528
Line 528 hard-codes 1 where line 462 uses “Exit MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.
ta.falling(adx_x, 1)ta.falling(adx_x, slope_len_x) -
Likely bug
ta.falling(adx_x, 1) ignores the settings line 528
Line 528 hard-codes 1 where line 462 uses “Exit MACD MacdlLine Slope Lenth”. Changing those settings moves one band but not this one.
ta.falling(adx_x, 1)ta.falling(adx_x, slope_len_x) -
Likely bug
ta.pivothigh(2, 2) ignores the settings line 364
Line 364 hard-codes 2 where line 420 uses “Pin Bar Sensitivity 2”. Changing those settings moves one band but not this one.
ta.pivothigh(2, 2)ta.pivothigh(high, p_bar_sens_2) -
Likely bug
ta.pivothigh(high, 3, 0) ignores the settings line 416
Line 416 hard-codes 3 where line 420 uses “Pin Bar Sensitivity 2”. Changing those settings moves one band but not this one.
ta.pivothigh(high, 3, 0)ta.pivothigh(high, p_bar_sens_2, 0) -
Likely bug
ta.pivothigh(high, 4, 1) ignores the settings line 416
Line 416 hard-codes 4 where line 420 uses “Pin Bar Sensitivity 2”. Changing those settings moves one band but not this one.
ta.pivothigh(high, 4, 1)ta.pivothigh(high, p_bar_sens_2, 1) -
Likely bug
ta.pivothigh(high, 4, 1) ignores the settings line 416
Line 416 hard-codes 4 where line 420 uses “Pin Bar Sensitivity 2”. Changing those settings moves one band but not this one.
ta.pivothigh(high, 4, 1)ta.pivothigh(high, p_bar_sens_2, 1) -
Likely bug
ta.pivotlow(2, 2) ignores the settings line 365
Line 365 hard-codes 2 where line 421 uses “Pin Bar Sensitivity 2”. Changing those settings moves one band but not this one.
ta.pivotlow(2, 2)ta.pivotlow(low, p_bar_sens_2) -
Likely bug
ta.pivotlow(low, 3, 0) ignores the settings line 417
Line 417 hard-codes 3 where line 421 uses “Pin Bar Sensitivity 2”. Changing those settings moves one band but not this one.
ta.pivotlow(low, 3, 0)ta.pivotlow(low, p_bar_sens_2, 0) -
Likely bug
ta.pivotlow(low, 4, 1) ignores the settings line 417
Line 417 hard-codes 4 where line 421 uses “Pin Bar Sensitivity 2”. Changing those settings moves one band but not this one.
ta.pivotlow(low, 4, 1)ta.pivotlow(low, p_bar_sens_2, 1) -
Likely bug
ta.pivotlow(low, 4, 1) ignores the settings line 417
Line 417 hard-codes 4 where line 421 uses “Pin Bar Sensitivity 2”. Changing those settings moves one band but not this one.
ta.pivotlow(low, 4, 1)ta.pivotlow(low, p_bar_sens_2, 1) -
Likely bug
ta.valuewhen(up_w_fr, high[2], 1) ignores the settings line 366
Line 366 hard-codes 1 where line 489 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 367
Line 367 hard-codes 0 where line 489 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 368
Line 368 hard-codes 1 where line 489 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 369
Line 369 hard-codes 0 where line 489 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.valuewhen(up_fr, high[fr_period], 0) ignores the settings line 478
Line 478 hard-codes 0 where line 489 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 479
Line 479 hard-codes 0 where line 489 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(dn_fr, low[fr_period], 1) ignores the settings line 494
Line 494 hard-codes 1 where line 489 uses “Exit Fractals - Past Fractal”. Changing those settings moves one band but not this one.
ta.valuewhen(dn_fr, low[fr_period], 1)ta.valuewhen(dn_fr, low[fr_period], fr_past_x) -
Likely bug
ta.valuewhen(up_fr, high[fr_period], 1) ignores the settings line 495
Line 495 hard-codes 1 where line 489 uses “Exit Fractals - Past Fractal”. Changing those settings moves one band but not this one.
ta.valuewhen(up_fr, high[fr_period], 1)ta.valuewhen(up_fr, high[fr_period], fr_past_x) -
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 50), period_stop (line 52) 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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| General DescriptionThis script can make you free from entry decisions. You just have to manage your exits or additionally manage your exits. Exiting a trend is more important than enter a trade. Use a small time frame for the grid signals to get the distance between the trades as accurate as possible for the selected grid gap distance since TV back tests are carried out with closed bars. Before set up the grid-tool: pre-analyse the market to make sure it is in a trend or will be soon. Select the grid gap and grid position size that you are comfortable with. Define the start date for the grid (start of a new trend), select a signal and use optionally filters, stop loss and take profit. Monitor the trend and your exit levels. The default values are suitable for Bitcoin on ByBit (one tick = 0.5). | false | bool | unused |
| Trade DirectionLong = long entries only, Short = short entries only, both = long and short entries. | Long | string · options ['Long', 'Short', 'Both'] | 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. If repainting \'Allowed\' is selected, 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. Signals on current time frame (\'Current\' time frame filter is selected) do not repaint by default. | Allowed | string · 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_buy_11 exit_filter_sell_1 exit_filter_sell_11 exit_filter_buy_2 exit_filter_buy_22 exit_filter_sell_2 exit_filter_sell_22 line 631 line 960 |
| Plot Info PanelInfo panel for current unrealized profit or loss for the open position. | true | bool | line 220 |
| Plot Position Avarage Price Line.This plots the position avarage price line. Green = position is in profit, red = position is in loss. | true | bool | position_avg_price |
| Scalping ModeWorks only with TP/SL and their enabled counter (output filters are optional). Choose an entry signal and define the scalping signal using entry filters. Makes strategy entry signal idle between exit event and new scalping signal. | false | bool | scalp_l scalp_s entry os_b entry os_b entry os_b entry os_s entry os_s entry os_s line 1035 line 1038 line 1040 line 1059 line 1061 line 1063 |
| Strategy trigger and border levels: | |||
| Enable Strategy Switch/Trigger LevelThis enables the strategy price level that must be crossed. Otherwise the strategy entry signals will be ignored. The stop loss and take profit is not affected. | false | bool | trig_line en_strat_st |
| Strategy Switch/Trigger LevelDefine the price level which must be crossed (up or down) to make the strategy entry signals work. | 0 | float · min 0 · step 200 | trig_line line 903 |
| Enable Upper Border LevelIn case the market has crossed this level, the strategy entry signals will be turned off (long and short). The stop loss and take profit is not affected. Works when "Strategy Switch/Trigger Level" is not activated or an activated trigger level was crossed. | false | bool | bup_line en_strat_bup |
| Strategy Upper Border LevelDefine strategy upper border level. | 0 | float · min 0 · step 200 | bup_line line 908 |
| Enable Lower Border LevelIn case the market has crossed this level, the strategy entry signals will be turned off (long and short). The stop loss and take profit is not affected. Works when "Strategy Switch/Trigger Level" is not activated or an activated trigger level was crossed. | false | bool | bdn_line en_strat_bdn |
| Strategy Lower Border LevelDefine strategy lower border level. | 0 | float · min 0 · step 200 | bdn_line line 913 |
| Strategy Behaviour When A Border Level Is CrossedSelect the strategy behaviour when a border level is crossed. "Turn Off Entries" = The strategy entry signals will be turned off (long and short). The stop loss and take profit is not affected. "Idle" = The strategy remains idle. Affects entries, stop loss, take profit and exit filters. Position remains open. "Close All" = The entire position will be closed and strategy remains idle. | Close All | string · options ['Turn Off Entries', 'Idle', 'Close All'] | line 920 line 922 |
| Extend LinesSelect the trigger and border line extention | Right | string · options ['Right', 'Both'] | trig_line bup_line bdn_line |
| Enable "Close & Stop" LevelIn case the market has crossed this level, the entire position will be closed and the strategy remains idle. This Feature works on current bar and is independent of time and date. | false | bool | clst_line strat_cl_st |
| "Close & Stop" LevelDefine "Close & Stop" level. | 0 | float · min 0 · step 100 | clst_line line 898 |
| Define the period of the grid/trend: | |||
| Instant GridThis enables the grid with current time and date. Do not change input settings while running an instant grid otherwise the grid will restart at current bar. | false | bool | line 960 line 1033 line 1088 |
| Period start (no label in the script)Trend/grid start date and time. In case of live trading you have to set the period to the current date and time otherwise history trades will influence the position management. | timestamp('01 SEP 2022 00:00 +0000') | time | trig_line bup_line bdn_line line 232 |
| Period stop (no label in the script)Trend/grid end date and time. | timestamp('31 Dec 2122 00:00 +0000') | time | line 232 |
| Backtesting and live-trading lot size: | |||
| Lot Size - BacktestingAffects backtesting only. | 0.01 | float · min 0 · step 0.01 | pos_qty |
| Lot Size - Live TradingAlertatron Bitcoin lot size string for Bybit exchange. Affects live trading only. | 50 | int · min 0 · step 50 | pos_qty_lv |
| Entry signals: | |||
| --- 1st ENTRY SIGNAL ---The grid entry signals are time independent. The Fractals signal is a breakout signal. The reverse fractal and the Pin bar signal are bottom fishing signal. | Grid - reentry | string · options ['---', 'Grid - reentry', 'Grid - counter trend', 'Fractals', 'Reverse fractal', 'Pin bar', 'BB reverse'] | opt_sig_buy_1 opt_sig_sell_1 |
| --- 2nd ENTRY SIGNAL ---The grid entry signals are time independent. The Fractals signal is a breakout signal. The reverse fractal and the pin bar signal are bottom fishing signals. | --- | string · options ['---', 'Grid - reentry', 'Grid - counter trend', 'Fractals', 'Reverse fractal', 'Pin bar', 'BB reverse'] | opt_sig_buy_2 opt_sig_sell_2 |
| Grid parameter: | |||
| Grid Gap - Base CurrencyThe minimum trigger-gap between two trades in case of a selected grid signal. | 500 | float · min 0 · step 50 | re_grid |
| First position size: | |||
| Enable First PositionThis enables the first position that will be opened when entry condition is met. In case all positions are closed, a new "first position" will be opened. Works when no exit filters are selected. | false | bool | pos_qty pos_qty_lv entry os_b entry os_s line 1040 line 1063 line 1093 line 1099 |
| Instantly On Current Bar CloseThis opens the first position immediately when the grid is placed and the current bar is closed. | false | bool | entry os_b entry os_s line 1040 line 1063 line 1093 line 1099 |
| Position Start-Size - BacktestingThis replaces the default strategy position size ("Lot Size - Backtesting") and is the starting position size. Backtesting only. | 0.05 | float · min 0.000001 · step 0.01 | pos_qty |
| Position Start-Size - Live TradingThis replaces the default strategy live trading position size ("Lot Size - Live Trading") and is the starting position size. Live trading only. | 250 | float · min 0.000001 · step 50 | pos_qty_lv |
| Automatic position size increase for each trade (Martingale): | |||
| Enable Position Auto-IncreaseThis enables the automatic increase in position size for each trade. With "Position Factor = 1" you get the martingale sequence. This \'automatic increase\' works until a position has been closed. After a closing event, this function remains inactive. Works not with "Trade Direction" = "Both". | false | bool | pos_qty pos_qty_lv |
| Position FactorThis factor controls the position size. The next position size is: strategy_position_size + strategy_position_size * position_factor. Keep in mind that a take profit event reduces the current position size. | 0.5 | float · min 0.000001 · step 0.1 | pos_qty mart_lot_size |
| Position CountThis value determines how often the position is increased. | 4 | int · min 1 · step 1 | pos_c_cond |
| Position Start-Size - BacktestingThis replaces the default strategy position size ("Lot Size - Backtesting") and is the starting position size for "Auto-Increase". Backtesting only. | 0.01 | float · min 0.000001 · step 0.001 | pos_qty |
| Position Start-Size - Live TradingThis replaces the default live trading strategy position size ("Lot Size - Live Trading") and is the starting position size for "Auto-Increase". Live trading only. | 100 | float · min 0.000001 · step 50 | mart_lot_size pos_qty_lv |
| Take profit based on average-position-price: | |||
| Enable Take Profit - Average-Position-Price ProfitProfit taking condition: current price >= average price of positions + "Take Average-Price Of Positions Profit..." AND current price >= average-price of positions + "Take Profit Step...". Enable when scalping mode is used. | true | bool | enabled_sl_tp close os_b close os_s line 1044 line 1067 line 1103 line 1107 |
| Take Average-Position-Price Profit - Quantity Of Position (Percent)Reduction of current position in percent. Affects backtesting and live trading. | 10 | float · min 0 · max 100 · step 5 | av_tp_qty_c_l av_tp_qty_c_s |
| Take Average-Position-Price Profit - Base CurrencyThe profit in points of base currency, calculated from the average price of all open trades. | 500 | float · min 0 · step 50 | av_profit_l av_profit_s |
| Take Profit Step - Base CurrencyThe minimum distance between two profit-taking events in case of "Take Average-Entry Profit - Quantity Of Position (Percent)" < 100. | 500 | float · min 0 · step 50 | tp_step |
| Enable Take Profit CountEnables "Take Profit Count". If disabled the stepwise take profit is endless. Enable when scalping mode is used. | false | bool | av_tp_qty_c_l av_tp_qty_c_s enabled_sl_tp |
| Take Profit CountDefines how many times a take profit event will happen before the entire position will be closed. Once the counter limit has been reached the counter gets reseted. | 3 | int · min 1 · step 1 | count_con_tp_l count_con_tp_s |
| Break even stop loss: | |||
| Close On Break Even And Remain IdleSets the stop loss to break even after the first take profit event. Strategy remains idle after a break even close event. Works on live trading too but the triggering lot size is the backtest lot size. | false | bool | break_ev |
| Close Partly On Break EvenSets a partly stop loss on break even. Strategy will not be further affected after a partly break even close event. Works on live trading too but the triggering lot size is the backtest lot size. | false | bool | rep_even_long rep_even_short |
| Percent Close On Break EvenPercent of position that will be closed after a break even event. | 50 | int · min 0 · max 100 · step 5 | rep_ev_qty_var close os_b close os_s |
| Min Lot Size (Backtesting lot size)Min lot size to trigger break even partly close. Current lot size > "Min Lot Size" | 0.1 | float · min 0 · step 0.01 | rep_even_long rep_even_short |
| Stop loss based on average-position price or recent top/bottom: | |||
| 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...". Enable when scalping mode is used. | true | bool | enabled_sl_tp close os_b close os_s line 1046 line 1069 line 1105 line 1109 |
| Toggle: Average-Position-Price Loss (Default) / Top/Bottom Based LossStop loss condition top/bottom mode: current price <> last local top/bottom AND step condition. Stop loss condition average-position-price loss mode: price <> average entry position price AND step condition. Default = selected. | true | bool | av_loss_l av_loss_s |
| Stop Average-Position-Price Loss - Quantity Of Position (Percent)Reduction of current position in percent. Affects backtesting and live trading. | 30 | float · min 0 · max 100 · step 5 | av_sl_qty_c_l av_sl_qty_c_s |
| Stop Average-Position-Price Loss - Base CurrencyThe loss in points of base currency, calculated from the average-position-price of all open trades. | 500 | float · min 0 · step 50 | av_loss_l av_loss_s |
| Stop Loss Step - Base CurrencyThe minimum distance between two stop-loss events in case of "Stop Average-Position-Price Loss - Quantity Of Position (Percent)" < 100. | 500 | float · min 0 · step 50 | sl_step |
| Top/Bottom SensitivityNumber of past candles within the top and bottom are detected. For "Top/Bottom Based Loss" only. | 20 | int · min 1 · step 1 | top bottom |
| Enable Stop Loss CountEnables "Stop Loss Count". If disabled the stepwise stop loss is endless. Enable when scalping mode is used. | false | bool | av_sl_qty_c_l av_sl_qty_c_s enabled_sl_tp |
| Stop Loss CountDefines how many times a take profit event will happen before the entire position will be closed. Once the counter limit has been reached the counter gets reseted. | 3 | int · min 1 · step 1 | count_con_sl_l count_con_sl_s |
| 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. | Current | string · options ['Current', '5m', '10m', '15m', '30m', '1H', '2H', '3H', '4H', '6H', '8H', '12H', 'D', '3D', 'W', 'M'] | entry_filter_buy_1 entry_filter_sell_1 entry_filter_buy_2 entry_filter_sell_2 exit_filter_buy_1 exit_filter_sell_1 exit_filter_buy_2 exit_filter_sell_2 |
| Time Frame - Entry Filter 2The time frame for the 2nd ENTRY SIGNAL filter. Choose always a higher time frame than the current. Lower time frames than the current may result in false values. | Current | string · options ['Current', '5m', '10m', '15m', '30m', '1H', '2H', '3H', '4H', '6H', '8H', '12H', 'D', '3D', 'W', 'M'] | entry_filter_buy_2 entry_filter_sell_2 |
| Entry Filter 1Various filter signals for the 1nd ENTRY SIGNAL. | --- | string · options ['---', 'Fractals trend lines filter (no tf filter)', 'Bar breakout 1 filter', 'Bar breakout 2 filter', 'SMA filter', 'MACD filter', 'MACD(fast) slope filter', 'RSI50 filter', 'Fractals filter', 'Segments filter (no tf filter)', 'Fractals 1-2-3 filter', 'Reverse fractal filter', 'EMA21/SMA20 filter', 'BB reverse filter (no tf filter)', 'ALMA slope filter', 'SuperTrend filter', 'EMA1 x EMA2 filter', 'ADX DMI filter', 'ADX slope filter', 'HMA slope filter', '2HMA cross filter', 'TRIX slope filter', 'Parabolic SAR 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'] | entry_filter_sig_buy_1 entry_filter_sig_sell_1 entry_filter_buy_11 entry_filter_sell_11 |
| Entry Filter 2Various filter signals for the 2nd ENTRY SIGNAL. | --- | string · options ['---', 'Fractals trend lines filter (no tf filter)', 'Bar breakout 1 filter', 'Bar breakout 2 filter', 'SMA filter', 'MACD filter', 'MACD(fast) slope filter', 'RSI50 filter', 'Fractals filter', 'Segments filter (no tf filter)', 'Fractals 1-2-3 filter', 'Reverse fractal filter', 'EMA21/SMA20 filter', 'BB reverse filter (no tf filter)', 'ALMA slope filter', 'SuperTrend filter', 'EMA1 x EMA2 filter', 'ADX DMI filter', 'ADX slope filter', 'HMA slope filter', '2HMA cross filter', 'TRIX slope filter', 'Parabolic SAR 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'] | entry_filter_sig_buy_2 entry_filter_sig_sell_2 entry_filter_buy_22 entry_filter_sell_22 |
| Exit filters: | |||
| Toggle Exit Mode 1/2Mode 1: All open positions will be closed. Entry signals are not affected. Mode 2: All open positions will be closed. New entry signals are inactive while exit signal is valid. Mode 1 = default = selected. | true | bool | kijun_buy_x kijun_sell_x kumo_buy_x kumo_sell_x bb_long_x bb_short_x trix_slo_up_x trix_slo_dn_x hma_up_x hma_dn_x hma_c_up_x hma_c_dn_x buy_up_line sell_dn_line ema_1x2_buy_x ema_1x2_sell_x alma_slo_up_x alma_slo_dn_x macd_buy_x macd_sell_x macd_slope_up_x macd_slope_dn_x rsi_f_buy_x rsi_f_sell_x fr_upx_x fr_dnx_x sup_buy_x sup_sell_x psar_buy psar_sell adx_thres_f_x dmi_long_x dmi_short_x adx_dn_x sma_buy_x sma_sell_x |
| Exit QuantityPercent of position that will be closed. Affects backtesting and live trading. | 100 | int · min 0 · max 100 · step 5 | qyt_exit_var close os_b close os_s |
| Time Frame - Exit Filter 1The time frame for Exit filter 1. Choose always a higher time frame than the current. Lower time frames than the current may result in false values. | Current | string · options ['Current', '5m', '10m', '15m', '30m', '1H', '2H', '3H', '4H', '6H', '8H', '12H', 'D', '3D', 'W', 'M'] | exit_filter_buy_1 exit_filter_sell_1 |
| Time Frame - Exit Filter 2The time frame for Exit filter 2. Choose always a higher time frame than the current. Lower time frames than the current may result in false values. | Current | string · options ['Current', '5m', '10m', '15m', '30m', '1H', '2H', '3H', '4H', '6H', '8H', '12H', 'D', '3D', 'W', 'M'] | exit_filter_buy_2 exit_filter_sell_2 |
| Exit filter 1Various exit signals for the 1nd ENTRY SIGNAL and the 2nd ENTRY SIGNAL. The exit signals are OR connected. | --- | string · options ['---', 'Fractals trend lines filter (no tf-filter)', 'ALMA slope exit', 'Reverse fractal exit', 'SMA exit', 'MACD exit', 'MACD(fast) slope exit', 'HMA slope exit', '2HMA cross exit', 'EMA1 x EMA2 exit', 'ADX slope exit', 'ADX Threshold exit', 'DMI exit', 'TRIX slope exit', 'BB reverse exit', 'RSI50 exit', 'Fractals exit', 'SuperTrend exit', 'Parabolic SAR exit', 'Cloud exit', 'Kijun exit'] | exit_sig_buy_1 exit_sig_sell_1 exit_filter_buy_11 exit_filter_sell_11 no_exit_filter |
| Exit filter 2Various exit signals for both the 1nd ENTRY SIGNAL and the 2nd ENTRY SIGNAL. The exit signals are OR connected. | --- | string · options ['---', 'Fractals trend lines filter (no tf-filter)', 'ALMA slope exit', 'Reverse fractal exit', 'SMA exit', 'MACD exit', 'MACD(fast) slope exit', 'HMA slope exit', '2HMA cross exit', 'EMA1 x EMA2 exit', 'ADX slope exit', 'ADX Threshold exit', 'DMI exit', 'TRIX slope exit', 'BB reverse exit', 'RSI50 exit', 'Fractals exit', 'SuperTrend exit', 'Parabolic SAR exit', 'Cloud exit', 'Kijun exit'] | exit_sig_buy_2 exit_sig_sell_2 exit_filter_buy_22 exit_filter_sell_22 no_exit_filter |
| Pin bar and segment parameters: | |||
| 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.6 | float · step 0.02 | pin_up_def pin_dn_def |
| Pin Bar Sensitivity 2Condition: high/low >< last two high/low. | 1 | int · min 0 · step 1 | pivot_up pivot_dn |
| Segment Max BarsThe Maximum bars between two segment highs or lows. | 10 | int · min 0 · step 1 | line 550 line 555 line 560 line 574 line 579 line 584 |
| Entry and filter signal parameters: | |||
| Fractals Period | 2 | int · min 1 | up_fr dn_fr fractal_up_v fractal_dn_v fractal_dn_v_1 fractal_up_v_1 |
| RSI Period | 14 | int · min 1 | rsi_f |
| MA Period | 50 | int · min 1 | sma_buy sma_sell sma_buy_f sma_sell_f |
| SuperTrend Multiplier | 3 | float · min 1 · step 0.1 | SuperTrend Dir |
| SuperTrend Length | 6 | int · min 1 | SuperTrend Dir |
| ALMA Window Size | 9 | int · min 1 · step 1 | alma_f |
| ALMA Offset | 0.85 | float · min 0 · step 0.05 | alma_f |
| ALMA Sigma | 6 | float · min 1 · step 1 | alma_f |
| DMI ADX Length | 10 | int · min 1 | diplus_s diminus_s adx_s |
| DMI ADX Smooth | 10 | int · min 1 | diplus_s diminus_s adx_s |
| DMI ADX Threshold | 25 | int · min 1 | adx_above_thres |
| MACD MacdlLine Slope LenthMACD\'s fast line | 1 | int · min 1 | macd_slope_up |
| HMA Length | 100 | int · min 1 · step 5 | hma_f |
| 2HMA Period | 25 | int · min 1 · step 1 | hma_n_f hma_m_f |
| EMA1 Length | 10 | int · min 1 · step 2 | ema1_f |
| EMA2 Length | 20 | int · min 1 · step 2 | ema2_f |
| TRIX Length | 10 | int · min 1 | trix_f |
| BB Length (signal) | 20 | int · min 1 | dev_s upper_bb_s lower_bb_s |
| BB StdDev Factor (signal) | 2 | float · min 0.1 · step 0.2 | dev_s |
| BB Length (filter)Formula to adapt BB length of a lower TF to a higher TF: (higher TF in minutes) / (lower TF) * (BB Length of higher TF) | 20 | int · min 1 · step 10 | dev_f upper_bb_f lower_bb_f |
| BB StdDev Factor (filter) | 2 | float · min 0.1 · step 0.2 | dev_f |
| Exit signal parameters: | |||
| Exit Fractals - Period | 2 | int · min 1 | up_fr_x dn_fr_x fractal_up_v_x fractal_dn_v_x |
| Exit Fractals - Past Fractal | 0 | int · min 0 | fractal_up_v_x fractal_dn_v_x |
| Exit RSI Period | 14 | int · min 1 | rsi_f_x |
| Exit MA Period | 50 | int · min 1 | sma_buy_x sma_sell_x |
| Exit SuperTrend Multiplier | 2 | float · min 1 | SuperTrend_x Dir_x |
| Exit SuperTrend Length | 5 | int · min 1 | SuperTrend_x Dir_x |
| Exit DMI ADX Length | 10 | int · min 1 | diplus_x diminus_x adx_x |
| Exit DMI ADX Smooth | 10 | int · min 1 | diplus_x diminus_x adx_x |
| Exit DMI ADX Threshold | 25 | int · min 1 | adx_thres_f_x |
| Exit MACD MacdlLine Slope LenthMACD\'s fast line | 1 | int · min 1 | macd_slope_up_x macd_slope_dn_x |
| EXIT HMA Length | 100 | int · min 1 · step 5 | hma_x |
| Exit 2HMA Period | 25 | int · min 1 · step 1 | hma_n_x hma_m_x |
| Exit EMA1 Length | 10 | int · min 1 · step 2 | ema1_x |
| Exit EMA2 Length | 20 | int · min 1 · step 2 | ema2_x |
| Exit ALMA Window Size | 9 | int · min 1 · step 1 | alma_x |
| Exit ALMA Offset | 0.85 | float · min 0 · step 0.05 | alma_x |
| Exit ALMA Sigma | 6 | float · min 1 · step 1 | alma_x |
| Exit TRIX Length | 10 | int · min 1 | trix_x |
| Exit BB Length | 20 | int · min 1 | dev_x upper_bb_x lower_bb_x |
| Exit BB StdDev Factor | 2 | float · min 0.1 · step 0.2 | dev_x |
What it calculates
- Lowest / HighestTKlength
TK · line 259 - Lowest / HighestKJlength
KJ · line 260 - Lowest / HighestSBlength
SB · line 262 - Crossoverhigh, KJ
kijun_buy_x · line 305 - Crossunderlow, KJ
kijun_sell_x · line 306 - Crossoverhigh, kumo_high
kumo_buy_x · line 307 - Crossunderlow, kumo_low
kumo_sell_x · line 308 - Crossunderlow, lower_bb_x
bb_long_x · line 336 - Crossoverhigh, upper_bb_x
bb_short_x · line 337 - Change / EMAta.ema(ta.ema(ta.ema(math.log(close), trix_len_f), trix_len_f), trix_len_f)
trix_f · line 339 - Change / EMAta.ema(ta.ema(ta.ema(math.log(close), trix_len_x), trix_len_x), trix_len_x)
trix_x · line 340 - Risingtrix_f, 1
trix_slo_up_f · line 341 - Risingtrix_x, 1
trix_slo_up_x · line 342 - Fallingtrix_x, 1
trix_slo_dn_x · line 343 - HMAclose, HMA Length (100)
hma_f · line 345 - HMAclose, EXIT HMA Length (100)
hma_x · line 346 - Risinghma_f, 1
hma_up_f · line 347 - Fallinghma_f, 1
hma_dn_f · line 348 - Risinghma_x, 1
hma_up_x · line 349 - Fallinghma_x, 1
hma_dn_x · line 350 - HMAhl2, 2HMA Period (25)
hma_n_f · line 354 - HMAhl2, Exit 2HMA Period (25)
hma_n_x · line 359 - Crossoverhma_m_x, hma_n_x
hma_c_up_x · line 361 - Crossunderhma_m_x, hma_n_x
hma_c_dn_x · line 362 - Pivothigh2, 2
up_w_fr · line 364 - Pivotlow2, 2
dn_w_fr · line 365 - Valuewhenup_w_fr, high[2], 1
y1_frup_1 · line 366 - Valuewhenup_w_fr, high[2], 0
y0_frup_0 · line 367 - Valuewhendn_w_fr, low[2], 1
y1_frdn_1 · line 368 - Valuewhendn_w_fr, low[2], 0
y0_frdn_0 · line 369 - Crossoverhigh, y_up_lvl
buy_up_line · line 401 - Crossunderlow, y_dn_lvl
sell_dn_line · line 402 - Pivothighhigh, Pin Bar Sensitivity 2 (1), 0
pivot_up · line 420 - Pivotlowlow, Pin Bar Sensitivity 2 (1), 0
pivot_dn · line 421 - Crossoverema1_x, ema2_x
ema_1x2_buy_x · line 441 - Crossunderema1_x, ema2_x
ema_1x2_sell_x · line 442 - ALMAclose, ALMA Window Size (9), ALMA Offset (0.85), ALMA Sigma (6)
alma_f · line 445 - Risingalma_f, 1
alma_slo_up_f · line 446 - ALMAclose, Exit ALMA Window Size (9), Exit ALMA Offset (0.85), Exit ALMA Sigma (6)
alma_x · line 448 - Risingalma_x, 1
alma_slo_up_x · line 449 - Fallingalma_x, 1
alma_slo_dn_x · line 450 - MACDclose, 12, 26, 9
macdLine_f · line 452 - MACDclose, 12, 26, 9
signalLine_f · line 452 - MACDclose, 12, 26, 9
histLine_f · line 452 - CrossovermacdLine_f, signalLine_f
macd_buy_x · line 457 - CrossundermacdLine_f, signalLine_f
macd_sell_x · line 458 - RisingmacdLine_f, MACD MacdlLine Slope Lenth (1)
macd_slope_up · line 460 - RisingmacdLine_f, Exit MACD MacdlLine Slope Lenth (1)
macd_slope_up_x · line 461 - FallingmacdLine_f, Exit MACD MacdlLine Slope Lenth (1)
macd_slope_dn_x · line 462 - RSIclose, RSI Period (14)
rsi_f · line 465 - RSIclose, Exit RSI Period (14)
rsi_f_x · line 472 - Crossoverrsi_f_x, 50
rsi_f_buy_x · line 473 - Crossunderrsi_f_x, 50
rsi_f_sell_x · line 474 - PivothighFractals Period (2), Fractals Period (2)
up_fr · line 476 - PivotlowFractals Period (2), Fractals Period (2)
dn_fr · line 477 - Valuewhenup_fr, high[fr_period], 0
fractal_up_v · line 478 - Valuewhendn_fr, low[fr_period], 0
fractal_dn_v · line 479 - Crossoverhigh, fractal_up_v
fr_upx · line 481 - Crossunderlow, fractal_dn_v
fr_dnx · line 482 - PivothighExit Fractals - Period (2), Exit Fractals - Period (2)
up_fr_x · line 487 - PivotlowExit Fractals - Period (2), Exit Fractals - Period (2)
dn_fr_x · line 488 - Valuewhenup_fr_x, high[fr_period_x], Exit Fractals - Past Fractal (0)
fractal_up_v_x · line 489 - Valuewhendn_fr_x, low[fr_period_x], Exit Fractals - Past Fractal (0)
fractal_dn_v_x · line 490 - Crossoverhigh, fractal_up_v_x
fr_upx_x · line 491 - Crossunderlow, fractal_dn_v_x
fr_dnx_x · line 492 - Valuewhendn_fr, low[fr_period], 1
fractal_dn_v_1 · line 494 - Valuewhenup_fr, high[fr_period], 1
fractal_up_v_1 · line 495 - SupertrendSuperTrend Multiplier (3), SuperTrend Length (6)
SuperTrend · line 500 - SupertrendSuperTrend Multiplier (3), SuperTrend Length (6)
Dir · line 500 - SupertrendExit SuperTrend Multiplier (2), Exit SuperTrend Length (5)
SuperTrend_x · line 507 - SupertrendExit SuperTrend Multiplier (2), Exit SuperTrend Length (5)
Dir_x · line 507 - Crossoverhigh, SuperTrend_x
sup_buy_x · line 508 - Crossunderlow, SuperTrend_x
sup_sell_x · line 509 - Crossover / SARhigh, ta.sar(start, inc, max)
psar_buy · line 511 - Crossunder / SARlow, ta.sar(start, inc, max)
psar_sell · line 512 - DMIDMI ADX Length (10), DMI ADX Smooth (10)
diplus_s · line 515 - DMIDMI ADX Length (10), DMI ADX Smooth (10)
diminus_s · line 515 - DMIDMI ADX Length (10), DMI ADX Smooth (10)
adx_s · line 515 - Risingadx_s, 1
adx_up_f · line 522 - DMIExit DMI ADX Length (10), Exit DMI ADX Smooth (10)
diplus_x · line 524 - DMIExit DMI ADX Length (10), Exit DMI ADX Smooth (10)
diminus_x · line 524 - DMIExit DMI ADX Length (10), Exit DMI ADX Smooth (10)
adx_x · line 524 - Crossunderadx_x, Exit DMI ADX Threshold (25)
adx_thres_f_x · line 525 - Crossoverdiplus_x, diminus_x
dmi_long_x · line 526 - Crossunderdiplus_x, diminus_x
dmi_short_x · line 527 - Fallingadx_x, 1
adx_dn_x · line 528 - Crossoverclose[1], sma_f(close, ma_period_x)
sma_buy_x · line 537 - Crossunderclose[1], sma_f(close, ma_period_x)
sma_sell_x · line 538 - Pivothighhigh, Top/Bottom Sensitivity (20), 0
top · line 949 - Pivotlowlow, Top/Bottom Sensitivity (20), 0
bottom · line 951
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 350 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open os_b long | entry_long_1 and not en_scalp_mode | On | 1036 |
| Open os_b long | entry_long_2 and not en_scalp_mode | On | 1039 |
| Open os_b long | inst_pos and en_1st_pos_f and no_open_pos and en_strat and not en_scalp_mode | On | 1041 |
| Open os_b long | scalp_l | On | 1043 |
| Close os_b | av_tp_en and av_profit_l and not no_open_pos | On | 1045 |
| Close os_b | av_sl_en and av_loss_l and not no_open_pos | On | 1047 |
| Close os_b | exit_long and not exit_long[1] and not no_open_pos | On | 1049 |
| Close os_b | border_close and en_close and not no_open_pos | On | 1051 |
| Close os_b | break_ev and not no_open_pos | On | 1053 |
| Close os_b | strat_cl_st and not no_open_pos | On | 1055 |
| Close os_b | rep_even_long | On | 1057 |
| Open os_s short | entry_short_1 and not en_scalp_mode | On | 1060 |
| Open os_s short | entry_short_2 and not en_scalp_mode | On | 1062 |
| Open os_s short | inst_pos and en_1st_pos_f and no_open_pos and en_strat and not en_scalp_mode | On | 1064 |
| Open os_s short | scalp_s | On | 1066 |
| Close os_s | av_tp_en and av_profit_s and not no_open_pos | On | 1068 |
| Close os_s | av_sl_en and av_loss_s and not no_open_pos | On | 1070 |
| Close os_s | exit_short and not exit_short[1] and not no_open_pos | On | 1072 |
| Close os_s | border_close and en_close and not no_open_pos | On | 1074 |
| Close os_s | break_ev and not no_open_pos | On | 1076 |
| Close os_s | strat_cl_st and not no_open_pos | On | 1078 |
| Close os_s | rep_even_short | On | 1080 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| (no title) | alert | BybitAPI(BTCUSD) { continue(if=positionShort); market(position= 0); } BybitAPI(BTCUSD) { wait(0.5s); market(side=buy, amount=' + str.tostring(pos_qty_lv) + '); } \n #bot | 1091 |
| (no title) | alert | BybitAPI(BTCUSD) { continue(if=positionShort); market(position= 0); } BybitAPI(BTCUSD) { wait(0.5s); market(side=buy, amount=' + str.tostring(pos_qty_lv) + '); } \n #bot | 1094 |
| (no title) | alert | BybitAPI(BTCUSD) { continue(if=positionLong); market(position= 0); } BybitAPI(BTCUSD) { wait(0.5s); market(side=sell, amount=' + str.tostring(pos_qty_lv) + '); } \n #bot | 1097 |
| (no title) | alert | BybitAPI(BTCUSD) { continue(if=positionLong); market(position= 0); } BybitAPI(BTCUSD) { wait(0.5s); market(side=sell, amount=' + str.tostring(pos_qty_lv) + '); } \n #bot | 1100 |
| (no title) | alert | BybitAPI(BTCUSD) { market(position= ' + str.tostring(av_tp_qty_c_l_var) + ' %p); } \n #bot | 1104 |
| (no title) | alert | BybitAPI(BTCUSD) { market(position=' + str.tostring(av_sl_qty_c_l_var) + ' %p); } \n #bot | 1106 |
| (no title) | alert | BybitAPI(BTCUSD) { market(position= ' + str.tostring(av_tp_qty_c_s_var) + ' %p); } \n #bot | 1108 |
| (no title) | alert | BybitAPI(BTCUSD) { market(position=' + str.tostring(av_sl_qty_c_s_var) + ' %p); } \n #bot | 1110 |
| (no title) | alert | BybitAPI(BTCUSD) { market(position=' + str.tostring(qyt_exit_var) + ' %p); } \n #bot | 1113 |
| (no title) | alert | BybitAPI(BTCUSD) { market(position= 0); } \n #bot | 1116 |
| (no title) | alert | BybitAPI(BTCUSD) { market(position= 0); } \n #bot | 1119 |
| (no title) | alert | BybitAPI(BTCUSD) { market(position= 0); } \n #bot | 1122 |
| (no title) | alert | BybitAPI(BTCUSD) { market(position=' + str.tostring(rep_ev_qty_var) + ' %p); } \n #bot | 1125 |
| (no title) | alert | BybitAPI(BTCUSD) { market(position=' + str.tostring(rep_ev_qty_var) + ' %p); } \n #bot | 1127 |
Does it repaint?
Yes
At least one pattern in the source can repaint; it is marked Check below.
- ClearHigher-timeframe data1 request.security call(s), none with lookahead on.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- CheckIntrabar recalculationreads realtime-only state. Live values can differ from history.
- 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
Not run on other markets: the script requests BINANCE:BTCUSDT NaN, and that data is not available here ("NaN" is not a timeframe the engine reads). Its results would rest on empty values.
Similar scripts
Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Grid Tool this page | — | v5 strategy | 0.0% | 0 | 0.0% |
| The Strategy - Ichimoku Kinko Hyo and more by ramsay09 | lowest rising rsi alma macd pivothigh pivotlow valuewhen supertrend dmi ema falling | v5 strategy | +10.3% | 57 | 16.6% |
| VXD Supercycle by Vvaz_ | supertrend ema pivothigh pivotlow valuewhen highest lowest rsi | v5 strategy | does not run in Zeal Terminal | ||
| X48 - Strategy - MA Type Cross + TPSL - Future&Spot - V.2 by X4815162342 | ema rsi highest lowest pivothigh pivotlow valuewhen | v5 strategy | does not run in Zeal Terminal | ||
| -Backtesting System by HALDRO | alma dmi rising falling highest lowest rsi | v5 strategy | +1.2% | 2 | 2.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
VerifiedNothing to change.
Does it run in Pine Script v6?
Not tested
Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © ramsay09-//@version=5+//@version=6strategy(title='Grid Tool', shorttitle='Grid', overlay=true, initial_capital=10000, pyramiding=3000, calc_on_every_tick=false, default_qty_type=strategy.fixed, default_qty_value=0.01, currency=currency.USD, ⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 263 ms | With a workaround 1,000 bars in 638 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report.
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/// © ramsay09//@version=5strategy(title='Grid Tool', shorttitle='Grid', overlay=true, initial_capital=10000, pyramiding=3000, calc_on_every_tick=false, default_qty_type=strategy.fixed, default_qty_value=0.01, currency=currency.USD, commission_type=strategy.commission.percent, commission_value=0.075, margin_long=0, margin_short=0, max_lines_count=500)general_info = input.bool(title='General Description', defval=false, tooltip="This script can make you free from entry decisions. You just have to manage your exits or additionally manage your exits. Exiting a trend is more important than enter a trade. Use a small time frame for the grid signals to get the distance between the trades as accurate as possible for the selected grid gap distance since TV back tests are carried out with closed bars. Before set up the grid-tool: pre-analyse the market to make sure it is in a trend or will be soon. Select the grid gap and grid position size that you are comfortable with. Define the start date for the grid (start of a new trend), select a signal and use optionally filters, stop loss and take profit. Monitor the trend and your exit levels. The default values are suitable for Bitcoin on ByBit (one tick = 0.5).")//-------------------------------------------------------------------------------------- inputs -----------------------------------------------------------------------------------------------entry_type = input.string('Long', title='Trade Direction', options=['Long', 'Short', 'Both'], tooltip='Long = long entries only, Short = short entries only, both = long and short entries.')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. If repainting \'Allowed\' is selected, 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. Signals on current time frame (\'Current\' time frame filter is selected) do not repaint by default.')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. Green = position is in profit, red = position is in loss.')en_scalp_mode = input.bool(false, title='Scalping Mode', tooltip='Works only with TP/SL and their enabled counter (output filters are optional). Choose an entry signal and define the scalping signal using entry filters. Makes strategy entry signal idle between exit event and new scalping signal.')en_trig_lvl = input.bool(false, title='Enable Strategy Switch/Trigger Level', group='Strategy trigger and border levels:', tooltip='This enables the strategy price level that must be crossed. Otherwise the strategy entry signals will be ignored. The stop loss and take profit is not affected.')trig_lvl = input.float(0, title='Strategy Switch/Trigger Level', minval=0, step=200, group='Strategy trigger and border levels:', tooltip='Define the price level which must be crossed (up or down) to make the strategy entry signals work.')en_border_up = input.bool(false, title='Enable Upper Border Level', group='Strategy trigger and border levels:', tooltip='In case the market has crossed this level, the strategy entry signals will be turned off (long and short). The stop loss and take profit is not affected. Works when "Strategy Switch/Trigger Level" is not activated or an activated trigger level was crossed.')bup_lvl = input.float(0, title='Strategy Upper Border Level', minval=0, step=200, group='Strategy trigger and border levels:', tooltip='Define strategy upper border level.')en_border_dn = input.bool(false, title='Enable Lower Border Level', group='Strategy trigger and border levels:', tooltip='In case the market has crossed this level, the strategy entry signals will be turned off (long and short). The stop loss and take profit is not affected. Works when "Strategy Switch/Trigger Level" is not activated or an activated trigger level was crossed.')bdn_lvl = input.float(0, title='Strategy Lower Border Level', minval=0, step=200, group='Strategy trigger and border levels:', tooltip='Define strategy lower border level.')border_con = input.string('Close All', title='Strategy Behaviour When A Border Level Is Crossed', options=['Turn Off Entries', 'Idle', 'Close All'], group='Strategy trigger and border levels:', tooltip='Select the strategy behaviour when a border level is crossed. "Turn Off Entries" = The strategy entry signals will be turned off (long and short). The stop loss and take profit is not affected. "Idle" = The strategy remains idle. Affects entries, stop loss, take profit and exit filters. Position remains open. "Close All" = The entire position will be closed and strategy remains idle.')extend_lines = input.string('Right', title='Extend Lines', options=['Right', 'Both'], group='Strategy trigger and border levels:', tooltip='Select the trigger and border line extention')en_close_stop = input.bool(false, title='Enable "Close & Stop" Level', group='Strategy trigger and border levels:', tooltip='In case the market has crossed this level, the entire position will be closed and the strategy remains idle. This Feature works on current bar and is independent of time and date.')cl_st_lvl = input.float(0, title='"Close & Stop" Level', minval=0, step=100, group='Strategy trigger and border levels:', tooltip='Define "Close & Stop" level.')//---------------------------- Backtest periode inputs -----------------------------------inst_grid = input.bool(false, title='Instant Grid', group='Define the period of the grid/trend:', tooltip='This enables the grid with current time and date. Do not change input settings while running an instant grid otherwise the grid will restart at current bar.')period_start = input.time(title='', inline='start_timestamp', defval=timestamp('01 SEP 2022 00:00 +0000'), group='Define the period of the grid/trend:', tooltip='Trend/grid start date and time. In case of live trading you have to set the period to the current date and time otherwise history trades will influence the position management.')period_stop = input.time(title='', inline='end_timestamp', defval=timestamp('31 Dec 2122 00:00 +0000'), group='Define the period of the grid/trend:', tooltip='Trend/grid end date and time.')//backtesting lot sizelot_size_b = input.float(0.01, title='Lot Size - Backtesting', minval= 0, step= 0.01, tooltip='Affects backtesting only.', group='Backtesting and live-trading lot size:') //Alertatron lot size on Bybitlot_size_lv = input.int(50, title='Lot Size - Live Trading', minval= 0, step= 50, tooltip='Alertatron Bitcoin lot size string for Bybit exchange. Affects live trading only.', group='Backtesting and live-trading lot size:')//------------------------ entry signal inputs --------------------------x_opt_1 = input.string('Grid - reentry', title='--- 1st ENTRY SIGNAL ---', options=['---', 'Grid - reentry', 'Grid - counter trend', 'Fractals', 'Reverse fractal', 'Pin bar', 'BB reverse'], tooltip='The grid entry signals are time independent. The Fractals signal is a breakout signal. The reverse fractal and the Pin bar signal are bottom fishing signal.', group='Entry signals:')x_opt_2 = input.string('---', title='--- 2nd ENTRY SIGNAL ---', options=['---', 'Grid - reentry', 'Grid - counter trend', 'Fractals', 'Reverse fractal', 'Pin bar', 'BB reverse'], tooltip='The grid entry signals are time independent. The Fractals signal is a breakout signal. The reverse fractal and the pin bar signal are bottom fishing signals.', group='Entry signals:')//grid parametergrid_gap = input.float(500, title='Grid Gap - Base Currency', minval=0, step=50, tooltip='The minimum trigger-gap between two trades in case of a selected grid signal.', group='Grid parameter:') //---------------------------- 1st position factor inputs ------------------------------en_1st_pos_f = input.bool(false, title='Enable First Position', group='First position size:', tooltip='This enables the first position that will be opened when entry condition is met. In case all positions are closed, a new "first position" will be opened. Works when no exit filters are selected.')inst_pos = input.bool(false, title='Instantly On Current Bar Close', group='First position size:', tooltip='This opens the first position immediately when the grid is placed and the current bar is closed.')pos_start_1st = input.float(0.05, title='Position Start-Size - Backtesting', minval=0.000001, step=0.01, group='First position size:', tooltip='This replaces the default strategy position size ("Lot Size - Backtesting") and is the starting position size. Backtesting only.')pos_start_1st_lv = input.float(250, title='Position Start-Size - Live Trading', minval=0.000001, step=50, group='First position size:', tooltip='This replaces the default strategy live trading position size ("Lot Size - Live Trading") and is the starting position size. Live trading only.')//-------------------------------- auto-increase of position inputs -----------------------------------en_pos_mart = input.bool(false, title='Enable Position Auto-Increase', group='Automatic position size increase for each trade (Martingale):', tooltip='This enables the automatic increase in position size for each trade. With "Position Factor = 1" you get the martingale sequence. This \'automatic increase\' works until a position has been closed. After a closing event, this function remains inactive. Works not with "Trade Direction" = "Both".')pos_factor = input.float(0.5, title='Position Factor', minval=0.000001, step=0.1, group='Automatic position size increase for each trade (Martingale):', tooltip='This factor controls the position size. The next position size is: strategy_position_size + strategy_position_size * position_factor. Keep in mind that a take profit event reduces the current position size.')pos_count_in = input.int(4, title='Position Count', minval=1, step=1, group='Automatic position size increase for each trade (Martingale):', tooltip='This value determines how often the position is increased.')pos_start_mart = input.float(0.01, title='Position Start-Size - Backtesting', minval=0.000001, step=0.001, group='Automatic position size increase for each trade (Martingale):', tooltip='This replaces the default strategy position size ("Lot Size - Backtesting") and is the starting position size for "Auto-Increase". Backtesting only.')pos_start_mart_lv = input.float(100, title='Position Start-Size - Live Trading', minval=0.000001, step=50, group='Automatic position size increase for each trade (Martingale):', tooltip='This replaces the default live trading strategy position size ("Lot Size - Live Trading") and is the starting position size for "Auto-Increase". Live trading only.')//------------------------------ take average 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 price of positions + "Take Average-Price Of Positions Profit..." AND current price >= average-price of positions + "Take Profit Step...". Enable when scalping mode is used.')av_tp_qty = input.float(10, title='Take Average-Position-Price Profit - Quantity Of Position (Percent)', minval=0, step=5, maxval=100, group='Take profit based on average-position-price:', tooltip='Reduction of current position in percent. Affects backtesting and live trading.')av_tp = input.float(500, title='Take Average-Position-Price Profit - Base Currency', minval=0, step=50, group='Take profit based on average-position-price:', tooltip='The profit in points of base currency, calculated from the average price of all open trades.')avtp_step = input.float(500, title='Take Profit Step - Base Currency', minval=0, step=50, group='Take profit based on average-position-price:', tooltip='The minimum distance between two profit-taking events in case of "Take Average-Entry Profit - Quantity Of Position (Percent)" < 100.')en_tp_counter = input.bool(title='Enable Take Profit Count', defval=false, group='Take profit based on average-position-price:', tooltip='Enables "Take Profit Count". If disabled the stepwise take profit is endless. Enable when scalping mode is used.')tp_count = input.int(3, title='Take Profit Count', minval=1, step=1, group='Take profit based on average-position-price:', tooltip='Defines how many times a take profit event will happen before the entire position will be closed. Once the counter limit has been reached the counter gets reseted.')//---------------------------------- break even stop loss -----------------------------------break_even = input.bool(title='Close On Break Even And Remain Idle', defval=false, group='Break even stop loss:', tooltip='Sets the stop loss to break even after the first take profit event. Strategy remains idle after a break even close event. Works on live trading too but the triggering lot size is the backtest lot size.')rep_even = input.bool(title='Close Partly On Break Even', defval=false, group='Break even stop loss:', tooltip='Sets a partly stop loss on break even. Strategy will not be further affected after a partly break even close event. Works on live trading too but the triggering lot size is the backtest lot size.')rep_ev_qty = input.int(50, title='Percent Close On Break Even', minval= 0, maxval= 100, step= 5, group='Break even stop loss:', tooltip= 'Percent of position that will be closed after a break even event.')be_min_lot = input.float(0.1, title='Min Lot Size (Backtesting lot size)', minval= 0, step= 0.01, group='Break even stop loss:', tooltip= 'Min lot size to trigger break even partly close. Current lot size > "Min Lot Size"')//---------------------------- stop loss of average position inputs ------------------------------av_sl_en = input.bool(title='Enable Stop Loss - Average-Position-Price Loss', defval=true, group='Stop loss based on average-position price or recent top/bottom:', 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...". Enable when scalping mode is used.')tb_tog = input.bool(title='Toggle: Average-Position-Price Loss (Default) / Top/Bottom Based Loss', defval=true, group='Stop loss based on average-position price or recent top/bottom:', tooltip='Stop loss condition top/bottom mode: current price <> last local top/bottom AND step condition. Stop loss condition average-position-price loss mode: price <> average entry position price AND step condition. Default = selected.')av_sl_qty = input.float(30, title='Stop Average-Position-Price Loss - Quantity Of Position (Percent)', minval=0, step=5, maxval=100, group='Stop loss based on average-position price or recent top/bottom:', tooltip='Reduction of current position in percent. Affects backtesting and live trading.')av_sl = input.float(500, title='Stop Average-Position-Price Loss - Base Currency', minval=0, step=50, group='Stop loss based on average-position price or recent top/bottom:', tooltip='The loss in points of base currency, calculated from the average-position-price of all open trades.')avsl_step = input.float(500, title='Stop Loss Step - Base Currency', minval=0, step=50, group='Stop loss based on average-position price or recent top/bottom:', tooltip='The minimum distance between two stop-loss events in case of "Stop Average-Position-Price Loss - Quantity Of Position (Percent)" < 100.')sl_sen = input.int(20, title='Top/Bottom Sensitivity', minval=1, step=1, group='Stop loss based on average-position price or recent top/bottom:', tooltip='Number of past candles within the top and bottom are detected. For "Top/Bottom Based Loss" only.')en_sl_counter = input.bool(title='Enable Stop Loss Count', defval=false, group='Stop loss based on average-position price or recent top/bottom:', tooltip='Enables "Stop Loss Count". If disabled the stepwise stop loss is endless. Enable when scalping mode is used.')sl_count = input.int(3, title='Stop Loss Count', minval=1, step=1, group='Stop loss based on average-position price or recent top/bottom:', tooltip='Defines how many times a take profit event will happen before the entire position will be closed. Once the counter limit has been reached the counter gets reseted.')//---------------------------- entry filters and time frame inputs ------------------------------htf_entr_opt_1 = input.string('Current', title='Time Frame - Entry Filter 1', options=['Current', '5m', '10m', '15m', '30m', '1H', '2H', '3H', '4H', '6H', '8H', '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_entr_opt_2 = input.string('Current', title='Time Frame - Entry Filter 2', options=['Current', '5m', '10m', '15m', '30m', '1H', '2H', '3H', '4H', '6H', '8H', '12H', 'D', '3D', 'W', 'M'], tooltip='The time frame for the 2nd 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', 'MACD(fast) slope filter', 'RSI50 filter', 'Fractals filter', 'Segments filter (no tf filter)', 'Fractals 1-2-3 filter', 'Reverse fractal filter', 'EMA21/SMA20 filter', 'BB reverse filter (no tf filter)', 'ALMA slope filter', 'SuperTrend filter', 'EMA1 x EMA2 filter', 'ADX DMI filter', 'ADX slope filter', 'HMA slope filter', '2HMA cross filter', 'TRIX slope filter', 'Parabolic SAR 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'], tooltip='Various filter signals for the 1nd ENTRY SIGNAL.', group='Entry filters:')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', 'MACD(fast) slope filter', 'RSI50 filter', 'Fractals filter', 'Segments filter (no tf filter)', 'Fractals 1-2-3 filter', 'Reverse fractal filter', 'EMA21/SMA20 filter', 'BB reverse filter (no tf filter)', 'ALMA slope filter', 'SuperTrend filter', 'EMA1 x EMA2 filter', 'ADX DMI filter', 'ADX slope filter', 'HMA slope filter', '2HMA cross filter', 'TRIX slope filter', 'Parabolic SAR 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'], tooltip='Various filter signals for the 2nd ENTRY SIGNAL.', group='Entry filters:')//-------------------------- exit filters and time frame inputs ----------------------------tog_exit = input.bool(title='Toggle Exit Mode 1/2', defval=true, tooltip='Mode 1: All open positions will be closed. Entry signals are not affected. Mode 2: All open positions will be closed. New entry signals are inactive while exit signal is valid. Mode 1 = default = selected.', group='Exit filters:')qyt_exit = input.int(100, title='Exit Quantity', minval= 0, maxval= 100, step= 5, tooltip= 'Percent of position that will be closed. Affects backtesting and live trading.', group='Exit filters:')htf_exit_opt_1 = input.string('Current', title='Time Frame - Exit Filter 1', options=['Current', '5m', '10m', '15m', '30m', '1H', '2H', '3H', '4H', '6H', '8H', '12H', 'D', '3D', 'W', 'M'], tooltip='The time frame for Exit filter 1. 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', '8H', '12H', 'D', '3D', 'W', 'M'], tooltip='The time frame for Exit filter 2. 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=['---', 'Fractals trend lines filter (no tf-filter)', 'ALMA slope exit', 'Reverse fractal exit', 'SMA exit', 'MACD exit', 'MACD(fast) slope exit', 'HMA slope exit', '2HMA cross exit', 'EMA1 x EMA2 exit', 'ADX slope exit', 'ADX Threshold exit', 'DMI exit', 'TRIX slope exit', 'BB reverse exit', 'RSI50 exit', 'Fractals exit', 'SuperTrend exit', 'Parabolic SAR exit', 'Cloud exit', 'Kijun exit'], tooltip='Various exit signals for the 1nd ENTRY SIGNAL and the 2nd ENTRY SIGNAL. The exit signals are OR connected.', group='Exit filters:')exit_f_2 = input.string('---', title='Exit filter 2', options=['---', 'Fractals trend lines filter (no tf-filter)', 'ALMA slope exit', 'Reverse fractal exit', 'SMA exit', 'MACD exit', 'MACD(fast) slope exit', 'HMA slope exit', '2HMA cross exit', 'EMA1 x EMA2 exit', 'ADX slope exit', 'ADX Threshold exit', 'DMI exit', 'TRIX slope exit', 'BB reverse exit', 'RSI50 exit', 'Fractals exit', 'SuperTrend exit', 'Parabolic SAR exit', 'Cloud exit', 'Kijun exit'], tooltip='Various exit signals for both the 1nd ENTRY SIGNAL and the 2nd ENTRY SIGNAL. The exit signals are OR connected.', group='Exit filters:')//------------------------- Signal parameter inputs ----------------------------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='Pin bar and segment parameters:')p_bar_sens_2 = input.int(1, title='Pin Bar Sensitivity 2', step=1, minval=0, tooltip='Condition: high/low >< last two high/low.', group='Pin bar and segment parameters:')sb = input.int(title='Segment Max Bars', defval=10, minval=0, step=1, tooltip='The Maximum bars between two segment highs or lows.', group='Pin bar and segment parameters:')//--------------------- filters inputs --------------------fr_period = input.int(2, title='Fractals Period', minval=1, group='Entry and filter signal parameters:')rsi_period = input.int(14, title='RSI Period', minval=1, group='Entry and filter signal parameters:')ma_period = input.int(50, title='MA Period', minval=1, group='Entry and filter signal parameters:')mult = input.float(3, title='SuperTrend Multiplier', minval=1, step=0.1, group='Entry and filter signal parameters:')len = input.int(6, title='SuperTrend Length', minval=1, group='Entry and filter 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)windowsize_f = input.int(title="ALMA Window Size", defval=9, minval=1, step=1, group='Entry and filter signal parameters:', tooltip='')offset_f = input.float(title="ALMA Offset", defval=0.85, minval=0, step=0.05, group='Entry and filter signal parameters:', tooltip='')sigma_f = input.float(title="ALMA Sigma", defval=6, minval=1, step=1, group='Entry and filter signal parameters:', tooltip='')di_length_s = input.int(10, title='DMI ADX Length', minval=1, group='Entry and filter signal parameters:')adx_smooth_s = input.int(10, title='DMI ADX Smooth', minval=1, group='Entry and filter signal parameters:')adx_thres_s = input.int(25, title='DMI ADX Threshold', minval=1, group='Entry and filter signal parameters:')slope_len = input.int(1, minval=1, title='MACD MacdlLine Slope Lenth', tooltip='MACD\'s fast line', group='Entry and filter signal parameters:')hma_len_f = input.int(100, minval=1, step=5, title='HMA Length', group='Entry and filter signal parameters:')hma2_len_f = input.int(25, title = "2HMA Period", minval=1, step=1, group='Entry and filter signal parameters:')ema1_len_f = input.int(10, minval=1, step=2, title='EMA1 Length', group='Entry and filter signal parameters:')ema2_len_f = input.int(20, minval=1, step=2, title='EMA2 Length', group='Entry and filter signal parameters:')trix_len_f = input.int(10, title="TRIX Length", minval=1, group='Entry and filter signal parameters:')bb_length_s = input.int(20, minval=1, title='BB Length (signal)', group='Entry and filter signal parameters:', tooltip='')bb_std_fac_s = input.float(2, minval=0.1, step=0.2, title='BB StdDev Factor (signal)', group='Entry and filter signal parameters:', tooltip='')bb_length_f = input.int(20, minval=1, step=10, title='BB Length (filter)', group='Entry and filter signal parameters:', tooltip='Formula to adapt BB length of a lower TF to a higher TF: (higher TF in minutes) / (lower TF) * (BB Length of higher TF)')bb_std_fac_f = input.float(2, minval=0.1, step=0.2, title='BB StdDev Factor (filter)', group='Entry and filter signal parameters:', tooltip='')//--------------------- exits inputs --------------------fr_period_x = input.int(2, title='Exit Fractals - Period', minval=1, group='Exit signal parameters:')fr_past_x = input.int(0, title='Exit Fractals - Past Fractal', minval=0, group='Exit signal parameters:')rsi_period_x = input.int(14, title='Exit RSI Period', minval=1, group='Exit signal parameters:')ma_period_x = input.int(50, title='Exit MA Period', minval=1, group='Exit signal parameters:')mult_x = input.float(2, title='Exit SuperTrend Multiplier', minval=1, group='Exit signal parameters:')len_x = input.int(5, title='Exit SuperTrend Length', minval=1, group='Exit signal parameters:')di_length_x = input.int(10, title='Exit DMI ADX Length', minval=1, group='Exit signal parameters:')adx_smooth_x = input.int(10, title='Exit DMI ADX Smooth', minval=1, group='Exit signal parameters:')adx_thres_x = input.int(25, title='Exit DMI ADX Threshold', minval=1, group='Exit signal parameters:')slope_len_x = input.int(1, minval=1, title='Exit MACD MacdlLine Slope Lenth', tooltip='MACD\'s fast line', group='Exit signal parameters:')hma_len_x = input.int(100, minval=1, step=5, title='EXIT HMA Length', group='Exit signal parameters:')hma2_len_x = input.int(25, title = "Exit 2HMA Period", minval=1, step=1, group='Exit signal parameters:')ema1_len_x = input.int(10, minval=1, step=2, title='Exit EMA1 Length', group='Exit signal parameters:')ema2_len_x = input.int(20, minval=1, step=2, title='Exit EMA2 Length', group='Exit signal parameters:')windowsize_x = input.int(9, title="Exit ALMA Window Size", minval=1, step=1, group='Exit signal parameters:', tooltip='')offset_x = input.float(0.85, title="Exit ALMA Offset", minval=0, step=0.05, group='Exit signal parameters:', tooltip='')sigma_x = input.float(6, title="Exit ALMA Sigma", minval=1, step=1, group='Exit signal parameters:', tooltip='')trix_len_x = input.int(10, title="Exit TRIX Length", minval=1, group='Exit signal parameters:', tooltip='')bb_length_x = input.int(20, minval=1, title='Exit BB Length', group='Exit signal parameters:', tooltip='')bb_std_fac_x = input.float(2, minval=0.1, step=0.2, title='Exit BB StdDev Factor', group='Exit signal parameters:', tooltip='')//--------------- Current unrealized profit or loss for the open position -------------------if panel var info_panel = table.new(position = position.bottom_left, columns = 1, rows = 2, bgcolor=color.new(color.blue, 92), frame_width=1, border_width=1) text0 = "Position Size: " + str.tostring(strategy.position_size, "#.0000") text1 = "Unrealized Profit/Loss: " + str.tostring(strategy.openprofit, "#.00") table.cell(table_id=info_panel, column=0, row=0, text=text0, text_halign=text.align_left, text_size= size.small, text_color=color.new(color.silver, 0)) table.cell(table_id=info_panel, column=0, row=1, text=text1, text_halign=text.align_left, text_size= size.small, text_color=color.new(color.silver, 0))//------------------------- entry direction --------------------------long = entry_type != 'Short' // long or bothshort = entry_type != 'Long' // short or bothboth = entry_type == 'Both' // both//----------------------- Backtest periode --------------------------------backtest_period() => time >= period_start and time <= period_stop ? true : false//-------------------------------- plots ----------------------------//plot trigger leveltrig_line = en_trig_lvl ? line.new(x1=period_start, x2=time, xloc = xloc.bar_time, y1=trig_lvl, y2=trig_lvl, extend=extend_lines == 'Right' ? extend.right : extend.both, color=color.new(color.yellow, 40), style=line.style_solid, width=2) : na//plot upper border levelbup_line = en_border_up ? line.new(x1=period_start, x2=time, xloc = xloc.bar_time, y1=bup_lvl, y2=bup_lvl, extend=extend_lines == 'Right' ? extend.right : extend.both, color=color.new(color.red, 40), style=line.style_solid, width=3) : na//plot lower border levelbdn_line = en_border_dn ? line.new(x1=period_start, x2=time, xloc = xloc.bar_time, y1=bdn_lvl, y2=bdn_lvl, extend=extend_lines == 'Right' ? extend.right : extend.both, color=color.new(color.green, 40), style=line.style_solid, width=3) : na//plot "close & stop" levelclst_line = en_close_stop ? line.new(x1=bar_index[1], x2=bar_index, y1=cl_st_lvl, y2=cl_st_lvl, extend=extend.right, color=color.new(color.white, 10), style=line.style_solid, width=1) : naline.delete(trig_line[1])line.delete(bup_line[1])line.delete(bdn_line[1])line.delete(clst_line[1])//average price plotplot(plot_avg_price ? strategy.position_avg_price : na, linewidth=1, color=close > strategy.position_avg_price and long or close < strategy.position_avg_price and short ? color.new(color.green, 30) : color.new(color.red, 30), title='position_avg_price')//-------------------- 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)// 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 filters ------------------------// cross conditions for "Strong" filtered signalsvar bool sasb_x = trueif ta.crossover(SA, SB) and low > kumo_high sasb_x := true sasb_xif ta.crossunder(SA, SB) and high < kumo_low sasb_x := false sasb_xvar 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 filterskijun_buy_f = close > KJkumo_buy_f = close > kumo_highkumo_flip_buy_f = SA > SBprice_filtered_kumo_flip_buy_f = sasb_x and low > kumo_highchikou_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 < SBprice_filtered_kumo_flip_sell_f = not sasb_x and high < kumo_lowchikou_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 = tog_exit ? ta.crossover(high, KJ) : high > KJkijun_sell_x = tog_exit ? ta.crossunder(low, KJ) : low < KJkumo_buy_x = tog_exit ? ta.crossover(high, kumo_high) : high > kumo_highkumo_sell_x = tog_exit ? ta.crossunder(low, kumo_low) : low < kumo_low//--------------------- Bollinger Bands ------------------------f_stdev(_bb_len) => ta.stdev(close, _bb_len)f_sma(_sma_len) => ta.sma(close, _sma_len)dev_s = bb_std_fac_s * f_stdev(bb_length_s)dev_f = bb_std_fac_f * f_stdev(bb_length_f)dev_x = bb_std_fac_x * f_stdev(bb_length_x)//signalupper_bb_s = f_sma(bb_length_s) + dev_slower_bb_s = f_sma(bb_length_s) - dev_sbb_long_s = low < lower_bb_s // ta.crossunder(low, lower_bb_s) bb_short_s = high > upper_bb_s // ta.crossover(high, upper_bb_s)//filterupper_bb_f = f_sma(bb_length_f) + dev_flower_bb_f = f_sma(bb_length_f) - dev_fvar bool bb_dnx_buy = falsevar bool bb_upx_sell = falseif low < lower_bb_f and backtest_period() bb_dnx_buy := true bb_upx_sell := falseif high > upper_bb_f and backtest_period() bb_upx_sell := true bb_dnx_buy := falsebb_long_f = bb_dnx_buy // [pine] [/pine]bb_short_f = bb_upx_sell//exitupper_bb_x = f_sma(bb_length_x) + dev_xlower_bb_x = f_sma(bb_length_x) - dev_xbb_long_x = tog_exit ? ta.crossunder(low, lower_bb_x) : low < lower_bb_xbb_short_x = tog_exit ? ta.crossover(high, upper_bb_x) : high > upper_bb_x//-------------------------- trix --------------------------trix_f = 10000 * ta.change(ta.ema(ta.ema(ta.ema(math.log(close), trix_len_f), trix_len_f), trix_len_f))trix_x = 10000 * ta.change(ta.ema(ta.ema(ta.ema(math.log(close), trix_len_x), trix_len_x), trix_len_x))trix_slo_up_f = ta.rising(trix_f, 1) trix_slo_up_x = tog_exit ? ta.rising(trix_x, 1) and not ta.rising(trix_x, 1)[1] : ta.rising(trix_x, 1)trix_slo_dn_x = tog_exit ? ta.falling(trix_x, 1) and not ta.falling(trix_x, 1)[1] : ta.falling(trix_x, 1)//------------------------- hma ----------------------------hma_f = ta.hma(close, hma_len_f) // entry filter //[repaint == 'Allowed' ? 0 : 1] hma_x = ta.hma(close, hma_len_x) // exit hma_up_f = ta.rising(hma_f, 1)hma_dn_f = ta.falling(hma_f, 1) // entry filterhma_up_x = tog_exit ? ta.rising(hma_x, 1) and not ta.rising(hma_x, 1)[1] : ta.rising(hma_x, 1) // exit hma_dn_x = tog_exit ? ta.falling(hma_x, 1) and not ta.falling(hma_x, 1)[1] : ta.falling(hma_x, 1)//------------------- 2hma cross -----------------------f_hma3(_src, _len) => ta.wma(ta.wma(close, (_len/2)/3)*3 - ta.wma(close, (_len/2)/2) - ta.wma(close, (_len/2)), (_len/2)) //entry filterhma_n_f = ta.hma(hl2, hma2_len_f) //[repaint == 'Allowed' ? 0 : 1] hma_m_f = f_hma3(hl2, hma2_len_f) //[repaint == 'Allowed' ? 0 : 1]hma_c_up_f = hma_m_f > hma_n_fhma_c_dn_f = hma_m_f < hma_n_f//exithma_n_x = ta.hma(hl2, hma2_len_x) //[repaint == 'Allowed' ? 0 : 1] hma_m_x = f_hma3(hl2, hma2_len_x) //[repaint == 'Allowed' ? 0 : 1]hma_c_up_x = tog_exit ? ta.crossover(hma_m_x, hma_n_x) : hma_m_x > hma_n_xhma_c_dn_x = tog_exit ? ta.crossunder(hma_m_x, hma_n_x) : hma_m_x < hma_n_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 25 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 40 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 25 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 40 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// exit / filter//frup_buy = ta.crossover(high, y0_frup_0)//frdn_sell = ta.crossunder(low, y0_frdn_0)buy_up_line = tog_exit ? ta.crossover(high, y_up_lvl) : high > y_up_lvl// or frup_buysell_dn_line = tog_exit ? ta.crossunder(low, y_dn_lvl) : low < y_dn_lvl// or frdn_sell//------------------------ 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 Entry Grid ", 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]//-------------------------- pin bar entry signal-------------------------------candle_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//------------------ ema21/sma20 filter -------------------------ema_f(src, ema_len) => ta.ema(src, ema_len) // ma function definitionsma_f(src, sma_len) => ta.sma(src, sma_len)ema_21 = ema_f(close, 21) sma_20 = sma_f(close, 20)ma_cross_buy = high > ema_21 and high > sma_20 and ema_21 > sma_20ma_cross_sell = low < ema_21 and low < sma_20 and ema_21 < sma_20//------------------------ ema1 x ema2 ---------------------------ema1_f = ema_f(close, ema1_len_f)ema2_f = ema_f(close, ema2_len_f)ema1_x = ema_f(close, ema1_len_x)ema2_x = ema_f(close, ema2_len_x)ema_1x2_buy_f = ema1_f > ema2_fema_1x2_buy_x = tog_exit ? ta.crossover(ema1_x, ema2_x) : ema1_x > ema2_xema_1x2_sell_x = tog_exit ? ta.crossunder(ema1_x, ema2_x) : ema1_x < ema2_x//--------------------- alma ------------------------//filtersalma_f = ta.alma(close, windowsize_f, offset_f, sigma_f)alma_slo_up_f = ta.rising(alma_f, 1) //exitsalma_x = ta.alma(close, windowsize_x, offset_x, sigma_x)alma_slo_up_x = tog_exit ? ta.rising(alma_x, 1) and not ta.rising(alma_x, 1)[1] : ta.rising(alma_x, 1)alma_slo_dn_x = tog_exit ? ta.falling(alma_x, 1) and not ta.falling(alma_x, 1)[1] : ta.falling(alma_x, 1)//----------------------- macd filter -----------------------[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 = tog_exit ? ta.crossover(macdLine_f, signalLine_f) : macdLine_f > signalLine_fmacd_sell_x = tog_exit ? ta.crossunder(macdLine_f, signalLine_f) : macdLine_f < signalLine_f//macd fast line slopemacd_slope_up = ta.rising(macdLine_f, slope_len) //entry and filtermacd_slope_up_x = tog_exit ? ta.rising(macdLine_f, slope_len_x) and not ta.rising(macdLine_f, slope_len_x)[1] : ta.rising(macdLine_f, slope_len_x) //exitmacd_slope_dn_x = tog_exit ? ta.falling(macdLine_f, slope_len_x) and not ta.falling(macdLine_f, slope_len_x)[1] : ta.falling(macdLine_f, slope_len_x)//---------------------- rsi filters and entry signal------------------------//entryrsi_f = ta.rsi(close, rsi_period)rsi_f_buy = rsi_f > 50rsi_f_sell = rsi_f < 50//filtersrsi_f_buy_f = rsi_f > 50rsi_f_sell_f = rsi_f < 50//exitrsi_f_x = ta.rsi(close, rsi_period_x)rsi_f_buy_x = tog_exit ? ta.crossover(rsi_f_x, 50) : rsi_f_x > 50rsi_f_sell_x = tog_exit ? ta.crossunder(rsi_f_x, 50) : 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 = ta.crossover(high, fractal_up_v)fr_dnx = ta.crossunder(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 = tog_exit ? ta.crossover(high, fractal_up_v_x) : high > fractal_up_v_xfr_dnx_x = tog_exit ? ta.crossunder(low, fractal_dn_v_x) : low < fractal_dn_v_x//----------- higher low and higher high - lower high and lower low - entry --------------fractal_dn_v_1 = ta.valuewhen(dn_fr, low[fr_period], 1)fractal_up_v_1 = ta.valuewhen(up_fr, high[fr_period], 1)hl_hh_buy = fractal_dn_v > fractal_dn_v_1 and high > fractal_up_v // 123 signal and filterlh_ll_sell = fractal_up_v < fractal_up_v_1 and low < fractal_dn_v//-------------------- SuperTrend filter and entry signal ---------------------//entry[SuperTrend, Dir] = ta.supertrend(mult, len)sup_buy = high > SuperTrendsup_sell = 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 = tog_exit ? ta.crossover(high, SuperTrend_x) : high > SuperTrend_xsup_sell_x = tog_exit ? ta.crossunder(low, SuperTrend_x) : low < SuperTrend_x//----------------- Parabolic SAR Signal (pb/ps) and filter -------------------psar_buy = tog_exit ? ta.crossover(high, ta.sar(start, inc, max)) : high > ta.sar(start, inc, max)[0]psar_sell = tog_exit ? ta.crossunder(low, ta.sar(start, inc, max)) : low < ta.sar(start, inc, max)[0]//-------------------------- ADX entry and filter ---------------------------//adx signal 1/2 and filter[diplus_s, diminus_s, adx_s] = ta.dmi(di_length_s, adx_smooth_s)adx_above_thres = adx_s > adx_thres_slong_1 = diplus_s > diminus_s and adx_s < diplus_s and adx_s > diminus_s // ADX DMI entry and filter classicshort_1 = diplus_s < diminus_s and adx_s > diplus_s and adx_s < diminus_slong_2 = diplus_s > diminus_s and adx_above_thresshort_2 = diplus_s < diminus_s and adx_above_thres//filteradx_up_f = ta.rising(adx_s, 1) // ADX filter rising/falling//exit[diplus_x, diminus_x, adx_x] = ta.dmi(di_length_x, adx_smooth_x)adx_thres_f_x = tog_exit ? ta.crossunder(adx_x, adx_thres_x) : adx_x < adx_thres_x // ADX exit classicdmi_long_x = tog_exit ? ta.crossover(diplus_x, diminus_x) : diplus_x > diminus_x // dmi exit dmi_short_x = tog_exit ? ta.crossunder(diplus_x, diminus_x) : diplus_x < diminus_xadx_dn_x = tog_exit ? ta.falling(adx_x, 1) and not ta.falling(adx_x, 1)[1] : ta.falling(adx_x, 1) // ADX exit falling //-------------------------- SMA50 filter and entry---------------------------//entrysma_buy = close[2] > ema_f(close, ma_period)sma_sell = close[2] < ema_f(close, ma_period)//filterssma_buy_f = close[2] > sma_f(close, ma_period)sma_sell_f = close[2] < sma_f(close, ma_period)//exitsma_buy_x = tog_exit ? ta.crossover(close[1], sma_f(close, ma_period_x)) : close[1] > sma_f(close, ma_period_x)sma_sell_x = tog_exit ? ta.crossunder(close[1], sma_f(close, ma_period_x)) : close[1] < sma_f(close, ma_period_x)//--------------------------- 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]//-------------------------------------------------------------------------- Entry Signal Options ----------------------------------------------------------------------// buy signal options 1opt_sig_buy_1 = x_opt_1 == '---' ? false : x_opt_1 == 'BB reverse' ? bb_long_s : x_opt_1 == 'Grid - counter trend' ? grid_ct_buy : x_opt_1 == 'Grid - reentry' ? grid_re_buy : x_opt_1 == 'Pin bar' ? p_bar_buy : x_opt_1 == 'Fractals' ? fr_upx : x_opt_1 == 'Reverse fractal' ? rev_dn_fr_buy : false// sell signal options 1opt_sig_sell_1 = x_opt_1 == '---' ? false : x_opt_1 == 'BB reverse' ? bb_short_s : x_opt_1 == 'Grid - counter trend' ? grid_ct_sell : x_opt_1 == 'Grid - reentry' ? grid_re_sell : x_opt_1 == 'Pin bar' ? p_bar_sell : x_opt_1 == 'Fractals' ? fr_dnx : x_opt_1 == 'Reverse fractal' ? rev_up_fr_sell : false// buy signal options 2opt_sig_buy_2 = x_opt_2 == '---' ? false : x_opt_2 == 'BB reverse' ? bb_long_s : x_opt_2 == 'Grid - counter trend' ? grid_ct_buy : x_opt_2 == 'Grid - reentry' ? grid_re_buy : x_opt_2 == 'Pin bar' ? p_bar_buy : x_opt_2 == 'Fractals' ? fr_upx : x_opt_2 == 'Reverse fractal' ? rev_dn_fr_buy : false// sell signal options 2opt_sig_sell_2 = x_opt_2 == '---' ? false : x_opt_2 == 'BB reverse' ? bb_short_s : x_opt_2 == 'Grid - counter trend' ? grid_ct_sell : x_opt_2 == 'Grid - reentry' ? grid_re_sell : x_opt_2 == 'Pin bar' ? p_bar_sell : x_opt_2 == 'Fractals' ? fr_dnx : x_opt_2 == 'Reverse fractal' ? rev_up_fr_sell : false//------------------------------------------------------------------------------ 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 == 'EMA1 x EMA2 filter' ? ema_1x2_buy_f : entry_f_1 == '2HMA cross filter' ? hma_c_up_f : entry_f_1 == 'HMA slope filter' ? hma_up_f : entry_f_1 == 'MACD(fast) slope filter' ? macd_slope_up : 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 : entry_f_1 == 'SMA filter' ? sma_buy_f : entry_f_1 == 'ADX slope filter' ? adx_up_f : entry_f_1 == 'ADX DMI filter' ? adx_above_thres : entry_f_1 == 'Fractals 1-2-3 filter' ? hl_hh_buy : entry_f_1 == 'Reverse fractal filter' ? rev_dn_fr_buy : entry_f_1 == 'EMA21/SMA20 filter' ? ma_cross_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 : trueentry_filter_sig_sell_1 = entry_f_1 == '---' ? true : entry_f_1 == 'TRIX slope filter' ? not trix_slo_up_f : entry_f_1 == 'EMA1 x EMA2 filter' ? not ema_1x2_buy_f : entry_f_1 == '2HMA cross filter' ? hma_c_dn_f : entry_f_1 == 'HMA slope filter' ? hma_dn_f : entry_f_1 == 'MACD(fast) slope filter' ? not macd_slope_up : 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 : entry_f_1 == 'SMA filter' ? sma_sell_f : entry_f_1 == 'ADX slope filter' ? not adx_up_f : entry_f_1 == 'ADX DMI filter' ? adx_above_thres : entry_f_1 == 'Fractals 1-2-3 filter' ? lh_ll_sell : entry_f_1 == 'Reverse fractal filter' ? rev_up_fr_sell : entry_f_1 == 'EMA21/SMA20 filter' ? ma_cross_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 : trueentry_filter_sig_buy_2 = entry_f_2 == '---' ? true : entry_f_2 == 'TRIX slope filter' ? trix_slo_up_f : entry_f_2 == 'EMA1 x EMA2 filter' ? ema_1x2_buy_f : entry_f_2 == '2HMA cross filter' ? hma_c_up_f : entry_f_2 == 'HMA slope filter' ? hma_up_f : entry_f_2 == 'MACD(fast) slope filter' ? macd_slope_up : 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 : entry_f_2 == 'SMA filter' ? sma_buy_f : entry_f_2 == 'ADX slope filter' ? adx_up_f : entry_f_2 == 'ADX DMI filter' ? adx_above_thres : entry_f_2 == 'Fractals 1-2-3 filter' ? hl_hh_buy : entry_f_2 == 'Reverse fractal filter' ? rev_dn_fr_buy : entry_f_2 == 'EMA21/SMA20 filter' ? ma_cross_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 : trueentry_filter_sig_sell_2 = entry_f_2 == '---' ? true : entry_f_2 == 'TRIX slope filter' ? not trix_slo_up_f : entry_f_2 == 'EMA1 x EMA2 filter' ? not ema_1x2_buy_f : entry_f_2 == '2HMA cross filter' ? hma_c_dn_f : entry_f_2 == 'HMA slope filter' ? hma_dn_f: entry_f_2 == 'MACD(fast) slope filter' ? not macd_slope_up : 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 : entry_f_2 == 'SMA filter' ? sma_sell_f : entry_f_2 == 'ADX slope filter' ? not adx_up_f : entry_f_2 == 'ADX DMI filter' ? adx_above_thres : entry_f_2 == 'Fractals 1-2-3 filter' ? lh_ll_sell : entry_f_2 == 'Reverse fractal filter' ? rev_up_fr_sell : entry_f_2 == 'EMA21/SMA20 filter' ? ma_cross_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 : true//entry buy filter 1 entry_filter_buy_1 = htf_entr_opt_1 == 'current' ? entry_filter_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 == '8H' ? '480' : 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_filter_sig_buy_1)entry_filter_buy_11 = entry_f_1 == 'Fractals trend lines filter (no tf filter)' ? buy_up_line[repaint == 'Allowed' ? 0 : 1] : entry_f_1 == 'Segments filter (no tf filter)' ? segments_buy[repaint == 'Allowed' ? 0 : 1] : entry_f_1 == 'BB reverse filter (no tf filter)' ? bb_long_f[repaint == 'Allowed' ? 0 : 1] : entry_f_1 == 'Price filtered Kumo flip filter (no tf filter)' ? price_filtered_kumo_flip_buy_f[repaint == 'Allowed' ? 0 : 1] : true//entry sell filter 1 entry_filter_sell_1 = htf_entr_opt_1 == 'Current' ? entry_filter_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 == '8H' ? '480' : 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_filter_sig_sell_1)entry_filter_sell_11 = entry_f_1 == 'Fractals trend lines filter (no tf filter)' ? sell_dn_line[repaint == 'Allowed' ? 0 : 1] : entry_f_1 == 'Segments filter (no tf filter)' ? segments_sell[repaint == 'Allowed' ? 0 : 1] : entry_f_1 == 'BB reverse filter (no tf filter)' ? bb_short_f[repaint == 'Allowed' ? 0 : 1] : entry_f_1 == 'Price filtered Kumo flip filter (no tf filter)' ? price_filtered_kumo_flip_sell_f[repaint == 'Allowed' ? 0 : 1] : true//entry buy filter 2 entry_filter_buy_2 = htf_entr_opt_2 == 'Current' ? entry_filter_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_1 == '8H' ? '480' : 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_filter_sig_buy_2)entry_filter_buy_22 = entry_f_2 == 'Fractals trend lines filter (no tf filter)' ? buy_up_line[repaint == 'Allowed' ? 0 : 1] : entry_f_2 == 'Segments filter (no tf filter)' ? segments_buy[repaint == 'Allowed' ? 0 : 1] : entry_f_2 == 'BB reverse filter (no tf filter)' ? bb_long_f[repaint == 'Allowed' ? 0 : 1] : entry_f_2 == 'Price filtered Kumo flip filter (no tf filter)' ? price_filtered_kumo_flip_buy_f[repaint == 'Allowed' ? 0 : 1] : true//entry sell filter 2 entry_filter_sell_2 = htf_entr_opt_2 == 'Current' ? entry_filter_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_1 == '8H' ? '480' : 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_filter_sig_sell_2)entry_filter_sell_22 = entry_f_2 == 'Fractals trend lines filter (no tf filter)' ? sell_dn_line[repaint == 'Allowed' ? 0 : 1] : entry_f_2 == 'Segments filter (no tf filter)' ? segments_sell[repaint == 'Allowed' ? 0 : 1] : entry_f_2 == 'BB reverse filter (no tf filter)' ? bb_short_f[repaint == 'Allowed' ? 0 : 1] : entry_f_2 == 'Price filtered Kumo flip filter (no tf filter)' ? price_filtered_kumo_flip_sell_f[repaint == 'Allowed' ? 0 : 1] : true//----------------------------------------------------------------------- exit filters ------------------------------------------------------------------------exit_sig_buy_1 = exit_f_1 == '---' ? false : exit_f_1 == 'BB reverse exit' ? bb_long_x : exit_f_1 == 'TRIX slope exit' ? trix_slo_up_x : exit_f_1 == 'EMA1 x EMA2 exit' ? ema_1x2_buy_x : exit_f_1 == '2HMA cross exit' ? hma_c_up_x : exit_f_1 == 'HMA slope exit' ? hma_up_x : exit_f_1 == 'ALMA slope exit' ? alma_slo_up_x : exit_f_1 == 'Reverse fractal exit' ? rev_dn_fr_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 : exit_f_1 == 'SMA exit' ? sma_buy_x : exit_f_1 == 'DMI exit' ? dmi_long_x : exit_f_1 == 'ADX slope exit' ? adx_dn_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_sig_sell_1 = exit_f_1 == '---' ? false : exit_f_1 == 'BB reverse exit' ? bb_short_x : exit_f_1 == 'TRIX slope exit' ? trix_slo_dn_x : exit_f_1 == 'EMA1 x EMA2 exit' ? ema_1x2_sell_x : exit_f_1 == '2HMA cross exit' ? hma_c_dn_x : exit_f_1 == 'HMA slope exit' ? hma_dn_x : exit_f_1 == 'ALMA slope exit' ? alma_slo_dn_x : exit_f_1 == 'Reverse fractal exit' ? rev_up_fr_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 : exit_f_1 == 'SMA exit' ? sma_sell_x : exit_f_1 == 'DMI exit' ? dmi_short_x : exit_f_1 == 'ADX slope exit' ? adx_dn_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_sig_buy_2 = exit_f_2 == '---' ? false : exit_f_2 == 'BB reverse exit' ? bb_long_x : exit_f_2 == 'TRIX slope exit' ? trix_slo_up_x : exit_f_2 == 'EMA1 x EMA2 exit' ? ema_1x2_buy_x : exit_f_2 == '2HMA cross exit' ? hma_c_up_x : exit_f_2 == 'HMA slope exit' ? hma_up_x : exit_f_2 == 'ALMA slope exit' ? alma_slo_up_x : exit_f_2 == 'Reverse fractal exit' ? rev_dn_fr_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 : exit_f_2 == 'SMA exit' ? sma_buy_x : exit_f_2 == 'DMI exit' ? dmi_long_x : exit_f_2 == 'ADX slope exit' ? adx_dn_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_sig_sell_2 = exit_f_2 == '---' ? false : exit_f_2 == 'BB reverse exit' ? bb_short_s : exit_f_2 == 'TRIX slope exit' ? trix_slo_dn_x : exit_f_2 == 'EMA1 x EMA2 exit' ? ema_1x2_sell_x : exit_f_2 == '2HMA cross exit' ? hma_c_dn_x : exit_f_2 == 'HMA slope exit' ? hma_dn_x : exit_f_2 == 'ALMA slope exit' ? alma_slo_dn_x : exit_f_2 == 'Reverse fractal exit' ? rev_up_fr_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 : exit_f_2 == 'SMA exit' ? sma_sell_x : exit_f_2 == 'DMI exit' ? dmi_short_x : exit_f_2 == 'ADX slope exit' ? adx_dn_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// higher timeframe filter//short exit buy filter 1exit_filter_buy_1 = htf_exit_opt_1 == 'Current' ? exit_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_entr_opt_1 == '8H' ? '480' : 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_sig_buy_1) exit_filter_buy_11 = exit_f_1 == 'Fractals trend lines filter (no tf-filter)' ? buy_up_line[repaint == 'Allowed' ? 0 : 1] : false//long exit sell filter 1 exit_filter_sell_1 = htf_exit_opt_1 == 'Current' ? exit_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_entr_opt_1 == '8H' ? '480' : 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_sig_sell_1)exit_filter_sell_11 = exit_f_1 == 'Fractals trend lines filter (no tf-filter)' ? sell_dn_line[repaint == 'Allowed' ? 0 : 1] : false//short exit buy filter 2 exit_filter_buy_2 = htf_exit_opt_2 == 'Current' ? exit_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_entr_opt_1 == '8H' ? '480' : 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_sig_buy_2)exit_filter_buy_22 = exit_f_2 == 'Fractals trend lines filter (no tf-filter)' ? buy_up_line[repaint == 'Allowed' ? 0 : 1] : false//long exit sell filter 2 exit_filter_sell_2 = htf_exit_opt_2 == 'Current' ? exit_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_entr_opt_1 == '8H' ? '480' : 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_sig_sell_2)exit_filter_sell_22 = exit_f_2 == 'Fractals trend lines filter (no tf-filter)' ? sell_dn_line[repaint == 'Allowed' ? 0 : 1] : false//------------------------------------------------------------ trigger and border levels -------------------------------------------------------//close & stop levelvar bool cl_st_sw = falseif (ta.cross(high, cl_st_lvl) or ta.cross(low, cl_st_lvl)) and barstate.isrealtime cl_st_sw := truestrat_cl_st = en_close_stop and cl_st_sw//trigger levelvar bool trig_sw = falseif (ta.cross(high, trig_lvl) or ta.cross(low, trig_lvl)) and backtest_period() trig_sw := trueen_strat_st = en_trig_lvl ? trig_sw : true//upper border levelvar bool upper_sw = trueif (ta.cross(high, bup_lvl) or ta.cross(low, bup_lvl)) and en_strat_st and backtest_period() upper_sw := falseen_strat_bup = en_border_up ? upper_sw : true//lower border levelvar bool lower_sw = trueif (ta.cross(high, bdn_lvl) or ta.cross(low, bdn_lvl)) and en_strat_st and backtest_period() lower_sw := falseen_strat_bdn = en_border_dn ? lower_sw : trueborder_close = en_strat_st and (not en_strat_bup or not en_strat_bdn) // border level closeen_strat = en_strat_st and en_strat_bup and en_strat_bdn // stops entries var bool en_idle = falsevar bool en_close = falseif border_con == 'Idle' en_idle := trueif border_con == 'Close All' en_close := truestrat_idle = en_idle ? en_strat : true // makes entire strategy idle if borders are crossed//----------------------------------------------------------- entry and exit conditions -----------------------------------------------------------exit_long = exit_filter_sell_1 or exit_filter_sell_2 or exit_filter_sell_11 or exit_filter_sell_22exit_short = exit_filter_buy_1 or exit_filter_buy_2 or exit_filter_buy_11 or exit_filter_buy_22long_filter = entry_filter_buy_1 and entry_filter_buy_2 and entry_filter_buy_11 and entry_filter_buy_22short_filter = entry_filter_sell_1 and entry_filter_sell_2 and entry_filter_sell_11 and entry_filter_sell_22es_l_cond = not exit_long and en_strates_s_cond = not exit_short and en_stratentry_long_1 = opt_sig_buy_1 and long_filter and es_l_condentry_long_2 = opt_sig_buy_2 and long_filter and es_l_condentry_short_1 = opt_sig_sell_1 and short_filter and es_s_condentry_short_2 = opt_sig_sell_2 and short_filter and es_s_cond//-------------------------------------------------------------- take average profit --------------------------------------------------------------tp_step = 0.tp_step := nz(high > tp_step[1] + avtp_step or low < tp_step[1] - avtp_step ? 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 > av_tp and tp_step_l and longav_profit_s = strategy.position_avg_price - close > av_tp and tp_step_s and short//--------------------------------------------------------- stop loss of average position --------------------------------------------------------sl_step = 0.sl_step := nz(high > sl_step[1] + avsl_step or low < sl_step[1] - avsl_step ? close : sl_step[1])sl_step_l = sl_step < sl_step[1]sl_step_s = sl_step > sl_step[1]top = .0top := nz(ta.pivothigh(high, sl_sen, 0), top[1])bottom = .0bottom := nz(ta.pivotlow(low, sl_sen, 0), bottom[1])av_loss_l = tb_tog ? strategy.position_avg_price - close > av_sl and sl_step_l and long : top - close > av_sl and sl_step_l and longav_loss_s = tb_tog ? close - strategy.position_avg_price > av_sl and sl_step_s and short : close - bottom > av_sl and sl_step_s and short//---------------------------------------------------------------- tp and sl counter ---------------------------------------------------------------no_open_pos = strategy.position_size == 0//break evenvar first_close_be = falsefirst_close_be := strategy.netprofit > 0 // enables break even. Profit of all completed trades. var even_sw = falseif ta.cross(close, strategy.position_avg_price)[repaint == 'Allowed' ? 0 : 1] and first_close_be and (inst_grid ? barstate.isrealtime : backtest_period()) even_sw := truebreak_ev = break_even and even_sw//tp countervar tp_ev_count_l = 0var tp_ev_count_s = 0if av_profit_l and long tp_ev_count_l := tp_ev_count_l +1if av_profit_s and short tp_ev_count_s := tp_ev_count_s +1count_con_tp_l = tp_ev_count_l >= tp_count or exit_long or no_open_pos // counter exit condition - longscount_con_tp_s = tp_ev_count_s >= tp_count or exit_short or no_open_pos // counter exit condition - shortsif count_con_tp_l // counter reset condioton for filter - longs tp_ev_count_l := 0if count_con_tp_s // counter reset condioton for filter - shorts. tp_ev_count_s := 0av_tp_qty_c_l = count_con_tp_l and en_tp_counter ? 100 : av_tp_qty // counter switch for tp - longsav_tp_qty_c_s = count_con_tp_s and en_tp_counter ? 100 : av_tp_qty // counter switch for tp - shorts//sl countervar sl_ev_count_l = 0var sl_ev_count_s = 0if av_loss_l and long sl_ev_count_l := sl_ev_count_l +1if av_loss_s and short sl_ev_count_s := sl_ev_count_s +1count_con_sl_l = sl_ev_count_l >= sl_count or exit_long or no_open_poscount_con_sl_s = sl_ev_count_s >= sl_count or exit_short or no_open_posif count_con_sl_l sl_ev_count_l := 0if count_con_sl_s sl_ev_count_s := 0av_sl_qty_c_l = count_con_sl_l and en_sl_counter ? 100 : av_sl_qtyav_sl_qty_c_s = count_con_sl_s and en_sl_counter ? 100 : av_sl_qty//scalping modevar scalp_sw = falseif long and long_filter and not long_filter[1] or short and short_filter and not short_filter[1] or both and (long_filter and not long_filter[1] or short_filter and not short_filter[1]) scalp_sw := trueif strategy.opentrades[1] != 0 and strategy.opentrades == 0 scalp_sw := falseenabled_sl_tp = av_tp_en and av_sl_en and en_tp_counter and en_sl_counterscalp_l = (entry_long_1 or entry_long_2) and en_scalp_mode and scalp_sw and enabled_sl_tp// and tp_ev_count_l < tp_countscalp_s = (entry_short_1 or entry_short_2) and en_scalp_mode and scalp_sw and enabled_sl_tp// and tp_ev_count_s < tp_count//---------------------------------------------------------- 1st position factor and auto-increase of position calc -----------------------------------------------------------------var first_close_mr = falsefirst_close_mr := strategy.closedtrades == 0 // makes martingale working until the first closepos_c_cond = pos_count_in > strategy.opentrades // trade counter conditionno_exit_filter = exit_f_1 == '---' and exit_f_2 == '---' // makes first position factor only working when no exit filters are active// calc and cond - backtestingpos_qty = en_pos_mart and pos_c_cond and first_close_mr and not both and no_exit_filter ? no_open_pos ? pos_start_mart : math.abs(strategy.position_size) * pos_factor : en_1st_pos_f ? no_open_pos ? pos_start_1st : lot_size_b : lot_size_b // martingale calc and sw - condition for martingale and 1st position - backtesting// calc and cond - live tradingvar float mart_lot_size = pos_start_mart_lv mart_lot_size := mart_lot_size * pos_factor + mart_lot_size[1]pos_qty_lv = en_pos_mart and pos_c_cond and first_close_mr and not both and no_exit_filter ? no_open_pos ? pos_start_mart_lv : mart_lot_size : en_1st_pos_f ? no_open_pos ? pos_start_1st_lv : lot_size_lv : lot_size_lv // martingale calc and sw - condition for martingale and 1st position - live trading // something like "get position_size" for lot size on bybit is needed for live trading.//------------------------------------- repetitive break even condition ----------------------------------rep_even_long = rep_even and low[1] > strategy.position_avg_price and low < strategy.position_avg_price and not no_open_pos and math.abs(strategy.position_size) > be_min_lotrep_even_short = rep_even and high[1] < strategy.position_avg_price and high > strategy.position_avg_price and not no_open_pos and math.abs(strategy.position_size) > be_min_lot //rep_even_long_lv = rep_even and low[1] > strategy.position_avg_price and low < strategy.position_avg_price and not no_open_pos and math.abs(strategy.position_size) > be_min_lot//rep_even_short_lv = rep_even and high[1] < strategy.position_avg_price and high > strategy.position_avg_price and not no_open_pos and math.abs(strategy.position_size) > be_min_lot // something like "get position_size" for lot size on bybit is needed for live trading.//---------------------------------------------------------------------- strategy entries and exits ---------------------------------------------------------------------// strategy entries and exits (backtesting)if inst_grid ? barstate.isrealtime and strat_idle and not break_ev[1] and not strat_cl_st[1] : backtest_period() and strat_idle and not break_ev[1] and not strat_cl_st[1] if long if entry_long_1 and not en_scalp_mode strategy.entry('os_b', strategy.long, qty= pos_qty) if entry_long_2 and not en_scalp_mode strategy.entry('os_b', strategy.long, qty= pos_qty) if inst_pos and en_1st_pos_f and no_open_pos and en_strat and not en_scalp_mode strategy.entry('os_b', strategy.long, qty= pos_qty) if scalp_l strategy.entry('os_b', strategy.long, qty= pos_qty) if av_tp_en and av_profit_l and not no_open_pos strategy.close('os_b', qty_percent= av_tp_qty_c_l) if av_sl_en and av_loss_l and not no_open_pos strategy.close('os_b', qty_percent= av_sl_qty_c_l) if exit_long and not exit_long[1] and not no_open_pos strategy.close('os_b', qty_percent= qyt_exit) if border_close and en_close and not no_open_pos strategy.close('os_b', qty_percent= 100) if break_ev and not no_open_pos strategy.close('os_b', qty_percent= 100) if strat_cl_st and not no_open_pos strategy.close('os_b', qty_percent= 100) if rep_even_long strategy.close('os_b', qty_percent= rep_ev_qty) if short if entry_short_1 and not en_scalp_mode strategy.entry('os_s', strategy.short, qty= pos_qty) if entry_short_2 and not en_scalp_mode strategy.entry('os_s', strategy.short, qty= pos_qty) if inst_pos and en_1st_pos_f and no_open_pos and en_strat and not en_scalp_mode strategy.entry('os_s', strategy.short, qty= pos_qty) if scalp_s strategy.entry('os_s', strategy.short, qty= pos_qty) if av_tp_en and av_profit_s and not no_open_pos strategy.close('os_s', qty_percent= av_tp_qty_c_s) if av_sl_en and av_loss_s and not no_open_pos strategy.close('os_s', qty_percent= av_sl_qty_c_s) if exit_short and not exit_short[1] and not no_open_pos strategy.close('os_s', qty_percent= qyt_exit) if border_close and en_close and not no_open_pos strategy.close('os_s', qty_percent= 100) if break_ev and not no_open_pos strategy.close('os_s', qty_percent= 100) if strat_cl_st and not no_open_pos strategy.close('os_s', qty_percent= 100) if rep_even_short strategy.close('os_s', qty_percent= rep_ev_qty)// strategy entries and exits (live trading with alertatron on bybit ) - alert messages - same conditions like strategy....()var float av_tp_qty_c_l_var = 100 - av_tp_qty_c_l // calc because of alertatron syntax stringvar float av_sl_qty_c_l_var = 100 - av_sl_qty_c_lvar float av_tp_qty_c_s_var = 100 - av_tp_qty_c_s var float av_sl_qty_c_s_var = 100 - av_sl_qty_c_svar float qyt_exit_var = 100 - qyt_exitvar float rep_ev_qty_var = 100 - rep_ev_qtyif inst_grid ? barstate.isrealtime and strat_idle and not break_ev[1] and not strat_cl_st[1] : backtest_period() and strat_idle and not break_ev[1] and not strat_cl_st[1]//entries if long and (entry_long_1 or entry_long_2) alert(message= 'BybitAPI(BTCUSD) { continue(if=positionShort); market(position= 0); } BybitAPI(BTCUSD) { wait(0.5s); market(side=buy, amount=' + str.tostring(pos_qty_lv) + '); } \n #bot', freq= alert.freq_once_per_bar) if long and inst_pos and en_1st_pos_f and no_open_pos and en_strat alert(message= 'BybitAPI(BTCUSD) { continue(if=positionShort); market(position= 0); } BybitAPI(BTCUSD) { wait(0.5s); market(side=buy, amount=' + str.tostring(pos_qty_lv) + '); } \n #bot', freq= alert.freq_once_per_bar) if short and (entry_short_1 or entry_short_2) alert(message= 'BybitAPI(BTCUSD) { continue(if=positionLong); market(position= 0); } BybitAPI(BTCUSD) { wait(0.5s); market(side=sell, amount=' + str.tostring(pos_qty_lv) + '); } \n #bot', freq= alert.freq_once_per_bar) if short and inst_pos and en_1st_pos_f and no_open_pos and en_strat alert(message= 'BybitAPI(BTCUSD) { continue(if=positionLong); market(position= 0); } BybitAPI(BTCUSD) { wait(0.5s); market(side=sell, amount=' + str.tostring(pos_qty_lv) + '); } \n #bot', freq= alert.freq_once_per_bar)//tp and sl if long and av_tp_en and av_profit_l and not no_open_pos alert(message= 'BybitAPI(BTCUSD) { market(position= ' + str.tostring(av_tp_qty_c_l_var) + ' %p); } \n #bot', freq= alert.freq_once_per_bar) if long and av_sl_en and av_loss_l and not no_open_pos alert(message= 'BybitAPI(BTCUSD) { market(position=' + str.tostring(av_sl_qty_c_l_var) + ' %p); } \n #bot', freq= alert.freq_once_per_bar) if short and av_tp_en and av_profit_s and not no_open_pos alert(message= 'BybitAPI(BTCUSD) { market(position= ' + str.tostring(av_tp_qty_c_s_var) + ' %p); } \n #bot', freq= alert.freq_once_per_bar) if short and av_sl_en and av_loss_s and not no_open_pos alert(message= 'BybitAPI(BTCUSD) { market(position=' + str.tostring(av_sl_qty_c_s_var) + ' %p); } \n #bot', freq= alert.freq_once_per_bar)//exit filters if long and not no_open_pos and exit_long and not exit_long[1] or short and exit_short and not exit_short[1] alert(message= 'BybitAPI(BTCUSD) { market(position=' + str.tostring(qyt_exit_var) + ' %p); } \n #bot', freq= alert.freq_once_per_bar)//start strategy, border exits if border_close and en_close and not no_open_pos alert(message= 'BybitAPI(BTCUSD) { market(position= 0); } \n #bot', freq= alert.freq_once_per_bar)//break even if break_ev and not no_open_pos alert(message= 'BybitAPI(BTCUSD) { market(position= 0); } \n #bot', freq= alert.freq_once_per_bar)//close & stop if strat_cl_st and not no_open_pos alert(message= 'BybitAPI(BTCUSD) { market(position= 0); } \n #bot', freq= alert.freq_once_per_bar)//repetitive break even if rep_even_long alert(message= 'BybitAPI(BTCUSD) { market(position=' + str.tostring(rep_ev_qty_var) + ' %p); } \n #bot', freq= alert.freq_once_per_bar) if rep_even_short alert(message= 'BybitAPI(BTCUSD) { market(position=' + str.tostring(rep_ev_qty_var) + ' %p); } \n #bot', freq= alert.freq_once_per_bar)