GO Markets
让交易更进一步
智慧交易,从选择值得信赖的全球券商开始。低点差、快速成交、零入金手续费、功能强大的交易平台,以及屡获殊荣的客户支持,让您的交易更进一步。


全球交易者共同的选择
自 2006 年起,GO Markets 已帮助全球数十万交易者实现他们的投资目标。凭借严格监管、以客户为本的服务,以及屡获殊荣的教育资源,我们始终是交易者值得信赖的合作伙伴。


















































GO Markets
让交易更进一步
探索上千种交易机会,享受专业机构水准的交易工具、流畅稳定的交易体验,以及屡获殊荣的客户支持。开户流程简单快捷,让您轻松开启交易之旅。
.jpg)
One of the most impactful books I’ve ever read is “The 7 Habits of Highly Effective People: Powerful Lessons in Personal Change” by Stephen Covey.
When it was first published in 1989, it quickly became one of the most influential works in business and personal development literature, and retained its place on bestseller lists for the next couple of decades.
The compelling, comprehensive, and structured framework for personal growth presented in the book has undoubtedly inspired many to rethink how they organise their lives and priorities, both professionally and personally.
Although its lessons were originally designed for self-improvement and positive structured growth, the underlying principles are universal, making them easily transferable to many areas of life, including trading.
In this article, you will explore how each of Covey’s seven original habits can be reframed within a trading context, in an attempt to offer a structure that may help guide you to becoming the best trader you can be.

