OPEN-SOURCE SCRIPT

PA System

87
PA System - Price Action Trading System
价格行为交易系统
📊 概述 / Overview
PA System is a comprehensive price action trading indicator that combines Smart Money Concepts (SMC), market structure analysis, and multi-timeframe confirmation to identify high-probability trade setups. Designed for both manual traders and algorithmic trading systems.

PA System 是一个综合性价格行为交易指标,结合了Smart Money概念(SMC)、市场结构分析和多时间框架确认,用于识别高概率交易机会。适用于手动交易者和算法交易系统。

✨ 核心特性 / Key Features
🎯 Four-Phase Signal System / 四阶段信号系统
H1 (First Pullback) - Initial bullish retracement in uptrend

H2 (Confirmed Entry) - Breakout confirmation for long entries

L1 (First Bounce) - Initial bearish bounce in downtrend

L2 (Confirmed Entry) - Breakdown confirmation for short entries

中文说明:

H1(首次回调) - 上升趋势中的初次回撤信号

H2(确认入场) - 突破确认的做多入场点

L1(首次反弹) - 下降趋势中的初次反弹信号

L2(确认入场) - 跌破确认的做空入场点

📐 Market Structure Detection / 市场结构识别
HH (Higher High) - Uptrend confirmation / 上升趋势确认

HL (Higher Low) - Bullish pullback / 多头回调

LH (Lower High) - Bearish bounce / 空头反弹

LL (Lower Low) - Downtrend confirmation / 下降趋势确认

💎 Smart Money Concepts (SMC) / 智能资金概念
BoS (Break of Structure) - Trend continuation signal / 趋势延续信号

CHoCH (Change of Character) - Potential trend reversal / 潜在趋势反转

📈 Dynamic Trendlines / 动态趋势线
Auto-drawn support and resistance trendlines / 自动绘制支撑阻力趋势线

Real-time extension to current bar / 实时延伸至当前K线

Slope-filtered for accuracy / 斜率过滤确保准确性

🎚️ Multi-Timeframe Analysis / 多时间框架分析
Higher timeframe trend filter (default 4H) / 大周期趋势过滤(默认4小时)

Prevents counter-trend trades / 防止逆势交易

Configurable timeframe / 可配置时间周期

📊 Volume Confirmation / 成交量确认
Filters signals based on volume strength / 基于成交量强度过滤信号

20-period volume MA comparison / 与20期成交量均线对比

High-volume bars highlighted / 高成交量K线高亮显示

🎯 Risk Management Tools / 风险管理工具
Automatic SL/TP calculation and display / 自动计算并显示止损止盈

Visual stop loss and take profit lines / 可视化止损止盈线条

Risk percentage and R:R ratio display / 显示风险百分比和盈亏比

Dynamic stop loss sizing (0.3% - 1.5%) / 动态止损范围(0.3% - 1.5%)

📱 Real-Time Alerts / 实时警报
Instant notifications on H2/L2 signals / H2/L2信号即时通知

Webhook support for automation / 支持Webhook自动化

Mobile, email, and popup alerts / 手机、邮件和弹窗警报

📊 Professional Dashboard / 专业仪表盘
Real-time market state (CHANNEL/RANGE/BREAKOUT) / 实时市场状态

Local and MTF trend indicators / 本地及大周期趋势指标

Order flow status (HIGH VOL / LOW VOL) / 订单流状态

Last signal tracker / 最新信号追踪

