首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Automated Buy on Trading视图

Automated Buy on Trading视图
EN

Stack Overflow用户
提问于 2021-03-02 11:37:51
回答 1查看 108关注 0票数 0

我在TradingView上使用了Matt De Long的MOMO策略,我想让交易自动化。我已将我的Gemini帐户链接到我的tradingview帐户。

基于MOMO代码,如何根据收到的警报自动执行购买或出售操作?

(退出多头/进入空头=卖出)(退出空头/进入多头=买入)

我必须为每个时间段创建新的代码吗?在这种情况下,我只想使用1小时图表。

我已经复制了下面的MOMO代码:

代码语言:javascript
复制
//@version=4
//author = https://www.tradingview.com/u/MattDeLong/

study("Trend Following MOMO", overlay=true)
//lh3On = input(title="Buy/Long Signal", type=input.bool, defval=true)
//hl3On = input(title="Sell/Short Signal", type=input.bool, defval=true)
lh3On = true
hl3On = true
emaOn = input(title="105ema / 30min", type=input.bool, defval=true)
assistantOn = input(title="Assistant", type=input.bool, defval=true)
textOn = input(title="Text", type=input.bool, defval=true)

threeHigherLows() =>
    low[0] >= low[1] and low[1] >= low[2]

threeLowerHighs() =>
    high[2] >= high[1] and high[1] >= high[0]

breakHigher() =>
    padding = timeframe.isintraday ? .02 : .1
    high >= high[1] + padding

breakLower() =>
    padding = timeframe.isintraday ? .02 : .1
    low <= low[1] - padding

lh3 = threeLowerHighs() and lh3On
lh3bh = lh3[1] and breakHigher() and lh3On

hl3 = threeHigherLows() and hl3On
hl3bl = hl3[1] and breakLower() and hl3On

ema8 = ema(close, 8)
ema21 = ema(close, 21)

isUptrend = ema8 >= ema21
isDowntrend = ema8 <= ema21
trendChanging = cross(ema8,ema21)

buySignal = lh3bh and lh3[2] and lh3[3] and isUptrend and timeframe.isintraday
sellSignal = hl3bl and hl3[2] and hl3[3] and isDowntrend and timeframe.isintraday

goingDown = hl3 and isDowntrend and timeframe.isintraday
goingUp = lh3 and isUptrend and timeframe.isintraday

//plotshape(goingDown and goingDown[1], style=shape.triangledown, location=location.abovebar, color=color.red, size=size.tiny)
//plotshape(goingUp and goingUp[1], style=shape.triangleup, location=location.belowbar, color=color.green, size=size.tiny)

plotshape(lh3, style=shape.circle, location=location.abovebar, color=color.red, size=size.auto)
plotshape(hl3, style=shape.circle, location=location.belowbar, color=color.green, size=size.auto)
plotshape(trendChanging and isUptrend and assistantOn, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, text='Exit Short\nEnter Long')
plotshape(trendChanging and isDowntrend and assistantOn, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, text='Exit Long\nEnter Short')
plotchar(trendChanging and isUptrend and close<open and assistantOn, char='!', location=location.abovebar, color=color.green, size=size.small)
//plotchar(trendChanging and isDowntrend and open<close and assistantOn, char='!', location=location.abovebar, color=color.red, size=size.small)


//RLT 105ema / 30-min chart
ema105 = security(syminfo.tickerid, '30', ema(close, 105))
ema205 = security(syminfo.tickerid, '30', ema(close, 20))
plot(emaOn ? ema105 : na, linewidth=4, color=color.purple, editable=true)
plot(emaOn ? ema205 : na, linewidth=2, color=color.purple, editable=true)

aa = plot(ema8, linewidth=3, color=color.green, editable=true)
bb = plot(ema21,linewidth=3, color=color.red, editable=true)
fill(aa, bb, color=isUptrend ? color.green : color.red)
buyZone =  isUptrend and lh3 and high < ema21 and timeframe.isintraday
sellZone = isDowntrend and hl3 and low > ema21 and timeframe.isintraday


// === ALERT === 

alertcondition(trendChanging, title="Trend Reversing", message="Trend Changing")
alertcondition(buyZone, title="Bullish Trend Following", message="BUY Zone, Perfect")
alertcondition(sellZone, title="Bearish Trend Following", message="SELL Zone, Perfect")
alertcondition(buySignal, title="Long Alert", message="Long")
alertcondition(sellSignal, title="Short Alert", message="Short")
EN