1. Be Proactive
Being proactive means recognising that we have the power to choose our responses and to shape outcomes through appropriate preparation with subsequent planned reactions.
In a Trading Context:
For traders, this means anticipating potential problems before they arise and putting measures in place to better mitigate risk.
Rather than waiting for issues to unfold, the proactive trader identifies potential areas of concern and ensures that they have access to the right tools, resources, and people to prepare effectively, whatever the market may throw at them.
What This Means for You:
Being proactive may involve seeking out quality education and services, maintaining access to accurate and timely market information, continually assessing risk and opportunity, and having systems to manage those risks within defined limits.
Consequences of Non-Action:
Inadequate preparation and a lack of defined systems often lead to poor trading decisions and less-than-desired outcomes.
Failing to assess risk properly can result in significant and often avoidable losses.
By contrast, a proactive approach builds resilience and confidence, ensuring that when challenges arise, your response is measured and less emotionally driven by what is happening on the screen in front of you.
2. Begin with the End in Mind
Covey's second habit is about defining purpose. It suggests that effective people are more likely to achieve what is possible if they start with a clear understanding of their destination, so every action aligns with that ultimate vision.
In a Trading Context:
Ask yourself: What is my true purpose for trading?
Many traders may instinctively answer “to make money,” but money is surely only a vehicle to achieve something else in your world for you and those you care about, not a purpose per se.
You need to clarify what trading success really means for you.
Is it a greater degree of financial independence through increased income or capital growth, the freedom of having more time, achieving a personal challenge of becoming a successful trader, or a combination of any of these?
What This Means to You:
Try framing your purpose as, “I must become a better trader so that I can…” and complete a list with your genuine reasons for tackling the market and its challenges.
This helps you establish meaningful short-term development goals that keep you moving toward your vision. Keep that purpose visible, as a note near your trading screen that reminds you why you are doing this.
Consequences of Non-Action:
Traders with a clearly defined purpose are more likely to stay disciplined and consistent.
Those without one often drift, chasing short-term gains without direction. There is ample evidence that formalising your development in whatever context through goal setting can significantly increase the likelihood of success. Why would trading be any different?
Surely the bottom-line question to ask yourself is, “Am I willing to risk my potential by trading without purpose?”
3. Put First Things First
This habit is about time management and prioritisation. This involves focusing your efforts and energy on what truly matters. As part of the exploration of this concept, Covey emphasised distinguishing between what is important and what is merely urgent.
In a Trading Context:
Trading demands commitment, learning, and reflection.
It is not just about screen time but about using that time effectively.
Managing activities to ensure your effort is spent wisely on planning, measuring, journaling and performance evaluation, and refining systems, accordingly, are all critical to sustaining both improvements in results and balance.
What This Means to You:
Traders often believe they need to spend more time trading when what they really need is to focus on better time allocation.
It is logical to suggest that prioritising activities that can often contribute directly to improvement, such as system testing, reviewing performance, analysing results, and refining your strategy, is worthwhile.
These high-value tasks are what make the difference between “busy trading” and “more effective trading.”
Consequences of Non-Action:
If you fail to control your trading time effectively, you will be more likely to spend much of it on low-impact activities that produce little progress.
Over time, this not only hurts your results but also reduces the real “hourly value” of your trading effort.
In business terms, and of course, you should be treating your trading as you would any business activity; poor prioritisation can inflate your costs and diminish your potential trading outcomes.
4. Think Win: Win
Covey's fourth habit encouraged an attitude of mutual benefit, where seeking solutions that facilitate positive outcomes for all parties.
In a Trading Context:
In trading, this concept must be adapted to suggest that developing a mindset that recognises every well-executed plan as a win, even when an individual trade results in a loss.
Some trading ideas will simply not work out, and so some losses are inevitable, but if they remain within defined limits, they should not be viewed as failures but rather as a successful adherence to a trading plan. In the aim of developing consistency in action, and the widely held belief that this is one of the cornerstones of successful trading, then it surely is a win to fulfil this.
So, in simple terms, the real “win” lies in a combination of maintaining discipline, following your system, and controlling risk beyond just looking at the P/L of a single trade.
What This Means to You:
Building and trading clear, unambiguous systems that you follow consistently has got to be the goal.
This process produces reliable data that you can later analyse and subsequently use to refine specific strategies and personal performance.
When you do this, every outcome, whether profit or loss, can serve as valuable feedback.
For example, a controlled loss that fits your plan is proof that your system works and that you are protecting your capital.
Alternatively, a trailing stop strategy, which means you exit trades in a timely way and give less profit back to the market, provides positive feedback that your system has merit in achieving outcomes.
Consequences of Non-Action:
Without this mindset shift, traders can become emotionally reactive, interpreting normal drawdowns as personal defeats.
This fosters loss aversion and other biases that can erode decision-making quality if left unchecked. Through the process of redefining “winning,” you are potentially safeguarding both your capital and, importantly, your trading confidence (a key component of trading discipline).
5. Seek First to Understand and Then Take Action
Covey's fifth habit emphasises empathy, the act of listening and aiming to fully understand before responding. In trading, this principle translates to understanding the market environment before taking any action.
In a Trading Context:
Many traders act impulsively, driven by excitement or fear, which often results in entering trades without taking into account the full context of what is happening in the market, and/or the potential short-term influences on sentiment that may increase risk.
This “minimalisation bias,” defined as acting on limited information, will rarely produce consistent results. Instead, adopt a process that begins with observation and comprehension.
What This Means to You:
Establishing a daily pre-trading routine is critical. This may include a review of key markets, sentiment indicators, and potential catalysts for change, such as imminent key data releases. Understanding what the market is telling you before you decide what to do is the aim of having this sort of daily agenda.
This approach may not only improve trade selection but also enable you to get into a state of psychological readiness that can facilitate decision-making quality throughout the session.
Consequences of Non-Action:
Failing to prepare for the trading day ahead can mean not only exposing yourself to unnecessary risk but also arguably being more likely to miss potential opportunities.
A trader who acts without understanding is vulnerable both psychologically and financially. Conversely, being forewarned is being forearmed. When you aim to understand markets first before any type of trading activity, your actions are more likely to be deliberate, grounded, and more effective.
6. Synergise
Synergy in Covey's model means valuing differences and combining the strengths of those around you to create outcomes greater than the sum of their parts.
In a Trading Context:
In trading, synergy refers to the integration of multiple systems and disciplines that work together. This includes your plan, your record keeping and performance management processes, your time management, and your emotional balance.
No single system is enough; success comes from the synergy of elements that support and inform one another.
What This Means to You:
Integrating learning and measurement is an integral part of your trading development process. Journaling, for example, allows you to assess not only your technical performance but also your behavioural consistency.
This self-awareness allows you to refine your plan and so helps you operate with greater confidence.
The synergy between rational analysis and emotional composure is what is more likely to lead to consistently sound trading decisions.
Consequences of Non-Action:
When logic and emotion are out of balance, decision-making will inevitably suffer.
If your systems are incomplete, ambiguous, or poorly connected to the reality of your current level of understanding, competence and confidence, your results are likely to be inconsistent. Building synergy across all areas of your trading practice, including that of evaluation and development in critical trading areas, will help create cohesion, efficiency, and better performance.
7. Sharpen the Saw
Covey's final habit focuses on continuous learning and refinement, including maintaining and improving the tools at your disposal and skills and knowledge that allow you to perform effectively.
In a Trading Context:
In trading, this translates to creating a plan to achieve ongoing, purposeful learning.
Even small insights can make a large difference in results. Successful traders continually refine their knowledge, ask new questions, and apply lessons from experience.
What This Means to You:
Trading learning can, of course, take many forms. Discovering new indicators that may offer some confluence to price action, testing different strategies, exploring new markets, or simply understanding more about yourself as a trader.
There is little doubt that active participation in learning keeps you engaged, adaptable and sharp. Even making sure you ask at least one question at a seminar or webinar or making a simple list at the end of each session of the "3 things I learned", can be invaluable in developing momentum for your growth as a trader.
Your record-keeping and performance metrics should generate fresh questions that can guide future development.
Consequences of Non-Action:
Without direction in your learning, your progress is likely to slow.
I often reference that when someone talks about trading experience in several years, this is only meaningful if there has been continuous growth, rather than staying in the same place every year (i.e. only one year of meaningful experience)
Passive trading learning, for example, reading an article without applying, watching a webinar without engagement, or measuring without closing the circle through putting an action plan together for your development, can all lead to stagnation.
It is fair to suggest that taking shortcuts in trading learning is likely to translate directly into shortcuts in result success.
Active, focused development is essential for sustained improvement.
Are You Ready for Action?
Stephen Covey’s The 7 Habits of Highly Effective People presented a timeless model for self-development and purposeful living.
When applied to trading, these same habits form a powerful framework for consistency, focus, and growth.
Trading is a pursuit that demands both technical skill and emotional strength. Success is rarely about finding the perfect system, but about developing the right habits that support consistent, rational decision-making over time.
By integrating the principles of Covey’s seven habits into your trading practice, you create a foundation not only for profitability but for continual personal growth.
.jpg)
数据截至日期:2025年11月26日
货币政策决定

