Multi-Symbol Golden Cross Alert

Autoview_official · study · 320 行 · 点赞 188 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Autoview_ext
// Your mind is your edge. When you believe that money comes easily and frequently, it does. Say it loud!
 
//@version=5
indicator("Multi-Symbol Golden Cross Alert", overlay=true, shorttitle="MS GC Alert")
 
// Input for short-term and long-term moving averages
shortTermMA = input.int(50, title="Short-term Moving Average", minval=1)
longTermMA = input.int(200, title="Long-term Moving Average", minval=1)
ma1 = ta.sma(close, shortTermMA)
ma2 = ta.sma(close, longTermMA)
plot(ma1, color=color.orange)
plot(ma2, color=color.white)
 
// Function to securely and simply call `security()` so that it never repaints and never looks ahead.
f_secureSecurity(_symbol, _res, _src) => request.security(_symbol, _res, _src[1], lookahead = barmerge.lookahead_on)
 
 
resolution = input.timeframe('D', "Resolution")
// Calculate the moving averages and detect golden crosses for each symbol
calcGoldenCross(symbol) =>
    closePrice = f_secureSecurity(symbol, resolution, close)
    shortMA = ta.sma(closePrice, shortTermMA)
    longMA = ta.sma(closePrice, longTermMA)
    gc_cross = ta.crossover(shortMA, longMA)
    [shortMA, longMA, gc_cross]
 
calcDeathCross(symbol) =>
    closePrice = f_secureSecurity(symbol, resolution, close)
    shortMA = ta.sma(closePrice, shortTermMA)
    longMA = ta.sma(closePrice, longTermMA)
    d_cross = ta.crossunder(shortMA, longMA)
    [shortMA, longMA, d_cross]
 
exchange = input.string("BINANCE", title="Exchange")
symbol1 = input.string("APEBUSD", title="Symbol")
symbol2 = input.string("BTCBUSD", title="Symbol")
symbol3 = input.string("ETHBUSD", title="Symbol")
symbol4 = input.string("BNBBUSD", title="Symbol")
symbol5 = input.string("BCHBUSD", title="Symbol")
symbol6 = input.string("XRPBUSD", title="Symbol")
symbol7 = input.string("EOSBUSD", title="Symbol")
symbol8 = input.string("LTCBUSD", title="Symbol")
symbol9 = input.string("TRXBUSD", title="Symbol")
symbol10 = input.string("ETCBUSD", title="Symbol")
symbol11 = input.string("LINKBUSD", title="Symbol")
symbol12 = input.string("ADABUSD", title="Symbol")
symbol13 = input.string("XMRBUSD", title="Symbol")
symbol14 = input.string("DASHBUSD", title="Symbol")
symbol15 = input.string("ZECBUSD", title="Symbol")
symbol16 = input.string("XTZBUSD", title="Symbol")
 
// Declare the moving averages and golden crosses for each symbol
[APE_shortMA, APE_longMA, APE_gc_cross] = calcGoldenCross(exchange + ":" + symbol1)
[BTC_shortMA, BTC_longMA, BTC_gc_cross] = calcGoldenCross(exchange + ":" + symbol2)
[ETH_shortMA, ETH_longMA, ETH_gc_cross] = calcGoldenCross(exchange + ":" + symbol3)
[BNB_shortMA, BNB_longMA, BNB_gc_cross] = calcGoldenCross(exchange + ":" + symbol4)
[BCH_shortMA, BCH_longMA, BCH_gc_cross] = calcGoldenCross(exchange + ":" + symbol5)
[XRP_shortMA, XRP_longMA, XRP_gc_cross] = calcGoldenCross(exchange + ":" + symbol6)
[EOS_shortMA, EOS_longMA, EOS_gc_cross] = calcGoldenCross(exchange + ":" + symbol7)
[LTC_shortMA, LTC_longMA, LTC_gc_cross] = calcGoldenCross(exchange + ":" + symbol8)
[TRX_shortMA, TRX_longMA, TRX_gc_cross] = calcGoldenCross(exchange + ":" + symbol9)
[ETC_shortMA, ETC_longMA, ETC_gc_cross] = calcGoldenCross(exchange + ":" + symbol10)
[LINK_shortMA, LINK_longMA, LINK_gc_cross] = calcGoldenCross(exchange + ":" + symbol11)
[ADA_shortMA, ADA_longMA, ADA_gc_cross] = calcGoldenCross(exchange + ":" + symbol12)
[XMR_shortMA, XMR_longMA, XMR_gc_cross] = calcGoldenCross(exchange + ":" + symbol13)
[DASH_shortMA, DASH_longMA, DASH_gc_cross] = calcGoldenCross(exchange + ":" + symbol14)
[ZEC_shortMA, ZEC_longMA, ZEC_gc_cross] = calcGoldenCross(exchange + ":" + symbol15)
[XTZ_shortMA, XTZ_longMA, XTZ_gc_cross] = calcGoldenCross(exchange + ":" + symbol16)
 
