简体   繁体   English

交易视图上的自动交易买入

[英]Automated Trading Buy on Trading View

I'm using the MOMO strategy on TradingView by Matt De Long and I'm wanting to automate trades.我正在使用 Matt De Long 在 TradingView 上的 MOMO 策略,并且我想要自动化交易。 I have my Gemini account linked to my tradingview account.我的 Gemini 账户与我的 tradingview 账户相关联。

Based on the MOMO Code, how do I automate a Buy or Sell based on the Alerts I receive?根据 MOMO 代码,我如何根据收到的警报自动进行买入或卖出?

(Exit Long / Enter Short = Sell) (Exit Short / Enter Long = Buy) (退出多头/进入空头=卖出)(退出空头/进入多头=买入)

Will I have to create new code for each time Frame?我必须为每个时间框架创建新代码吗? In this case I want to only use the 1 hour charts.在这种情况下,我只想使用 1 小时图表。

I've copied the MOMO Code Below:我复制了下面的 MOMO 代码:

//@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")

if you want this to run on 1 hour use the code below and deploy it on chart with timeframe of 1 hour如果您希望它在 1 小时内运行,请使用下面的代码并将其部署在图表上,时间范围为 1 小时

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

I am doing the same for the code above.我对上面的代码做同样的事情。 Hope it helps.希望能帮助到你。 Feel free to ask for help if it doesn't work如果不起作用,请随时寻求帮助

//@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")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM