OPEN-SOURCE SCRIPT

Share Size

93
Purpose: The "Share Size" indicator is a powerful risk management tool designed to help traders quickly determine appropriate share/contract sizes based on their predefined risk per trade and the current market's volatility (measured by ATR). It calculates potential dollar differences from recent highs/lows and translates them into a recommended share/contract size, accounting for a user-defined ATR-based offset. This helps you maintain consistent risk exposure across different instruments and market conditions.

How It Works: At its core, the indicator aims to answer the question: "How many shares/contracts can I trade to keep my dollar risk within limits if my stop loss is placed at a recent high or low, plus an ATR-based buffer?"

Price Difference Calculation: It first calculates the dollar difference between the current close price and the high and low of the current bar (Now) and the previous 5 bars (1 to 5).
Tick Size & Value Conversion: These price differences are then converted into dollar values using the instrument's specific tickSize and tickValue. You can select common futures contracts (MNQ, MES, MGC, MCL), a generic "Stock" setting, or define custom values.
ATR Offset: An Average True Range (ATR) based offset is added to these dollar differences. This offset acts as a buffer, simulating a stop loss placed beyond the immediate high/low, accounting for market noise or volatility.
Risk-Based Share Size: Finally, using your Default Risk ($) input, the indicator calculates how many shares/contracts you can take for each of the 6 high/low scenarios (current bar, 5 previous bars) to ensure your dollar risk per trade remains constant.
Dynamic Table: All these calculations are presented in a clear, real-time table at the bottom-left of your chart. The table dynamically adjusts its "Label" to show the selected symbol preset, making it easy to see which instrument's settings are currently being used. The "Shares" rows indicate the maximum shares/contracts you can trade for a given risk and stop placement. The cells corresponding to the largest dollar difference (and thus smallest share size) for both high and low scenarios are highlighted, drawing your attention to the most conservative entry points.
Key Benefits:

Consistent Risk: Helps maintain a consistent dollar risk per trade, regardless of the instrument or its current price/volatility.
Dynamic Sizing: Automatically adjusts share/contract size based on market volatility and your chosen stop placement.
Quick Reference: Provides a real-time, easy-to-read table directly on your chart, eliminating manual calculations.
Informed Decision Making: Assists in quickly assessing trade opportunities and potential position sizes.
Setup Parameters (Inputs)
When you add the "Share Size" indicator to your chart, you'll see a settings dialog with the following parameters:

1. Symbol Preset:

Purpose: This is the primary setting to define the tick size and value for your chosen trading instrument.
Options:
MNQ (Micro Nasdaq 100 Futures)
MES (Micro E-mini S&P 500 Futures)
MGC (Micro Gold Futures)
MCL (Micro Crude Oil Futures)
Stock (Generic stock setting, with tick size/value of 0.01)
Custom (Allows you to manually input tick size and value)
Default: MNQ
Importance: Crucial for accurate dollar calculations. Ensure this matches the instrument you are trading.
2. Tick Size (Manual Override):

Purpose: Only used if Symbol Preset is set to Custom. This defines the smallest price increment for your instrument.
Type: Float
Default: 0.25
Hidden: This input is hidden (display=display.none) unless "Custom" is selected. You might need to change display=display.none to display=display.inline in the code if you want to see and adjust it directly in the settings for "Custom" mode.
3. Tick Value (Manual Override):

Purpose: Only used if Symbol Preset is set to Custom. This defines the dollar value of one tickSize increment.
Type: Float
Default: 0.50
Hidden: This input is hidden (display=display.none) unless "Custom" is selected. Similar to Tick Size, you might need to adjust its display property if you want it visible.
4. Default Risk ($):

Purpose: This is your maximum desired dollar risk per trade. All share size calculations will be based on this value.
Type: Float
Default: 50.0
Hidden: This input is hidden (display=display.none). It's a critical setting, so consider making it visible by changing display=display.none to display=display.inline in the code if you want users to easily adjust their risk.
ATR Offset Settings (Group): This group of settings allows you to fine-tune the ATR-based buffer added to your potential stop loss.

5. ATR Offset Length:

Purpose: Defines the lookback period for the Average True Range (ATR) calculation used for the offset.
Type: Integer
Default: 7
Hidden: This input is hidden (display=display.none).
6. ATR Offset Timeframe:

Purpose: Specifies the timeframe on which the ATR for the offset will be calculated. This allows you to use ATR from a higher timeframe for your stop buffer, even if your chart is on a lower timeframe.
Type: Timeframe string (e.g., "1" for 1 minute, "60" for 1 hour, "D" for Daily)
Default: "1" (1 Minute)
Hidden: This input is hidden (display=display.none).
7. ATR Offset Multiplier (x ATR):

Purpose: Multiplies the calculated ATR value to determine the final dollar offset added to your high/low price difference. A value of 1.0 means one full ATR is added. A value of 0.5 means half an ATR is added.
Type: Float
Minimum Value: 0 (no offset)
Default: 1.0
Hidden: This input is hidden (display=display.none).

免責聲明

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