Od tvrdého filtru k vrstvenému kontextu: Shannonova entropie a multi-timeframe LSTM v MetaTraderu 5

V tradingu bývá častou chybou snaha hledat signál dřív, než je vůbec vyhodnoceno, v jakém typu prostředí se trh nachází. Směrový model může na grafu působit přesvědčivě i v situaci, kdy je cenová řada z hlediska informace příliš chaotická na to, aby nesla použitelnou prediktivní strukturu. Právě tady se ukazuje rozdíl mezi popisem pohybu a posouzením kontextu.

V dřívějších verzích mých nástrojů jsem tento problém řešil pomocí Shannonovy entropie jako samostatného filtru. Myšlenka byla jednoduchá: pokud trh vykazuje příliš vysokou míru neuspořádanosti, nemá smysl přikládat predikčnímu výstupu velkou váhu. Tento přístup měl praktický význam, ale ukázal i své limity. Pevný práh na jednom timeframe byl příliš hrubý. V některých situacích odfiltroval nejen šum, ale i okamžiky, kdy se na vyšším timeframe formovala smysluplná struktura.

Současná architektura proto stojí na jiném principu. Shannonova entropie nezmizela, ale změnila roli.

Co Shannonova entropie v trhu skutečně říká

Shannonova entropie je míra neurčitosti. V cenových řadách ji lze chápat jako hrubý odhad toho, nakolik jsou krátkodobé změny uspořádané, nebo naopak rozpadlé do chaotického režimu. Sama o sobě neříká, kam trh půjde. Říká spíš, jak moc má smysl věřit, že aktuální pohyb nese čitelnou strukturu.

To je důležité. Vysoká volatilita ještě neznamená vysokou informaci. Trh může být dramatický a zároveň statisticky málo čitelný. Velké svíčky, prudké obraty a rychlé průrazy často vyvolávají dojem silného signálu, ale ve skutečnosti mohou představovat prostředí s nízkou prediktivní hodnotou.

Z tohoto pohledu je entropie užitečná ne jako generátor signálu, ale jako vrstva kontextu.

Proč nestačil tvrdý entropický filtr

První použitelná verze architektury pracovala s entropií jako s bránou. Pokud pomalá entropie překročila zvolenou mez, indikátor přestal generovat výstup nebo ho potlačil natolik, že obchodní rozhodnutí bylo de facto zablokováno.

To mělo jednu výhodu: v obdobích zjevného chaosu systém snižoval počet impulzivních vstupů. Pro praktické obchodování to nebyl zanedbatelný efekt.

Zároveň se ale ukázalo, že binární logika typu „nízká entropie = čitelné, vysoká entropie = nečitelné“ nevystihuje skutečné chování trhu dost přesně. Problém byl hlavně v tom, že tržní kontext není jednovrstevný. Nízký timeframe může vypadat chaoticky, zatímco vyšší timeframe drží stabilní směr, akumulaci nebo pokračující momentum. V takovém případě pevný filtr zakrýval příliš mnoho.

To vedlo k zásadní úpravě: entropie přestala být samostatným rozhodovacím pravidlem a stala se jednou ze součástí vstupních dat.

Nový přístup ve verzi 5.23

Ve verzi LSTM_Pure_MTF_Predictor v5.23 je model postaven jako čistá multi-timeframe LSTM architektura s GPU akcelerací přes MQL5GPULibrary_LSTM.dll. Základní logika je vrstvená, ale ne už binárně.

Model v každém kroku sekvence nepracuje jen s jedním timeframe. Současně čte tři časové rámce, například aktuální graf, H1 a H4. Pro každý timeframe se vytváří sada příznaků, která zahrnuje nejen tvar svíčky, momentum, ATR poměr, pozici v lokálním rozpětí a změny objemu, ale nově také:

  • rychlou Shannonovu entropii,
  • pomalou Shannonovu entropii,
  • rozdíl mezi rychlou a pomalou entropií.

To znamená, že entropie už nestojí mimo model jako soudce. Je součástí feature vektoru. Síť se s ní učí pracovat společně s ostatními informacemi.