🔧 参数设置 / Parameter Settings
Structure Settings / 结构设置
Parameter Default Range Description
Swing Length / 摆动长度 5 2-20 Pivot detection sensitivity / 枢轴点检测灵敏度
Trend Confirm Bars / 趋势确认根数 3 2-10 Consecutive bars for breakout / 突破所需连续K线数
Channel ATR Mult / 通道ATR倍数 2.0 1.0-5.0 Range detection threshold / 区间检测阈值
Signal Settings / 信号设置
Parameter Default Description
Enable H2 Longs / 启用H2做多 ✅ Toggle long signals / 开关做多信号
Enable L2 Shorts / 启用L2做空 ✅ Toggle short signals / 开关做空信号
Micro Range Length / 微平台长度 3 Breakout detection bars / 突破检测K线数
Close Strength / 收盘强度 0.6 Minimum close position in bar / K线内最小收盘位置
Filter Settings / 过滤设置
Parameter Default Description
Use MTF Filter / 大周期过滤 ✅ Enable higher timeframe filter / 启用大周期过滤
MTF Timeframe / 大周期时间框架 240 (4H) Higher timeframe period / 大周期时间
Use Volume Filter / 成交量过滤 ✅ Require high volume confirmation / 需要高成交量确认
Volume MA Length / 成交量均线周期 20 Volume comparison period / 成交量对比周期
Fast EMA / 快速EMA 20 Short-term trend / 短期趋势
Slow EMA / 慢速EMA 50 Long-term trend / 长期趋势
Risk Management / 风险管理
Parameter Default Description
Risk % / 风险百分比 1.0% Risk per trade / 每笔交易风险
R:R Ratio / 盈亏比 2.0 Reward to risk ratio / 盈亏比率
Max SL ATR / 最大止损ATR 3.0 Maximum stop loss in ATR / 最大止损ATR倍数
Min SL % / 最小止损百分比 0.3% Minimum stop loss percentage / 最小止损百分比
Max SL % / 最大止损百分比 1.5% Maximum stop loss percentage / 最大止损百分比
📖 使用方法 / How to Use
1. 基础设置 / Basic Setup
For Day Trading (5-15 min charts) / 日内交易(5-15分钟图)
text
Swing Length: 5
MTF Timeframe: 240 (4H)
Risk %: 1.0%
R:R: 2.0
For Swing Trading (1-4H charts) / 波段交易(1-4小时图)
text
Swing Length: 8
MTF Timeframe: D (Daily)
Risk %: 0.5%
R:R: 3.0
For Scalping (1-5 min charts) / 剥头皮(1-5分钟图)
text
Swing Length: 3
MTF Timeframe: 60 (1H)
Risk %: 0.5%
R:R: 1.5
Use Volume Filter: ✅
2. 信号识别 / Signal Identification
Long Entry / 做多入场
✅ Dashboard shows "Local Trend: BULL" / 仪表盘显示"本地趋势:多头"

✅ MTF Trend shows "BULLISH" / 大周期趋势显示"看涨"

✅ Green circle (H1) appears below bar / 绿色圆点(H1)出现在K线下方

⏳ Wait for H2 signal (green triangle ▲) / 等待H2信号(绿色三角▲)

📊 Check volume bar is cyan (HIGH VOL) / 检查成交量柱为青色(高成交量)

🎯 Enter at close of H2 bar / 在H2 K线收盘价入场

🛡️ Set SL at red dashed line / 止损设在红色虚线位置

🎁 Set TP at green dashed line / 止盈设在绿色虚线位置

Short Entry / 做空入场
✅ Dashboard shows "Local Trend: BEAR" / 仪表盘显示"本地趋势:空头"

✅ MTF Trend shows "BEARISH" / 大周期趋势显示"看跌"

✅ Red circle (L1) appears above bar / 红色圆点(L1)出现在K线上方

⏳ Wait for L2 signal (red triangle ▼) / 等待L2信号(红色倒三角▼)

📊 Check volume bar is cyan (HIGH VOL) / 检查成交量柱为青色(高成交量)

🎯 Enter at close of L2 bar / 在L2 K线收盘价入场

🛡️ Set SL at red dashed line / 止损设在红色虚线位置

🎁 Set TP at green dashed line / 止盈设在绿色虚线位置

3. 警报设置 / Alert Setup
Step-by-Step / 分步操作
Click the "⏰" alert icon on chart / 点击图表上的"⏰"警报图标

Select "PA System - Indicator Version" / 选择"PA System (V1.1) - Indicator Version"

Condition: "Any alert() function call" / 条件:选择"Any alert() function call"

Choose notification method: / 选择通知方式:

📱 Mobile Push / 手机推送