新西兰储备银行货币政策委员会于2025年11月26日星期三召开会议,以5票赞成1票反对的表决结果,决定将官方现金利率下调25个基点至2.25%。这是新西兰储备银行(RBNZ)自2024年8月以来第六次调整官方现金利率。自2024年8月至本次会议,官方现金利率从5.50%累计下调至2.25%,累计调整幅度为325个基点。 货币政策委员会在声明中表示,未来官方现金利率的调整将取决于中期通胀和经济前景的实际演变情况。委员会指出,降低官方现金利率将有助于巩固消费者和企业信心,并防范经济复苏速度低于实现通胀目标所需水平的风险。
委员会会议纪要披露的决策考量

图1:官方现金利率 / 基准利率(来源:RBNZ estimates.)
根据会议纪要记录,支持进一步降息的委员强调,经济中存在显著的超额产能,这为中期通胀回归并保持在2%目标中点附近提供了信心。委员会认为经济复苏处于早期阶段,通胀前景允许将更多重视放在避免产出和就业出现不必要的波动性上。保持当前宽松程度的货币条件将支撑经济活动的持久复苏。 投票反对的委员则强调,官方现金利率已经历了相当大幅度的下调,这些调整仍在传导至经济中。委员会表示,经济指标正在复苏,经济活动预期在2026年将增强。投票反对的委员特别强调了通胀和产出的上行风险,认为在本次会议维持官方现金利率不变将为未来降息提供选择空间。 委员会讨论了价格设定行为的风险。鉴于近期经历了高通胀环境且通胀预期仍略高于目标中点,企业定价行为可能对通胀上行意外变得更加敏感。经济中的闲置产能已经压缩了企业利润率,随着需求改善,利润率的某种程度恢复是预期的。如果这种利润率恢复发生得比预期更快,将构成通胀上行风险。 会议纪要还记录了委员会对复苏速度的不同看法。部分委员强调,家庭和企业持续谨慎可能进一步放缓国内需求复苏,这可能导致通胀低于目标中点。其他委员则强调,如果房价和家庭支出对较低抵押贷款利率的反应比假设的更强,可能导致中期通胀压力更具持续性。
通胀状况

