Khối Act & Risk · intermediate · 7 phút
Khối Act
Khối act: enter, close, flatten
#act#execution#v2
Khối `act:`
Thay vì gọi buy() hay sell(), Quanta v2 khuyến nghị cú pháp ra lệnh tự nhiên. Engine biên dịch chúng xuống primitive an toàn cho Backtest/Live. Engine cũng chấp nhận alias synonym bên dưới.
| Hành động | Cú pháp Quanta Story | Alias chấp nhận |
|---|---|---|
| Vào long % NAV | enter long with wnav 5pct | enter buy with wnav 5pct |
| Vào long cố định | enter long with size 1 (1 HĐ/cp) | enter buy with size 1 |
| Vào short % NAV | enter short with wnav 3pct | enter sell with wnav 3pct |
| Vào short cố định | enter short with size 5000 (5000 cp) | enter sell with size 5000 |
| Đóng long | close long tag "Cắt Lỗ" | close buy |
| Đóng short | close short | close sell |
| Đóng hết | close all / flatten all | — |
| Đính kèm nhãn | Thêm tag "..." ở cùng dòng hoặc note "..." ở dòng dưới | — |
Nhóm synonym
- Long:
buy()≡long()≡enter long≡enter buy≡close short≡close sell - Short:
sell()≡short()≡enter short≡enter sell≡close long≡close buy
Debug Console
Dùng print(...) trong logics: / act: để ghi giá trị ra Console (nút >_ góc dưới chart):
quanta
logics: rsi14 = rsi(c, 14) print("rsi", rsi14) print("last3", rsi14, bars: 3)
Ví dụ (canonical + một alias):
quanta
act: when buy_cond and not position.is_long: qty = position_size(2pct, atr(h,l,c,14)*2) enter long with size qty tag "Breakout" when position.is_long and c < sma(c, 50): close long tag "Trend Broken" note "Đóng do giá rớt dưới MA50" # alias tương đương enter long / close short: when cover_short: enter buy with wnav 5pct tag "Alias entry"