Prakticky řečeno: model nedostává pouze data o tom, co cena udělala, ale i informaci o tom, v jakém stupni lokálního chaosu nebo struktury se daný pohyb odehrál. Tím se otevírá jemnější interpretace trhu než u původního zapnuto/vypnuto filtru.

Měkký entropický filtr jako druhá vrstva

Vedle toho zůstala v systému ještě jedna entropická vrstva, ale v mnohem mírnější podobě.

Ve v5.23 lze zapnout volitelný confidence filter, který při zvýšené pomalé entropii nestopne model úplně, ale začne jeho výstupní pravděpodobnost stahovat směrem k neutrální hodnotě 50 %. Jinými slovy: čím chaotičtější prostředí, tím menší důvěra ve směrový výstup.

To je podstatný rozdíl oproti starším verzím. Dříve entropie fungovala jako tvrdá zábrana. Nyní funguje spíš jako mechanismus, který říká: „výstup existuje, ale jeho jistota je v tomto režimu omezená“.

Takový přístup je bližší realitě tržního chování. Trh se většinou nepřepíná skokově mezi čistým signálem a čistým šumem. Častěji přechází mezi různými stupni čitelnosti. A model by měl na tuto kontinuitu reagovat.

Co přesně LSTM modeluje

LSTM síť v tomto systému není použita jako černá skříňka pro magické signály. Nevydává příkazy typu „kup“ nebo „prodej“. Výstupem jsou dvě pravděpodobnostní složky, bullish a bearish, které se po normalizaci převádějí do procentního zobrazení.

Model se učí na klouzavých oknech historických dat. Cílová hodnota nevzniká jako pevná klasifikace jedné svíčky, ale jako transformovaná návratnost vzhledem k ATR a zvolenému horizontu predikce. Tím se výstup drží spíš v rovině podmíněné pravděpodobnosti než hrubého binárního rozhodnutí.

V praxi to znamená, že indikátor neříká „trh poroste“. Říká spíš: „na základě poslední sekvence více timeframe vstupů se pravděpodobnost býčího scénáře posouvá tímto směrem, s touto mírou jistoty“.

To je záměr. U obchodních modelů bývá nebezpečné zaměňovat odhad za příkaz.

Proč jsou v modelu tři timeframe současně

Použití více timeframe není kosmetická úprava. Je to pokus vyřešit přesně ten problém, na kterém ztroskotával původní přístup s jedním filtrem.

Nízký timeframe nese jemnou mikrodynamiku: těla svíček, knoty, lokální změny momenta, mikrovolatilitu. Vyšší timeframe nese širší strukturu: trend, akumulaci, stabilitu směru, kontext objemu a rozsahu pohybu.

Pokud model dostává oba pohledy současně, může se učit, že lokální chaos není vždy relevantní, pokud vyšší rámec drží konzistentní strukturu. Stejně tak se může učit opak: lokální klid nemusí znamenat nic důležitého, pokud vyšší timeframe ukazuje slábnutí nebo divergenci.

Právě tady dává návrat entropie nový smysl. Není to izolované číslo. Je to jedna z vrstev kontextu uvnitř širšího multi-timeframe čtení.

Shannon se nevrátil jako brána, ale jako jazyk

Nejpřesnější popis současné verze je tento:

Shannonova entropie nebyla opuštěna ani obnovena v původní podobě. Byla přeřazena.

Dříve fungovala jako vnější pravidlo. Dnes funguje:

  • uvnitř feature prostoru modelu,
  • a volitelně také jako měkký filtr důvěry nad výstupem.

To je kvalitativně jiný přístup. Místo pevné podmínky „obchodovat / neobchodovat“ vzniká model, který umí zohlednit míru chaosu jako jednu z proměnných. Neříká trhu, co je šum. Snaží se učit, kdy je chaos z hlediska širšího kontextu relevantní a kdy ne.

Praktický důsledek pro interpretaci výstupu