图2:消费者价格指数通胀(来源:Stats NZ, RBNZ estimates.)

图3:总体通胀与核心通胀指标(来源:Stats NZ, RBNZ estimates.)
根据新西兰统计局数据,2025年9月季度消费者物价指数年率为3.0%,位于货币政策委员会1%至3%目标区间的上限。这一数据与8月货币政策声明的预期一致。 分项数据显示,可贸易品通胀年率从6月季度的1.2%上升至9月季度的2.2%。非贸易品通胀年率从6月季度的3.7%下降至9月季度的3.5%,与8月声明预期一致。 核心通胀指标方面,RBNZ编制的五项核心通胀指标在9月季度的平均值为2.4%,较此前峰值水平已显著下降。这五项指标在9月季度的变动方向不一,平均值略有下降。季度核心通胀指标平均保持不变,处于与年率2%通胀一致的水平。 RBNZ指出,年度核心通胀指标自2023年以来已显著下降,但仍处于目标区间的上半部分。 RBNZ预测,年度消费者物价指数通胀将在2025年12月季度降至2.7%,然后在2026年中期降至接近2%目标中点的水平,这一预测基于食品、家庭能源和地方政府费率的通胀率预期下降,以及闲置产能继续降低潜在通胀压力。
产出缺口评估

图4:实际产出与潜在产出(来源:Stats NZ, RBNZ estimates.)

图5:产出缺口及其指标体系(来源:Stats NZ, NZIER,MBIE,RBNZ estimates.)
RBNZ估计,新西兰经济自2024年中期以来出现了显著的闲置产能。由于季度GDP的波动性导致产出缺口估算也出现波动,但RBNZ估计2025年全年产出缺口平均约为潜在GDP的负1.5%。 9月季度和2025年下半年的产出缺口估算略低于8月声明的假设,与经济活动较低以及产能压力指标套件持续疲弱一致。 RBNZ编制的多项产能压力指标显示,2024年和2025年迄今劳动力市场产能压力大幅缓解。大多数劳动力市场紧张度指标低于2000年以来的平均水平,部分指标接近2000年以来最疲弱水平。 RBNZ假设,随着2025年末GDP增长开始超过潜在增长率,产出缺口将在中期内逐步收窄,GDP增长预期将增强,因为较低利率继续传导至更强劲的需求,高全球经济不确定性的抑制效应减弱。
劳动力市场

