Strategy · Pine Script v4 · On the chart

CombinedBinHAndClucV8

by viktors1982· code credited to viktors.s@gmail.com

This strategy trades on the price chart using multiple indicators.

View on GitHub

Repaints

GitHub stars36on the repository
Pine versionv4older, still runs
Lines of code244
Settings39inputs
LicenceNone statedfile: MPL-2.0
Last update2 years ago10 Apr 2024

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

244 lines of Pine Script v4 from tradingview/pinescripts/strategies/CombinedBinHAndClucV8.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

CombinedBinHAndClucV8.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © viktors.s@gmail.com   
// freqtrade author: iterativ   
// translate to tradingview: viksal1982


//@version=4
strategy("CombinedBinHAndClucV8", overlay=true, currency=currency.EUR, default_qty_type=strategy.cash, default_qty_value=150, initial_capital = 33000, calc_on_every_tick=true,commission_type=strategy.commission.percent, commission_value =0.15)


startDate                   = input(title="Start Strat", type=input.time, defval=timestamp("01 Jan 2021 00:00 +0000") )
enableTimeout               = input(title="Stoploss - Enable Timeout", type=input.bool, defval=true)
timeoutMinuts               = input(title="Stoploss - Timeout minuts", type=input.integer, defval=280, step =1, minval = 100000 )

enableStoplossSMA           = input(title="Stoploss - Enable SMA for Stoploss", type=input.bool, defval=true)
sell_custom_stoploss_1      = input(title="Sell custom stoploss", type=input.float,     defval= -0.05, step =0.01, minval = -0.15, maxval =-0.03)


buy_dip_threshold_0     = input(title="Buy bb40 bbdelta close", type=input.float,     defval= 0.015, step =0.001, minval = 0.001, maxval = 0.1)
buy_dip_threshold_1     = input(title="Buy bb40 bbdelta close", type=input.float,     defval= 0.12, step =0.001, minval = 0.001, maxval = 0.2)
buy_dip_threshold_2     = input(title="Buy bb40 bbdelta close", type=input.float,     defval= 0.28, step =0.001, minval = 0.001, maxval = 0.4)
buy_dip_threshold_3     = input(title="Buy bb40 bbdelta close", type=input.float,     defval= 0.36, step =0.001, minval = 0.001, maxval = 0.44)


buy_bb40_length            = input(title="Buy bb40 length", type=input.integer,          defval= 40, step =1, minval = 5, maxval = 100) 
buy_bb40_bbdelta_close     = input(title="Buy bb40 bbdelta close", type=input.float,     defval= 0.031, step =0.001, minval = 0.005, maxval = 0.1)
buy_bb40_closedelta_close  = input(title="Buy bb40 closedelta close", type=input.float,  defval= 0.021, step =0.001, minval = 0.01,  maxval = 0.03)
buy_bb40_tail_bbdelta      = input(title="Buy bb40 tail bbdelta", type=input.float,      defval= 0.264, step =0.001, minval = 0.15,  maxval = 0.45)


buy_bb20_length            = input(title="Buy bb20 length", type=input.integer,          defval= 20, step =1, minval = 5, maxval = 100) 
buy_bb20_close_bblowerband = input(title="Buy bb20 close bblowerband", type=input.float, defval= 0.992, step =0.001, minval = 0.8,   maxval = 1.1)
buy_bb20_volume            = input(title="Buy bb20 volume", type=input.integer,          defval= 29,    step =1,     minval = 18,    maxval = 34 )
buy_rsi_diff               = input(title="Buy RSI Diff", type=input.float,               defval= 50.48,  step =0.1,   minval = 36.0,  maxval = 54.0)
buy_min_inc                = input(title="Buy Min Inc", type=input.float,                defval= 0.01,  step =0.1,   minval = 0.005,  maxval = 0.05)
buy_rsi_1h                 = input(title="Buy RSI 1h", type=input.float,                 defval= 67.0,  step =0.1,   minval =40.0,  maxval =70.0)
buy_rsi                    = input(title="Buy RSI", type=input.float,                    defval= 38.5,  step =0.1,   minval =30.0,  maxval =40.0)
buy_mfi                    = input(title="Buy MFI", type=input.float,                    defval= 36.0,  step =0.1,   minval =36.0,  maxval =65.0)
buy_volume_1               = input(title="Buy Volume 1", type=input.float,               defval= 2.0,  step =0.1,   minval =1.0,  maxval =10.0)
buy_ema_open_mult_1        = input(title="Buy EMA open mult 1", type=input.float,        defval= 0.02,  step =0.01,   minval =0.01,  maxval =0.05)