// Declare the moving averages and golden crosses for each symbol
[APE_shortMAd, APE_longMAd, APE_d_cross] = calcDeathCross(exchange + ":" + symbol1)
[BTC_shortMAd, BTC_longMAd, BTC_d_cross] = calcDeathCross(exchange + ":" + symbol2)
[ETH_shortMAd, ETH_longMAd, ETH_d_cross] = calcDeathCross(exchange + ":" + symbol3)
[BNB_shortMAd, BNB_longMAd, BNB_d_cross] = calcDeathCross(exchange + ":" + symbol4)
[BCH_shortMAd, BCH_longMAd, BCH_d_cross] = calcDeathCross(exchange + ":" + symbol5)
[XRP_shortMAd, XRP_longMAd, XRP_d_cross] = calcDeathCross(exchange + ":" + symbol6)
[EOS_shortMAd, EOS_longMAd, EOS_d_cross] = calcDeathCross(exchange + ":" + symbol7)
[LTC_shortMAd, LTC_longMAd, LTC_d_cross] = calcDeathCross(exchange + ":" + symbol8)
[TRX_shortMAd, TRX_longMAd, TRX_d_cross] = calcDeathCross(exchange + ":" + symbol9)
[ETC_shortMAd, ETC_longMAd, ETC_d_cross] = calcDeathCross(exchange + ":" + symbol10)
[LINK_shortMAd, LINK_longMAd, LINK_d_cross] = calcDeathCross(exchange + ":" + symbol11)
[ADA_shortMAd, ADA_longMAd, ADA_d_cross] = calcDeathCross(exchange + ":" + symbol12)
[XMR_shortMAd, XMR_longMAd, XMR_d_cross] = calcDeathCross(exchange + ":" + symbol13)
[DASH_shortMAd, DASH_longMAd, DASH_d_cross] = calcDeathCross(exchange + ":" + symbol14)
[ZEC_shortMAd, ZEC_longMAd, ZEC_d_cross] = calcDeathCross(exchange + ":" + symbol15)
[XTZ_shortMAd, XTZ_longMAd, XTZ_d_cross] = calcDeathCross(exchange + ":" + symbol16)
 
useAutoview = input.bool(true, "Using Autoview to place the trades live on the exchange?")
qty = input.float(50.50, "Amount to buy with")
 
// Alert if a golden cross occurs for each symbol
if APE_gc_cross
    if useAutoview
        alert("e=" + exchange + " s=" + symbol1 + "b=buy q=" + str.tostring(qty) + " u=currency t=market", alert.freq_once_per_bar)
    else
        alert("APE Golden Cross", alert.freq_once_per_bar)
    label.new(x=bar_index, y=high, text="APE Golden Cross", color=color.green, textcolor=color.white, style=label.style_label_down)
 
if BTC_gc_cross
    if useAutoview
        alert("e=" + exchange + " s=" + symbol2 + "b=buy q=" + str.tostring(qty) + " u=currency t=market", alert.freq_once_per_bar)
    else
        alert("BTC Golden Cross", alert.freq_once_per_bar)
    label.new(x=bar_index, y=high, text="BTC Golden Cross", color=color.green, textcolor=color.white, style=label.style_label_down)
 