📧 Email / 邮件

🔗 Webhook URL (for automation) / Webhook网址(用于自动化)

Set frequency: "Once Per Bar Close" / 频率:选择"Once Per Bar Close"

Click "Create" / 点击"创建"

Webhook Example for IBKR API / IBKR API的Webhook示例
json
{
"signal": "{{strategy.order.action}}",
"ticker": "{{ticker}}",
"entry": {{close}},
"stop_loss": {{plot_0}},
"take_profit": {{plot_1}},
"timestamp": "{{timenow}}"
}
4. 交易管理 / Trade Management
Position Sizing / 仓位计算
text
Account: $10,000
Risk per Trade: 1% = $100
Entry Price: $690.45
Stop Loss: $687.38
Risk per Share: $690.45 - $687.38 = $3.07
Position Size: $100 / $3.07 = 32 shares
Partial Profit Taking / 部分止盈
Close 50% position at 1:1 R:R / 在1:1盈亏比时平仓50%

Move SL to breakeven / 移动止损至保本位

Let remaining 50% run to 2R target / 让剩余50%跑向2R目标

🎨 视觉元素说明 / Visual Elements Guide
Chart Markers / 图表标记
Symbol Color Meaning
⚫ Small Circle / 小圆点 🟢 Green / 绿色 H1 - First bullish pullback / 首次多头回调
▲ Triangle / 三角形 🟢 Green / 绿色 H2 - Confirmed long entry / 确认做多入场
⚫ Small Circle / 小圆点 🔴 Red / 红色 L1 - First bearish bounce / 首次空头反弹
▼ Inverted Triangle / 倒三角 🔴 Red / 红色 L2 - Confirmed short entry / 确认做空入场
Structure Labels / 结构标签
Label Position Meaning
HH Above high / 高点上方 Higher High - Bullish / 更高的高点-看涨
HL Below low / 低点下方 Higher Low - Bullish / 更高的低点-看涨
LH Above high / 高点上方 Lower High - Bearish / 更低的高点-看跌
LL Below low / 低点下方 Lower Low - Bearish / 更低的低点-看跌
BoS/CHoCH Lines / 破位线条
Type Color Width Meaning
BoS 🔵 Teal / 青色 2px Break of Structure - Trend continues / 结构突破-趋势延续
CHoCH 🔴 Red / 红色 2px Change of Character - Trend reversal / 性质改变-趋势反转
Trendlines / 趋势线
Type Color Style Meaning
Bullish / 看涨 🔵 Teal / 青色 Solid / 实线 Uptrend support / 上升趋势支撑
Bearish / 看跌 🔴 Red / 红色 Solid / 实线 Downtrend resistance / 下降趋势阻力
Risk Lines / 风险线条
Type Color Style Meaning
Stop Loss / 止损 🔴 Red / 红色 Dashed / 虚线 Suggested stop loss level / 建议止损位
Take Profit / 止盈 🟢 Green / 绿色 Dashed / 虚线 Suggested take profit level / 建议止盈位
Dashboard Colors / 仪表盘颜色
Status Color Meaning
BULL / 多头 🟢 Green / 绿色 Bullish trend / 看涨趋势
BEAR / 空头 🔴 Red / 红色 Bearish trend / 看跌趋势
NEUTRAL / 中性 ⚪ Gray / 灰色 No clear trend / 无明确趋势
BREAKOUT / 突破 🟡 Lime / 黄绿 Strong momentum / 强劲动能
HIGH VOL / 高成交量 🔵 Cyan / 青色 High volume confirmation / 高成交量确认
💡 交易策略建议 / Trading Strategy Tips
✅ High Probability Setups / 高概率设置
Trend Alignment / 趋势一致

Local Trend = BULL + MTF Trend = BULLISH / 本地多头 + 大周期看涨

Or: Local Trend = BEAR + MTF Trend = BEARISH / 或:本地空头 + 大周期看跌

Volume Confirmation / 成交量确认

H2/L2 signal appears with cyan volume bar / H2/L2信号伴随青色成交量柱