Z uživatelského hlediska je důležité chápat, že vysoké procento bullish nebo bearish samo o sobě nestačí. Výstup modelu má smysl jen v kombinaci s informací o režimu trhu. Právě proto zůstává v systému zobrazení entropy fast/slow/delta a možnost entropického utlumení.

Tento indikátor tedy není navržen jako automat na jistotu. Je navržen jako nástroj, který spojuje:

  • více timeframe kontext,
  • pravděpodobnostní výstup,
  • a průběžné hodnocení míry tržního chaosu.

To je méně efektní než klasické šipky „kup/prodej“, ale metodicky přesnější.

Závěr

Vývoj této architektury ukázal jednu praktickou věc: problém obvykle není v tom, že by trh neposkytoval žádná data. Problém je v tom, že různá data mají různou váhu v různých typech prostředí.

Shannonova entropie byla nejprve použita jako samostatný filtr. To pomohlo, ale ukázalo se to jako příliš rigidní. Ve verzi 5.23 se vrací v přesnější roli: jako součást multi-timeframe vstupu a jako volitelný mechanismus pro utlumení přehnané jistoty v chaotických režimech.

Výsledkem není odstranění neurčitosti. Spíš její explicitnější zapracování do modelu.

A to je v tradingu obvykle užitečnější než předstírat, že neurčitost neexistuje.

Tomáš Bělák
Remind.cz

From Hard Filtering to Layered Context: Shannon Entropy and Multi-Timeframe LSTM in MetaTrader 5

One of the common mistakes in trading is trying to extract a signal before evaluating what kind of environment the market is currently in. A directional model may look convincing on a chart even when the price series is too chaotic, from an informational point of view, to carry usable predictive structure. This is where the difference between describing movement and evaluating context becomes important.

In earlier versions of my tools, I approached this problem by using Shannon entropy as a separate filter. The idea was simple: if the market showed too much disorder, there was little reason to trust the predictive output. This approach had practical value, but it also revealed its limitations. A fixed threshold on a single timeframe was too coarse. In some situations, it filtered out not only noise, but also moments when a meaningful structure was emerging on a higher timeframe.

The current architecture is therefore based on a different principle. Shannon entropy did not disappear, but its role changed.

What Shannon entropy actually says in market data

Shannon entropy is a measure of uncertainty. In price series, it can be understood as a rough estimate of how ordered short-term changes are, or how far they have dissolved into a chaotic regime. By itself, it does not say where the market will go. It says something more basic: how reasonable it is to assume that the current movement carries readable structure.

This matters because high volatility does not automatically mean high information. A market can be dramatic and still be statistically difficult to read. Large candles, sharp reversals, and fast breakouts often create the impression of strong signals, while in reality they may represent an environment with low predictive value.

From this point of view, entropy is useful not as a signal generator, but as a layer of context.

Why a hard entropy filter was not enough

The first practical version of the architecture used entropy as a gate. If slow entropy exceeded a chosen threshold, the indicator either stopped producing output or suppressed it enough that trading decisions were effectively blocked.

This had one clear advantage: during obviously chaotic periods, the system reduced the number of impulsive entries. From a practical trading perspective, that was not insignificant.

At the same time, however, it became clear that a binary logic such as “low entropy = readable, high entropy = unreadable” did not describe market behavior accurately enough. The main issue was that market context is not one-dimensional. A lower timeframe may look chaotic while a higher timeframe is still holding direction, accumulation, or sustained momentum. In such cases, a fixed filter hid too much.

That led to an important shift: entropy stopped being a standalone decision rule and became one of the components of the model’s input data.

The new approach in version 5.23

In LSTM_Pure_MTF_Predictor v5.23, the model is built as a pure multi-timeframe LSTM architecture with GPU acceleration through MQL5GPULibrary_LSTM.dll. The overall logic is still layered, but no longer binary.

At each sequence step, the model does not work with just one timeframe. It reads three timeframes simultaneously, for example the current chart, H1, and H4. For each timeframe, a feature set is built that includes not only candle shape, momentum, ATR ratio, range position, and volume-related change, but now also:

  • fast Shannon entropy,
  • slow Shannon entropy,
  • the difference between fast and slow entropy.

