OPEN-SOURCE SCRIPT

Spectral Crypto Trading

1. Simple Moving Average (SMA):

smaPrice = ta.sma(close, smaLength)

Where `smaPrice` is the simple moving average of closing prices over `smaLength` periods.

2. Z-Score (Statistical Component):

z = (close - smaPrice) / ta.stdev(close, smaLength)

Where `z` is the number of standard deviations away from the mean (smaPrice) the current close price is.

3. Quantum Component:

quantum_component = math.exp(-0.5 * z * z) * (1 + math.sin((math.pi / 2) * z)

This is an oscillator that combines the z-score with a sine function to produce a value that oscillates around 0, with a certain weight given by `quantumWeight`.

4. Economic Component:

emaFast = ta.ema(close, emaFastLength)
emaSlow = ta.ema(close, emaSlowLength)
economic_component = math.log(emaFast / emaSlow)

This component is based on the ratio of two exponential moving averages (`emaFast` and `emaSlow`) to assess market momentum.

5. Lyapunov Exponent:

lyapunov_index = ta.sma(math.log(math.max(1e-10, math.abs(economic_component + quantum_component)), smaLength)

The Lyapunov exponent is used here as a proxy for market stability, with a higher value indicating more stable conditions.

6. **Composite Crypto Outlook Index**:
```plaintext
crypto_outlook_index = 50 + quantumWeight * (quantum_component - 1) + economicWeight * economic_component + statisticalWeight * z + lyapunovWeight * lyapunov_index
```
The final index is calculated by summing the weighted values of the Quantum, Economic, Statistical components, and the Lyapunov index. The neutral level is set at 50, with values above indicating bullish conditions and values below indicating bearish conditions.

The trading strategy uses the following conditions:
- Long entry (`LongCondition`): `crypto_outlook_index > 70`
- Short entry (`shortCondition`): `crypto_outlook_index < 30`
- Long exit (`Exit Long`): `crypto_outlook_index < 50`
- Short exit (`Exit Short`): `crypto_outlook_index > 50`

The strategy enters a long position when the index is strongly bullish and exits when it crosses the neutral line towards bearish. Conversely, it enters a short position when the index is strongly bearish and exits when it crosses the neutral line towards bullish. The background color of the chart changes according to the index's position relative to the bullish (green) and bearish (red) thresholds.

Feragatname