asami.SmartTrend

The script fires **Buy/Sell signals** based on an EMA golden/death‑cross, but only when **volatility (ATR & Bollinger width), volume, and short‑term momentum** confirm that market conditions are meaningful. It also self‑tracks win‑rate and average P/L, displaying the stats in a table.
### **2\. Input Parameters**
| Category | Variable(s) | Function |
| :---- | :---- | :---- |
| Trend | `emaFast`, `emaSlow` | Determine EMA crossover direction |
| Oscillator | `rsiLength` | Oversold/overbought context only |
| MACD | `macdFast`, etc. | Extra momentum context (not plotted) |
| Volatility | `atrPeriod`, `atrMultiplier`, `bbLength`, `bbMult` | Measure relative ATR & BB width |
| Threshold | `minVolatilityThreshold` | Minimum % width to call vol “high” |
### **3\. Core Logic**
1. **Trend** – `fastMA > slowMA` is up‑trend, else down.
2. **Signal Generation**
* `crossover(fastMA, slowMA)` → **Buy**
* `crossunder(fastMA, slowMA)` → **Sell**
3. **Volatility & Volume Filter**
* Current ATR vs 100‑bar ATR average.
* Bollinger‑band width (% of middle band).
* Volume \> 1.5 × 20‑bar MA.
* If both conditions pass, table shows “HIGH”.
4. **Momentum Filter** – 3‑bar price %‑change must exceed the same threshold.
5. **Stat Tracking** – On every Buy→Sell pair it logs P/L %, counts total & successful signals, and updates accuracy / average profit.
### **4\. Visual Components**
* **Chart** – Plots fast/slow EMA, ATR‑based dynamic bands, upper/lower BB, plus triangle icons at each signal.
* **Table (top‑right)** – Displays volatility status, BB width %, ATR ratio, current or last signal, plus room to add accuracy/avg P/L lines.
### **5\. Alerts**
Three `alertcondition()` calls let you create TradingView alerts for **Buy**, **Sell**, or **any** signal and forward JSON/Webhooks to external trading bots.
### **6\. Usage Notes**
* The multilayer filter aims to fire only when **trend, volatility, and volume align**, reducing crossover whipsaws.
* Treat the built‑in statistics as a **research aid**; refine parameters (`minVolatilityThreshold`, `atrMultiplier`, etc.) per symbol and timeframe.
* Combine with proper risk management (SL/TP, position sizing) before live deployment.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Untuk akses pantas pada carta, tambah skrip ini kepada kegemaran anda — ketahui lebih lanjut di sini.
Penafian
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Untuk akses pantas pada carta, tambah skrip ini kepada kegemaran anda — ketahui lebih lanjut di sini.