//@version=5 indicator('test vp', overlay=true) //===================== Indicator 1 (Yellow and Blue line calculations) ===================== // Fast Trail Yellow line// AP1 = input.int(5, title ="ATR Period(Yellow line)") // ATR Period1 AF1 = input.float(1.5, title ="ATR Factor(Blue line)") // ATR Factor1 SL1 = AF1 * ta.atr(AP1) // Stop Loss Trail1 = 0.0 iff_1 = close > nz(Trail1[1], 0) ? close - SL1 : close + SL1 iff_2 = close < nz(Trail1[1], 0) and close[1] < nz(Trail1[1], 0) ? math.min(nz(Trail1[1], 0), close + SL1) : iff_1 Trail1 := close > nz(Trail1[1], 0) and close[1] > nz(Trail1[1], 0) ? math.max(nz(Trail1[1], 0), close - SL1) : iff_2 // Slow Trail Blue line// AP2 = input.int(5, title ="ATR Period(Blue line)") // ATR Period2 AF2 = input.float(1.0, title ="ATR Factor(Blue line)") // ATR Factor2 SL2 = AF2 * ta.atr(AP2) // Stop Loss Trail2 = 0.0 iff_3 = close > nz(Trail1[1], 0) ? close - SL2 : close + SL2 iff_4 = close < nz(Trail1[1], 0) and close[1] < nz(Trail1[1], 0) ? math.min(nz(Trail2[1], 0), close + SL2) : iff_3 Trail2 := close > nz(Trail1[1], 0) and close[1] > nz(Trail1[1], 0) ? math.max(nz(Trail2[1], 0), close - SL2) : iff_4 chngcolor1 = ta.crossover(Trail1, Trail2) chngcolor2 = ta.crossunder(Trail1, Trail2) plot(Trail1, 'Yellow Line', style=plot.style_line, color=Trail1 > Trail2 ? color.yellow : color.yellow, linewidth=2, editable = false) plot(Trail2, 'Blue Line', style=plot.style_line, color=Trail1 > Trail2 ? color.blue : color.blue, linewidth=2, editable = false) barcolor(color = chngcolor1 ? color.rgb(245, 243, 241) : chngcolor2 ? #fe9923 : na, editable = false) //========= Indicator 2 (Buy and Sell signals Calculations) ================ var nATRPeriod = 15 var nATRMultip = 4.0 xATR = ta.atr(nATRPeriod) nLoss = nATRMultip * xATR xATRTrailingStop = float(na) iff_6 = close > nz(xATRTrailingStop[1], 0) ? close - nLoss : close + nLoss iff_7 = close < nz(xATRTrailingStop[1], 0) and close[1] < nz(xATRTrailingStop[1], 0) ? math.min(nz(xATRTrailingStop[1]), close + nLoss) : iff_6 xATRTrailingStop := close > nz(xATRTrailingStop[1], 0) and close[1] > nz(xATRTrailingStop[1], 0) ? math.max(nz(xATRTrailingStop[1]), close - nLoss) : iff_7 pos = int(na) iff_8 = close[1] > nz(xATRTrailingStop[1], 0) and close < nz(xATRTrailingStop[1], 0) ? -1 : nz(pos[1], 0) pos := close[1] < nz(xATRTrailingStop[1], 0) and close > nz(xATRTrailingStop[1], 0) ? 1 : iff_8 color_1 = pos == -1 ? color.red : pos == 1 ? color.lime : color.blue //Plotting VWMA var len2 = 100 out = ta.vwma(close, len2) avg1 = math.avg(out, xATRTrailingStop) plot(avg1, linewidth = 2, color=color.new(color.aqua, 0), title='Light Blue line', editable = false) // Buy and Sell Signals buySignal = ta.crossover(close, xATRTrailingStop) sellSignal = ta.crossunder(close, xATRTrailingStop) // Created a varaible to Show & hide Buy/Sell signals buysig = buySignal sellsig = sellSignal // plot buy/sell signals plotshape(series=buysig, location=location.belowbar, color=color.green, style=shape.labelup, text="Buy", textcolor = color.white, size = size.small, title="Buy", editable = false) plotshape(series=sellsig, location=location.abovebar, color=color.red, style=shape.labeldown, text="Sell", textcolor = color.white, size = size.small, title="Sell", editable = false) // Tracking the signal state var int signalState = na if (buySignal) signalState := 1 if (sellSignal) signalState := -1 // Change Candle Color on Buy and Sell Signals barcolor(signalState == 1 ? #089981 : na, editable = false) barcolor(signalState == -1 ? color.red : na, editable = false) // Conditions for C-Buy // Tracking the last buy price for Cbuy signal var float lastbuyprice = na var bool cbuytrig = false if (buySignal) lastbuyprice := high cbuytrig := false // cbuy Signal Condition cbuysignal = not cbuytrig and not na(lastbuyprice) and close > lastbuyprice if (cbuysignal) cbuytrig := true // Plotting cbuy Signal plotshape(series=cbuysignal, location=location.belowbar, color=color.green, style=shape.labelup, text="C-Buy", textcolor = color.white, size = size.small, title="C-Buy", editable = false) // Condtions for C-Sell var float lastsellprice = na var bool cselltrig = false if (sellSignal) lastsellprice := low cselltrig := false csellsignal = not cselltrig and not na(lastsellprice) and close < lastsellprice if (csellsignal) cselltrig := true plotshape(series=csellsignal, location=location.abovebar, color=color.red, style=shape.labeldown, text="C-Sell", textcolor = color.white, size = size.small, title="C-Sell", editable = false)