sell_custom_roi_profit_1    = input(title="Sell custom roi profit 1", type=input.float,     defval= 0.01, step =0.01, minval = 0.01, maxval = 0.03)
sell_custom_roi_rsi_1       = input(title="Sell custom roi rsi 1"   , type=input.float,     defval= 50, step =0.01, minval = 40.0, maxval = 56.0)

sell_custom_roi_profit_2    = input(title="Sell custom roi profit 2", type=input.float,     defval= 0.04, step =0.01, minval = 0.01, maxval = 0.20)
sell_custom_roi_rsi_2       = input(title="Sell custom roi rsi 2"   , type=input.float,     defval= 50, step =0.01, minval = 42.0, maxval = 56.0)

sell_custom_roi_profit_3    = input(title="Sell custom roi profit 3", type=input.float,     defval= 0.08, step =0.01, minval = 0.15, maxval = 0.30)
sell_custom_roi_rsi_3       = input(title="Sell custom roi rsi 3"   , type=input.float,      defval= 56,   step =0.01, minval = 44.0, maxval = 58.0)

sell_custom_roi_profit_4    = input(title="Sell custom roi profit 4", type=input.float,     defval= 0.14, step =0.01, minval = 0.3, maxval = 0.7)
sell_custom_roi_rsi_4       = input(title="Sell custom roi rsi 4"   , type=input.float,      defval= 58,   step =0.01, minval = 44.0, maxval = 60.0)


sell_custom_roi_profit_5    = input(title="Sell custom roi profit 5", type=input.float,     defval= 0.04, step =0.01, minval = 0.01, maxval = 0.1)

sell_trail_profit_min_1    = input(title="Sell trail profit min 1", type=input.float,     defval= 0.1, step =0.01, minval = 0.1, maxval = 0.25)
sell_trail_profit_max_1    = input(title="Sell trail profit max 1", type=input.float,     defval= 0.4, step =0.01, minval = 0.3, maxval = 0.5)
sell_trail_down_1          = input(title="Sell trail down 1", type=input.float,     defval= 0.03, step =0.01, minval = 0.04, maxval = 0.1)


sell_trail_profit_min_2    = input(title="Sell trail profit min 2", type=input.float,     defval= 0.02, step =0.01, minval = 0.01, maxval =0.1)
sell_trail_profit_max_2    = input(title="Sell trail profit max 2", type=input.float,     defval= 0.1, step =0.01, minval = 0.08, maxval =0.25)
sell_trail_down_2          = input(title="Sell trail down 2", type=input.float,     defval= 0.015, step =0.01, minval = 0.01, maxval =0.2)




sell_rsi_main              = input(title="Sell RSI main", type=input.float  ,            defval= 80.0,  step =1,   minval = 50.0,  maxval = 90.0)





//strategy bb40
[middle, upper, lower] = bb(close, buy_bb40_length, 2)
bbdelta = abs(middle - lower)
closedelta = abs(close -close[1])
tail = abs(close - low)


//strategy bb20
[middle2, upper2, lower2] = bb(close, buy_bb20_length, 2)
p_middle = plot(middle2, color=color.aqua)
p_upper = plot(upper2, color=color.silver)
p_lower = plot(lower2, color=color.silver)
fill(p_lower,p_upper)

ema_slow = ema(close,50)
volume_mean_slow = sum(volume,30)/30
volume_mean_4 = sum(volume,4)/4
plot(ema_slow, color=color.red)

