OPEN-SOURCE SCRIPT

Random Coin Toss Strategy

124
📌 Overview
This strategy is a probability-based trading simulation that randomly decides trade direction using a coin-toss mechanism and executes trades with a customizable risk-reward ratio. It's designed primarily for testing entry frequency and risk dynamics, not predictive accuracy.

🎯 Core Concept
Every N bars (configurable), the strategy performs a pseudo-random coin toss.

Based on the result:

If heads → Buy

If tails → Sell


Once a position is opened, it sets a Stop-Loss (SL) and Take-Profit (TP) based on a multiple of the current ATR (Average True Range) value.

⚙️ Configurable Inputs
  1. ATR Length Period for ATR calculation, determines volatility basis.
  2. SL Multiplier SL distance = ATR × multiplier (e.g., 1.0 means 1x ATR).
  3. TP Multiplier TP distance = ATR × multiplier (e.g., 2.0 = 2x ATR).
  4. Entry Frequency Bars to wait between each new coin toss decision.
  5. Show TP/SL Zones Toggle on/off for drawing visual TP and SL zones.
  6. Box Size Number of bars used to define the width of the TP/SL boxes.


🔁 Entry & Exit Logic
Entry:
Happens only when no current position exists and it's the correct bar interval.
Entry direction is randomly decided.

Exit:
Positions exit at either:
  1. Take-Profit (TP) level
  2. Stop-Loss (SL) level

Both are calculated using the configured ATR-based distances.


🖼️ Visual Features
TP and SL zones:
Rendered as shaded rectangles (boxes) only once per trade.
Green box for TP zone, red box for SL zone.
Automatically deleted and redrawn for each new trade to avoid chart clutter.

ATR Display Table:
A minimal info table at the top-right shows the current ATR value.
Updates every few bars for performance.

🧪 Use Cases
Ideal for risk-reward modeling, strategy prototyping, and understanding how volatility-based SL/TP behavior affects results.

Great for backtesting frequency, RR tweaks (e.g., 2:5 or 3:1), and execution structure in random conditions.

⚠️ Disclaimer
Since the trade direction is random, this script is not meant for predictive trading but serves as a powerful experiment framework for studying how SL, TP, and volatility interact with random chance in a controlled, repeatable system.

免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。