图6:失业率(来源:Stats NZ, RBNZ estimates.)
Stats NZ公布的家庭劳动力调查数据显示,失业率在2025年9月季度为5.3%。RBNZ假设失业率在近期将大致保持不变,并预测随着经济增长恢复,失业率将在中期内下降。就业人数在9月季度环比保持不变,此前连续四个季度下降。在截至9月季度的一年中,就业人数下降0.6%,工作年龄人口增长0.9%。
职位空缺仍远低于COVID-19疫情前水平,但近几个月略有增加。总工时和支付工时在9月季度均有增长。RBNZ指出,疲弱的经济活动导致自2024年中期以来经济中出现显著闲置产能。职位分离率接近历史平均水平,但职位寻获率处于30年来最低水平。
劳动力成本指数显示的私营部门同岗位名义工资年增长率在2025年9月季度为2.1%,从2023年初4.5%的峰值下降。RBNZ假设工资增长将在中期内保持在这一水平附近。
家庭与企业
家庭消费在2025年上半年有所增长。截至6月季度的一年中,消费增长1.5%。RBNZ假设在预测期内家庭消费增长将增加,受较低利率支撑。住宅投资在2025年上半年保持大致稳定,此前经历了两年的大幅下降。RBNZ预期住宅投资将从2025年末开始增长。
委员会讨论显示,尽管抵押贷款利率下降且住房市场活动略有回升,但迄今为止房价总体上保持稳定。委员会评估认为,即将实施的抵押贷款价值比要求降低不太可能对房价产生实质性影响。委员会预期房价增长在预测期内将温和,大致与名义收入增长一致。
企业投资在2025年6月季度收缩。RBNZ预期企业投资在9月季度将保持疲弱,然后随着GDP增长增强在中期内增加。根据RBNZ最近的企业访谈,总体而言企业报告需求和活动仍然低迷,尽管农业部门报告需求强劲。企业报告总体成本压力有所缓解,但新西兰元走弱增加了进口材料的成本。
政府支出与人口
政府支出作为经济份额自2021年末以来有所下降,但在2025年上半年有所增加。RBNZ假设政府支出在中期内以历史上低迷的速度增长。新西兰的净移民自2024年末以来保持在历史低位。RBNZ的预测假设目前年度潜在GDP增长率约为1.5%,将在2028年增加至约2.5%。
出口与贸易条件
新西兰出口价格在2024年末至2025年中期大幅上涨。乳制品、肉类和园艺产品价格的上涨占了大部分涨幅。RBNZ指出,较高出口价格向经济的传导似乎与以往出口价格上涨时期有所不同。出口数量在6月季度下降。及时指标显示总体出口价格将在2025年下半年下降。RBNZ假设出口价格在中期内将以实际价格计算稳定在接近历史平均水平。
金融条件

图7:新西兰抵押贷款利率(来源:interest.to.nz, RBNZ.)
委员会讨论了新西兰国内金融条件的宽松。批发利率下降,新西兰元贸易加权指数自8月以来贬值。官方现金利率的下调降低了借贷成本和抵押贷款利率。 抵押贷款平均收益率已降至5.4%。委员会表示,由于近40%的固定利率抵押贷款将在12月和3月季度重新定价,基于当前市场定价,平均抵押贷款收益率预期将在2026年9月前进一步降至4.7%。 委员会讨论认为,尽管抵押贷款利率下降且住房市场活动略有回升,但迄今为止房价总体上保持稳定。 国内金融压力指标随着较低利率降低债务偿还压力而有所缓解。早期拖欠(提供受损贷款的早期指标)有所下降。住房不良贷款也有所下降,银行预期住房和商业地产减值将在2026年进一步减少。商业部门不良贷款仍然较高,尽管低于以往下行时期的水平。 新西兰元汇率低于8月声明时的水平。国际油价略有下降。
全球经济环境

