{"id":2344,"date":"2026-11-19T11:27:25","date_gmt":"2026-11-19T17:27:25","guid":{"rendered":"https:\/\/www.patternsmart.com\/cn\/?p=2344"},"modified":"2026-11-19T17:28:32","modified_gmt":"2026-11-19T17:28:32","slug":"tradingview-%e5%94%90%e5%a5%87%e5%ae%89%e9%80%9a%e9%81%93%e7%aa%81%e7%a0%b4%e6%8c%87%e6%a0%87%ef%bc%9aatr-%e6%b3%a2%e5%b9%85%e8%bf%87%e6%bb%a4%e4%b8%8e%e5%ae%8c%e6%95%b4-pine-script-v6-%e6%ba%90-2","status":"publish","type":"post","link":"https:\/\/www.patternsmart.com\/cn\/tradingview-%e5%94%90%e5%a5%87%e5%ae%89%e9%80%9a%e9%81%93%e7%aa%81%e7%a0%b4%e6%8c%87%e6%a0%87%ef%bc%9aatr-%e6%b3%a2%e5%b9%85%e8%bf%87%e6%bb%a4%e4%b8%8e%e5%ae%8c%e6%95%b4-pine-script-v6-%e6%ba%90-2\/","title":{"rendered":"TradingView \u5510\u5947\u5b89\u901a\u9053\u7a81\u7834\u6307\u6807\uff1aATR \u6ce2\u5e45\u8fc7\u6ee4\u4e0e\u5b8c\u6574 Pine Script v6 \u6e90\u7801"},"content":{"rendered":"<div class=\"postie-post\">\n<div>\n<h1>TradingView \u5510\u5947\u5b89\u901a\u9053\u7a81\u7834\u6307\u6807\uff1aATR \u6ce2\u5e45\u8fc7\u6ee4\u4e0e\u5b8c\u6574 Pine Script v6 \u6e90\u7801<\/h1>\n<p>&#013; <\/p>\n<p>\u5510\u5947\u5b89\u901a\u9053\uff08Donchian Channel\uff09\u56de\u7b54\u7684\u662f\u4e00\u4e2a\u660e\u786e\u95ee\u9898\uff1a\u6b64\u524d N \u6839\u5df2\u5b8c\u6210 K \u7ebf\u7684\u6700\u9ad8\u4ef7\u4e0e\u6700\u4f4e\u4ef7\u5206\u522b\u662f\u591a\u5c11\uff1f\u672c\u6307\u6807\u4ec5\u5728\u6536\u76d8\u786e\u8ba4\u4ef7\u683c\u7a81\u7834\u5386\u53f2\u901a\u9053\u8fb9\u754c\u65f6\u53d1\u51fa\u4fe1\u53f7\uff0c\u5e76\u8981\u6c42\u7a81\u7834 K \u7ebf\u7684\u6ce2\u5e45\u76f8\u5bf9\u4e8e ATR \u8db3\u591f\u5927\u3002\u5b83\u9002\u5408\u7814\u7a76\u548c\u9884\u8b66\uff0c\u5e76\u975e\u81ea\u52a8\u4ea4\u6613\u7cfb\u7edf\u3002<\/p>\n<p>&#013; <\/p>\n<h2>\u4e3a\u4ec0\u4e48\u5fc5\u987b\u4f7f\u7528\u524d\u4e00\u6839 K \u7ebf\u7684\u901a\u9053\uff1f<\/h2>\n<p>\u4e0a\u8fb9\u754c H(t)=max(high[t-1],&#8230;,high[t-N])\uff0c\u4e0b\u8fb9\u754c L(t)=min(low[t-1],&#8230;,low[t-N])\u3002\u5982\u679c\u8ba1\u7b97\u6700\u9ad8\u4ef7\u65f6\u5305\u542b\u5f53\u524d K \u7ebf\uff0c\u5c31\u4e0d\u53ef\u80fd\u6b63\u5e38\u51fa\u73b0\u6536\u76d8\u4ef7\u9ad8\u4e8e\u5305\u542b\u81ea\u8eab\u6700\u9ad8\u4ef7\u7684\u901a\u9053\u4e0a\u8f68\u3002\u56e0\u6b64\u4ee3\u7801\u4e2d <code>[1]<\/code> \u7684\u504f\u79fb\u4e0d\u53ef\u7701\u7565\u3002<\/p>\n<p>&#013; <\/p>\n<h2>\u4fe1\u53f7\u6761\u4ef6\u4e0e\u8ba1\u7b97\u65b9\u6cd5<\/h2>\n<p>ATR(14) \u662f\u5e73\u5747\u771f\u5b9e\u6ce2\u5e45\u3002\u771f\u5b9e\u6ce2\u5e45 TR=max(\u6700\u9ad8\u4ef7-\u6700\u4f4e\u4ef7\u3001|\u6700\u9ad8\u4ef7-\u524d\u6536\u76d8\u4ef7|\u3001|\u6700\u4f4e\u4ef7-\u524d\u6536\u76d8\u4ef7|)\uff0c\u518d\u4f7f\u7528 Wilder RMA \u5e73\u6ed1\u3002\u8fc7\u6ee4\u6761\u4ef6\u4e3a <code>high-low &gt;= 0.75 * ATR(14)<\/code>\u3002\u505a\u591a\u65b9\u5411\u7684\u63d0\u793a\u8981\u6c42\u5f53\u524d K \u7ebf\u5df2\u7ecf\u6536\u76d8\u3001\u6536\u76d8\u4ef7\u9ad8\u4e8e\u524d 20 \u6839 K \u7ebf\u7684\u6700\u9ad8\u4ef7\uff0c\u5e76\u4e14\u4e0a\u4e00\u6839\u5df2\u5b8c\u6210 K \u7ebf\u6ca1\u6709\u6536\u5728\u5176\u81ea\u8eab\u5386\u53f2\u901a\u9053\u4e0a\u65b9\uff1b\u5411\u4e0b\u7a81\u7834\u5219\u5b8c\u5168\u5bf9\u79f0\u3002\u8fd9\u79cd\u72b6\u6001\u5207\u6362\u5224\u65ad\u51cf\u5c11\u8fde\u7eed\u91cd\u590d\u6807\u8bb0\uff0c\u4f46\u4e0d\u4fdd\u8bc1\u6bcf\u6bb5\u8d8b\u52bf\u53ea\u6709\u4e00\u4e2a\u4fe1\u53f7\u3002<\/p>\n<p>&#013; <\/p>\n<h2>\u5047\u8bbe\u6570\u503c\u793a\u4f8b<\/h2>\n<p>\u5047\u8bbe\u524d 20 \u6839 K \u7ebf\u6700\u9ad8\u4ef7\u4e3a 102.40\uff0cATR \u4e3a 1.20\uff0c\u521a\u6536\u76d8 K \u7ebf\u7684\u6700\u9ad8\u4ef7 103.10\u3001\u6700\u4f4e\u4ef7 101.90\u3001\u6536\u76d8\u4ef7 102.75\u3002\u8be5 K \u7ebf\u6ce2\u5e45 1.20\uff0c\u5927\u4e8e\u6700\u4f4e\u95e8\u69db 0.90\uff080.75\u00d71.20\uff09\uff0c\u4e14\u6536\u76d8\u4ef7\u9ad8\u4e8e 102.40\u3002\u5982\u679c\u4e0a\u4e00\u6839 K \u7ebf\u7684\u6536\u76d8\u4ef7\u4e0d\u9ad8\u4e8e\u5b83\u5f53\u65f6\u7684\u5386\u53f2\u4e0a\u8f68\uff0c\u5219\u51fa\u73b0\u5411\u4e0a\u7a81\u7834\u6807\u8bb0\u3002\u4e0a\u8ff0\u6570\u636e\u4ec5\u7528\u4e8e\u6559\u5b66\uff0c\u5e76\u975e\u771f\u5b9e\u884c\u60c5\u3002<\/p>\n<figure><img decoding=\"async\" src=\"https:\/\/www.patternsmart.com\/cn\/wp-content\/uploads\/2026\/11\/6aff31bf5e319.png\" alt=\"Illustrative completed-bar breakout chart with prior Donchian high\" style=\"width:100%;max-width:980px;height:auto\"><figcaption>\u56fe\uff1a\u7a81\u7834\u8fb9\u754c\u4e0e K \u7ebf\u7684\u6559\u5b66\u793a\u610f\uff0c\u975e\u771f\u5b9e\u5386\u53f2\u884c\u60c5\u3002<\/figcaption><\/figure>\n<h2>\u5b8c\u6574 Pine Script v6 \u6e90\u7801<\/h2>\n<p>\u5c06\u4ee5\u4e0b\u5b8c\u6574\u6307\u6807\u590d\u5236\u5230 TradingView \u7684 Pine Editor \u4e2d\uff1a<\/p>\n<pre style=\"background:#f1f5f8;padding:18px;white-space:pre;font-family:Consolas,Monaco,monospace;line-height:1.65\"><code><a href=\"mailto:\/\/@version=6\">\/\/@version=6<\/a><br>indicator(\"Confirmed Donchian ATR Breakout\", overlay = true, max_labels_count = 500)<br><br>\/\/ User inputs: all price comparisons use completed candles only.<br>length = <a href=\"http:\/\/input.int\">input.int<\/a>(20, \"Donchian lookback\", minval = 2)<br>atrLength = <a href=\"http:\/\/input.int\">input.int<\/a>(14, \"ATR length\", minval = 1)<br>minRangeAtr = input.float(0.75, \"Minimum candle range \/ ATR\", minval = 0.0, step = 0.05)<br>showChannel = input.bool(true, \"Show prior channel\")<br><br>\/\/ [1] excludes the active candle: no self-referencing breakout threshold.<br>priorHigh = ta.highest(high, length)[1]<br>priorLow = ta.lowest(low, length)[1]<br>atr = ta.atr(atrLength)<br>ready = not na(priorHigh) and not na(priorLow) and not na(atr) and atr &gt; 0<br>rangePass = ready and (high - low) &gt;= minRangeAtr * atr<br>longSignal = barstate.isconfirmed and rangePass and close &gt; priorHigh and close[1] &lt;= priorHigh[1]<br>shortSignal = barstate.isconfirmed and rangePass and close &lt; priorLow and close[1] &gt;= priorLow[1]<br><br>plot(showChannel ? priorHigh : na, \"Prior high\", color = color.orange, linewidth = 2)<br>plot(showChannel ? priorLow : na, \"Prior low\", color = color.aqua, linewidth = 2)<br>plotshape(longSignal, title = \"Confirmed upside breakout\", style = shape.triangleup, location = location.belowbar, color = color.lime, size = size.small, text = \"UP\")<br>plotshape(shortSignal, title = \"Confirmed downside breakout\", style = shape.triangledown, location = location.abovebar, color = color.red, size = size.small, text = \"DN\")<br>alertcondition(longSignal, \"Confirmed upside breakout\", \"Confirmed Donchian upside breakout on {{ticker}} {{interval}}\")<br>alertcondition(shortSignal, \"Confirmed downside breakout\", \"Confirmed Donchian downside breakout on {{ticker}} {{interval}}\")<\/code><\/pre>\n<h2>\u5b89\u88c5\u548c\u9a8c\u8bc1\u6b65\u9aa4<\/h2>\n<ol>\n<li>\u6253\u5f00\u56fe\u8868\u4e0e Pine Editor\uff0c\u7c98\u8d34\u4ee3\u7801\uff0c\u4fdd\u5b58\u5e76\u6dfb\u52a0\u5230\u56fe\u8868\u3002<\/li>\n<li>\u521d\u59cb\u53c2\u6570\u5efa\u8bae\u4e3a\u901a\u9053 20\u3001ATR 14\u3001\u6700\u4f4e\u6ce2\u5e45\u6bd4\u7387 0.75\u3002<\/li>\n<li>\u9010\u4e00\u68c0\u67e5\u4fe1\u53f7 K \u7ebf\u7684\u6536\u76d8\u4ef7\u3001\u6b64\u524d 20 \u6839 K \u7ebf\u7684\u9ad8\u4f4e\u70b9\u53ca ATR\u3002<\/li>\n<li>\u5728\u521b\u5efa\u63d0\u9192\u65f6\u9009\u62e9\u5bf9\u5e94\u7684 alertcondition\uff0c\u5e76\u4f7f\u7528 Once Per Bar Close\u3002<\/li>\n<li>\u5728\u4e0d\u540c\u54c1\u79cd\u4e0e\u5468\u671f\u4e0a\u9a8c\u8bc1\u8df3\u7a7a\u3001\u4ea4\u6613\u65f6\u6bb5\u5207\u6362\u3001\u6d41\u52a8\u6027\u4e0d\u8db3\u53ca\u590d\u6743\u7b49\u60c5\u5f62\u3002<\/li>\n<\/ol>\n<p>&#013; <\/p>\n<h2>\u91cd\u7ed8\u3001\u6210\u4ea4\u4e0e\u5b9e\u9645\u9650\u5236<\/h2>\n<p><code>barstate.isconfirmed<\/code> \u53ef\u907f\u514d\u56fe\u8868 K \u7ebf\u5c1a\u672a\u6536\u76d8\u65f6\u63d0\u524d\u63d0\u793a\uff1b\u4f46\u5b9e\u65f6\u63d0\u9192\u4ecd\u53d7\u6570\u636e\u6e90\u53ca\u63d0\u9192\u8bbe\u7f6e\u5f71\u54cd\u3002\u4ee3\u7801\u6ca1\u6709\u4f7f\u7528 <code>request.security()<\/code>\uff0c\u56e0\u6b64\u4e0d\u5b58\u5728\u8de8\u5468\u671f\u6570\u636e\u63d0\u524d\u5f15\u7528\u95ee\u9898\u3002\u7a81\u7834\u540e\u4ecd\u53ef\u80fd\u7acb\u5373\u56de\u843d\uff1bATR \u8861\u91cf\u6ce2\u52a8\uff0c\u4e0d\u8861\u91cf\u65b9\u5411\u7684\u53ef\u9760\u6027\u3002\u6ce2\u5e45\u8fc7\u6ee4\u53ef\u80fd\u6392\u9664\u6709\u6548\u7684\u4f4e\u6ce2\u52a8\u7a81\u7834\uff0c\u4e5f\u53ef\u80fd\u63a5\u53d7\u6d88\u606f\u9a71\u52a8\u7684\u5f02\u5e38\u5c16\u5cf0\u3002\u56fe\u8868\u6536\u76d8\u4ef7\u4fe1\u53f7\u4e0d\u4ee3\u8868\u5b9e\u9645\u80fd\u4ee5\u8be5\u4ef7\u683c\u6210\u4ea4\uff0c\u70b9\u5dee\u3001\u6ed1\u70b9\u3001\u624b\u7eed\u8d39\u53ca\u6d41\u52a8\u6027\u5747\u4f1a\u5f71\u54cd\u7ed3\u679c\u3002<\/p>\n<p>&#013; <\/p>\n<h2>\u8fdb\u4e00\u6b65\u6539\u8fdb\u65b9\u5411<\/h2>\n<p>\u53ef\u4ee5\u7814\u7a76\u591a\u7a7a\u4e0d\u540c\u95e8\u69db\u3001\u6210\u4ea4\u91cf\u8fc7\u6ee4\u3001\u8d8b\u52bf\u73af\u5883\u8fc7\u6ee4\u6216\u7a81\u7834\u540e\u56de\u8e29\u786e\u8ba4\u3002\u4e0d\u8981\u53ea\u5728\u5355\u4e00\u6837\u672c\u4e0a\u4f18\u5316\u53c2\u6570\uff0c\u5e94\u4fdd\u7559\u6837\u672c\u5916\u6570\u636e\u5e76\u7edf\u8ba1\u5047\u7a81\u7834\u6bd4\u4f8b\u3002\u5982\u9700\u5c06\u6307\u6807\u6269\u5c55\u4e3a\u5b9a\u5236\u626b\u63cf\u6216\u63d0\u9192\u5de5\u5177\uff0c\u53ef\u53c2\u8003<a href=\"https:\/\/www.patternsmart.com\/cn\/custom\/\">\u4ea4\u6613\u8f6f\u4ef6\u5b9a\u5236\u5f00\u53d1\u670d\u52a1<\/a>\u3002<\/p>\n<p><strong>\u98ce\u9669\u63d0\u793a\uff1a<\/strong>\u672c\u6587\u4ec5\u7528\u4e8e\u6280\u672f\u5b66\u4e60\uff0c\u4e0d\u6784\u6210\u6295\u8d44\u5efa\u8bae\uff0c\u4e5f\u4e0d\u4fdd\u8bc1\u6536\u76ca\u3002\u5b9e\u9645\u4f7f\u7528\u524d\u5e94\u7ed3\u5408\u4ea4\u6613\u6210\u672c\u56de\u6d4b\u5e76\u72ec\u7acb\u9a8c\u8bc1\u4ee3\u7801\u884c\u4e3a\u3002<\/p>\n<\/p><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>TradingView \u5510\u5947\u5b89\u901a\u9053\u7a81\u7834\u6307\u6807\uff1aATR \u6ce2\u5e45\u8fc7\u6ee4\u4e0e\u5b8c\u6574 Pine Script v6 \u6e90\u7801 &#038;#0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2345,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_seo_schema_type":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"fifu_image_url":"","fifu_image_alt":"","_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[142,233,217],"tags":[102,433,434,432],"class_list":["post-2344","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tradingview","category-233","category-217","tag-atr","tag-donchian-channel","tag-pine-script","tag-tradingview"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/www.patternsmart.com\/cn\/wp-content\/uploads\/2026\/11\/6aff31bf5e319.png","_links":{"self":[{"href":"https:\/\/www.patternsmart.com\/cn\/wp-json\/wp\/v2\/posts\/2344","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.patternsmart.com\/cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.patternsmart.com\/cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.patternsmart.com\/cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.patternsmart.com\/cn\/wp-json\/wp\/v2\/comments?post=2344"}],"version-history":[{"count":0,"href":"https:\/\/www.patternsmart.com\/cn\/wp-json\/wp\/v2\/posts\/2344\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.patternsmart.com\/cn\/wp-json\/wp\/v2\/media\/2345"}],"wp:attachment":[{"href":"https:\/\/www.patternsmart.com\/cn\/wp-json\/wp\/v2\/media?parent=2344"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.patternsmart.com\/cn\/wp-json\/wp\/v2\/categories?post=2344"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.patternsmart.com\/cn\/wp-json\/wp\/v2\/tags?post=2344"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}