if ETH_gc_cross
    if useAutoview
        alert("e=" + exchange + " s=" + symbol3 + "b=buy q=" + str.tostring(qty) + " u=currency t=market", alert.freq_once_per_bar)
    else
        alert("ETH Golden Cross", alert.freq_once_per_bar)
    label.new(x=bar_index, y=high, text="ETH Golden Cross", color=color.green, textcolor=color.white, style=label.style_label_down)
 
if BNB_gc_cross
    if useAutoview
        alert("e=" + exchange + " s=" + symbol4 + "b=buy q=" + str.tostring(qty) + " u=currency t=market", alert.freq_once_per_bar)
    else
        alert("BNB Golden Cross", alert.freq_once_per_bar)
    label.new(x=bar_index, y=high, text="BNB Golden Cross", color=color.green, textcolor=color.white, style=label.style_label_down)
 
if BCH_gc_cross
    if useAutoview
        alert("e=" + exchange + " s=" + symbol5 + "b=buy q=" + str.tostring(qty) + " u=currency t=market", alert.freq_once_per_bar)
    else
        alert("BCH Golden Cross", alert.freq_once_per_bar)
    label.new(x=bar_index, y=high, text="BCH Golden Cross", color=color.green, textcolor=color.white, style=label.style_label_down)
 
if XRP_gc_cross
    if useAutoview
        alert("e=" + exchange + " s=" + symbol6 + "b=buy q=" + str.tostring(qty) + " u=currency t=market", alert.freq_once_per_bar)
    else
        alert("XRP Golden Cross", alert.freq_once_per_bar)
    label.new(x=bar_index, y=high, text="XRP Golden Cross", color=color.green, textcolor=color.white, style=label.style_label_down)
 
if EOS_gc_cross
    if useAutoview
        alert("e=" + exchange + " s=" + symbol7 + "b=buy q=" + str.tostring(qty) + " u=currency t=market", alert.freq_once_per_bar)
    else
        alert("EOS Golden Cross", alert.freq_once_per_bar)
    label.new(x=bar_index, y=high, text="EOS Golden Cross", color=color.green, textcolor=color.white, style=label.style_label_down)
 
if LTC_gc_cross
    if useAutoview
        alert("e=" + exchange + " s=" + symbol8 + "b=buy q=" + str.tostring(qty) + " u=currency t=market", alert.freq_once_per_bar)
    else
        alert("LTC Golden Cross", alert.freq_once_per_bar)
    label.new(x=bar_index, y=high, text="LTC Golden Cross", color=color.green, textcolor=color.white, style=label.style_label_down)
 
if TRX_gc_cross
    if useAutoview
        alert("e=" + exchange + " s=" + symbol9 + "b=buy q=" + str.tostring(qty) + " u=currency t=market", alert.freq_once_per_bar)
    else
        alert("TRX Golden Cross", alert.freq_once_per_bar)
    label.new(x=bar_index, y=high, text="TRX Golden Cross", color=color.green, textcolor=color.white, style=label.style_label_down)
 
if ETC_gc_cross
    if useAutoview
        alert("e=" + exchange + " s=" + symbol10 + "b=buy q=" + str.tostring(qty) + " u=currency t=market", alert.freq_once_per_bar)
    else
        alert("ETC Golden Cross", alert.freq_once_per_bar)
    label.new(x=bar_index, y=high, text="ETC Golden Cross", color=color.green, textcolor=color.white, style=label.style_label_down)
 
if LINK_gc_cross
    if useAutoview
        alert("e=" + exchange + " s=" + symbol11 + "b=buy q=" + str.tostring(qty) + " u=currency t=market", alert.freq_once_per_bar)
    else
        alert("LINK Golden Cross", alert.freq_once_per_bar)
    label.new(x=bar_index, y=high, text="LINK Golden Cross", color=color.green, textcolor=color.white, style=label.style_label_down)
 
if ADA_gc_cross
    if useAutoview
        alert("e=" + exchange + " s=" + symbol12 + "b=buy q=" + str.tostring(qty) + " u=currency t=market", alert.freq_once_per_bar)
    else
        alert("ADA Golden Cross", alert.freq_once_per_bar)
    label.new(x=bar_index, y=high, text="ADA Golden Cross", color=color.green, textcolor=color.white, style=label.style_label_down)
 
