背景
pine多币种策略警报
代码
pine脚本记录
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| //@version=6 strategy("Multi-Symbol Strategy", overlay=false)
// Input parameters for multiple tickers i_T1 = input.symbol("BTCUSD", title="Ticker 1") i_T2 = input.symbol("ETHUSD", title="Ticker 2") i_T3 = input.symbol("XRPUSD", title="Ticker 3")
// Strategy function f_strategy(_close) => smaFast = ta.sma(_close, 50) smaSlow = ta.sma(_close, 200) goLong = ta.crossover(smaFast, smaSlow) goShort = ta.crossunder(smaFast, smaSlow) // goLong := true signal = goLong ? 1 : goShort ? -1 : 0 [signal, smaFast, smaSlow]
// Screener function f_screener(_ticker) => message = "" [signal, _tickerClose] = request.security(_ticker, timeframe.period, f_strategy(close)) if signal == 1 message := "Buy " + _ticker + " @" + str.tostring(_tickerClose) else if signal == -1 message := "Sell " + _ticker + " @" + str.tostring(_tickerClose) if signal == 1 or signal == -1 alert(message, alert.freq_once_per_bar_close) signal
// Calculate signals for each ticker t1_signal = f_screener(i_T1) t2_signal = f_screener(i_T2) t3_signal = f_screener(i_T3) // Plot signals plot(t1_signal, title="T1 Signal", color=color.new(color.green, 80), linewidth=2) plot(t2_signal, title="T2 Signal", color=color.new(color.blue, 80), linewidth=2) plot(t3_signal, title="T3 Signal", color=color.new(color.red, 80), linewidth=2)
|
当取消注释goLong := true,那么每个币种都是买入信号。
设置图1分钟,每1分钟结束都可以同时收到3个币种的买入警报。