This means entropy no longer stands outside the model as a judge. It is part of the feature vector. The network learns to use it together with the rest of the information.

In practical terms, the model receives not only data about what price has done, but also information about the degree of local chaos or structure in which that movement took place. This allows for a more nuanced interpretation than the original on/off filter.

A soft entropy filter as a second layer

At the same time, one more entropy-based layer remains in the system, but in a much softer form.

In v5.23, an optional confidence filter can be enabled. When slow entropy becomes elevated, it does not shut the model down completely. Instead, it gradually pulls the output probability back toward the neutral value of 50%. In other words, the more chaotic the environment, the less confidence should be placed in the directional output.

This is a substantial change compared with earlier versions. Previously, entropy acted as a hard stop. Now it behaves more like a mechanism saying: “the output still exists, but its confidence is limited under these conditions.”

This is closer to how markets actually behave. Markets do not usually switch abruptly between pure signal and pure noise. More often, they move through different degrees of readability. A model should be able to reflect that continuity.

What the LSTM is actually modeling

The LSTM network in this system is not used as a black box for magical signals. It does not issue commands such as “buy” or “sell.” Its output consists of two probability components, bullish and bearish, which are normalized and then displayed as percentages.

The model is trained on rolling windows of historical data. The target is not a fixed one-bar classification, but a transformed return relative to ATR and the chosen prediction horizon. This keeps the output closer to conditional probability than to a crude binary decision.

In practice, that means the indicator does not say “the market will rise.” It says something closer to: “based on the recent multi-timeframe input sequence, the probability of a bullish scenario is shifting in this direction, with this degree of confidence.”

That distinction is intentional. In trading models, it is often dangerous to confuse an estimate with a command.

Why the model uses three timeframes at once

The use of multiple timeframes is not a cosmetic addition. It is an attempt to solve exactly the problem on which the earlier single-filter approach failed.

A lower timeframe carries fine micro-dynamics: candle bodies, wicks, local momentum changes, and short-term volatility. A higher timeframe carries broader structure: trend, accumulation, directional stability, and the wider context of price range and volume behavior.

If the model receives both views at once, it can learn that local chaos is not always important if the higher timeframe is holding a consistent structure. It can also learn the opposite: local calm may mean very little if the higher timeframe is already showing weakening or divergence.

This is where the return of entropy gains a new meaning. It is no longer an isolated number. It is one layer of context inside a broader multi-timeframe reading.

Shannon did not return as a gate, but as a language

The most accurate description of the current version is this:

Shannon entropy was neither abandoned nor restored in its original form. It was reassigned.

Previously, it functioned as an external rule. Now it functions:

  • inside the model’s feature space,
  • and optionally as a soft confidence filter over the output.

This is a qualitatively different approach. Instead of a fixed condition such as “trade / do not trade,” the model can treat the degree of chaos as one variable among others. It does not try to dictate what noise is. It tries to learn when chaos matters in the context of the wider market structure and when it does not.

The practical consequence for interpreting the output

From the user’s perspective, one important point remains: a high bullish or bearish percentage is not enough on its own. The model’s output only makes sense together with information about the market regime. This is why the system still displays entropy fast/slow/delta values and allows optional entropy-based damping.

This indicator is therefore not designed as a certainty machine. It is designed as a tool that combines:

  • multi-timeframe context,
  • probability-based output,
  • and continuous evaluation of market chaos.

This is less spectacular than classic “buy/sell” arrows, but methodologically more precise.

Conclusion

The development of this architecture revealed one practical point: the problem is usually not that the market provides no data. The problem is that different data carry different weight in different environments.

Shannon entropy was first used as a standalone filter. That helped, but it turned out to be too rigid. In version 5.23, it returns in a more precise role: as part of the multi-timeframe input and as an optional mechanism for damping excessive confidence in chaotic regimes.

The result is not the removal of uncertainty. It is a more explicit integration of uncertainty into the model.

And in trading, that is often more useful than pretending uncertainty does not exist.

Tomáš Bělák
Remind.cz