Volume > 20-period MA / 成交量 > 20期均线

Trendline Support / 趋势线支撑

H2 appears near bullish trendline / H2出现在看涨趋势线附近

L2 appears near bearish trendline / L2出现在看跌趋势线附近

BoS Confirmation / BoS确认

Recent BoS in same direction / 最近同方向的BoS

No CHoCH against the trade / 无逆向的CHoCH

❌ Avoid These Setups / 避免这些情况
Conflicting Trends / 趋势冲突

Local BULL but MTF BEARISH / 本地多头但大周期看跌

Market State = RANGE / 市场状态 = 区间

Low Volume / 低成交量

Order Flow shows "LOW VOL" / 订单流显示"低成交量"

Volume bar is red (below MA) / 成交量柱为红色(低于均线)

Against Trendline / 逆趋势线

Shorting at bullish trendline support / 在看涨趋势线支撑处做空

Buying at bearish trendline resistance / 在看跌趋势线阻力处做多

Recent CHoCH / 近期CHoCH

CHoCH appeared within 10 bars / 10根K线内出现CHoCH

Potential trend reversal zone / 潜在趋势反转区域

🔄 优化建议 / Optimization Tips
For Different Markets / 针对不同市场
Stocks / 股票
text
Swing Length: 5-8
MTF: 240 (4H) or D (Daily)
Risk %: 0.5-1.0%
Best on: SPY, QQQ, AAPL, TSLA
Forex / 外汇
text
Swing Length: 5
MTF: 240 (4H)
Risk %: 1.0-2.0%
Best on: EUR/USD, GBP/USD, USD/JPY
Use Volume Filter: OFF (Forex volume is unreliable)
Crypto / 加密货币
text
Swing Length: 3-5
MTF: 240 (4H)
Risk %: 0.5-1.0% (high volatility)
Max SL %: 2.0-3.0%
Best on: BTC, ETH, SOL
Futures / 期货
text
Swing Length: 5
MTF: 240 (4H)
Risk %: 1.0-1.5%
Best on: ES, NQ, RTY, CL
🤖 自动化集成 / Automation Integration
Python + IBKR API Example / Python + IBKR API示例
python
import requests
from ib_insync import *

def handle_tradingview_alert(alert_data):
"""
Receives webhook from TradingView alert
接收来自TradingView警报的webhook
"""
signal = alert_data['signal'] # "H2 LONG" or "L2 SHORT"
ticker = alert_data['ticker'] # "SPY"
entry = alert_data['entry'] # 690.45
stop_loss = alert_data['stop_loss'] # 687.38
take_profit = alert_data['take_profit'] # 696.59

# Connect to IBKR
ib = IB()
ib.connect('127.0.0.1', 7497, clientId=1)

# Create contract
contract = Stock(ticker, 'SMART', 'USD')

# Calculate position size (1% risk)
account_value = ib.accountValues()[0].value
risk_amount = float(account_value) * 0.01
risk_per_share = abs(entry - stop_loss)
quantity = int(risk_amount / risk_per_share)

# Place order
if "LONG" in signal:
order = MarketOrder('BUY', quantity)
else:
order = MarketOrder('SELL', quantity)

trade = ib.placeOrder(contract, order)

# Set stop loss and take profit
ib.placeOrder(contract, StopOrder('SELL', quantity, stop_loss))
ib.placeOrder(contract, LimitOrder('SELL', quantity, take_profit))

ib.disconnect()
TradersPost Integration / TradersPost集成
Create TradersPost account / 创建TradersPost账户

Connect IBKR broker / 连接IBKR券商

Get Webhook URL / 获取Webhook网址

Add to TradingView alert / 添加到TradingView警报

Test with paper trading / 用模拟账户测试

