OPEN-SOURCE SCRIPT

Rich's DikFat Money-Counter - ITM/OTM Options Price Viewer

Güncellendi
Script Overview
<p>This Pine Script is a custom indicator designed for use on the TradingView platform. It analyzes options contracts, extracting key information from the options symbol, and then visualizes the relationship between the current price of the underlying asset and the option's strike price. Here’s a detailed explanation of the script and its components:</p>

Key Features
  • Symbol Format Validation: The script checks whether the current symbol matches the expected format of an options symbol (like TSLA250131C400.0).
  • Extraction of Option Components: It extracts the base symbol (e.g., TSLA), expiration date (e.g., 250131), option type (C for call, P for put), and strike price (e.g., 400.0) from the options symbol.
  • Price Difference Calculation: It calculates the difference between the current price of the base asset (e.g., TSLA) and the option's strike price. Depending on whether the option is a call or put, the calculation is adjusted.
  • Visualization: The result is plotted on the chart, with color-coded filling to indicate whether the price difference is positive (ITM) or negative (OTM).


Detailed Explanation of Code Components

1. Indicator Definition
<pre>
indicator("Rich's DikFat Money-Counter - In the Money/Out of the Money Options Price Viewer", shorttitle="Options Price Viewer", overlay=true)
</pre>
<p>This line defines the indicator's name, short title, and specifies that it should be plotted on the price chart (with <code>overlay=true</code>).</p>

2. Symbol Detection
<pre>
currentSymbol = syminfo.ticker
</pre>
<p>This retrieves the symbol of the current asset being analyzed. The script expects this symbol to be an options contract, for example, <code>TSLA250131C400.0</code>.</p>

