html
<!DOCTYPE html>
<html>
<head>
<title>Add SMA20 to TradingView Chart</title>
</head>
<body>
<div id="tv_chart_container" style="height: 500px; width: 1000px"></div>
<script type="text/javascript" src="https://s3.tradingview.com/tv.js"></script>
<script type="text/javascript">
new TradingView.widget({
"container_id": "tv_chart_container",
"autosize": true,
"symbol": "NASDAQ:AAPL",
"interval": "D",
"timezone": "Etc/UTC",
"theme": "light",
"style": "1",
"locale": "zh_CN", // 或其它语言代码,如 "en"
"toolbar_bg": "#f1f3f6",
"enable_publishing": false,
"allow_symbol_change": true,
"studies": [
"MASimple@tv-basicstudies", // 这里将直接添加SMA20
],
"show_popup_button": true,
"popup_width": "1000",
"popup_height": "650"
});
// 如果你需要在图表创建后动态添加SMA20,你可以使用以下代码
// 注意:以下代码中的widget应替换为你创建图表实例的变量名
widget.onChartReady(function() {
widget.chart().createStudy('Moving Average', false, false, [20], null, {"plot.color": "#FF0000"});
});
</script>
</body>
</html>