我已将策略配置到Tradingview中,但是现在我想将此策略转换为警报。 我已经进行了一些测试,但是我的警报条件并不完全像测试策略那样适用,例如,“购买”条件会重复多次,一次就足够了,现在必须等待“卖出”条件。
我尝试了一些代码也无法正常工作。.恐怕我对Pinescript不好:/
这里的策略:
Here the full code :
`
//@version=3
study(title="Sweat Dreams", overlay=true)
//strategy(title="Test", shorttitle="Teststrat", overlay=true, precision=6, pyramiding=0, initial_capital=200, currency="USD", default_qty_type=strategy.percent_of_equity, default_qty_value=99.0, commission_value=0.05)
ksrc = input(defval="open", title="Kagi Source")
krev = input(defval=0.001, title="Kagi Reversal Size")
ktf = input(defval="20", title="Kagi Timeframe")
l = input(10,'lines wma')
lsourse = input(close,'lines sourse')
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Definitions
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Kagi
lines = wma(lsourse,l)
psrc = lines
kagisrc = kagi(tickerid, ksrc, krev)
kagi = security(kagisrc, ktf, close)
x = psrc > kagi ? true : false
y = psrc < kagi ? true : false
//Kagi Color
// kagicolor = (psrc > kagi) ? lime : (psrc < kagi) ? red : na
kagicolor = x ? lime : y ? red : na
// k1 = (psrc > kagi) ? blue : white
// k2 = (psrc < kagi) ? red : k1
// kcol = k1 ? k1 : k2
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Plots
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
buy = x and not x[1] ? psrc : na
sell = y and not y[1] ? psrc : na
//Kagi Price Fill
//fill(kagiplot, priceplot, color=kagicolor, transp=80, title="Kagi Fill")
fromMonth = input(defval = 8, title = "From Month", minval = 1)
fromDay = input(defval = 23, title = "From Day", minval = 1)
fromYear = input(defval = 2019, title = "From Year", minval = 2014)
toMonth = input(defval = 1, title = "To Month", minval = 1)
toDay = input(defval = 1, title = "To Day", minval = 1)
toYear = input(defval = 9999, title = "To Year", minval = 2014)
//strategy.entry("Buy", true, when=(buy and (time > timestamp(fromYear, fromMonth, fromDay, 00, 00)) and (time < timestamp(toYear, toMonth, toDay, 23, 59))))
//strategy.close("Buy", when=(sell and (time < timestamp(toYear, toMonth, toDay, 23, 59))))
// === ALERTS ===
buyalert = (buy and (time > timestamp(fromYear, fromMonth, fromDay, 00, 00)) and (time < timestamp(toYear, toMonth, toDay, 23, 59)))
sellalert = (sell and (time < timestamp(toYear, toMonth, toDay, 23, 59)))
plot(buyalert, "buy", color=green)
plot(sellalert, "sell", color=red)
//plotshape( buy, color=lime, style=shape.arrowdown, text=".", size=size.small )
//plotshape( sell, color=blue, style=shape.arrowdown, text=":", size=size.small)
//alertcondition( Buy, 'Buy', 'e=binance a=acc b=buy t=limit p=0.02% q=99.5% s=neousdt' )
//alertcondition( sell, 'Sell', 'e=binance a=acc b=sell t=limit p=-0.02% q=99.5% s=neousdt' )`
这里的警报:
plotshape( buy, color=lime, style=shape.arrowdown, text=".", size=size.small )
plotshape( sell, color=blue, style=shape.arrowdown, text=":", size=size.small)
alertcondition( Buy, 'Buy', 'e=binance a=acc b=buy t=limit p=0.02% q=99.5% s=neousdt' )
alertcondition( sell, 'Sell', 'e=binance a=acc b=sell t=limit p=-0.02% q=99.5% s=neousdt' )
我希望警报条件在“买入”时发生一次,在“卖出”中发生一次,并且触发的方式与策略模拟完全相同:$