{"id":2837,"date":"2026-11-28T18:00:37","date_gmt":"2026-11-29T00:00:37","guid":{"rendered":"https:\/\/www.patternsmart.com\/cn\/?p=2837"},"modified":"2026-11-29T00:07:32","modified_gmt":"2026-11-29T00:07:32","slug":"pine-script%e7%ad%96%e7%95%a5%e5%a6%82%e4%bd%95%e6%8c%89%e5%9b%ba%e5%ae%9a%e7%8e%b0%e9%87%91%e9%a3%8e%e9%99%a9%e9%a2%84%e7%ae%97%e8%ae%a1%e7%ae%97%e5%85%a5%e5%9c%ba%e6%95%b0%e9%87%8f","status":"publish","type":"post","link":"https:\/\/www.patternsmart.com\/cn\/pine-script%e7%ad%96%e7%95%a5%e5%a6%82%e4%bd%95%e6%8c%89%e5%9b%ba%e5%ae%9a%e7%8e%b0%e9%87%91%e9%a3%8e%e9%99%a9%e9%a2%84%e7%ae%97%e8%ae%a1%e7%ae%97%e5%85%a5%e5%9c%ba%e6%95%b0%e9%87%8f\/","title":{"rendered":"Pine Script\u7b56\u7565\u5982\u4f55\u6309\u56fa\u5b9a\u73b0\u91d1\u98ce\u9669\u9884\u7b97\u8ba1\u7b97\u5165\u573a\u6570\u91cf"},"content":{"rendered":"<div class=\"postie-post\">\n<p>\u56fa\u5b9a\u5408\u7ea6\u6570\u91cf\u4f1a\u4f7f\u7b56\u7565\u5728\u6b62\u635f\u8ddd\u79bb\u53d8\u5316\u65f6\u627f\u62c5\u4e0d\u540c\u73b0\u91d1\u98ce\u9669\u3002\u5bf9\u4e8e\u70b9\u503c\u660e\u786e\u7684\u54c1\u79cd\uff0c\u56fa\u5b9a\u73b0\u91d1\u98ce\u9669\u9884\u7b97\u63d0\u4f9b\u53ef\u91cd\u590d\u7684\u4ed3\u4f4d\u8ba1\u7b97\u89c4\u5219\uff0c\u4f46\u4e0d\u80fd\u4fdd\u8bc1\u6700\u5927\u4e8f\u635f\u3002<\/p>\n<h2>\u671f\u8d27\u6570\u503c\u5b9e\u4f8b<\/h2>\n<p>\u5047\u8bbe\u6bcf\u70b9\u4ef7\u503c50\u7f8e\u5143\uff0c\u6700\u5c0f\u53d8\u52a80.25\uff0c\u98ce\u9669\u9884\u7b97200\u7f8e\u5143\u3002\u4e24\u70b9\u6b62\u635f\u7b49\u4e8e\u516b\u8df3\uff0c\u6bcf\u5f20\u98ce\u9669100\u7f8e\u5143\uff0c\u53ef\u4ea4\u6613\u4e24\u5f20\u3002\u56db\u70b9\u6b62\u635f\u7b49\u4e8e\u5341\u516d\u8df3\uff0c\u6bcf\u5f20\u98ce\u9669200\u7f8e\u5143\uff0c\u53ef\u4ea4\u6613\u4e00\u5f20\u3002\u4e94\u70b9\u6b62\u635f\u65f6\u4e00\u5f20\u4e5f\u8d85\u9884\u7b97\uff0c\u56e0\u6b64\u8df3\u8fc7\u5165\u573a\u3002<\/p>\n<figure><img decoding=\"async\" src=\"https:\/\/www.patternsmart.com\/cn\/wp-content\/uploads\/2026\/11\/PS_TV_Risk_CN.png\" alt=\"PS_TV_Risk_CN.png\" width=\"800\" height=\"360\" style=\"max-width:100%;height:auto\"><figcaption>200\u7f8e\u5143\u9884\u7b97\u4e0b\uff0c\u4e24\u70b9\u6b62\u635f\u53ef\u4ea4\u6613\u4e24\u5f20\uff0c\u56db\u70b9\u6b62\u635f\u53ef\u4ea4\u6613\u4e00\u5f20\u3002<\/figcaption><\/figure>\n<h2>Pine Script\u5b9e\u73b0<\/h2>\n<p>\u5148\u5c06\u6b62\u635f\u8ddd\u79bb\u5411\u4e0a\u53d6\u6574\u4e3a\u6574\u6570\u8df3\uff0c\u518d\u4e58\u4ee5syminfo.pointvalue\u8ba1\u7b97\u5355\u5f20\u98ce\u9669\uff0c\u6700\u540e\u5411\u4e0b\u53d6\u6574\u5408\u7ea6\u6570\u91cf\u3002\u793a\u4f8b\u5047\u5b9a\u54c1\u79cd\u76c8\u4e8f\u5e01\u79cd\u4e0e\u98ce\u9669\u9884\u7b97\u5e01\u79cd\u4e00\u81f4\uff0c\u54c1\u79cd\u91c7\u7528\u6574\u6570\u5408\u7ea6\u4e14\u70b9\u503c\u6709\u6548\u4e3a\u6b63\u3002\u5747\u7ebf\u4ea4\u53c9\u4ec5\u4f5c\u4e3a\u793a\u4f8b\u5165\u573a\u89e6\u53d1\u5668\u3002<\/p>\n<pre style=\"white-space:pre;font-family:Consolas,Monaco,monospace\"><code><a href=\"mailto:\/\/@version=6\">\/\/@version=6<\/a><br>strategy(&quot;Cash risk sizing example&quot;, overlay=true, pyramiding=0)<br>riskCash = input.float(200, &quot;Risk budget&quot;, minval=1)<br>stopPoints = input.float(2, &quot;Stop distance&quot;, minval=0.01)<br>ticks = math.max(1, math.ceil(stopPoints \/ syminfo.mintick))<br>distance = ticks * syminfo.mintick<br>riskPerContract = distance * syminfo.pointvalue<br>qty = math.floor(riskCash \/ riskPerContract)<br>signal = ta.crossover(close, ta.sma(close, 20))<br>if signal and strategy.position_size == 0 and qty &gt;= 1<br>\u00a0\u00a0\u00a0\u00a0strategy.entry(&quot;L&quot;, strategy.long, qty=qty)<br>\u00a0\u00a0\u00a0\u00a0strategy.exit(&quot;LX&quot;, &quot;L&quot;, loss=ticks)<\/code><\/pre>\n<p>strategy.exit\u7684loss\u53c2\u6570\u8868\u793a\u76f8\u5bf9\u4e8e\u5165\u573a\u4ef7\u7684\u8df3\u6570\uff0c\u9000\u51fa\u5173\u8054\u5165\u573aL\u3002\u9ed8\u8ba4\u7b56\u7565\u884c\u4e3a\u4e0b\uff0c\u5e02\u4ef7\u5165\u573a\u901a\u5e38\u5728\u4e0b\u4e00\u53ef\u7528\u4ef7\u683c\u66f4\u65b0\u6a21\u62df\u6210\u4ea4\uff0c\u5386\u53f2\u56de\u6d4b\u4e00\u822c\u5bf9\u5e94\u4e0b\u4e00\u6839\u5f00\u76d8\u3002TradingView\u7ecf\u7eaa\u5546\u6a21\u62df\u5668\u5e76\u975e\u5b9e\u76d8\u6267\u884c\u573a\u6240\u3002\u4fdd\u8bc1\u91d1\u3001\u6570\u91cf\u6b65\u957f\u3001\u5e01\u79cd\u6362\u7b97\u53ca\u7ecf\u7eaa\u5546\u9650\u5236\u9700\u72ec\u7acb\u9a8c\u8bc1\u3002<\/p>\n<h2>\u9884\u7b97\u6d4b\u8bd5<\/h2>\n<p>\u6d4b\u8bd5\u4e24\u70b9\u3001\u56db\u70b9\u3001\u4e94\u70b9\u8ddd\u79bb\u53ca\u4e0d\u7b26\u5408\u62a5\u4ef7\u5355\u4f4d\u7684\u8f93\u5165\uff0c\u4f8b\u59822.01\u57280.25\u8df3\u957f\u4e0b\u5411\u4e0a\u53d6\u6574\u4e3a2.25\u3002\u6bcf\u70b950\u7f8e\u5143\u65f6\u5355\u5f20\u98ce\u9669112.50\u7f8e\u5143\uff0c\u6570\u91cf\u4e3a\u4e00\u3002\u6bd4\u8f83\u6a21\u62df\u6b62\u635f\u4e0e\u8ba1\u5165\u8d39\u7528\u6ed1\u70b9\u540e\u7684\u5b9e\u9645\u4e8f\u635f\uff0c\u5305\u542b\u8df3\u7a7a\u7a7f\u8d8a\u6b62\u635f\u60c5\u5f62\uff0c\u5e76\u5728\u9002\u7528\u65f6\u4f7f\u7528Bar Magnifier\u3002\u6b62\u635f\u6210\u4ea4\u53ef\u80fd\u52a3\u4e8e\u89e6\u53d1\u4ef7\uff0c\u624b\u7eed\u8d39\u53ca\u6c47\u7387\u53d8\u5316\u4e5f\u53ef\u80fd\u4f7f\u4e8f\u635f\u8d85\u51fa\u540d\u4e49\u9884\u7b97\u3002\u672c\u6559\u5b66\u793a\u4f8b\u5e76\u975e\u5b8c\u6574\u4ea4\u6613\u7cfb\u7edf\u3002<\/p>\n<p>\u5b98\u65b9\u53c2\u8003\uff1a<a href=\"https:\/\/www.tradingview.com\/pine-script-docs\/concepts\/strategies\/\">\u5e73\u53f0\u6280\u672f\u6587\u6863<\/a>\u3002<\/p>\n<p>\u793a\u4f8b\u672a\u5b9e\u9645\u7f16\u8bd1\u6216\u56de\u6d4b\uff0c\u4ec5\u4f9b\u6559\u5b66\uff0c\u4ea4\u6613\u5b58\u5728\u4e8f\u635f\u98ce\u9669\u3002<\/p>\n<p>\u5982\u9700\u8fdb\u4e00\u6b65\u5b9a\u5236\u6b64\u7b56\u7565\u601d\u8def\uff0c\u8bf7\u8054\u7cfb\u6211\u4eec\u4e86\u89e3<a href=\"https:\/\/www.patternsmart.com\/cn\/custom\/\">TradingView\u4ea4\u6613\u7b56\u7565\u5b9a\u5236\u5f00\u53d1\u670d\u52a1<\/a>\u3002<\/p>\n<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u56fa\u5b9a\u5408\u7ea6\u6570\u91cf\u4f1a\u4f7f\u7b56\u7565\u5728\u6b62\u635f\u8ddd\u79bb\u53d8\u5316\u65f6\u627f\u62c5\u4e0d\u540c\u73b0\u91d1\u98ce\u9669\u3002\u5bf9\u4e8e\u70b9\u503c\u660e\u786e\u7684\u54c1\u79cd\uff0c\u56fa\u5b9a\u73b0\u91d1\u98ce\u9669\u9884\u7b97\u63d0\u4f9b\u53ef\u91cd\u590d\u7684\u4ed3\u4f4d\u8ba1\u7b97 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2838,"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,520,233],"tags":[434,141,340,442,342,639],"class_list":["post-2837","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tradingview","category-520","category-233","tag-pine-script","tag-tradingview","tag-340","tag-442","tag-342","tag-639"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/www.patternsmart.com\/cn\/wp-content\/uploads\/2026\/11\/PS_TV_Risk_CN.png","_links":{"self":[{"href":"https:\/\/www.patternsmart.com\/cn\/wp-json\/wp\/v2\/posts\/2837","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=2837"}],"version-history":[{"count":0,"href":"https:\/\/www.patternsmart.com\/cn\/wp-json\/wp\/v2\/posts\/2837\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.patternsmart.com\/cn\/wp-json\/wp\/v2\/media\/2838"}],"wp:attachment":[{"href":"https:\/\/www.patternsmart.com\/cn\/wp-json\/wp\/v2\/media?parent=2837"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.patternsmart.com\/cn\/wp-json\/wp\/v2\/categories?post=2837"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.patternsmart.com\/cn\/wp-json\/wp\/v2\/tags?post=2837"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}