OPEN-SOURCE SCRIPT
Zaktualizowano

Simple Grid Trading v1.0 [PUCHON]

409
Simple Grid Trading v1.0 [PUCHON]

Overview

This is a Long-Only Grid Trading Strategy developed in Pine Script v6 for TradingView. It is designed to profit from market volatility by placing a series of Buy Limit orders at predefined price levels. As the price drops, the strategy accumulates positions. As the price rises, it sells these positions at a profit.

Features

  • Grid Types: Supports both Arithmetic (equal price spacing) and Geometric (equal percentage spacing) grids.
  • Flexible Order Management: Uses strategy.order for precise control and prevents duplicate orders at the same level.
  • Performance Dashboard: A real-time table displaying key metrics like Capital, Cashflow, and Drawdown.
  • Advanced Metrics: Includes Max Drawdown (MaxDD), Avg Monthly Return, and CAGR calculations.
  • Customizable: Fully adjustable price range, grid lines, and lot size.


Dashboard Metrics

The dashboard (default: Bottom Right) provides a quick snapshot of the strategy's performance:

  • Initial Capital: The starting capital defined in the strategy settings.
  • Lot Size: The fixed quantity of assets purchased per grid level.
  • Avg. Profit per Grid: The average realized profit for each closed trade.
  • Cashflow: The total realized net profit (closed trades only).
  • MaxDD: Maximum Drawdown. The largest percentage drop in equity (realized + unrealized) from a peak.
  • Avg Monthly Return: The average percentage return generated per month.
  • CAGR: Compound Annual Growth Rate. The mean annual growth rate of the investment over the specified time period.


Strategy Settings (Inputs)

Grid Settings

  • Upper Price: The highest price level for the grid.
  • Lower Price: The lowest price level for the grid.
  • Number of Grid Lines: The total number of levels (lines) in the grid.
  • Grid Type:
    Arithmetic: Distance between lines is fixed in price terms (e.g., $10, $20, $30).
    Geometric: Distance between lines is fixed in percentage terms (e.g., 1%, 2%, 3%).
  • Lot Size: The fixed amount of the asset to buy at each level.


Dashboard Settings

  • Show Dashboard: Toggle to hide/show the performance table.
  • Position: Choose where the dashboard appears on the chart (e.g., Bottom Right, Top Left).


How It Works

  1. Initialization: On the first bar, the script calculates the price levels based on your Upper/Lower price and Grid Type.
  2. Entry Logic:
    The strategy places Buy Limit orders at every grid level below the current price.
    It checks if a position already exists at a specific level to avoid "stacking" multiple orders on the same line.
  3. Exit Logic:
    For every Buy order, a corresponding Sell Limit (Take Profit) order is placed at the next higher grid level.
  4. MaxDD Calculation:
    • The script continuously tracks the highest equity peak.
    • It calculates the drawdown on every bar (including intra-bar movements) to ensure accuracy.
    • Displayed as a percentage (e.g., 5.25%).


Disclaimer

This script is for educational and backtesting purposes only. Grid trading involves significant risk, especially in strong trending markets where the price may move outside your grid range. Always use proper risk management.
Informacje o Wersji
Update v1.1.0

  • Removed Lot Size Input: The strategy now uses the default order size defined in the Strategy Properties (Settings -> Properties -> Order Size). This allows for more flexible position sizing management directly from the TradingView interface.
  • Dashboard Update: Removed the "Lot Size" row and added a "Version" indicator.

Wyłączenie odpowiedzialności

Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.