TradingView
dax50
16. Nov. 2020 09:56

Daily GAP Stats 

NIO Inc.NYSE

Beschreibung

I did not write the script from scratch but rather started editing code of an existing one. The original code came from a script called GAP DETECTOR by @Asch-


First up: I am a trader, not a programmer and therefore my code most likely is inefficient. If someone with more expertise would like to help and optimize it - feel free to get in touch, I am always happy to learn some new tricks. :)




This script does 2 things:

- It shows daily gaps stats based on user inputs
- It shows color coded labels on gap days with additional information in tooltips (important: make sure to read 'known issues/limitations' at the end)


User Inputs
==========

Although the input dialog is pretty straight forward, I do a quick rundown:

- Length: max lookback time

- Gap Direction: self explanatory

- Show All Gaps | Cont Only | Reversal Only | Off:
This refers to the way labels are displayed on gap days (again: make sure to read known issues/limitations!)
- Show All Gaps: does what it says
- Cont Only: only shows gaps where price continued in the gap direction. If you filter for gap ups and chose 'Cont only' you will only see labels on gap days where price closed above the open (and vice versa if you scan for gap downs).
- Reversal Only: you will only see labels for closes below the open on gap up days (and the opposite on gap down days)
- Off: self explanatory

- Gap Measure in ATR/PCT: self explanatory, ATR is calculated over a 10d period

- Gap Size (Abs Values): no negative values allowed here. If you filter for gap downs and enter 3 it means it will show gaps where the stock fell more than 3 ATR/PCT on the open.

- RVOL Factor: along with significant gaps should come significant volume. RVOL = volume of the gap day / 20d average volume

- Viewing Options: Placing the stats label in the window is a bit tricky (see knonw issues/limitations) and I was not sure which way I liked better. See for yourself what works best for you.


Known Isusses/Limitations:
=======================


- Positioning of the stats table:
As to my knowledge, Tradingview only allows label positioning relative to price and not relative to the chart window. I tried to always display the gap stats table in the upper right corner, using 52wk high as y-coordinate. This works ok most of the time, but is not pretty. If anybody has some fancy way to tag the label in a fixed position, please get in touch.

- Max number of labels per script:
TradingView has a limitation that allows a maxium of ~50 labels per script. If there are more labels, TradingView will automatically cut the oldest ones, without any notification. I have found this behaviour to be rather inconsistent - sometimes it'll dump labels even if there are a lot fewer than 50. Hopefully TradingView will drop this limitation at one point in the future.
Important: The inconsistent display of the gap day labels has NO INFLUENCE on the calculations in the gap stats table - the count and the calculations are complete and correct!

Versionshinweise

Option 'OFF' for show labels on gap down days was missing.

Versionshinweise

- added missing documentation
- changed default viewing option to 'Label' from 'Tooltip'

Versionshinweise

fixed an issue with calculation when there was only one gap (showing 0% vs 100%)

Versionshinweise

Fixed: label/tooltip with stats disappeared when there were not enough bars on the chart to calculate the y-coordinate for positioning the label

Versionshinweise

Updated example chart

Versionshinweise

Fixed: Now showing 'No Gaps to show' when there are 0 gaps in the underlying stock (before the indicator completely disappeared w/o a message)

Versionshinweise

Updated the calculation method for the label positioning on the chart: if price history has fewer than 250 bars (needed to determine the 52wk high/low) it will now use the historoy highest high / lowest low for the calculation

Versionshinweise

...

Versionshinweise

UPDATE: Tradingview increased the number of labels from 50 to 500 per script, so limitation #2 is pretty much gone. tradingview.com/blog/en/drawings-count-new-parameters-21535/

UPDATE: Added the description to the code.

Versionshinweise

.

Versionshinweise

- Updated label style
- Fixed minor calculation error
Kommentare
Davidsippl
Hi, sehr hilfreiches Skript. Andere verlangen dafür Geld, vielen Dank!
Eine Frage was genau kann ich unter der Angabe "Avg Close in Range" verstehen? Bezieht sich das auf den Vortag?
drexdis
Hi, nice indicator. I see the up arrows but the stats text on the right side of the screen doesn't appear at all like in your photo.
Why are the gap up stats missing? Thanks
Stockinger
Servus,
ich benutze deine gap stats für Stocks. Sehr schöne Arbeit und funktioniert echt gut. Wäre es möglich bei dem RVOL Factor einfach nur eine fixe Volumenmenge eingeben zu können ohne das Teilen durch den 20 Tage Durchschnitt ?
dax50
@Stockinger, geht bestimmt...ich bin gerade unterwegs, daher komme ich frühstens Mitte nächster Woche dazu. VG.
Stockinger
@dax50, danke für die schnelle Antwort.
dax50
@Stockinger, ich komme im Moment leider nicht dazu, da die Umstellung doch mehr Aufwand ist, als ursprünglich gedacht - sorry. Mit Einführung von Pine Script 5 sind viele nützliche Features eingeführt worden (z.B. was die Darstellung / Positionierung der Fenster betrifft), so dass ich in einer ruhigen Minute eine komplette Überarbeitung des Scripts angehen und Deinen Wunsch berücksichtigen werde. Aber wann genau das sein wird, kann ich leider noch nicht sagen.
Davidsippl
@dax50, Hey ich finde dein Skript super und würde mich sehr freuen über ein Update!!!
vicosobase
Excellent
LaMpiR
Thank you. Is there a way to fix the position, since it keeps moving?
dax50
@LaMpiR, last time I checked there was no way to use a fixed position within a chart window, instead it was only possible to position the window relative to the datapoints of the price chart.
Mehr