OPEN-SOURCE SCRIPT

Dynamic Testing

Input Parameters
  • `lookbackPeriod`: Number of candles to check for determining the highest high (resistance) and lowest low (support) levels.
  • `atrPeriod`: The period for calculating the Average True Range (ATR), a measure of market volatility.
  • `atrMultiplierSL`: Multiplier to calculate the stop-loss distance relative to the ATR.
  • `atrMultiplierTP1` and `atrMultiplierTP2`: Multipliers to calculate two take-profit levels relative to ATR.
  • `rewardToRisk`: The ratio between reward (profit) and risk (stop loss) for trade management.


---

Core Calculations
ATR (Average True Range)
atr = ta.atr(atrPeriod)

ATR is computed using the specified period to gauge price volatility.

Volume SMA
volumeSMA = ta.sma(volume, atrPeriod)

The script calculates the simple moving average of volume over the same period as ATR. This is used as a threshold for validating high-volume scenarios.

---

Support and Resistance Levels
  • `support`: Lowest price over the last `lookbackPeriod` candles.
  • `resistance`: Highest price over the same period.
  • `supportBuffer` and `resistanceBuffer`: These are "buffered" zones around support and resistance, calculated using half of the ATR to prevent false breakouts.


---

Entry Scenarios
Bullish Entry (`isBullishEntry`)
  1. The close is above the buffered support level.
  2. The low of the current candle touches or breaks below the support level.
  3. The trading volume is greater than the `volumeSMA`.


Bearish Entry (`isBearishEntry`)
  1. The close is below the buffered resistance level.
  2. The high of the current candle touches or exceeds the resistance level.
  3. The trading volume is greater than the `volumeSMA`.


---

Box Visualization
Bullish and Bearish Boxes
  • Bullish Box (`bullishBox`):
    - A green, semi-transparent rectangle around the support level to highlight the bullish entry zone.
    - Dynamically updates based on recent price action.
  • Bearish Box (`bearishBox`):
    - A red, semi-transparent rectangle around the resistance level to highlight the bearish entry zone.
    - Adjusts similarly as price evolves.


---

Stop Loss and Take Profit Calculations
Bullish Trades
  • Stop Loss (`bullishSL`): Calculated as [code]support - atrMultiplierSL * ATR[/code].
  • Take Profit 1 (`bullishTP1`):[code]support + rewardToRisk * atrMultiplierTP1 * ATR[/code].
  • Take Profit 2 (`bullishTP2`):[code]support + rewardToRisk * atrMultiplierTP2 * ATR[/code].


Bearish Trades
  • Stop Loss (`bearishSL`):[code]resistance + atrMultiplierSL * ATR[/code].
  • Take Profit 1 (`bearishTP1`):[code]resistance - rewardToRisk * atrMultiplierTP1 * ATR[/code].
  • Take Profit 2 (`bearishTP2`):[code]resistance - rewardToRisk * atrMultiplierTP2 * ATR[/code].


---

Visualization for Key Levels
Bullish Scenario
  • Green lines represent `bullishTP1` and `bullishTP2` for profit targets.
  • A red line indicates the `bullishSL`.
  • Labels like "TP1," "TP2," and "SL" dynamically appear at respective levels to make the targets and risk visually clear.


Bearish Scenario
  • Red lines represent `bearishTP1` and `bearishTP2`.
  • A green line marks the `bearishSL`.
  • Similar dynamic labeling for `TP1`, `TP2`, and `SL` at corresponding bearish levels.


---

Dynamic Updates
  • Both the entry boxes and key level visualizations (lines and labels) adjust dynamically based on real-time price and volume data.


---

Purpose
  1. Identify high-probability bullish and bearish trade setups.
  2. Define clear entry zones (using boxes) and exit levels (TP1, TP2, SL).
  3. Incorporate volatility (via ATR) and volume into decision-making.


---

Technical Summary
  • Dynamically visualize support/resistance levels.
  • Set risk-managed trades using ATR-based stop-loss and profit levels.
  • Automate visual trade zones for enhanced chart clarity.


---
Bill Williams IndicatorsBreadth IndicatorsCandlestick analysisstoploss

Скрипт с открытым кодом

В истинном духе TradingView автор этого скрипта опубликовал его с открытым исходным кодом, чтобы трейдеры могли понять, как он работает, и проверить на практике. Вы можете воспользоваться им бесплатно, но повторное использование этого кода в публикации регулируется Правилами поведения. Вы можете добавить этот скрипт в избранное и использовать его на графике.

Хотите использовать этот скрипт на графике?

Отказ от ответственности