9-20 EMA Crossover with TP and SL

jrd2212 · study · 25 行 · 点赞 303 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=5
indicator("9-20 EMA Crossover with TP and SL", overlay=true)
 
// Define the Exponential Moving Averages
ema9 = ta.ema(close, 9)
ema20 = ta.ema(close, 20)
 
// Plot the Exponential Moving Averages on the chart
plot(ema9, color=color.blue, linewidth=2, title="EMA 9")
plot(ema20, color=color.orange, linewidth=2, title="EMA 20")
 
// Detect crossover and crossunder
longCondition = ta.crossover(ema9, ema20)
shortCondition = ta.crossunder(ema9, ema20)
 
// Define take profit (3% ROI) and stop loss (-1% ROI) prices
takeProfitLong = close * 1.03
stopLossLong = close * 0.99
takeProfitShort = close * 0.97
stopLossShort = close * 1.01
 
 
// Send alerts when a condition is met
alertcondition(longCondition, title="Buy Signal", message="Buy order: 9 EMA crossed above 20 EMA")
alertcondition(shortCondition, title="Sell Signal", message="Sell order: 9 EMA crossed below 20 EMA")

← 返回列表