OPEN-SOURCE SCRIPT

asami.factor Buy/Sell Strategy

53
### **1\. Purpose**

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.

Declinazione di responsabilità

Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.