Pinescript - 将警报添加到策略中以进行自动交易

问题描述 投票:0回答:0

这是我基于具有波动率和趋势过滤器的布林带的跟随趋势策略:

//@version=5
strategy("Breakout Strategy v2",overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, commission_type=strategy.commission.percent, commission_value=0.06, slippage = 2, default_qty_value=100)
 
// Define the length of the Bollinger Bands
bbLength = input.int (15,title="BBLength")
bbDev = input.float (2.0,title="BBDev")
 
// Calculate the Bollinger Bands
[middle, upper, lower] = ta.bb (close, bbLength, bbDev)
 
// Trend and filter options
trendfilterperiod=input(130,title="Trend Filter MA Period")
trendfiltertype=input.string (title="Trend Filter MA Type", defval="EMA",options=["EMA","SMA"])
 
volatilityfilter=input.bool(true,title="Volatility Filter")
volatilitystdevlength=input(20,title="Vol Filter STDev Length")
volatilitystdevmalength=input(30,title="Vol Filter STDev MA Length")
 
// Plot the Bollinger Bands and EMA/SMA
plot(upper, color = color.red, linewidth = 2)
plot(lower, color = color.blue, linewidth = 2)
plot (ta.ema(close,trendfilterperiod))
plot (ta.sma(close,trendfilterperiod),color=color.yellow)
 
start = timestamp(input(2018, "start year"), input(1, "start month"), input(1, "start day"), 00, 00)
end = timestamp(input(2050, "end year"), input(1, "end month"), input(1, "end day"), 00, 00)
 
// Trend and filter conditions
TrendConditionL=if trendfiltertype =="EMA"
    close>ta.ema(close,trendfilterperiod)
else
    close>ta.sma(close,trendfilterperiod)
 
TrendConditionS=if trendfiltertype =="EMA"
    close<ta.ema(close,trendfilterperiod)
else
    close<ta.sma(close,trendfilterperiod)
 
VolatilityCondition=if volatilityfilter
    ta.stdev(close,volatilitystdevlength)>ta.sma(ta.stdev(close,volatilitystdevlength),volatilitystdevmalength)
else 
    true
 
// Buy if price crosses below upper Bollinger Band
ConditionEntryL = ta.crossover(close, upper) and TrendConditionL and VolatilityCondition and time > start and time < end
ConditionEntryS = ta.crossunder(close, lower) and TrendConditionS and VolatilityCondition and time > start and time < end
 
// Sell if price crosses above lower Bollinger Band
ConditionExitL = ta.crossunder(close, lower)
ConditionExitS = ta.crossover(close, upper)
 
// Define the state variables
var bool open_long = false
var bool open_short = false
 
// Open Long position
OpenLong = ConditionEntryL and not open_long
if OpenLong
    strategy.entry("Long", strategy.long)
    open_long := true
 
// Close Long position
CloseLong = ConditionExitL and open_long
if CloseLong
    strategy.close("Long")
    open_long := false
 
// Open Short position
OpenShort = ConditionEntryS and not open_short
if OpenShort
    strategy.entry("Short", strategy.short)
    open_short := true
 
// Close Short position
CloseShort = ConditionExitS and open_short
if CloseShort
    strategy.close("Short")
    open_short := false

我想在 Trading View 上添加提醒,向 Wundertrading 发送命令,以便在 Bybit 上自动开仓和平仓。

现在我单独使用一个指标,但我想将所有指标合二为一。有几个人告诉我,现在可以通过策略发出警报,但我做不到。 有人能帮我吗? 谢谢。

bots trading
© www.soinside.com 2019 - 2024. All rights reserved.