图8:贸易伙伴增长预测的变化情况(来源:Bloomberg, RBNZ estimates.)
委员会表示,全球经济增长受益于强劲的人工智能相关投资,但预期将在2026年放缓,因为贸易壁垒将对活动产生影响。关税对全球经济的影响低于最初预期。全球股票市场保持强劲,由美国科技板块持续上涨带动。油价已降至约四年来最低水平。
委员会对新西兰主要贸易伙伴的全球增长预测在2025年为2.9%,这一预测自5月声明以来已上调;年度贸易伙伴增长预期将在2026年放缓至2.6%,与8月声明保持一致。中国经济在2025年第三季度同比增长4.8%,出口增长6.7%,但国内需求疲软。
委员会讨论了全球前景的风险。人工智能应用的回报仍存在不确定性,存在股市更显著调整和投资减少的风险。几个发达经济体的通胀仍然较高,全球政策不确定性也仍然很高。委员会指出中国增长面临下行风险,以及美国经济政策的不确定性和美国通胀走高的相关风险。
新西兰主要贸易伙伴的总体通胀在2025年上半年降至1.6%,预期2025年平均为1.8%。贸易伙伴年度通胀在9月季度升至1.8%,预期将进一步上升至2026年平均2.0%。
官方现金利率路径(OCR)与风险评估
RBNZ表示,在中期经济前景的条件下,预测OCR将低于8月声明时的水平。这主要反映了对2025年经济中存在更大程度闲置产能的评估,以及出口价格前景较低。在中期内,OCR预期将回归至长期中性估算区间的中部。
RBNZ在声明中指出,通胀前景的风险大致平衡。家庭和企业如果更加谨慎,可能放缓新西兰经济复苏的步伐。或者,如果国内需求对较低利率的反应比预期更强,复苏可能更快更强。 委员会讨论了经济中显著的闲置产能。除了短期因素外,经济的中期供给能力因生产率和工作年龄人口增长疲弱而有所降低。估算显示目前潜在产出的年增长率约为1.5%。 委员会讨论了不可持续的财政动态和全球央行政治化加剧可能为更高且更持久的通胀创造条件的风险。
委员会成员为:Christian Hawkesby(主席)、Carl Hansen、Hayley Gourley、Karen Silk、Paul Conway、Prasanna Gai。财政部观察员为James Beard,委员会秘书为Chris Bloor。
相关官方文件和详细数据请参考:
新西兰储备银行官方网站:https://www.rbnz.govt.nz
新西兰储备银行货币政策决定:https://www.rbnz.govt.nz/monetary-policy/monetary-policy-decisions
新西兰储备银行货币政策声明:https://www.rbnz.govt.nz/monetary-policy/monetary-policy-statement
新西兰储备银行官方现金利率(OCR):https://www.rbnz.govt.nz/monetary-policy/official-cash-rate-decisions
新西兰统计局官方网站:https://www.stats.govt.nz
新西兰储备银行经济数据与预测:https://www.rbnz.govt.nz/statistics
新西兰储备银行通胀数据:https://www.rbnz.govt.nz/statistics/inflation
新西兰储备银行金融稳定报告:https://www.rbnz.govt.nz/financial-stability/financial-stability-report
新西兰储备银行2025年11月货币政策声明(完整版PDF):
https://www.rbnz.govt.nz/-/media/project/sites/rbnz/files/publications/monetary-policy-statements/2025/nov-261125/monetary-policy-statement-november-2025.pdf
新西兰储备银行官方现金利率决定新闻稿(2025年11月26日):
https://www.rbnz.govt.nz/hub/news/2025/11/ocr-lowered-to-2-25-percent
新西兰储备银行2025年11月货币政策声明简报(PDF):
https://www.rbnz.govt.nz/-/media/project/sites/rbnz/files/publications/monetary-policy-statements/2025/nov-261125/november-2025-monetary-policy-statement-briefing.pdf
免责声明
本文内容仅为一般性建议(General Advice),未考虑任何个人的具体投资目标、财务状况或特定需求,不构成任何形式的个人财务建议(Personal Advice)、投资建议、税务建议、法律建议或任何金融产品推荐等。本文陈述的所有信息均基于新西兰储备银行(RBNZ)、新西兰统计局(Stats NZ)等公开渠道已发布的历史数据和官方声明,不包含任何对未来市场走向、经济表现、投资回报或政策变化的预测、预判或前瞻性陈述,过往表现和历史数据不代表未来结果。所有投资均涉及风险,包括可能损失全部本金,外汇、差价合约(CFD)、衍生品等杠杆类产品具有高风险特性,可能导致快速且重大的损失,据统计大部分散户投资者账户在交易CFD时出现亏损,市场价格可能因各种因素剧烈波动。本文引用的信息来源于公开渠道,虽已尽力确保准确性,但不对信息的完全准确性、完整性、及时性或适用性作出任何明示或暗示的保证,信息可能存在延迟、需要更正,或因市场和政策环境快速变化而不再适用于当前情况。在做出任何投资或财务决策前,您应当仔细考虑自身的财务状况、投资目标和风险承受能力,进行适当性评估以确保相关产品或策略符合您的需求,并咨询持有澳大利亚金融服务牌照(AFSL)的财务顾问、税务专业人士或法律顾问,同时了解并遵守您所在司法管辖区的相关法律法规。本文提及的任何第三方机构、产品或服务不构成推荐或认可,相关商标、名称归其合法所有者。在法律允许的最大范围内,作者及相关方对因使用、依赖或无法使用本文信息而导致的任何直接、间接、附带、特殊或后果性损失不承担任何责任。投资有风险,决策需谨慎。
%20(1).jpg)
在使用 TradingView 的 Pine Script 进行策略或指标开发时,operators(运算符)是最基础却也最关键的组成部分。无论是数据计算、条件判断,还是逻辑组合,都离不开这些运算符的参与。理解并熟练掌握 operators 的运作方式,不仅能提高脚本编写的效率,也能让策略逻辑更加清晰严谨。本文将对 TradingView 中常见的运算符类型做一个简明介绍,以帮助读者快速建立完整的概念框架。
1. Arithmetic operators(算术运算符):主要用于数值计算,是构建指标公式的核心。例如 +、-、*、/ 用来执行加减乘除;% 则用于取余数。在编写移动平均、价差、振幅等计算时,这类运算符是最常见的基础工具。
2. Comparison operators(比较运算符):用于比较两个值的大小或相等性,如 >、<、>=、<=、== 和 !=。这些运算符通常出现在条件语句中,例如判断价格是否突破均线、成交量是否高于过去均值等。比较运算的结果为布尔值(true/false),为策略信号的触发提供依据。
3. Logical operators(逻辑运算符):则负责将多个条件组合在一起,例如 and、or、not。通过逻辑运算符,可以形成更复杂的交易规则,例如“价格突破阻力位 且 成交量放大”或“满足任意一个指标信号即触发”等。
4. Ternary operators: 在 Pine Script 中,?: 三元运算符(Ternary Operator)是一种紧凑而强大的条件表达方式。通常在编写脚本时,我们需要根据某个条件返回不同的结果,而最常见的方式是使用 if…else 条件结构。然而,当你希望在一行中表达逻辑、或在表达式内根据条件动态赋值时,传统的条件语句显得冗长,这时三元运算符就成为更优雅的选择。三元运算符的语法结构如下:condition ? valueWhenConditionIsTrue : valueWhenConditionIsFalse它的工作方式非常直观:如果 condition 为 true,则返回 valueWhenConditionIsTrue;若为 false,则返回 valueWhenConditionIsFalse。正因如此,它常用于快速返回基于条件判断的结果,而无需展开完整的条件语句。举例如下:timeframe.isintraday ? color.red :timeFrame.isdaily ? color.green :timeframe.ismonthly ? color.blue : na这个表达式会从左到右依序判断条件:首先检查 timeframe.isintraday,若成立则返回 color.red;否则继续判断 timeframe.isdaily。如为 true,则返回 color.green;否则进入下一层判断 timeframe.ismonthly。如果此条件成立,则返回 color.blue,若不成立,最终返回 na。
5. History – referencing operators:在 Pine Script 中,可以使用 [] 历史引用运算符(history-referencing operator)来引用时间序列的过去数值。过去的数值指的是脚本在当前柱(current bar)执行时,变量在之前的柱(past bars)中所具有的值。[] 运算符被放置在变量、表达式或函数调用之后。方括号中的数值代表我们希望引用的过去的偏移量。例如,如果想引用当前柱之前第 2 根柱的 volume(成交量)值,可以写作:volume[2]由于时间序列会随着脚本在每一根新柱上运行而动态增长,因此固定的历史偏移量在不同柱上会对应不同的实际数据。下面我们来看看为什么同一个偏移量会得到动态变化的结果,也了解时间序列为何与数组(arrays)截然不同。在 Pine Script 中,变量 close(或等价写法 close[0])表示当前柱的收盘价。如果脚本正在数据集(dataset,即图表上的所有柱)中的第 3 根柱上运行:
- close 保存的是第 3 根柱的收盘价
- close[1] 保存的是第 2 根柱的收盘价
- close[2] 保存的是第 1 根柱的收盘价
- close[3] 将返回 na,因为该位置不存在柱,因此没有可用数值
当相同的代码运行到下一根柱(数据集中的第 4 根柱)时:
- close 变为第 4 根柱的收盘价
- close[1] 现在指向第 3 根柱的收盘价
- 第 1 根柱的收盘价现在变为 close[3] 所对应
- close[4] 此时返回 na
在 Pine Script 的运行环境中,脚本会从图表最左侧开始,对数据集中每一根历史柱执行一次。当计算进入下一根柱时,Pine Script 会在序列(series)的索引 0 处加入一个新元素,并将已有元素的索引依序向后移动。相比之下,数组(arrays)可以具有固定或可变大小,但其数据内容与索引结构不会被运行环境自动改变。因此,Pine Script 的时间序列(series)与数组本质上非常不同,它们唯一相似之处仅在于都使用索引语法。当图表所对应的市场处于开盘状态,并且脚本在图表的最后一根柱(实时柱,realtime bar)上运行时,close 返回的是当前价格。只有在该实时柱最终收盘、脚本最后一次在此柱执行时,close 才会包含该柱实际的收盘价。Pine Script 提供了一个变量 bar_index 来指示脚本当前正在执行的柱号:
- 在第一根柱上,bar_index = 0
- 每当脚本在下一根柱执行时,其值会加 1
- 在最后一根柱上,bar_index 等于数据集中的柱数减一
在 Pine Script 中使用 [] 运算符时有另一项重要注意事项:历史引用可能会返回 na。na 表示一个非数字值,任何表达式只要使用到 na,最终结果也会变成 na(类似 NaN 的概念)。这种情况常见于脚本在数据集前几根柱执行时,但在某些条件下也可能出现在后面的柱中。如果你的代码未使用 na() 或 nz() 等函数明确处理这些特殊情况,na 值可能会导致错误的计算结果,并影响一直到实时柱为止的所有计算。6. Assignment and reassignment operators:= 运算符用于为已声明的变量赋予初始值或引用。它表示这是一个新的变量,并且以这个值开始。:= 则用于为已经存在的变量重新赋值。它的含义是:使用脚本中先前声明过的这个变量,并为它赋予一个新值。那些先声明、然后再使用 := 进行重新赋值的变量,被称为可变变量(mutable variables)。以下所有示例都是有效的变量重新赋值方式。举例如下:var float pHi = napHi := nz(ta.pivothigh(5, 5), pHi)var 关键字告诉 Pine Script:我们只希望这个变量在数据集的第一根柱上被初始化为na。float 关键字则告诉编译器我们正在声明一个浮点类型(float) 的变量。虽然变量声明由于使用了 var 只会在第一根柱上执行,但下面这行代码:pHi := nz(ta.pivothigh(5, 5), pHi)会在图表上的每一根柱上执行。在每根柱上,该语句首先检查 ta.pivothigh() 是否返回 na —— 因为当函数没有找到新的枢轴点(pivot)时,它确实会返回 na。nz() 函数负责执行“检查 na”这个动作:
- 当 nz() 的第一个参数(ta.pivothigh(5, 5))为 na 时,它会返回第二个参数 pHi;
- 当 ta.pivothigh() 找到新的枢轴点并返回其价格时,这个值就会被赋给 pHi。
因此,当找到新枢轴点时,我们更新 pHi;而当没有新枢轴出现、函数返回 na 时,我们再次将原来的 pHi 赋值给自己,从而保持先前的数值不变。7. Compound assignment operators:复合赋值运算符(compound assignment operator)将算术运算符与重新赋值运算符组合在一起。它提供了一种简写方式,用于对变量执行算术运算并将结果重新赋值给同一个变量。例如,counter += 1 会在 counter 当前值的基础上加 1,并将加过之后的新值重新赋给 counter。这与写成 counter := counter + 1 的效果完全相同。需要注意的是,变量必须在使用复合赋值运算符之前已被声明。通过以上内容,我们系统地梳理了 Pine Script 中最常用的几类运算符,包括三元运算符、历史引用运算符 []、变量的声明与重新赋值方式,以及更便捷的复合赋值运算符。这些看似基础的语法结构,实际上构成了 Pine Script 在处理时间序列数据、编写策略逻辑与构建指标时的核心基础。