OPEN-SOURCE SCRIPT

EMA Crossover Strategy

//version=5
strategy("EMA Crossover Strategy", overlay=true)

// Define the length of EMAs
ema50Length = 50
ema200Length = 200

// Calculate the EMAs
ema50 = ta.ema(close, ema50Length)
ema200 = ta.ema(close, ema200Length)

// Plot the EMAs on the chart
plot(ema50, title="50 EMA", color=color.green, linewidth=2)
plot(ema200, title="200 EMA", color=color.red, linewidth=2)

// Define the crossover condition
longCondition = ta.crossover(ema50, ema200)
shortCondition = ta.crossunder(ema50, ema200)

// Generate alerts
alertcondition(longCondition, title="Buy Signal", message="50 EMA is above 200 EMA - Buy")
alertcondition(shortCondition, title="Sell Signal", message="50 EMA is below 200 EMA - Sell")

// Execute trades based on the conditions
if (longCondition)
strategy.entry("Buy", strategy.long)

if (shortCondition)
strategy.close("Buy")
Bands and ChannelsCandlestick analysisChart patterns

开源脚本

本着真正的TradingView精神,此脚本的作者已将其开源,以便交易者可以理解和验证它。向作者致敬!您可以免费使用它,但在出版物中重复使用此代码受网站规则约束。 您可以收藏它以在图表上使用。

想在图表上使用此脚本?

免责声明