<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Gor Dragongor on Medium]]></title>
        <description><![CDATA[Stories by Gor Dragongor on Medium]]></description>
        <link>https://medium.com/@gorx1?source=rss-9032587a0ac4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*4fyQdqfvMMlardSheRUeJw.jpeg</url>
            <title>Stories by Gor Dragongor on Medium</title>
            <link>https://medium.com/@gorx1?source=rss-9032587a0ac4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 09:59:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gorx1/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Adaptive Window Size]]></title>
            <link>https://medium.com/@gorx1/adaptive-window-size-3469d8803bd3?source=rss-9032587a0ac4------2</link>
            <guid isPermaLink="false">https://medium.com/p/3469d8803bd3</guid>
            <category><![CDATA[quantitative-finance]]></category>
            <category><![CDATA[time-series-analysis]]></category>
            <dc:creator><![CDATA[Gor Dragongor]]></dc:creator>
            <pubDate>Sun, 08 Dec 2024 14:18:01 GMT</pubDate>
            <atom:updated>2024-12-08T14:24:31.291Z</atom:updated>
            <content:encoded><![CDATA[<p>I’m posting it here because for an unknown reason TradingView banned this publication, I asked why and asked to reconsider, but given the history of how their moderation works it could be a dead end.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ez-KBKPn-KD3kD3RPV_7IA.png" /></figure><pre>//@version=6<br>indicator(&#39;Adaptive Window Size&#39;, &#39;AWS&#39;, timeframe = &#39;&#39;, timeframe_gaps = true)<br><br><br>qsfs(src) =&gt;<br>    var start = src<br>    var total = 0.0<br><br>    total += math.abs(src - nz(src[1], src))<br><br>    net = math.abs(src - start)<br><br>    math.sqrt(nz(net / total, 1))<br><br>aws(sig) =&gt;<br>    math.min(math.ceil(math.exp(1 / sig)), bar_index + 1)<br><br><br>source = input(close)<br><br><br>sig = qsfs(source)<br>aws = aws (sig   )<br>mws = bar_index + 1 <br><br><br>plot(aws, &#39;AWS&#39;, color.purple, 1, plot.style_stepline                        )<br>plot(mws, &#39;MWS&#39;, color.gray  , 1, plot.style_stepline, display = display.none)</pre><p>🙏🏻 … this is the prequel to a significant drop about to arrive with ETA = [1, 2] days, before I switch to other matters in the Universe. I think I’m also gonna drop weighted Fourier / smth based on it a bit later, just so it can be googled easily for every1 on the internet, but that one is not so significant…</p><p>This one, @ O(1) algo complexity on data updates, offers you properly gained adaptive length that you can simply plug into all your stuff without worrying about anything anymore, esp if you don’t consider seasonalities and use moving windows and wonder which length should you pick. Just copy the first 2 functions and the lines 22 &amp; 23. That’s exactly what you see &amp; what I did on the chart above, I’ve just put these inside my <a href="https://www.tradingview.com/script/4LByGQj0-Weighted-percentile-nearest-rank/">WPNR</a> script.</p><p>…</p><p>Based on <a href="https://www.tradingview.com/script/lSMGNb08-Quick-scan-for-signal/">QSFS</a> , (had a doubt or 2 bout sqrt transforming the final result there, turned out it was all true after all) we define AWS (Adaptive Window Size) as:</p><pre>aws(sig) =&gt;<br>    math.min(math.ceil(math.exp(1 / sig)), bar_index + 1)</pre><p><em>where sig is output of qsfs()</em></p><p>I’ve tried couple of dozens of formulas on real and synthetic data, yet only the main R&amp;D I was doing (the incoming drop) provided the undisputed answer. So the logic behind exp(1 / sig) and sqrt transforming the final ratio in qsfs() will be explaned very soon but not here. As usually bruteforcing rarely helps, it’s all about the way of conscious strive to the truth. Anyways, you can confidently use this one from now on, this is really it, a piece of the Source.</p><p><em>Have your ever had fun about adaptive methods that require hyperparameters (in worst case, the ‘length’ itself 💀💀 xD)? Me too, ironic isn’t, tho it’s everywhere around in mainstream.</em></p><p>∞</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3469d8803bd3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mean Price]]></title>
            <link>https://medium.com/@gorx1/mean-price-006a2e0f0d87?source=rss-9032587a0ac4------2</link>
            <guid isPermaLink="false">https://medium.com/p/006a2e0f0d87</guid>
            <category><![CDATA[sampling-methods]]></category>
            <category><![CDATA[quantitative-finance]]></category>
            <category><![CDATA[time-series-analysis]]></category>
            <category><![CDATA[data-aggregation]]></category>
            <dc:creator><![CDATA[Gor Dragongor]]></dc:creator>
            <pubDate>Sun, 24 Nov 2024 22:09:28 GMT</pubDate>
            <atom:updated>2024-11-24T22:09:28.475Z</atom:updated>
            <content:encoded><![CDATA[<pre>//@version=5<br>indicator(&#39;Mean Price&#39;, &#39;MP&#39;, true, timeframe = &#39;&#39;)<br><br>mean_price(op, hi, lo, cl, bt, st, robust = false) =&gt;<br>    bar_nt = (op * 1 + hi * 2 + lo * 2 + cl * 3 + bt * 2 + st * 2) / 12<br>    bar_up = (op * 1 + hi * 4 + lo * 2 + cl * 5 + bt * 3 + st * 3) / 18<br>    bar_dn = (op * 1 + hi * 2 + lo * 4 + cl * 5 + bt * 3 + st * 3) / 18<br><br>    hc = math.abs(hi - cl)<br>    lc = math.abs(lo - cl)<br><br>    mean_price = if cl &gt;  op<br>        bar_up<br>    else         if cl &lt;  op<br>        bar_dn<br>    else         if cl == op<br>        if      hc &lt;  lc<br>            bar_up<br>        else if hc &gt;  lc<br>            bar_dn<br>        else if hc == lc<br>            bar_nt<br><br>    robust ? bar_nt : mean_price<br><br>robust = input(false)<br><br>src = mean_price(open, high, low, close, hl2, hl2, robust)<br><br>plot(src, &#39;Source&#39;, color.purple, 2, plot.style_cross)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5KlEROpLzq0PSgp3TRo66g.png" /><figcaption>one way you can visualize it</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gtAUeYdWF1dJWOEZLuEQxA.png" /><figcaption>another way you can visualize it</figcaption></figure><p>Available on TradingView:</p><p><a href="https://www.tradingview.com/script/J2cucDtO-Mean-Price/">Mean Price</a></p><p>…</p><p>This method of financial time series (aka bars) downsampling is literally, naturally, and thankfully the best you can do in terms of maximizing info gain. You can finally chill and feed it to your studies &amp; eyes, and probably use nothing else anymore.</p><p>(HL2 and <a href="https://www.tradingview.com/v/LdXVFeYb/">occ3</a> also have use cases, but other aggregation methods? Not really, even if they do, the use cases are ‘very’ specific). Tho in order to understand why, you gotta read the following wall, or just believe me telling you, ‘I put it on my momma’.</p><p>The true story about trading volumes and why this is all a big misdirection<br><em>Actually, you don’t need to be a quant to get there. All you gotta do is stop blindly following other people’s contextual (at best) solutions, eg OC2 aggregation xD, and start using your own brain to figure things out.</em></p><p>Every individual trade (basically an imprint on 1D price space that emerges when market orders hit the order book) has several features like: price, time, volume, AND direction (Up if a market buy order hits the asks, Down if a market sell order hits the bids). Now, the last two features — volume and direction — can be effectively combined into one (by multiplying volume by 1 or -1), and this is probably how every order matching engine should output data. If we’re not considering size/direction, we’re leaving data behind. Moreover, trades aren’t just one-price dots all the time. One trade can consume liquidity on several levels of the order book, so a single trade can be several ticks big on the price axis.</p><p><em>You may think now that there are no zero-volume ticks. Well, yes and no. It depends on how you design an exchange and whether you allow intra-spread trades/mid-spread trades (now try to Google it). Intra-spread trades could happen if implemented when a matching engine receives both buy and sell orders at the same microsecond period. This way, you can match the orders with each other at a better price for both parties without even hitting the book and consuming liquidity. Also, if orders have different sizes, the remaining part of the bigger order can be sent to the order book. Basically, this type of trade can be treated as an OTC trade, having zero volume because we never actually hit the book — there’s no imprint. Another reason why it makes sense is when we think about volume as an impact or imbalance act, and how the medium (order book in our case) responds to it, providing information. OTC and mid-spread trades are not aggressive sells or buys; they’re neutral ticks, so to say. However huge they are, sometimes many blocks on NYSE, they don’t move the price because there’s no impact on the medium (again, which is the order book) — they’re not providing information.</em></p><p>… Now, we need to aggregate these trades into, let’s say, 1-hour bars (remember that a trade can have either positive or negative volume). We either don’t want to do it, or we don’t have this kind of information. What we can do is take already aggregated OHLC bars and extract all the info from them. Given the market is fractal, bars &amp; trades gotta have the same set of features:</p><p>- Highest &amp; lowest ticks (high &amp; low) &lt;- by price;<br>- First &amp; last ticks (open &amp; close) &lt;- by time;<br>- Biggest and smallest ticks &lt;- by volume.*</p><p>*e.g., in the array [224, 234, -234, -23, 2323, -213, -534, -1212, 11, 24, -43],<br>2323: biggest trade,<br>-1212: smallest trade.</p><p>Now, in our world, somehow nobody started to care about the biggest and smallest trades and their inclusion in OHLC data, while this is actually natural. It’s the same way as it’s done with high &amp; low and open &amp; close: we choose the minimum and maximum value of a given feature/axis within the aggregation period.</p><p>So, we don’t have these 2 values: biggest and smallest ticks. The best we can do is infer them, and given the fact the biggest and smallest ticks can be located with the same probability everywhere, all we can do is predict them in the middle of the bar, both in time and price axes. That’s why you can see two HL2’s in each of the 3 formulas in the code.</p><p><em>So, summed up absolute volumes that you see in almost every trading platform are actually just a derivative metric, something that I call Type 2 time series in my own (proprietary ‘for now’) methods. It doesn’t have much to do with market orders hitting the non-uniform medium (aka order book); it’s more like a statistic. Still wanna use VWAP? Ok, but you gotta understand you’re weighting Type 1 (natural) time series by Type 2 (synthetic) ones.</em></p><p>How to combine all the data in the right way (khmm khhm ‘order’)</p><p>Now, since we have 6 values for each bar, let’s see what information we have about them, what we don’t have, and what we can do about it:<br>- Open and close: we got both when and where (time (order) and price);<br>- High and low: we got where, but we don’t know when;<br>- Biggest &amp; smallest trades: we know shit, we infer it the way it was described before.’</p><p>By using the location of the close &amp; open prices relative to the high &amp; low prices, we can make educated guesses about whether high or low was made first in a given bar. It’s not perfect, but it’s ultimately all we can do — this is the very last bit of info we can extract from the data we have.</p><p>There are 2 methods for inferring volume delta (which I call simply volume) that are presented everywhere, even here on TradingView. Funny thing is, this is actually 2 parts of the 1 method. I wonder how many folks see through it xD. The same method can be used for both inferring volume delta AND making educated guesses whether high or low was made first.</p><p>Imagine and/or find the cases on your charts to understand faster:</p><p>* Close &gt; open means we have an up bar and probably the volume is positive, and probably high was made later than low.<br>* Close &lt; open means we have a down bar and probably the volume is negative, and probably low was made later than high.<br><em>Now that’s the point when you see that these 2 mentioned methods are actually parts of the 1 method:</em></p><p>If close = open, we still have another clue: distance from open/close pair to high (HC), and distance from open/close pair to low (LC):</p><p>* HC &lt; LC, probably high was made later.<br>* HC &gt; LC, probably low was made later.<br>And only if close = open and HC = LC, only in this case we have no clue whether high or low was made earlier within a bar. We simply don’t have any more information to even guess. This bar is called a neutral bar.</p><p>At this point, we have both time (order) and price info for each of our 6 values. Now, we have to solve another weighted average problem, and that’s it. We’ll weight prices according to the order we’ve guessed. In the neutral bar case, open has a weight of 1, close has a weight of 3, and both high and low have weights of 2 since we can’t infer which one was made first. In all cases, biggest and smallest ticks are modeled with HL2 and weighted like they’re located in the middle of the bar in a time sense.</p><p>P.S.: I’ve also included a “robust” method where all the bars are treated like neutral ones. I’ve used it before; obviously, it has lesser info gain -&gt; works a bit worse.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=006a2e0f0d87" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>