ema_12  =  ema(close,12)
ema_26 =  ema(close,26)
ema_20  =  ema(close,20)
ema_50  =  ema(close,50)
ema_100  =  ema(close,100)
ema_200 =  ema(close,200)
sma_5   =  sma(close,5)
sma_9   =  sma(close,9)
sma_200   =  sma(close,200)

rsi_5m     =  rsi(close,14)

atr_5m  = atr(14)
sma_high = sma(high,20)
sma_low= sma(low,20)


sma_200_dec = sma_200 < sma_200[20]

mfi_5m = mfi(close, 14)

plotchar(rsi_5m, "rsi_5m", "", location = location.top)

//1h ... !


ema_20_1h = security(syminfo.tickerid, '60', ema_20)
ema_100_1h = security(syminfo.tickerid, '60', ema_100)
ema_50_1h = security(syminfo.tickerid, '60', ema_50)
ema_200_1h = security(syminfo.tickerid, '60', ema_200)
rsi_1h = security(syminfo.tickerid, '60', rsi_5m)
atr_1h = security(syminfo.tickerid, '60', atr_5m)
sma_high_1h = security(syminfo.tickerid, '60', sma_high) + atr_1h
sma_low_1h = security(syminfo.tickerid, '60', sma_low) - atr_1h
close_1h = security(syminfo.tickerid, '60', close)
sma_200_1h = security(syminfo.tickerid, '60', sma_200)
sma_200_dec_1h = security(syminfo.tickerid, '60', sma_200_dec)



float Hlv_1h = na
Hlv_1h := close_1h > sma_high_1h ? 1 : close_1h < sma_low_1h ? -1 : Hlv_1h[1]
sslDown_1h = Hlv_1h < 0 ? sma_high_1h: sma_low_1h
sslUp_1h   = Hlv_1h < 0 ? sma_low_1h : sma_high_1h


//  BUY logic :)
bb40_long = close > ema_200_1h and ema_50 > ema_200 and ema_50_1h > ema_200_1h and  ((highest(open,2) - close)/close) < buy_dip_threshold_1 and ((highest(open,12) - close)/close) < buy_dip_threshold_2  and lower[1] > 0 and bbdelta > close * buy_bb40_bbdelta_close and  closedelta > close * buy_bb40_closedelta_close and tail < bbdelta * buy_bb40_tail_bbdelta and close < lower[1] and close <= close[1] 
bb20_long = close > ema_200 and close > ema_200_1h and ema_50_1h > ema_100_1h and ema_50_1h > ema_200_1h and ((highest(open,2) - close)/close) < buy_dip_threshold_1 and ((highest(open,12) - close)/close) < buy_dip_threshold_2    and close < ema_slow and close < buy_bb20_close_bblowerband * lower2 and volume < volume_mean_slow[1] * buy_bb20_volume 
ssl_long  = close < sma_5 and sslUp_1h > sslDown_1h and ema_50 > ema_200 and ema_50_1h > ema_200_1h and ((highest(open,2) - close)/close) < buy_dip_threshold_1 and ((highest(open,12) - close)/close) < buy_dip_threshold_2 and ((highest(open,144) - close)/close) < buy_dip_threshold_3  and rsi_5m < rsi_1h - buy_rsi_diff
rsi_sma_long =  sma_200 > sma_200[20] and sma_200_1h > sma_200_1h[16] and ((highest(open,2) - close)/close) < buy_dip_threshold_1 and ((highest(open,12) - close)/close) < buy_dip_threshold_2 and ((highest(open,144) - close)/close) < buy_dip_threshold_3 and ((lowest(open,24) - close)/close) > buy_min_inc and rsi_1h > buy_rsi_1h and rsi_5m < buy_rsi and mfi_5m < buy_mfi
ema_volume_long  = close > ema_100_1h and ema_50_1h > ema_100_1h and ((highest(open,2) - close)/close) < buy_dip_threshold_1 and ((highest(open,12) - close)/close) < buy_dip_threshold_2 and ((highest(open,144) - close)/close) < buy_dip_threshold_3 and  volume_mean_4 * buy_volume_1 > volume and ema_26 > ema_12 and ema_26 - ema_12 > open * buy_ema_open_mult_1 and ema_26[1] - ema_12[1] > open/100 and close < lower2
//-------------------------