if XMR_gc_cross
    if useAutoview
        alert("e=" + exchange + " s=" + symbol13 + "b=buy q=" + str.tostring(qty) + " u=currency t=market", alert.freq_once_per_bar)
    else
        alert("XMR Golden Cross", alert.freq_once_per_bar)
    label.new(x=bar_index, y=high, text="XMR Golden Cross", color=color.green, textcolor=color.white, style=label.style_label_down)
 
if DASH_gc_cross
    if useAutoview
        alert("e=" + exchange + " s=" + symbol14 + "b=buy q=" + str.tostring(qty) + " u=currency t=market", alert.freq_once_per_bar)
    else
        alert("DASH Golden Cross", alert.freq_once_per_bar)
    label.new(x=bar_index, y=high, text="DASH Golden Cross", color=color.green, textcolor=color.white, style=label.style_label_down)
 
if ZEC_gc_cross
    if useAutoview
        alert("e=" + exchange + " s=" + symbol15 + "b=buy q=" + str.tostring(qty) + " u=currency t=market", alert.freq_once_per_bar)
    else
        alert("ZEC Golden Cross", alert.freq_once_per_bar)
    label.new(x=bar_index, y=high, text="ZEC Golden Cross", color=color.green, textcolor=color.white, style=label.style_label_down)
 
if XTZ_gc_cross
    if useAutoview
        alert("e=" + exchange + " s=" + symbol6 + "b=buy q=" + str.tostring(qty) + " u=currency t=market", alert.freq_once_per_bar)
    else
        alert("XTZ Golden Cross", alert.freq_once_per_bar)
    label.new(x=bar_index, y=high, text="XTZ Golden Cross", color=color.green, textcolor=color.white, style=label.style_label_down)
 
if APE_d_cross
    if useAutoview
        alert("e=" + exchange + " s=" + symbol1 + "b=sell t=market", alert.freq_once_per_bar)
    else
        alert("APE Death Cross", alert.freq_once_per_bar)
    label.new(x=bar_index, y=low, text="APE Death Cross", color=color.red, textcolor=color.white, style=label.style_label_up)
 
if BTC_d_cross
    if useAutoview
        alert("e=" + exchange + " s=" + symbol2 + "b=sell t=market", alert.freq_once_per_bar)
    else
        alert("BTC Death Cross", alert.freq_once_per_bar)
    label.new(x=bar_index, y=low, text="BTC Death Cross", color=color.red, textcolor=color.white, style=label.style_label_up)
 
if ETH_d_cross
    if useAutoview
        alert("e=" + exchange + " s=" + symbol3 + "b=sell t=market", alert.freq_once_per_bar)
    else
        alert("ETH Death Cross", alert.freq_once_per_bar)
    label.new(x=bar_index, y=low, text="ETH Death Cross", color=color.red, textcolor=color.white, style=label.style_label_up)
 
if BNB_d_cross
    if useAutoview
        alert("e=" + exchange + " s=" + symbol4 + "b=sell t=market", alert.freq_once_per_bar)
    else
        alert("BNB Death Cross", alert.freq_once_per_bar)
    label.new(x=bar_index, y=low, text="BNB Death Cross", color=color.red, textcolor=color.white, style=label.style_label_up)
 
if BCH_d_cross
    if useAutoview
        alert("e=" + exchange + " s=" + symbol5 + "b=sell t=market", alert.freq_once_per_bar)
    else
        alert("BCH Death Cross", alert.freq_once_per_bar)
    label.new(x=bar_index, y=low, text="BCH Death Cross", color=color.red, textcolor=color.white, style=label.style_label_up)
 
if XRP_d_cross
    if useAutoview
        alert("e=" + exchange + " s=" + symbol6 + "b=sell t=market", alert.freq_once_per_bar)
    else
        alert("XRP Death Cross", alert.freq_once_per_bar)
    label.new(x=bar_index, y=low, text="XRP Death Cross", color=color.red, textcolor=color.white, style=label.style_label_up)
 
