asami.factor Buy/Sell Strategy

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.
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Per un accesso rapido a un grafico, aggiungi questo script ai tuoi preferiti: per saperne di più clicca qui.
Declinazione di responsabilità
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Per un accesso rapido a un grafico, aggiungi questo script ai tuoi preferiti: per saperne di più clicca qui.