AYILON is a fully automated perpetual swap trading bot running on Cloudflare Workers. Every minute, a scheduled cron job wakes the bot, fetches live market data, runs the analysis pipeline, and places orders via the OKX API if conditions are met.
running = true.The bot fetches 100 candles each from the 1H and 4H timeframes simultaneously. It scans every high and low price across these candles to identify support and resistance levels.
For each candidate price level, the bot counts how many candles touched it. A candle "touches" a level if its high or low is within a ±0.3% tolerance band of that level.
| Age of touches | Required touches to be valid | Reasoning |
|---|---|---|
| Within last 20 candles | 2 touches | Market recently respected this level — likely still active |
| Older than 20 candles | 3 touches | Needs more confirmation since it hasn't been tested recently |
| Older than 100 candles | Ignored | Too stale — market structure has likely changed |
After collecting all valid levels, nearby duplicates are merged. Any two levels within 0.5% of each other are considered the same zone. The top 4 supports (below price) and top 4 resistances (above price) are kept per timeframe.
After grading and merging 1H + 4H levels, the final set is capped at 5 supports + 5 resistances, sorted by proximity to current price.
Every detected level is assigned a grade based on how many timeframes confirm it and how strong the touch history is. The grade is logged with each trade so performance by tier can be tracked over time.
| Condition | Grade | Action |
|---|---|---|
| Found on 1H and 4H (within 0.5%) | S | Trade — highest priority |
| 4H only, 4+ total touches | A | Trade |
| Any level with ≥1 touch in last 20 candles | A | Trade |
| 1H only, old touches, exactly 2 touches | B | Trade — lower confidence |
LONG #1/3 @ 105000 | [S급] L:104800 | SL:101200 | TP:108500 | sz:0.0042
On top of price-based S/R, the bot builds a volume profile from 4H candles to find high-volume price clusters where the market has historically spent significant time and energy.
After filtering, up to 3 volume-confirmed supports + 3 resistances are merged into the main level pool. These volume-backed S/R levels carry extra weight in the final signal decision.
AYILON supports 10 trading strategies. Your subscription plan determines which are available. All strategies share the same DCA entry logic, position sizing, and risk management framework described in sections 06–13.
| # | Strategy | Direction | Key Signal | Risk | Plan |
|---|---|---|---|---|---|
| 1 | RSI Oversold DCA Long | Long Only | RSI ≤ 30 | Low | Basic+ |
| 2 | MA Support DCA | Long Only | MA alignment + price touches MA | Low | Basic+ |
| 3 | S/R Bounce | Long / Short | 5m price touches S/R level + momentum | Medium | Basic+ |
| 4 | MA Crossover + RSI | Long / Short | 10/34 MA cross + RSI 65↑ / 35↓ | Medium | Mid+ |
| 5 | Bollinger Band Mean Reversion | Long / Short | Price touches lower/upper BB band | Medium | Mid+ |
| 6 | Breakout + Volume | Long Bias | Price breaks resistance + volume ≥ 2× avg | Medium | Mid+ |
| 7 | MA Ribbon Long | Long Only | 6 MAs aligned bullish + recent N-bar low holds | Low | Mid+ |
| 8 | MACD Divergence | Long / Short | Price vs MACD divergence confirmed | High | Premium |
| 9 | Funding Rate Contrarian | Long / Short | Funding rate ≥ +0.10% → short; ≤ −0.05% → long | High | Premium |
| 10 | ATR Trend Following | Long Bias | ADX > 25 + price pulls back 1 ATR in uptrend | Medium | Premium |
Enters a long position when the 14-period RSI on the user-selected timeframe drops to or below 30 (oversold). DCA entries are placed at N-equal intervals between the first entry price and the swing low (SL). Take profit targets the nearest resistance level above entry. Short side (RSI ≥ 70) is disabled — momentum can sustain above 70 for extended periods in bull markets.
Requires at least 3 of 6 moving averages (10, 20, 50, 100, 200 SMA + 34 EMA) to be in bullish alignment (price above all selected MAs). Enters long when the 5m candle wicks down to the nearest MA and closes above it — a pullback-to-MA bounce. Long only; no short entries.
The built-in default strategy. Detects support and resistance levels from 1H/4H candles using swing highs/lows and volume profile. Enters long when the 5m price touches a support level with a bullish bounce candle. Enters short when a bearish impulse candle with above-average volume is followed by a 50% retracement to resistance. SL = swing low (long) / swing high (short) of the 3 preceding 5m candles.
Long: 10 EMA crosses above 34 EMA (golden cross) AND RSI ≥ 65 on the signal candle. Short: 10 EMA crosses below 34 EMA (death cross) AND RSI ≤ 35. DCA entries are spaced between the signal candle price and the swing low/high of the preceding 3 candles on the 5m chart. Note: RSI condition is checked at the candle that closes the crossover — if RSI has not yet reached the threshold, the bot waits for confirmation on the next candle.
Uses a 20-period BB with 2 standard deviations. Enters long when the 5m candle closes below the lower band and the next candle closes back inside the band (re-entry confirmation). Enters short on the mirror condition at the upper band. Trend filter: long entries are skipped when the daily trend is strongly bearish (price below 200 SMA).
Identifies the 20-period resistance level on the 1H chart. Enters long when a 5m candle closes above this level with volume ≥ 2× the 20-period average volume. The broken resistance becomes the first DCA reference price. SL = candle low of the breakout bar. Long-biased; short breakdowns available on Premium with an additional RSI filter.
Requires 6 MAs (10, 20, 34, 50, 100, 200) to be in full bullish alignment (each MA above the next longer one). Enters long when price touches the shortest MA (10) in the ribbon and the last 3 candles on 5m show a pullback. This strategy only fires in confirmed strong uptrends. Long only.
Detects bullish divergence (price makes lower low, MACD histogram makes higher low) for long entries, and bearish divergence for shorts. Divergence is confirmed over the last 10 candles on the user-selected timeframe. Requires an RSI filter (RSI > 40 for longs, RSI < 60 for shorts) to avoid divergence trades in strongly trending markets.
Perpetual swap funding rates reveal market sentiment. When the funding rate exceeds +0.10% per 8h (the market is heavily long), the bot fades the crowd with a short entry. When it drops below −0.05% (heavily short), it enters long. This strategy is checked once per funding interval and does not use 5m signal detection.
Requires ADX > 25 (strong trend confirmed) on the 1H chart and price to be in an uptrend (above 50 SMA). Enters long when price pulls back by exactly 1 ATR from the recent high and starts recovering. SL = entry minus 1.5 ATR. Long-biased; short entries require ADX > 30 and price below 50 SMA.
AYILON uses a Fixed Fractional position sizing model. You define what percentage of your equity to risk per trade, and the bot calculates contract size accordingly. This keeps risk consistent regardless of account balance changes.
Instead of a fixed price interval between DCA entries, AYILON divides the zone between the first entry price and the stop loss into N equal parts. This guarantees all entries stay within the valid trade zone regardless of how far or close the SL is.
Example (Long, 3 entries): First entry at 100,000, SL (swing low) at 97,000. Gap = 1,000. Entries: 100,000 → 99,000 → 98,000. SL: 97,000.
| Mode | How it works | Best for |
|---|---|---|
| Equal | Each entry gets identical capital: riskBudget / numEntries |
Default — safe and predictable |
| Martingale | Each subsequent entry multiplies by the configured factor: base × factor^(n−1) |
Aggressive average improvement — significantly higher risk |
If the bot already holds an open position in one direction (e.g., LONG), it will never open a SHORT until that position is fully closed. This prevents being caught on both sides of the market simultaneously.
The bot tracks how many entries have been placed in the current setup. Once the user-configured numEntries limit is reached (default: 3), no further entries are allowed for this setup.
All DCA entries are pre-calculated at signal time and must fall between the first entry price and the stop loss level. The bot will not place an entry at or beyond the SL price. If the current market price is already below a scheduled entry level when that cron tick fires, that entry is skipped.
TP is the nearest structural level in the trade direction — not a fixed profit percentage.
The bot uses an equity-based loss mechanism rather than a traditional price-level stop order. Instead of setting a fixed SL price at entry, the bot continuously monitors the combined impact of today's realized losses and current floating losses against your configured loss limit.
On every cron tick, after all N entries are filled, the bot calculates:
If total_loss_pct ≥ loss_limit → close all open positions immediately and cancel any pending TP algo orders.
With multi-entry DCA, the average entry price shifts with each new entry. A price-based SL set at entry #1's 5m candle low becomes irrelevant when entry #3 is placed at a significantly lower price. An equity-based loss limit is cleaner: it accounts for all entries together, plus any losses already realized earlier today.
close-position API for the full open position. Market order executes at current price.The stop check is only active after all N entries are filled. Before the full position is built, checking the loss limit would be premature — the position is still being averaged in and a partial floating loss during entry is normal.
The daily loss limit is a circuit breaker that stops the bot from trading after a bad day, preventing a series of losses from compounding into a catastrophic drawdown.
| Setting | Default | Description |
|---|---|---|
| Enabled | Yes | Active by default — strongly recommended to keep on |
| Limit | 5% | Bot pauses if today's realized loss reaches 5% of equity |
| Reset | Daily | Loss counter resets at midnight UTC each day |
running = false in configFrom the dashboard, you can either:
Walk-through of a complete LONG trade on BTC-USDT-SWAP with default settings:
| Setting | Value |
|---|---|
| Equity | $10,000 USDT |
| Max Position Size | 12% → $1,200 total |
| Leverage | 5× |
| Entries | 3 (equal: $400 each) |
| BTC price at entry | $100,000 |
| Parameter | Default | Range | Notes |
|---|---|---|---|
| Max Position Size | 12% | 1–100% | Half-Kelly default |
| Max Leverage | 5× | 1–100× | Warning triggers above 20× |
| Number of Entries | 3 | 2–10 | Kelly warning above 40% total |
| Entry Sizing | Equal | Equal / Martingale | Equal recommended |
| Daily Loss Limit | 5% | 0.1–10% | Enabled by default |
| S/R tolerance (detection) | 0.3% | Fixed | Touch band for level confirmation |
| S/R tolerance (dedup) | 0.5% | Fixed | Merge nearby duplicate levels |
| Entry touch tolerance | 0.4% | Fixed | Distance from level for entry |
| SL distance range | 3–6% | Fixed | Below 3% or above 6% = skip |
| Fractional entry range | ±2% | Fixed | Max drift from first entry for #2/#3 |
| Recency window | 20 candles | Fixed | 2 touches sufficient within this range |
| Max S/R age | 100 candles | Fixed | Older levels ignored |
| Volume profile buckets | 50 | Fixed | Granularity of volume zones |
| Volume zone threshold | 2× avg | Fixed | Min volume to count as a zone |
| Vol zone ↔ S/R overlap | ±1% | Fixed | Zone must be near S/R to be used |
| Partial close on TP | 50% | Fixed | SL moves to break-even after |
Demo Mode routes all API calls to OKX's paper trading environment. All analysis logic, order placement, and SL/TP monitoring run identically — but no real money is used.
When Demo Mode is enabled, the bot adds the x-simulated-trading: 1 header to every OKX API request. OKX's server routes these requests to their simulated trading system automatically.
| Live Mode | Demo Mode | |
|---|---|---|
| API Header | Standard OKX headers | + x-simulated-trading: 1 |
| API Keys | Live account keys | OKX Demo account keys |
| Funds | Real USDT | Virtual balance |
| Bot logic | Identical | Identical |
| Dashboard badge | — | DEMO shown |
Run Demo Mode for at least 2–4 weeks before switching to live trading. This lets you verify that the bot's entry and exit behavior matches your expectations across different market conditions without financial risk.