3. Symbol Format Validation
<pre>
isOptionSymbol = str.length(currentSymbol) >= 9 and str.match(currentSymbol, "^[A-Za-z]+[0-9]{6}[CP][0-9]+(\.[0-9]+)?$") != ""
</pre>
<p>This checks whether the current symbol matches the expected format for an option:</p>
  • The symbol must have at least 9 characters.
  • It must follow a specific pattern: a base symbol (letters), a 6-digit expiration date, an option type (<code>C</code> for Call or <code>P</code> for Put), and a strike price that could include decimals.
    [/list>

    4. Extracting Option Components
    <p>If the symbol is a valid option symbol, the following code extracts the components:</p>
    <pre>
    baseSymbol := str.match(currentSymbol, "^[A-Za-z]+")
    expirationDate := str.substring(currentSymbol, str.length(baseSymbol), str.length(baseSymbol) + 6)
    optionType := str.substring(currentSymbol, str.length(baseSymbol) + 6, str.length(baseSymbol) + 7)
    strikePrice := str.substring(currentSymbol, str.length(baseSymbol) + 7, str.length(currentSymbol))
    </pre>
    • <b>baseSymbol</b>: Extracts the letters representing the stock symbol (e.g., TSLA).
    • <b>expirationDate</b>: Extracts the expiration date in the form of a 6-digit number (e.g., 250131).
    • <b>optionType</b>: Extracts the option type (<code>C</code> for Call, <code>P</code> for Put).
    • <b>strikePrice</b>: Extracts the strike price, which is the value after the option type (e.g., 400.0).
      [/list>

      5. Fetching the Base Symbol Price
      <pre>
      baseSymbolClose = request.security(baseSymbol, "1", close)
      </pre>
      <p>This line uses the <code>request.security()</code> function to get the most recent close price of the base symbol (e.g., TSLA) on a 1-minute chart.</p>

      6. Converting the Strike Price to a Float
      <pre>
      strikePriceFloat = na(strikePrice) ? na : str.tonumber(strikePrice)
      </pre>
      <p>Converts the strike price string to a numerical value (float). If the strike price is not available (i.e., <code>na</code>), it will not proceed with calculations.</p>

      7. Price Difference Calculation
      <pre>
      priceDifference = baseSymbolClose - strikePriceFloat
      </pre>
      <p>This calculates the difference between the base symbol's close price and the strike price. For a <b>Call</b> option, this represents how much the stock price is above or below the strike price.</p>

      8. Adjusting for Put Options
      <pre>
      if optionType == "P"
      priceDifference := strikePriceFloat - baseSymbolClose
      </pre>
      <p>If the option is a <b>Put</b>, the price difference is reversed because a Put option becomes valuable when the stock price is below the strike price.</p>

      9. Plotting the Price Difference
      <pre>
      priceDiffPlot = plot(priceDifference, title="Price Difference (Strike - Base)", color=color.blue, linewidth=2, style=plot.style_line, offset=0)
      </pre>
      <p>This line plots the calculated price difference as a blue line.</p>

      10. Zero Line Plot
      <pre>
      zeroLinePlot = plot(0, "Zero Midline", color=color.white, linewidth=1, style=plot.style_line, offset=0)
      </pre>
      <p>This plots a white line at the zero level. This helps visually separate when the price difference is positive or negative.</p>

      11. Filling the Area Between the Price Difference and Zero Line
      <pre>
      fill(priceDiffPlot, zeroLinePlot, color=color.new(priceDifference > 0 ? color.green : color.red, 70))
      </pre>
      <p>This fills the area between the price difference plot and the zero line:</p>
      • Green if the price difference is positive (indicating the option is <b>In the Money</b> for Calls or <b>Out of the Money</b> for Puts).
      • Red if the price difference is negative (indicating the option is <b>Out of the Money</b> for Calls or <b>In the Money</b> for Puts).
      Final Thoughts
      <p>This script is useful for traders and options investors who want to track the status of an option relative to the current price of the underlying asset. The green and red fill colors provide an immediate visual cue for whether the option is ITM or OTM. By applying this indicator on TradingView, users can easily see whether a particular option is valuable (ITM) or worthless (OTM) based on the current market price of the underlying asset. This makes it a valuable tool for quick decision-making in options trading.</p>
Sürüm Notları
Script Overview
<p>This Pine Script is a custom indicator designed for use on the TradingView platform. It analyzes options contracts, extracting key information from the options symbol, and then visualizes the relationship between the current price of the underlying asset and the option's strike price. Here’s a detailed explanation of the script and its components:</p>

Key Features
  • Symbol Format Validation: The script checks whether the current symbol matches the expected format of an options symbol (like TSLA250131C400.0).
  • Extraction of Option Components: It extracts the base symbol (e.g., TSLA), expiration date (e.g., 250131), option type (C for call, P for put), and strike price (e.g., 400.0) from the options symbol.
  • Price Difference Calculation: It calculates the difference between the current price of the base asset (e.g., TSLA) and the option's strike price. Depending on whether the option is a call or put, the calculation is adjusted.
  • Visualization: The result is plotted on the chart, with color-coded filling to indicate whether the price difference is positive (ITM) or negative (OTM).


Detailed Explanation of Code Components

1. Indicator Definition
<pre>
indicator("Rich's DikFat Money-Counter - In the Money/Out of the Money Options Price Viewer", shorttitle="Options Price Viewer", overlay=true)
</pre>
<p>This line defines the indicator's name, short title, and specifies that it should be plotted on the price chart (with <code>overlay=true</code>).</p>

2. Symbol Detection
<pre>
currentSymbol = syminfo.ticker
</pre>
<p>This retrieves the symbol of the current asset being analyzed. The script expects this symbol to be an options contract, for example, <code>TSLA250131C400.0</code>.</p>

3. Symbol Format Validation
<pre>
isOptionSymbol = str.length(currentSymbol) >= 9 and str.match(currentSymbol, "^[A-Za-z]+[0-9]{6}[CP][0-9]+(\.[0-9]+)?$") != ""
</pre>
<p>This checks whether the current symbol matches the expected format for an option:</p>
  • The symbol must have at least 9 characters.
  • It must follow a specific pattern: a base symbol (letters), a 6-digit expiration date, an option type (<code>C</code> for Call or <code>P</code> for Put), and a strike price that could include decimals.
    [/list>

    4. Extracting Option Components
    <p>If the symbol is a valid option symbol, the following code extracts the components:</p>
    <pre>
    baseSymbol := str.match(currentSymbol, "^[A-Za-z]+")
    expirationDate := str.substring(currentSymbol, str.length(baseSymbol), str.length(baseSymbol) + 6)
    optionType := str.substring(currentSymbol, str.length(baseSymbol) + 6, str.length(baseSymbol) + 7)
    strikePrice := str.substring(currentSymbol, str.length(baseSymbol) + 7, str.length(currentSymbol))
    </pre>
    • <b>baseSymbol</b>: Extracts the letters representing the stock symbol (e.g., TSLA).
    • <b>expirationDate</b>: Extracts the expiration date in the form of a 6-digit number (e.g., 250131).
    • <b>optionType</b>: Extracts the option type (<code>C</code> for Call, <code>P</code> for Put).
    • <b>strikePrice</b>: Extracts the strike price, which is the value after the option type (e.g., 400.0).
      [/list>

      5. Fetching the Base Symbol Price
      <pre>
      baseSymbolClose = request.security(baseSymbol, "1", close)
      </pre>
      <p>This line uses the <code>request.security()</code> function to get the most recent close price of the base symbol (e.g., TSLA) on a 1-minute chart.</p>

      6. Converting the Strike Price to a Float
      <pre>
      strikePriceFloat = na(strikePrice) ? na : str.tonumber(strikePrice)
      </pre>
      <p>Converts the strike price string to a numerical value (float). If the strike price is not available (i.e., <code>na</code>), it will not proceed with calculations.</p>

      7. Price Difference Calculation
      <pre>
      priceDifference = baseSymbolClose - strikePriceFloat
      </pre>
      <p>This calculates the difference between the base symbol's close price and the strike price. For a <b>Call</b> option, this represents how much the stock price is above or below the strike price.</p>

      8. Adjusting for Put Options
      <pre>
      if optionType == "P"
      priceDifference := strikePriceFloat - baseSymbolClose
      </pre>
      <p>If the option is a <b>Put</b>, the price difference is reversed because a Put option becomes valuable when the stock price is below the strike price.</p>

      9. Plotting the Price Difference
      <pre>
      priceDiffPlot = plot(priceDifference, title="Price Difference (Strike - Base)", color=color.blue, linewidth=2, style=plot.style_line, offset=0)
      </pre>
      <p>This line plots the calculated price difference as a blue line.</p>

      10. Zero Line Plot
      <pre>
      zeroLinePlot = plot(0, "Zero Midline", color=color.white, linewidth=1, style=plot.style_line, offset=0)
      </pre>
      <p>This plots a white line at the zero level. This helps visually separate when the price difference is positive or negative.</p>

      11. Filling the Area Between the Price Difference and Zero Line
      <pre>
      fill(priceDiffPlot, zeroLinePlot, color=color.new(priceDifference > 0 ? color.green : color.red, 70))
      </pre>
      <p>This fills the area between the price difference plot and the zero line:</p>
      • Green if the price difference is positive (indicating the option is <b>In the Money</b> for Calls or <b>Out of the Money</b> for Puts).
      • Red if the price difference is negative (indicating the option is <b>Out of the Money</b> for Calls or <b>In the Money</b> for Puts).
      Final Thoughts
      <p>This script is useful for traders and options investors who want to track the status of an option relative to the current price of the underlying asset. The green and red fill colors provide an immediate visual cue for whether the option is ITM or OTM. By applying this indicator on TradingView, users can easily see whether a particular option is valuable (ITM) or worthless (OTM) based on the current market price of the underlying asset. This makes it a valuable tool for quick decision-making in options trading.</p>
CyclesoptionsTrend Analysis

Açık kaynak kodlu komut dosyası

Gerçek TradingView ruhuna uygun olarak, bu komut dosyasının yazarı komut dosyasını açık kaynak olarak yayınlamıştır, böylece yatırımcılar betiği anlayabilir ve doğrulayabilir. Yazar çok yaşa! Ücretsiz olarak kullanabilirsiniz, ancak bu kodun yayında yeniden kullanımı Ev kurallarına tabidir. Bir grafikte kullanmak için favorilere ekleyebilirsiniz.

Bu komut dosyasını bir grafikte kullanmak ister misiniz?

Feragatname