// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © maruful_bd_yhoo //@version=5 strategy("~Sig - strategy", overlay = false) // Inputs fastest = input( 6, "Fastest lookback") faster = fastest * 2 slow = input( 20, "Slow lookback" ) slower = 24 slowest = int(slow * 1.5) signalLength_macd = input (7, "MACD signal length") //=== Calculations [ macdLine, signal_fastest, _ ] = ta.macd(close, fastest, faster, signalLength_macd) [ macdLine_faster, signal_faster, _ ] = ta.macd(close, faster, slower, signalLength_macd) [_, s, _] = ta.macd(close, 12, 24, 7) // === plotting === //p_signal_fastest = plot(signal_fastest, title="Signal fastest", color= ta.rising(signal_fastest, 3) ? #FFFFFF : #34495E, linewidth = 1) p_signal_s = plot(s, title="MACD signal faster", color= ta.rising(s, 2) ? #5DADE2 : color.red, linewidth = 1, style=plot.style_stepline) //p_signal_slowest = plot(signal_slowest, title="MACD signal fastestest", color= ta.rising(signal_slowest, 4) ? bullish2 : bearish2 , linewidth = 1, style=plot.style_stepline) //fill ( p_signalLine, p_signalLine2, color = ta.rising( signalLine2, 7) ? bullFill1 : bearFill1) //======================================================================== // Strategy, placing / closing orders //======================================================================== // close SHORT if( ta.rising(s, 3) ) strategy.close("short") //___________ Find a price for entry short_entry_price = close + 2.0 // open SHORT if( ta.falling(s, 3) ) strategy.entry("short", strategy.short, 0.3, short_entry_price) // === Reverse MACD [ _, rev_macdLine_original, _] = ta.macd(close, 33, 7, signalLength_macd) [ macdLine2, rev_macdLine2_original, _] = ta.macd(close, 14, 7, signalLength_macd) rev_macdLine = rev_macdLine_original rev_macdLine2 = rev_macdLine2_original //p_rev_macdLine = plot( rev_macdLine, title = "Rev. MACD", color= ta.rising( rev_macdLine, 7) ? bearish : bullish, linewidth = 1 ) //p_rev_macdLine2 = plot( rev_macdLine2, title = "Rev. MACD", color= ta.rising( rev_macdLine2, 3) ? bearish : bullish, linewidth = 1, style= plot.style_circles ) //fill( p_rev_macdLine, p_rev_macdLine2, color = ta.rising( rev_macdLine2, 7) ? bearFill2 : bullFill2 ) //=== Color candles based on price action fastest2 = input( 7, "Short EMA lookback") slow2 = input( 14, "Medium EMA lookback") ema_high = ta.ema( high, 7) ema_medium = ta.ema( close, slow2) ema_fastest = ta.ema( close, 6) ema_low_fastest = ta.ema( low, fastest2 ) //==== color the candlesticks //barcolor( close > ema_medium ? candle_bullish : close <= ema_fastest ? candle_bearish : candle_bearish_lite ) // ===================================================================== //=== CVD calculation and coloring the bars accordingly after comparison // This source code is adapted from "Cummulative Volume Delta" by footlz ema_len = input(10, title="CVD lookback [colored candles]") v = volume o = open c = close vbuy = 0.0 vsell = 0.0 if c > o vbuy := v * math.abs(o / c - 1) if c < o vsell := v * math.abs(o / c - 1) delta = ta.cum(vbuy - vsell) ema = ta.alma(delta, ema_len, .85, 6) //ema := ta.rma (ema, 2) ema_color = delta >= ema ? #3eb370 : #e9546b barcolor( delta >= ema ? #dddddd : #34495E ) cvd = ta.ema( delta, 18) //______________________________________________ LONG strategy if( delta < cvd ) strategy.close("long") if( delta >= cvd ) strategy.entry("long", strategy.long, 0.3)