/////////////////////////////////////////////////////// // // SaherElm IT Center XTrade VBM15M Strategy // --------------------------------------------- // in this strategy i must use: // - Price Action Candle Recognition; // - VBM Buy and Sell; // - Multpile Strategies Oscillator; // // Maintainer: // ------------ // Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) // ////////////////////////////////////////////////////// // //@version=5 indicator(title="SaherElm XTrade VBM15M Strategy", shorttitle = "XTS_VBM15M", overlay = true) // // START Inputs .... // // // Determines Show Signals or not ... showSignals = input.bool(defval = true, title = "Show Signals", group = "Strategy") showStopLosses = input.bool(defval = true, title = "Show Stop Losses", group = "Strategy") // // Show Signals based on their types ... showLongSignals = input.bool(defval = true, title = "Show Long Signals", group = "Signals") showShortSignals = input.bool(defval = true, title = "Show Short Signals", group = "Signals") // // Show Stop Losses based on their types ... swingLoopback = input.int(defval = 7, title = "Swing Loopback Period", group = "Stop Loss") showLongStopLosses = input.bool(defval = true, title = "Show Long Stop Losses", group = "Stop Loss") showShortStopLosses = input.bool(defval = true, title = "Show Short Stop Losses", group = "Stop Loss") // // END Inputs .... // // // START Functions .... // ////////////////////////////// // START Price Action Candles ////////////////////////////// // // Retrieve Specific Candle Height (based on low and high) ... getCandleRange() => high - low // // Retrieve Candle Ranges Thirs Section ... getCandleThird() => getCandleRange() / 3 // // Determines a Candle is Bullish or not ... isBullishCandle() => close > low + (getCandleThird() * 2) // // Determines a Candle is Bearish or not ... isNeutralCandle() => close < low + (getCandleThird() * 2) and close > low + getCandleThird() // // Determines a Candle is Neutral or not ... isBearishCandle() => close < low + getCandleThird() ///////////////////////////// // END Price Action Candles ///////////////////////////// ////////////////////// // START MPS HIS ////////////////////// // biggest(series) => max = 0.0 max := nz(max[1], series) if series > max max := series max ////////////////////// // END MPS HIS ////////////////////// // // END Functions .... // // // START Calculations .... // // var shortColor = color.red var longColor = color.lime ////////////////////////////// // START Price Action Candles ////////////////////////////// // var bullishColor = color.lime var bullishShape = shape.arrowup var bullishTitle = "Bullish" var bullishType = 1 // var bearishColor = color.red var bearishShape = shape.arrowdown var bearishTitle = "Bearish" var bearishType = -1 // var neutralColor = color.gray var neutralShape = shape.circle var neutralTitle = "Neutral" var neutralType = 0 // candleType = isBullishCandle() ? bullishType : isNeutralCandle() ? neutralType : isBearishCandle() ? bearishType : neutralType // prevCandleType = not na(candleType[1]) ? candleType[1] : neutralType // candleNeighborhoodBaseType = prevCandleType + candleType ///////////////////////////// // END Price Action Candles ///////////////////////////// ////////////////////// // START VBM Buy Sell ////////////////////// // VBMBSFactor = 4 VBMBSPd = 7 // VBMBSUp = hl2 - (VBMBSFactor * ta.atr(VBMBSPd)) VBMBSDown = hl2 + (VBMBSFactor * ta.atr(VBMBSPd)) // // Trend Up ... float VBMBSTrendUp = na VBMBSTrendUp := close[1] > VBMBSTrendUp[1] ? math.max(VBMBSUp, VBMBSTrendUp[1]) : VBMBSUp // // Trend Down ... float VBMBSTrendDown = na VBMBSTrendDown := close[1] < VBMBSTrendDown[1] ? math.min(VBMBSDown, VBMBSTrendDown[1]) : VBMBSDown // float VBMBSTrend = na VBMBSTrend := close > VBMBSTrendDown[1] ? 1 : close < VBMBSTrendUp[1] ? -1 : nz(VBMBSTrend[1], 1) // VBMBSMACD = VBMBSTrend == 1 ? VBMBSTrendUp : VBMBSTrendDown // VBMBSLinecolor = VBMBSTrend == 1 ? bullishColor : bearishColor // VBMBSUpArrow = ta.cross(close, VBMBSMACD) and close > VBMBSMACD VBMBSDownArrow = ta.cross(VBMBSMACD, close) and close < VBMBSMACD // VBMBSLongSignal = VBMBSTrend == 1 and VBMBSTrend[1] == -1 ? VBMBSTrend : na VBMBSHasLongSignal = not na (VBMBSLongSignal) // VBMBSShortSignal = VBMBSTrend == -1 and VBMBSTrend[1] == 1 ? VBMBSTrend : na VBMBSHasShortSignal = not na (VBMBSShortSignal) // VBMBSHasSignal = VBMBSHasLongSignal or VBMBSHasShortSignal ////////////////////// // END VBM Buy Sell ////////////////////// ////////////////////// // START MPS HIS ////////////////////// // MPSScale = 75.0 // // Momentum ... MPSLengthM = 17 MPSSrcM = close // MPSLength = 17 MPSSrc = close // // Momentum ... MPSSz = ta.linreg(MPSSrcM - math.avg(math.avg(ta.highest(high, MPSLengthM), ta.lowest(low, MPSLengthM)), ta.sma(close, MPSLengthM)), MPSLengthM, 0) MPSNi = biggest(MPSSz) // // Momentum Conditions ... MPSSc1 = MPSSz >= 0 MPSSc2 = MPSSz < 0 MPSSc3 = MPSSz >= MPSSz[1] MPSSc4 = MPSSz < MPSSz[1] // // Momentum Identifiers ... isMPSMomentumBullish = (MPSSc1 and MPSSc3) or (MPSSc1 and MPSSc4) isMPSMomentumBearish = (MPSSc2 and MPSSc4) or (MPSSc2 and MPSSc3) ////////////////////// // END MPS HIS ////////////////////// //////////////////////////// // START Last Market Price //////////////////////////// // lastMarketLowest = ta.lowest(low, swingLoopback) lastMarketLowest2 = ta.lowest(low, swingLoopback * 2) lastMarketLowest3 = ta.lowest(low, swingLoopback * 3) // lastMarketHighest = ta.highest(high, swingLoopback) lastMarketHighest2 = ta.highest(high, swingLoopback * 2) lastMarketHighest3 = ta.highest(high, swingLoopback * 3) //////////////////////////// // END Last Market Price //////////////////////////// /////////////////////// // START Strategy ... /////////////////////// // canShowStopLoss = showSignals and showStopLosses and (showLongSignals or showShortSignals) and (showLongStopLosses or showShortStopLosses) canShowLongStopLoss = canShowStopLoss and showLongStopLosses // and not na(ATRSLLongStopLoss) canShowShortStopLoss = canShowStopLoss and showShortStopLosses // and not na(ATRSLShortStopLoss) // hasSignal = VBMBSHasSignal // hasLongSignal = hasSignal and isBullishCandle() and VBMBSHasLongSignal and isMPSMomentumBullish longSignal = hasLongSignal ? VBMBSLongSignal : na float longStopLoss = lastMarketLowest // hasShortSignal = hasSignal and isBearishCandle() and VBMBSHasShortSignal and isMPSMomentumBearish shortSignal = hasShortSignal ? VBMBSShortSignal : na float shortStopLoss = lastMarketHighest // canShowSignal = showSignals and (showLongSignals or showShortSignals) canShowLongSignal = canShowSignal and showLongSignals and hasLongSignal canShowShortSignal = canShowSignal and showShortSignals and hasShortSignal /////////////////////// // END Strategy ... /////////////////////// // // END Calculations .... // // // START Plots .... // // // Signals ... plotshape(canShowLongSignal ? longSignal : na, title = "Long Signal", color = longColor, location = location.belowbar, style = shape.triangleup, size = size.normal) plotshape(canShowShortSignal ? shortSignal : na, title = "Short Signal", color = shortColor, location = location.abovebar, style = shape.triangledown, size = size.normal) // // Stop Losses ... plot(series = canShowLongStopLoss ? longStopLoss : na, color = color.fuchsia, linewidth = 1, style = plot.style_stepline, title = "Long Stop Loss") plot(series = canShowShortStopLoss ? shortStopLoss : na, color = color.aqua, linewidth = 1, style = plot.style_stepline, title = "Short Stop Loss") // // END Plots .... // // // START Alerts ... // alertcondition(hasSignal, "XST_SHULL5M > Signal") alertcondition(hasLongSignal, "XST_SHULL5M > Long Signal") alertcondition(hasShortSignal, "XST_SHULL5M > Short Signal") // // END Alerts ... // ////////////////////////////////////////////////////// // TODOS: // ------- // - [] //////////////////////////////////////////////////////