回答 1

Stack Overflow用户

发布于 2021-03-02 22:35:40

如果您希望它在1小时内运行,请使用以下代码并将其部署到图表上,时间框架为1小时

我已将security(syminfo.tickerid, "30", ....)更改为security(syminfo.tickerid, "60",...

我正在为上面的代码做同样的事情。希望能有所帮助。如果不起作用,请随时寻求帮助

代码语言:javascript
复制
//@version=4
//author = https://www.tradingview.com/u/MattDeLong/

study("Trend Following MOMO", overlay=true)
//lh3On = input(title="Buy/Long Signal", type=input.bool, defval=true)
//hl3On = input(title="Sell/Short Signal", type=input.bool, defval=true)
lh3On = true
hl3On = true
emaOn = input(title="105ema / 60 min", type=input.bool, defval=true)   //Change made here, this doesn't have impact on code, just the input screen
assistantOn = input(title="Assistant", type=input.bool, defval=true)
textOn = input(title="Text", type=input.bool, defval=true)

threeHigherLows() =>
    low[0] >= low[1] and low[1] >= low[2]

threeLowerHighs() =>
    high[2] >= high[1] and high[1] >= high[0]

breakHigher() =>
    padding = timeframe.isintraday ? .02 : .1
    high >= high[1] + padding

breakLower() =>
    padding = timeframe.isintraday ? .02 : .1
    low <= low[1] - padding

lh3 = threeLowerHighs() and lh3On
lh3bh = lh3[1] and breakHigher() and lh3On

hl3 = threeHigherLows() and hl3On
hl3bl = hl3[1] and breakLower() and hl3On

ema8 = ema(close, 8)
ema21 = ema(close, 21)

isUptrend = ema8 >= ema21
isDowntrend = ema8 <= ema21
trendChanging = cross(ema8,ema21)

buySignal = lh3bh and lh3[2] and lh3[3] and isUptrend and timeframe.isintraday
sellSignal = hl3bl and hl3[2] and hl3[3] and isDowntrend and timeframe.isintraday

goingDown = hl3 and isDowntrend and timeframe.isintraday
goingUp = lh3 and isUptrend and timeframe.isintraday

//plotshape(goingDown and goingDown[1], style=shape.triangledown, location=location.abovebar, color=color.red, size=size.tiny)
//plotshape(goingUp and goingUp[1], style=shape.triangleup, location=location.belowbar, color=color.green, size=size.tiny)

plotshape(lh3, style=shape.circle, location=location.abovebar, color=color.red, size=size.auto)
plotshape(hl3, style=shape.circle, location=location.belowbar, color=color.green, size=size.auto)
plotshape(trendChanging and isUptrend and assistantOn, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, text='Exit Short\nEnter Long')
plotshape(trendChanging and isDowntrend and assistantOn, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, text='Exit Long\nEnter Short')
plotchar(trendChanging and isUptrend and close<open and assistantOn, char='!', location=location.abovebar, color=color.green, size=size.small)
//plotchar(trendChanging and isDowntrend and open<close and assistantOn, char='!', location=location.abovebar, color=color.red, size=size.small)


//RLT 105ema / 30-min chart
ema105 = security(syminfo.tickerid, '60', ema(close, 105))       //Change made here
ema205 = security(syminfo.tickerid, '60', ema(close, 20))        //Change made here
plot(emaOn ? ema105 : na, linewidth=4, color=color.purple, editable=true)
plot(emaOn ? ema205 : na, linewidth=2, color=color.purple, editable=true)

aa = plot(ema8, linewidth=3, color=color.green, editable=true)
bb = plot(ema21,linewidth=3, color=color.red, editable=true)
fill(aa, bb, color=isUptrend ? color.green : color.red)
buyZone =  isUptrend and lh3 and high < ema21 and timeframe.isintraday
sellZone = isDowntrend and hl3 and low > ema21 and timeframe.isintraday


// === ALERT === 

alertcondition(trendChanging, title="Trend Reversing", message="Trend Changing")
alertcondition(buyZone, title="Bullish Trend Following", message="BUY Zone, Perfect")
alertcondition(sellZone, title="Bearish Trend Following", message="SELL Zone, Perfect")
alertcondition(buySignal, title="Long Alert", message="Long")
alertcondition(sellSignal, title="Short Alert", message="Short")
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66432969

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档