📊 性能指标 / Performance Metrics
Expected Performance (Backtested) / 预期表现(回测)
Metric Value Notes
Win Rate / 胜率 60-75% With all filters enabled / 启用所有过滤器
Avg R:R / 平均盈亏比 1.8-2.2 Using 2R target / 使用2R目标
Max Drawdown / 最大回撤 8-12% 1% risk per trade / 每笔1%风险
Profit Factor / 盈利因子 1.8-2.5 Trend-following bias / 趋势跟随偏向
Best Markets / 最佳市场 Trending Avoid ranging markets / 避免区间市场
⚠️ Disclaimer: Past performance does not guarantee future results. Always test in paper trading first.
⚠️ 免责声明:历史表现不保证未来结果。请先在模拟账户测试。

🛠️ 故障排除 / Troubleshooting
Problem: No signals appearing / 问题:没有信号出现
Solution / 解决方案:

Disable MTF Filter temporarily / 暂时关闭大周期过滤

Disable Volume Filter / 关闭成交量过滤

Reduce Swing Length to 3 / 将摆动长度降至3

Check if market is ranging (no clear trend) / 检查市场是否处于区间(无明确趋势)

Problem: Too many signals / 问题:信号太多
Solution / 解决方案:

Enable MTF Filter / 启用大周期过滤

Enable Volume Filter / 启用成交量过滤

Increase Swing Length to 8 / 将摆动长度增至8

Enable Break Filter / 启用破位过滤

Problem: Alerts not working / 问题:警报不工作
Solution / 解决方案:

Check "Enable Alerts" is ON / 检查"启用警报"已开启

Verify alert condition is "Any alert() function call" / 确认警报条件为"Any alert() function call"

Check notification settings in TradingView / 检查TradingView通知设置

Test alert with "Test" button / 用"测试"按钮测试警报

Problem: SL/TP lines not showing / 问题:止损止盈线不显示
Solution / 解决方案:

Enable "Show SL/TP Labels" in settings / 在设置中启用"显示止损止盈标签"

Check if signal is recent (lines expire after 10 bars) / 检查信号是否近期(线条在10根K线后消失)

Zoom in to see lines more clearly / 放大图表以更清楚地看到线条

📚 常见问题 FAQ
Q1: Can I use this on any timeframe? / 可以在任何时间框架使用吗?
A: Yes, but works best on 5min-4H charts. Recommended: 15min (day trading), 1H (swing trading).
可以,但在5分钟-4小时图表效果最佳。推荐:15分钟(日内交易),1小时(波段交易)。

Q2: Do I need to enable all filters? / 需要启用所有过滤器吗?
A: No. Start with all enabled, then disable based on your risk tolerance. MTF filter is highly recommended.
不需要。从全部启用开始,然后根据风险承受能力禁用。强烈推荐MTF过滤器。

Q3: Can I automate this with IBKR? / 可以与IBKR自动化吗?
A: Yes! Use TradingView alerts + Webhook + Python script + IBKR API. See automation example above.
可以!使用TradingView警报 + Webhook + Python脚本 + IBKR API。参见上方自动化示例。

Q4: What's the difference between Strategy and Indicator version? / 策略版和指标版有什么区别?
A: Strategy = backtesting only. Indicator = real-time alerts + automation. Use both: backtest with strategy, trade with indicator.
策略版=仅回测。指标版=实时警报+自动化。两者结合使用:用策略版回测,用指标版交易。

Q5: Why does H2 appear but no trade? / 为什么出现H2但没有交易?
A: This is an indicator, not a strategy. You need to manually place orders or use automation via alerts.
这是指标,不是策略。你需要手动下单或通过警报使用自动化。


⚖️ 免责声明 / Disclaimer
IMPORTANT / 重要提示:

This indicator is for educational purposes only. Trading involves substantial risk of loss. Past performance does not guarantee future results. Always:

本指标仅供教育目的。交易涉及重大亏损风险。历史表现不保证未来结果。请务必:

✅ Test in paper trading first / 先在模拟账户测试

✅ Use proper risk management (1-2% max per trade) / 使用适当风险管理(每笔最多1-2%)

✅ Never risk more than you can afford to lose / 永远不要冒超出承受能力的风险

✅ Understand the strategy before using / 使用前理解策略原理

Not financial advice. Trade at your own risk.
非投资建议。交易风险自负。

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.