// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ //@version=5 strategy("nicky190201 MACD VWAP strategy", overlay=true, process_orders_on_close = true) gr_str='Strategy Settings' issltplines=input(true,"Show SL/TP lines",group = gr_str) tppct=input(20,"Take Profit pts",group=gr_str) slpct=input(10,"Stop Loss pts",group=gr_str) isMoveSL=input(true,"Move SL",inline = "msl",group = gr_str) firstTPMove=input(10,"TP pts",inline = "msl",group = gr_str) isAtr=input(false,"Include ATR on SL/TP",group = gr_str) isB1B2=input(true,"EntryBand1Band2",group = gr_str) isB2B3=input(true,"EntryBand2Band3",group = gr_str) //VWAP{ hideonDWM = input(false, title="Hide VWAP on 1D or Above", group="VWAP Settings") var anchor = input.string(defval = "Session", title="Anchor Period", options=["Session", "Week", "Month", "Quarter", "Year", "Decade", "Century", "Earnings", "Dividends", "Splits"], group="VWAP Settings") src = input(title = "Source", defval = hlc3, group="VWAP Settings") offset = input(0, title="Offset", group="VWAP Settings") showBand_1 = input(true, title="", group="Standard Deviation Bands Settings", inline="band_1") stdevMult_1 = input(1.0, title="Bands Multiplier #1", group="Standard Deviation Bands Settings", inline="band_1") showBand_2 = input(true, title="", group="Standard Deviation Bands Settings", inline="band_2") stdevMult_2 = input(2.0, title="Bands Multiplier #2", group="Standard Deviation Bands Settings", inline="band_2") showBand_3 = input(true, title="", group="Standard Deviation Bands Settings", inline="band_3") stdevMult_3 = input(3.0, title="Bands Multiplier #3", group="Standard Deviation Bands Settings", inline="band_3") if barstate.islast and ta.cum(volume) == 0 runtime.error("No volume is provided by the data vendor.") new_earnings = request.earnings(syminfo.tickerid, earnings.actual, barmerge.gaps_on, barmerge.lookahead_on, ignore_invalid_symbol=true) new_dividends = request.dividends(syminfo.tickerid, dividends.gross, barmerge.gaps_on, barmerge.lookahead_on, ignore_invalid_symbol=true) new_split = request.splits(syminfo.tickerid, splits.denominator, barmerge.gaps_on, barmerge.lookahead_on, ignore_invalid_symbol=true) isNewPeriod = switch anchor "Earnings" => not na(new_earnings) "Dividends" => not na(new_dividends) "Splits" => not na(new_split) "Session" => timeframe.change("D") "Week" => timeframe.change("W") "Month" => timeframe.change("M") "Quarter" => timeframe.change("3M") "Year" => timeframe.change("12M") "Decade" => timeframe.change("12M") and year % 10 == 0 "Century" => timeframe.change("12M") and year % 100 == 0 => false isEsdAnchor = anchor == "Earnings" or anchor == "Dividends" or anchor == "Splits" if na(src[1]) and not isEsdAnchor isNewPeriod := true float vwapValue = na float upperBandValue1 = na float lowerBandValue1 = na float upperBandValue2 = na float lowerBandValue2 = na float upperBandValue3 = na float lowerBandValue3 = na if not (hideonDWM and timeframe.isdwm) [_vwap, _stdevUpper, _] = ta.vwap(src, isNewPeriod, 1) vwapValue := _vwap stdevAbs = _stdevUpper - _vwap upperBandValue1 := _vwap + stdevAbs * stdevMult_1 lowerBandValue1 := _vwap - stdevAbs * stdevMult_1 upperBandValue2 := _vwap + stdevAbs * stdevMult_2 lowerBandValue2 := _vwap - stdevAbs * stdevMult_2 upperBandValue3 := _vwap + stdevAbs * stdevMult_3 lowerBandValue3 := _vwap - stdevAbs * stdevMult_3 plot(vwapValue, title="VWAP", color=#2962FF, offset=offset) upperBand_1 = plot(upperBandValue1, title="Upper Band #1", color=color.green, offset=offset, display = showBand_1 ? display.all : display.none) lowerBand_1 = plot(lowerBandValue1, title="Lower Band #1", color=color.green, offset=offset, display = showBand_1 ? display.all : display.none) fill(upperBand_1, lowerBand_1, title="Bands Fill #1", color= color.new(color.green, 95) , display = showBand_1 ? display.all : display.none) upperBand_2 = plot(upperBandValue2, title="Upper Band #2", color=color.olive, offset=offset, display = showBand_2 ? display.all : display.none) lowerBand_2 = plot(lowerBandValue2, title="Lower Band #2", color=color.olive, offset=offset, display = showBand_2 ? display.all : display.none) fill(upperBand_2, lowerBand_2, title="Bands Fill #2", color= color.new(color.olive, 95) , display = showBand_2 ? display.all : display.none) upperBand_3 = plot(upperBandValue3, title="Upper Band #3", color=color.teal, offset=offset, display = showBand_3 ? display.all : display.none) lowerBand_3 = plot(lowerBandValue3, title="Lower Band #3", color=color.teal, offset=offset, display = showBand_3 ? display.all : display.none) fill(upperBand_3, lowerBand_3, title="Bands Fill #3", color= color.new(color.teal, 95) , display = showBand_3 ? display.all : display.none) //VWAP} //MACD{ // Getting inputs gr_macd="MACD" fast_length = input(title="Fast Length", defval=12,group = gr_macd) slow_length = input(title="Slow Length", defval=26,group = gr_macd) macdsrc = input(title="Source", defval=close,group = gr_macd) signal_length = input.int(title="Signal Smoothing", minval = 1, maxval = 50, defval = 9,group = gr_macd) sma_source = input.string(title="Oscillator MA Type", defval="EMA", options=["SMA", "EMA"],group = gr_macd) sma_signal = input.string(title="Signal Line MA Type", defval="EMA", options=["SMA", "EMA"],group = gr_macd) // Plot colors // col_macd = input(#2962FF, "MACD Line  ", group="Color Settings", inline="MACD") // col_signal = input(#FF6D00, "Signal Line  ", group="Color Settings", inline="Signal") // col_grow_above = input(#26A69A, "Above   Grow", group="Histogram", inline="Above") // col_fall_above = input(#B2DFDB, "Fall", group="Histogram", inline="Above") // col_grow_below = input(#FFCDD2, "Below Grow", group="Histogram", inline="Below") // col_fall_below = input(#FF5252, "Fall", group="Histogram", inline="Below") // // Calculating fast_ma = sma_source == "SMA" ? ta.sma(macdsrc, fast_length) : ta.ema(macdsrc, fast_length) slow_ma = sma_source == "SMA" ? ta.sma(macdsrc, slow_length) : ta.ema(macdsrc, slow_length) macd = fast_ma - slow_ma signal = sma_signal == "SMA" ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length) hist = macd - signal // hline(0, "Zero Line", color=color.new(#787B86, 50)) // plot(hist, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below))) // plot(macd, title="MACD", color=col_macd) // plot(signal, title="Signal", color=col_signal) //MACD} //ATR{ atrlen=input(14,"ATR Length",group = "ATR") atr=ta.atr(14) //ATR} //Function{ var lstlngprice = 0.0 var lstshtprice = 0.0 var lsttplprice = 0.0 var lsttpsprice = 0.0 var lstsllprice = 0.0 var lstslsprice = 0.0 var lstTP1LongMove=0.0 var lstTP1ShortMove=0.0 var isSL1Moved=false ticktoprice(tick)=> (tick) * syminfo.mintick stoplosscacl(isbuy)=> price = 0.0 if isbuy price := close - (slpct) else price := close + (slpct) price takeprofitcacl(isbuy,pt)=> price = 0.0 if isbuy price := close + (pt) else price := close - (pt) price //Funtcion} macdbuy=ta.crossover(macd,signal) macdsell=ta.crossunder(macd,signal) vwapbuy=closelowerBandValue2 vwapsell=close>upperBandValue1 and closelowerBandValue3 vwapSsell=close>upperBandValue2 and close 0 and isMoveSL and (ta.crossover(close,lstTP1LongMove) or close>lstTP1LongMove) and not isSL1Moved lstsllprice := lstlngprice strategy.exit("exit_TP/SL","long",limit=lsttplprice,stop=lstsllprice) isSL1Moved:=true if strategy.position_size < 0 and isMoveSL and (ta.crossunder(close,lstTP1ShortMove) or close 0 and issltplines? lstlngprice : na,color=color.yellow,style=plot.style_linebr,title="Entry Price Long") plot(strategy.position_size < 0 and issltplines? lstshtprice : na,color=color.yellow,style=plot.style_linebr,title="Entry Price Short") plot(strategy.position_size > 0 and issltplines? lsttplprice : na,color=color.green,style=plot.style_linebr,title="TP Price Long") plot(strategy.position_size > 0 and issltplines? lstsllprice : na,color=color.red,style=plot.style_linebr,title="SL Price Long") plot(strategy.position_size < 0 and issltplines? lsttpsprice : na,color=color.green,style=plot.style_linebr,title="TP Price Short") plot(strategy.position_size < 0 and issltplines? lstslsprice : na,color=color.red,style=plot.style_linebr,title="SL Price Short")