本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © slhtgh
//@version=4
study(title="SALEH All in One Strategy", shorttitle="slhtgh", overlay = true)
trend = input(title="Display EMA 200", type=input.bool, defval=true)
trendma = ema(close, 200)
labeled = input(title="Display strategy name with signals", type=input.bool, defval=true)
indicators = input(title="Display indicators", type=input.bool, defval=false)
plot(trend ? trendma : na, title = "200 EA", color=color.black, linewidth = 3)
// MACD
macdenabler = input(title="Enable MACD ? 🎯", type=input.bool, defval=true)
fast_length = input(title="Fast Length", type=input.integer, defval=12)
slow_length = input(title="Slow Length", type=input.integer, defval=26)
srcmacd = input(title="Source", type=input.source, defval=close)
signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)
sma_signal = input(title="Simple MA(Signal Line)", type=input.bool, defval=true)
// Calculation
fast_ma = ema(srcmacd, fast_length)
slow_ma = ema(srcmacd, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)
hist = macd - signal
//Strategy
buymacd = crossover (macd, signal) and close > trendma and macd < 0
sellmacd = crossunder (macd, signal) and close < trendma and macd > 0
plotshape(labeled and macdenabler ? buymacd :na, style = shape.triangleup, size = size.small, location = location.belowbar, color = color.red, title = "MACD Buy L", text = "MACD")
plotshape(labeled and macdenabler ? sellmacd :na, style = shape.triangledown, size = size.small, location = location.abovebar, color = color.red, title = "MACD Sell L", text = "MACD")
plotshape(labeled or not macdenabler ? na : buymacd, style = shape.triangleup, size = size.small, location = location.belowbar, color = color.red, title = "MACD Buy")
plotshape(labeled or not macdenabler ? na : sellmacd, style = shape.triangledown, size = size.small, location = location.abovebar, color = color.red, title = "MACD Sell")
alertcondition(buymacd or sellmacd, title = "MACD Strategy", message = "MACD signal was generated on {{ticker}} at {{timenow}}")
//Donchian Channels
donenabler = input(title="Enable Donchian Channels ? 🎯", type=input.bool, defval=true)
lendon = 20 //input(20, minval=1)
lowerdon = lowest(lendon)
upperdon = highest(lendon)
basisdon = avg(upperdon, lowerdon)
//Tady by to chtělo ošetřit případ, kdy ani jedno ještě nenastalo.
gorilla = barssince (lowerdon[1] > lowerdon)
stegosaurus = barssince (upperdon[1] < upperdon)
buydon = low > trendma and gorilla[1] <= stegosaurus[1] and high > upperdon[1]
selldon = high < trendma and gorilla[1] >= stegosaurus[1] and low < lowerdon[1]
plotshape(labeled and donenabler ? buydon :na, style = shape.triangleup, size = size.small, location = location.belowbar, color = color.blue, title = "Donchian Buy L", text = "Donchian")
plotshape(labeled and donenabler ? selldon :na, style = shape.triangledown, size = size.small, location = location.abovebar, color = color.blue, title = "Donchian Sell L", text = "Donchian")
plotshape(labeled or not donenabler ? na : buydon, style = shape.triangleup, size = size.small, location = location.belowbar, color = color.blue, title = "Donchian Buy")
plotshape(labeled or not donenabler ? na : selldon, style = shape.triangledown, size = size.small, location = location.abovebar, color = color.blue, title = "Donchian Sell")
donalertshard = (upperdon-lowerdon) *0.07
donalertshardlong = high > (upperdon[1] - donalertshard)
donalertshardshort = low < (lowerdon[1] + donalertshard)
donalert = (low > trendma and gorilla[1] <= stegosaurus[1] and donalertshardlong) or (high < trendma and gorilla[1] >= stegosaurus[1] and donalertshardshort)
alertcondition(donalert, title = "Donchian Strategy", message = "Donchian signal was generated on {{ticker}} at {{timenow}}")
//plot Donchian
plot(indicators and donenabler ? basisdon : na, "Basis Donchian", color=color.blue, linewidth = 1)
udon = plot(indicators and donenabler ? upperdon : na, "Upper Donchian", color=color.blue, linewidth = 2)
ldon = plot(indicators and donenabler ? lowerdon : na, "Lower Donchian", color=color.blue, linewidth = 2)
fill(udon, ldon, color=color.blue, transp=94, title="Background Donchian")
//Ichimoku strategy
ichimokuenabler = input(title="Enable Ichimoku Cloud ? 🎯", type=input.bool, defval=false)
conversionPeriods = 9//input(9, minval=1, title="Conversion Line Periods")
basePeriods = 26//input(26, minval=1, title="Base Line Periods")
laggingSpan2Periods = 52//input(52, minval=1, title="Lagging Span 2 Periods")
displacement = 26//input(26, minval=1, title="Displacement")
donchian(len) => avg(lowest(len), highest(len))
conversionLine = donchian(conversionPeriods)
baseLine = donchian(basePeriods)
leadLine1 = avg(conversionLine, baseLine)
leadLine2 = donchian(laggingSpan2Periods)
buyichi = low > trendma and low > leadLine1[displacement] and low > leadLine2[displacement] and crossover(conversionLine,baseLine)
sellichi = high < trendma and high < leadLine1[displacement] and high < leadLine2[displacement] and crossunder(conversionLine,baseLine)
//
plotshape(labeled and ichimokuenabler ? buyichi :na, style = shape.triangleup, size = size.small, location = location.belowbar, color = #00FF93, title = "Ichimoku Buy L", text = "Ichimoku")
plotshape(labeled and ichimokuenabler ? sellichi :na, style = shape.triangledown, size = size.small, location = location.abovebar, color = #00FF93, title = "Ichimoku Sell L", text = "Ichimoku")
plotshape(labeled or not ichimokuenabler ? na : buyichi, style = shape.triangleup, size = size.small, location = location.belowbar, color = #00FF93, title = "Ichimoku Buy")
plotshape(labeled or not ichimokuenabler ? na : sellichi, style = shape.triangledown, size = size.small, location = location.abovebar, color = #00FF93, title = "Ichimoku Sell")
//Ichimoku plotting
plot(ichimokuenabler and indicators ? conversionLine : na, color=#0496ff, title="Conversion Line")
plot(ichimokuenabler and indicators ? baseLine : na, color=#991515, title="Base Line")
plot(ichimokuenabler and indicators ? close : na, offset = -displacement + 1, color=#459915, title="Lagging Span")
p1 = plot(ichimokuenabler and indicators ? leadLine1 : na, offset = displacement - 1, color=color.green, title="Lead 1")
p2 = plot(ichimokuenabler and indicators ? leadLine2 : na, offset = displacement - 1, color=color.red, title="Lead 2")
fill(p1, p2, color = leadLine1 > leadLine2 ? color.green : color.red)
alertcondition(buyichi or sellichi, title = "Ichimoku Strategy", message = "Ichimoku signal was generated on {{ticker}} at {{timenow}}")
//
//
//
//
//
//All Enabled Alerts
alertcondition((ichimokuenabler and (buyichi or sellichi)) or (donenabler and donalert) or (macdenabler and (buymacd or sellmacd)), title = "Enabled Strategies", message = "SALEH signal was generated on {{ticker}} at {{timenow}}")
// adx inputs
adxlen = input(14, title="ADX Smoothing")
dilen = input(14, title="DI Length")
dirmov(len) =>
up = change(high)
down = -change(low)
plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
truerange = rma(tr, len)
plus = fixnan(100 * rma(plusDM, len) / truerange)
minus = fixnan(100 * rma(minusDM, len) / truerange)
[plus, minus]
adx(dilen, adxlen) =>
[plus, minus] = dirmov(dilen)
sum = plus + minus
adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
sig = adx(dilen, adxlen)
// Check adx
macd_crossup=macd < 0 and crossover(macd, signal)
macd_crossdown=macd > 0 and crossunder(macd, signal)
bullish = sig > 25 and macd_crossup
bearish = sig > 25 and macd_crossdown
alertcondition(bullish, title='Bullish MACD Crossover detected', message="Bullish trend detected")
alertcondition(bearish, title='Bearish MACD Crossover detected', message='Bearish trend detected')
plotshape(bullish, title="buy", text="Buy", color=color.green, style=shape.labelup, location=location.belowbar, size=size.small, textcolor=color.white, transp=0) //plot for buy icon
plotshape(bearish, title="sell", text="Sell", color=color.red, style=shape.labeldown, location=location.abovebar, size=size.small, textcolor=color.white, transp=0) //plot for sell icon