// © sacredprofit // client: abundancementor //@version=5 strategy(title = 'Scalping Strategy', shorttitle='Scalp Strat', overlay=true, process_orders_on_close = true, default_qty_type = strategy.percent_of_equity) x_session = input.session('0800-0800', 'Trade Session', group='Trade') x_cndl_body = input.bool(false, 'Use Whole Candle', group='Trade', tooltip='For a trade to be initiated, signal candle needs to be completely above/below Hull trend.') x_close_trades = input.bool(true, 'Close Trades at Session Close', group='Trade') x_show_session = input.bool(true, 'Show Out of Session', tooltip='Highlight out of session bars.', group='Trade') x_rr = input.float(1.5, 'Risk Reward Ratio', minval=0, step=0.1, group='Trade') x_offset_stop_loss = input.int(0, 'Stop Loss Offset (pips)', minval=0, group='Trade') x_lookback_len = input.int(5, 'Bars Back (Stop Loss)', tooltip='Number of bars back in which to look for a high or low to set the stop loss.', inline='Stop Loss', group='Trade') x_use_hull_sl = input.bool(false, 'Consider Hull', tooltip='When checked, Hull will be used as the stop loss if it is lower than low n bars back for long trades, and higher than high n bars back for short ones.', inline='Stop Loss', group='Trade') x_bs_cross = input.int(0, 'Bars Since Vortex Cross', tooltip='Limits how closs Vortex crosses can be to one another.', group='Trade') x_skip_sl = input.string('Greater', 'Skip Trade if Stop Loss (pips) is', ['Greater', 'Lesser'], inline='Stop Loss Skip', group='Trade') x_skip_val = input.float(100, 'than', minval=0, step=5, inline='Stop Loss Skip', group='Trade') x_use_skip_sl = input.bool(false, '', inline='Stop Loss Skip', group='Trade') // Volume Oscillator var cumVol = 0. cumVol += nz(volume) if barstate.islast and cumVol == 0 runtime.error('No volume is provided by the data vendor.') shortlen = input.int(5, minval=1, title = 'Short Length', group='Volume Oscillator') longlen = input.int(10, minval=1, title = 'Long Length', group='Volume Oscillator') short = ta.ema(volume, shortlen) long = ta.ema(volume, longlen) osc = 100 * (short - long) / long // hline(0, color = #787B86, title='Zero') // plot(osc, color=#2962FF) // Hull Suite by InSilico //INPUT src = input(close, title='Source', group='Hull Suite') modeSwitch = input.string('Hma', title='Hull Variation', options=['Hma', 'Thma', 'Ehma'], group='Hull Suite') length = input(100, title='Length(180-200 for floating S/R , 55 for swing entry)', group='Hull Suite') lengthMult = input(3.0, title='Length multiplier (Used to view higher timeframes with straight band)', group='Hull Suite') useHtf = input(false, title='Show Hull MA from X timeframe? (good for scalping)', group='Hull Suite') htf = input.timeframe('240', title='Higher timeframe', group='Hull Suite') switchColor = input(true, 'Color Hull according to trend?', group='Hull Suite') candleCol = input(false, title='Color candles based on Hull\'s Trend?', group='Hull Suite') visualSwitch = input(true, title='Show as a Band?', group='Hull Suite') thicknesSwitch = input(1, title='Line Thickness', group='Hull Suite') transpSwitch = input.int(40, title='Band Transparency', step=5, group='Hull Suite') //FUNCTIONS //HMA HMA(_src, _length) => ta.wma(2 * ta.wma(_src, _length / 2) - ta.wma(_src, _length), math.round(math.sqrt(_length))) //EHMA EHMA(_src, _length) => ta.ema(2 * ta.ema(_src, _length / 2) - ta.ema(_src, _length), math.round(math.sqrt(_length))) //THMA THMA(_src, _length) => ta.wma(ta.wma(_src, _length / 3) * 3 - ta.wma(_src, _length / 2) - ta.wma(_src, _length), _length) //SWITCH Mode(modeSwitch, src, len) => modeSwitch == 'Hma' ? HMA(src, len) : modeSwitch == 'Ehma' ? EHMA(src, len) : modeSwitch == 'Thma' ? THMA(src, len / 2) : na //OUT _hull = Mode(modeSwitch, src, int(length * lengthMult)) HULL = useHtf ? request.security(syminfo.ticker, htf, _hull) : _hull MHULL = HULL[0] SHULL = HULL[2] //COLOR hullColor = switchColor ? HULL > HULL[2] ? #00ff00 : #ff0000 : #ff9800 //PLOT ///< Frame Fi1 = plot(MHULL, title='MHULL', color=color.new(hullColor, osc > 0 ? 50 : 70), linewidth=thicknesSwitch) Fi2 = plot(visualSwitch ? SHULL : na, title='SHULL', color=color.new(hullColor, osc > 0 ? 50 : 70), linewidth=thicknesSwitch) ///< Ending Filler fill(Fi1, Fi2, title='Band Filler', color=color.new(hullColor, osc > 0 ? transpSwitch : 70)) ///BARCOLOR barcolor(color=candleCol ? switchColor ? hullColor : na : na) // Vortex Indicator period_ = input.int(20, title='Length', minval=2, group='Vortex') VMP = math.sum( math.abs( high - low[1]), period_ ) VMM = math.sum( math.abs( low - high[1]), period_ ) STR = math.sum( ta.atr(1), period_ ) VIP = VMP / STR VIM = VMM / STR // plot(VIP, title='VI +', color=#2962FF) // plot(VIM, title='VI -', color=#E91E63) // CONDITIONS src_bull_hull = x_cndl_body ? low : close src_bear_hull = x_cndl_body ? high : close is_bull_hull = src_bull_hull > MHULL and HULL > HULL[2] is_bear_hull = src_bear_hull < SHULL and HULL < HULL[2] is_bull_vi = ta.crossover(VIP, VIM) and ta.barssince(ta.crossover(VIM, VIP)) > x_bs_cross is_bear_vi = ta.crossover(VIM, VIP) and ta.barssince(ta.crossover(VIP, VIM)) > x_bs_cross plotshape(ta.crossover(VIP, VIM) and ta.barssince(ta.crossover(VIM, VIP)) <= x_bs_cross, 'Vortex (Failed)', shape.triangleup, location.belowbar, color.silver, size=size.auto) plotshape(ta.crossover(VIM, VIP) and ta.barssince(ta.crossover(VIP, VIM)) <= x_bs_cross, 'Vortex (Failed)', shape.triangledown, location.abovebar, color.silver, size=size.auto) is_bull_bear_vlm = osc > 0 is_buy = is_bull_hull and is_bull_vi and is_bull_bear_vlm is_sell = is_bear_hull and is_bear_vi and is_bull_bear_vlm plotshape(is_bull_vi, 'Vortex (Bull)', shape.triangleup, location.belowbar, color.green, size=size.tiny) plotshape(is_bear_vi, 'Vortex (Bear)', shape.triangledown, location.abovebar, color.red, size=size.tiny) stop_loss_long = (x_use_hull_sl ? math.min(ta.lowest(low[1], x_lookback_len), MHULL) : ta.lowest(low[1], x_lookback_len)) * (1 - (x_offset_stop_loss/100 * 0.01)) stop_loss_short = (x_use_hull_sl ? math.max(ta.highest(high[1], x_lookback_len), SHULL) : ta.highest(high[1], x_lookback_len)) * (1 + (x_offset_stop_loss/100 * 0.01)) plot(stop_loss_long, 'stop_loss_long', display = display.data_window) plot(stop_loss_short, 'stop_loss_short', display = display.data_window) var float stop_loss = na is_position_chg = ta.change(strategy.position_size) stop_loss := switch strategy.position_size > 0 and is_position_chg => stop_loss_long strategy.position_size < 0 and is_position_chg => stop_loss_short strategy.position_size == 0 => na => stop_loss var float take_profit = na take_profit := (math.abs(stop_loss - strategy.position_avg_price) / syminfo.mintick) * x_rr s_take_profit = switch strategy.position_size > 0 => strategy.position_avg_price + (take_profit * syminfo.mintick) strategy.position_size < 0 => strategy.position_avg_price - (take_profit * syminfo.mintick) plot(stop_loss, 'stop_loss', color.red, style=plot.style_linebr) plot(s_take_profit, 's_take_profit', color.green, style=plot.style_linebr) is_session = time('', x_session) bgcolor(x_show_session and not is_session ? color.new(color.blue, 95) : na, title='Out of Session') plot(math.abs((stop_loss_long - close) / syminfo.mintick), 'math.abs((stop_loss_long - close) / syminfo.mintick)', display=display.data_window) plot(math.abs((stop_loss_short - close) / syminfo.mintick), 'math.abs((stop_loss_short - close) / syminfo.mintick)', display=display.data_window) if strategy.position_size == 0 if is_buy and is_session if not x_use_skip_sl or (x_use_skip_sl and (x_skip_sl == 'Greater' and math.abs((stop_loss_long - close) / syminfo.mintick) < x_skip_val) or (x_skip_sl == 'Lesser' and math.abs((stop_loss_long - close) / syminfo.mintick) > x_skip_val)) strategy.entry('Long', strategy.long) if is_sell and is_session if not x_use_skip_sl or (x_use_skip_sl and (x_skip_sl == 'Greater' and math.abs((stop_loss_short - close) / syminfo.mintick) < x_skip_val) or (x_skip_sl == 'Lesser' and math.abs((stop_loss_short - close) / syminfo.mintick) > x_skip_val)) strategy.entry('Sell', strategy.short) strategy.exit('Exit', profit=take_profit, stop=stop_loss, comment_loss = 'Stop Loss', comment_profit = 'Take Profit') if not is_session and is_session[1] and x_close_trades strategy.close_all('End of Session')