afterStartDate = (time >= startDate)
longCondition = (bb40_long == 1 or bb20_long == 1 or ssl_long ==1 or rsi_sma_long ==1 or ema_volume_long==1 ) and afterStartDate and strategy.position_size <= 0

//SELL logic
bb_close_sell    = close > upper2 and close[1] > upper2[1] and close[2] > upper2[2] and close[3] > upper2[3]
rsi_main_sell    = rsi_5m > sell_rsi_main

//stoploss timeout
istimeout = enableTimeout? barssince(longCondition) >= (timeoutMinuts/5): na // 60 * 5 = 300 min

st_loss =  (strategy.position_avg_price * (1 + sell_custom_stoploss_1))
plot(st_loss, color=color.red, style=plot.style_linebr, linewidth=2, title='st_loss')
isstoploss = st_loss > close and (enableStoplossSMA ? sma_200_dec and sma_200_dec_1h : true)

rioProfit4 = (strategy.position_avg_price * (1 + sell_custom_roi_profit_4))
plot(rioProfit4, color=color.green, style=plot.style_linebr, linewidth=2, title='rioProfit4')
roi_sell_4 = (rsi_5m < sell_custom_roi_rsi_4 and rioProfit4 < close)  

rioProfit3 = (strategy.position_avg_price * (1 + sell_custom_roi_profit_3))
plot(rioProfit3, color=color.green, style=plot.style_linebr, linewidth=2, title='rioProfit3')
roi_sell_3 = (rsi_5m <  sell_custom_roi_rsi_3 and rioProfit3 < close)  

rioProfit2 = (strategy.position_avg_price * (1 + sell_custom_roi_profit_2))
plot(rioProfit2, color=color.green, style=plot.style_linebr, linewidth=2, title='rioProfit2')
roi_sell_2 = (rsi_5m <  sell_custom_roi_rsi_2 and rioProfit2 < close)  

rioProfit1 = (strategy.position_avg_price * (1 + sell_custom_roi_profit_1))
plot(rioProfit1, color=color.green, style=plot.style_linebr, linewidth=2, title='rioProfit1')
roi_sell_1 = (rsi_5m < sell_custom_roi_rsi_1 and rioProfit1 < close)  


open_trade =  barssince(longCondition) 
plotchar(open_trade, "open_trade", "", location = location.top)
trailProfit1_min      =   (strategy.position_avg_price * (1 + sell_trail_profit_min_1))
trailProfit1_max      =   (strategy.position_avg_price * (1 + sell_trail_profit_max_1))
trailProfit1_max_rate =  0 //(strategy.position_size > 0) ? highest(close, open_trade) : na
trailProfit1_down     =   (close * (1 + sell_trail_down_1)) 
trailProfit1          =  close > trailProfit1_min and close < trailProfit1_max and (trailProfit1_max_rate - strategy.position_avg_price) > trailProfit1_down


trailProfit2_min      =   (strategy.position_avg_price * (1 + sell_trail_profit_min_2))
trailProfit2_max      =   (strategy.position_avg_price * (1 + sell_trail_profit_max_2))
trailProfit2_max_rate =  0//highest(close, barssince(longCondition))
trailProfit2_down     =   (close * (1 + sell_trail_down_2)) 
trailProfit2          =  close > trailProfit2_min and close < trailProfit2_max and (trailProfit2_max_rate - strategy.position_avg_price) > trailProfit2_down



//profit = strategy.netprofit
//plotchar(profit, "profit", "", location = location.top)
//trailProfit1 = (strategy.position_avg_price * (1 + sell_trail_profit_min_1)) > close and  (strategy.position_avg_price * (1 + sell_trail_profit_max_1))