if EOS_d_cross
    if useAutoview
        alert("e=" + exchange + " s=" + symbol7 + "b=sell t=market", alert.freq_once_per_bar)
    else
        alert("EOS Death Cross", alert.freq_once_per_bar)
    label.new(x=bar_index, y=low, text="EOS Death Cross", color=color.red, textcolor=color.white, style=label.style_label_up)
 
if LTC_d_cross
    if useAutoview
        alert("e=" + exchange + " s=" + symbol8 + "b=sell t=market", alert.freq_once_per_bar)
    else
        alert("LTC Death Cross", alert.freq_once_per_bar)
    label.new(x=bar_index, y=low, text="LTC Death Cross", color=color.red, textcolor=color.white, style=label.style_label_up)
 
if TRX_d_cross
    if useAutoview
        alert("e=" + exchange + " s=" + symbol9 + "b=sell t=market", alert.freq_once_per_bar)
    else
        alert("TRX Death Cross", alert.freq_once_per_bar)
    label.new(x=bar_index, y=low, text="TRX Death Cross", color=color.red, textcolor=color.white, style=label.style_label_up)
 
if ETC_d_cross
    if useAutoview
        alert("e=" + exchange + " s=" + symbol10 + "b=sell t=market", alert.freq_once_per_bar)
    else
        alert("ETC Death Cross", alert.freq_once_per_bar)
    label.new(x=bar_index, y=low, text="ETC Death Cross", color=color.red, textcolor=color.white, style=label.style_label_up)
 
if LINK_d_cross
    if useAutoview
        alert("e=" + exchange + " s=" + symbol11 + "b=sell t=market", alert.freq_once_per_bar)
    else
        alert("LINK Death Cross", alert.freq_once_per_bar)
    label.new(x=bar_index, y=low, text="LINK Death Cross", color=color.red, textcolor=color.white, style=label.style_label_up)
 
if ADA_d_cross
    if useAutoview
        alert("e=" + exchange + " s=" + symbol12 + "b=sell t=market", alert.freq_once_per_bar)
    else
        alert("ADA Death Cross", alert.freq_once_per_bar)
    label.new(x=bar_index, y=low, text="ADA Death Cross", color=color.red, textcolor=color.white, style=label.style_label_up)
 
if XMR_d_cross
    if useAutoview
        alert("e=" + exchange + " s=" + symbol13 + "b=sell t=market", alert.freq_once_per_bar)
    else
        alert("XMR Death Cross", alert.freq_once_per_bar)
    label.new(x=bar_index, y=low, text="XMR Death Cross", color=color.red, textcolor=color.white, style=label.style_label_up)
 
if DASH_d_cross
    if useAutoview
        alert("e=" + exchange + " s=" + symbol14 + "b=sell t=market", alert.freq_once_per_bar)
    else
        alert("DASH Death Cross", alert.freq_once_per_bar)
    label.new(x=bar_index, y=low, text="DASH Death Cross", color=color.red, textcolor=color.white, style=label.style_label_up)
 
if ZEC_d_cross
    if useAutoview
        alert("e=" + exchange + " s=" + symbol15 + "b=sell t=market", alert.freq_once_per_bar)
    else
        alert("ZEC Death Cross", alert.freq_once_per_bar)
    label.new(x=bar_index, y=low, text="ZEC Death Cross", color=color.red, textcolor=color.white, style=label.style_label_up)
 
if XTZ_d_cross
    if useAutoview
        alert("e=" + exchange + " s=" + symbol16 + "b=sell t=market", alert.freq_once_per_bar)
    else
        alert("XTZ Death Cross", alert.freq_once_per_bar)
    label.new(x=bar_index, y=low, text="XTZ Death Cross", color=color.red, textcolor=color.white, style=label.style_label_up)
// Plot the moving averages and golden crosses for each symbol
// plot(APE_shortMA, title="APE Short-term MA", color=color.blue, linewidth=1)
// plot(APE_longMA, title="APE Long-term MA", color=color.red, linewidth=1)
// plotshape(APE_gc_cross, title="APE Golden Cross", style=shape.labeldown, location=location.abovebar,

← 返回列表