OPEN-SOURCE SCRIPT

Dynamic Gann Levels [XrayTrades]

アップデート済
This indicator dynamically captures the highest and lowest points visible on the chart and calculates Gann Support and Resistance Levels. The inputs are detailed below.

Why create this indicator?
There is no other indicator with the same functionality on TradingView.
These calculations are time-consuming; the speed at which this indicator calculates any number of rotations and degrees and visually displays them on the chart is invaluable to me, and hopefully others who use/perform these calculations.

Works on any time frame:
Year, month, week, day, etc. Smaller timeframes (intraday) for higher prices may require adjusting the y-axis of the chart after the calculation of levels due to the nature of squaring numbers.

Inputs:
  • Resistance: Up (from pivot low) - This toggles on/off levels calculated from the lowest point visible on the chart’s current view.
  • Support: Down (from pivot high) - This toggles on/off levels calculated from the highest point visible on the chart’s current view.
  • 360 - Toggles on/off the levels of full rotations (360 degrees) from price
  • 180 - Toggles on/off the levels of half rotations (180 degrees) from price
  • 90 - Toggles on/off the levels of quarter rotations (90 degrees) from price
  • 45 - Toggles on/off the levels of eighth rotations (45 degrees) from price
  • Full Rotations Visible - The number of rotations to be displayed on the chart


How to use this indicator:
  1. Adjust chart window to change the highs and lows.
  2. Select the degrees, direction, and number of rotations in the indicator settings.
  3. The colored values beside the indicator represent the values (high and low) used in generating the Gann levels. Should the cursor be on the chart, ensure it is to the right of the high and low pivots, as this is dynamic in TradingView depending upon cursor location. Note: This is only for the user to know which value(s) are used; cursor position does not impact actual calculations and levels displayed.
  4. The levels will be drawn to the right of the most recent price, labeled with the degrees and direction as well as the price value at the level.


About the calculations:
These calculations are derived from the Natural Square Calculator of Gann Theory, also known as the Square of Nines.
  • Details:
    Take the square root of the selected value (lowest and or highest point).
    Add (for up or subtract for down) 0.25 for every 45 degrees of rotation to the desired calculation.
    Square this. Round to two decimal places.
  • Ex: Low of 100. Calculate Gann resistance level for 360 degrees. (√(100)+2)² = 144.
  • Ex: High of 100. Calculate Gann support level for 180 degrees. (√(100)-1)² = 81.
リリースノート
Added Feature - Scaling Down Large Numbers

Why: Requested by indicator users.
What: Allows the indicator to scale down numbers larger than 1000 (normalize to three digits) for Gann calculations and then rescale (restore) the output to the original magnitude before charting levels.
For example: $65,000 will be scaled down to 650 for Gann calculations, and then the outputs will be rescaled (multiplied by 100 in this instance) before being drawn on the chart.

Toggle: By default, this operation is enabled but can be turned off in the settings.

How: Details on the mathematics behind this feature:

  1. Take the logarithm of the highest price visible on the chart. Divide this by the logarithm of 10 and subtract 3, stopping at 0. This gives the scaling magnitude.
    magnitude = math.max(0, math.ceil(math.log(high_vis) / math.log(10)) - 3)
  2. Divide the highest (or lowest) visible price on the chart by 10 raised to magnitude (10^magnitude).
    high_vis / math.pow(10, magnitude)
    low_vis / math.pow(10, magnitude)
  3. Perform regular Gann calculations with these as the high and low inputs (see indicator description above for details).
  4. Scale up the Gann calculation outputs by multiplying by10^magnitude and draw to chart.
    gann * math.pow(10, magnitude)

リリースノート
Added Features - Label size and color selections

Access in indicator settings: 'Label Size' and color selection options.
GannPivot points and levelsSupport and Resistance

オープンソーススクリプト

TradingViewの精神に則り、このスクリプトの作者は、トレーダーが理解し検証できるようにオープンソースで公開しています。作者に敬意を表します!無料で使用することができますが、このコードを投稿で再利用するには、ハウスルールに準拠する必要があります。 お気に入りに登録してチャート上でご利用頂けます。

チャートでこのスクリプトを利用したいですか?

免責事項