//barssince(longCondition)


//--------------------------
 
 

//DEBUG 
plotchar(bb40_long, "bb40_long", "", location = location.top)
plotchar(bb20_long, "bb20_long", "", location = location.top)
plotchar(ssl_long, "ssl_long", "", location = location.top)
plotchar(rsi_sma_long, "rsi_sma_long", "", location = location.top)
plotchar(ema_volume_long, "ema_volume_long", "", location = location.top)

plotchar(bb_close_sell, "bb_close_sell", "", location = location.top)
plotchar(rsi_main_sell, "rsi_main_sell", "", location = location.top)

//--------------




if (longCondition)
    strategy.entry("Entry", strategy.long, when=(bb40_long) , comment = 'bb40_long')
    strategy.entry("Entry", strategy.long, when=(bb20_long) , comment = 'bb20_long')
    strategy.entry("Entry", strategy.long, when=(ssl_long)  , comment = 'ssl_long')
    strategy.entry("Entry", strategy.long, when=(rsi_sma_long)  , comment = 'rsi_sma_long')
    strategy.entry("Entry", strategy.long, when=(ema_volume_long)  , comment = 'ema_volume_long')

if (strategy.position_size > 0)
    strategy.close(id="Entry", when=(bb_close_sell) , comment = 'bb_close_sell')
    strategy.close(id="Entry", when=(rsi_main_sell)     , comment = 'rsi_main_sell')
    
    strategy.close(id="Entry", when=(roi_sell_4)     , comment = 'roi_sell_4')
    strategy.close(id="Entry", when=(roi_sell_3)     , comment = 'roi_sell_3')
    strategy.close(id="Entry", when=(roi_sell_2)     , comment = 'roi_sell_2')
    strategy.close(id="Entry", when=(roi_sell_1)     , comment = 'roi_sell_1')
    strategy.close(id="Entry", when=(istimeout)      , comment = 'stoploss - timeout ')
    strategy.close(id="Entry", when=(isstoploss)      , comment = 'stoploss')
    
    strategy.close(id="Entry", when=(trailProfit1)      , comment = 'trailProfit1')
    strategy.close(id="Entry", when=(trailProfit2)      , comment = 'trailProfit2')

Overview

CombinedBinHAndClucV8 enters long positions when price dips meet conditions on Bollinger Bands 40 and 20, RSI, MFI, volume and other thresholds. It exits at custom ROI profit levels based on RSI or after timeout or SMA stoploss if enabled. The strategy uses fixed position size and starts from a set date. It repaints on the live bar and lacks a default stop loss.

Details

Published by

viktors1982 on GitHub

Code credit

viktors.s@gmail.com, as written in the script's header

Type

Strategy, Pine Script v4

Draws

On the price chart

Category

Oscillators & momentum, Moving averages, Volatility & bands, Volume

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)
  • The strategy enters trades without a stop loss

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Start Strattimetimestamp("01 Jan 2021 00:00 +0000")startDate
Stoploss - Enable TimeoutbooltrueenableTimeout
Stoploss - Timeout minutsint280timeoutMinuts
Stoploss - Enable SMA for StoplossbooltrueenableStoplossSMA
Sell custom stoplossfloat-0.05sell_custom_stoploss_1
Buy bb40 bbdelta closefloat0.015buy_dip_threshold_0
Buy bb40 bbdelta closefloat0.12buy_dip_threshold_1
Buy bb40 bbdelta closefloat0.28buy_dip_threshold_2
Buy bb40 bbdelta closefloat0.36buy_dip_threshold_3
Buy bb40 lengthint40buy_bb40_length
Buy bb40 bbdelta closefloat0.031buy_bb40_bbdelta_close
Buy bb40 closedelta closefloat0.021buy_bb40_closedelta_close
Show all 39 settings
SettingTypeDefaultVariable
Buy bb40 tail bbdeltafloat0.264buy_bb40_tail_bbdelta
Buy bb20 lengthint20buy_bb20_length
Buy bb20 close bblowerbandfloat0.992buy_bb20_close_bblowerband
Buy bb20 volumeint29buy_bb20_volume
Buy RSI Difffloat50.48buy_rsi_diff
Buy Min Incfloat0.01buy_min_inc
Buy RSI 1hfloat67.0buy_rsi_1h
Buy RSIfloat38.5buy_rsi
Buy MFIfloat36.0buy_mfi
Buy Volume 1float2.0buy_volume_1
Buy EMA open mult 1float0.02buy_ema_open_mult_1
Sell custom roi profit 1float0.01sell_custom_roi_profit_1
Sell custom roi rsi 1float50sell_custom_roi_rsi_1
Sell custom roi profit 2float0.04sell_custom_roi_profit_2
Sell custom roi rsi 2float50sell_custom_roi_rsi_2
Sell custom roi profit 3float0.08sell_custom_roi_profit_3
Sell custom roi rsi 3float56sell_custom_roi_rsi_3
Sell custom roi profit 4float0.14sell_custom_roi_profit_4
Sell custom roi rsi 4float58sell_custom_roi_rsi_4
Sell custom roi profit 5float0.04sell_custom_roi_profit_5
Sell trail profit min 1float0.1sell_trail_profit_min_1
Sell trail profit max 1float0.4sell_trail_profit_max_1
Sell trail down 1float0.03sell_trail_down_1
Sell trail profit min 2float0.02sell_trail_profit_min_2
Sell trail profit max 2float0.1sell_trail_profit_max_2
Sell trail down 2float0.015sell_trail_down_2
Sell RSI mainfloat80.0sell_rsi_main
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

BB+RSI+OBV

by hasnocool
106 stars

This strategy combines Bollinger Bands, the Relative Strength Index (RSI), and On-Balance Volume (OBV) to generate trade signals directly on the price chart. Long entries trigger when price is above the middle SMA band, RSI is over 50, and OBV is rising. Short

Strategy v4 Volatility & bandsOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of BB+RSI+OBV
330 stars

This strategy plots MACD line, signal line, Bollinger Bands, and RSI on the price chart. It signals long entries on MACD crossover above signal with RSI below 50 and price below BB basis, plus optional DMI filter. Short entries are available but disabled by de

Strategy v5 Oscillators & momentumVolatility & bands
Updated 2 months ago · None stated GitHub repository of MACD + BB + RSI [Alorse]
257 stars

This overlay strategy is built for ES futures on the one-minute chart. It plots a volume-weighted moving average of price opens and standard-deviation bands at Fibonacci ratios, plus a second longer volume-weighted average from a higher-timeframe open. Call an

Strategy v5 Volatility & bandsMoving averages
Updated 6 weeks ago · None stated GitHub repository of ES Futures 1M No Repaint
105 stars

This overlay strategy looks for gold scalps from break of structure and change of character. It enters long when a bullish break, a bullish character change, and an optional volume filter align, and short on the opposite set. Optional RSI levels can block trad

Strategy v6 SMC / ICT / price actionOscillators & momentum Repaints

Take Profits & Stop Losses

by PythonForForex
64 stars

This educational strategy demonstrates moving average crossovers filtered by RSI momentum, incorporating ATR-based risk management. It calculates a 10-period SMA, a 30-period SMA, a 14-period RSI, and a 14-period ATR. Long entries trigger when the fast SMA cro

Strategy v5 Moving averagesOscillators & momentum
Updated 4 years ago · None stated GitHub repository of Take Profits & Stop Losses

Momentum Rider DAILY FINAL

by greenpeas007
58 stars

This strategy combines exponential moving averages (EMA 9, 21, 50), RSI, MACD, and Supertrend indicators to enter long positions. It triggers trades using six dynamic setups based on momentum breakouts, EMA crossovers, and pullbacks. Position sizing is compute

Strategy v6 TrendOscillators & momentum Repaints
Updated 4 months ago · Custom licence GitHub repository of Momentum Rider DAILY FINAL

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers