Skip to main content

Build an Auto-Optimizing Trading System — Parameter Loop + Telegram Notifications

A strategy that never re-evaluates its parameters is a strategy that slowly dies. Markets shift, volatility changes, and what worked last month may not work today.

The solution? A workflow that periodically re-optimizes itself and sends you a Telegram notification with the results — all running automatically on ApudFlow.

The Complete Workflow​

[Schedule Trigger] → [Fetch Prices] → [Swing Finder] → [Backtest] → [Parameter Loop]
│
▼
[Telegram Notify]

This workflow runs every day at market close, sweeps parameter combinations, finds the best one, and messages you the results on Telegram.

Why This Matters​

Without automation: You manually run sweeps, compare results, update parameters, re-deploy. The whole cycle takes 30 minutes and you probably only do it once a week.

With this workflow: The system re-optimizes daily and notifies you. You just read the message and know your strategy is running with today's best parameters.

Step-by-Step Build​

Step 1: Schedule Trigger​

Add a Schedule Trigger that runs daily at a specific time:

{
"everySeconds": 86400,
"type": "interval",
"runAt": "22:00 UTC"
}

This triggers the workflow once per day — after the markets close, when fresh OHLC data is available.

Step 2: Fetch Prices​

Add Fetch Prices to pull the latest market data. Use enough bars for meaningful backtest results:

{
"symbols": ["XAUUSD", "EURUSD"],
"timeframe": "1h",
"limit": 1000
}

Step 3: Swing Finder + Backtest​

These are your strategy workers — exactly as you'd configure them for manual sweeps. The Swing Finder detects swing points, and the Backtest evaluates performance with the parameters that the Parameter Loop provides each iteration.

Step 4: Parameter Loop — The Optimizer​

This is the heart of the system. Configure it to find the best parameters every time it runs.

Configuration:

{
"sweepParameters": [
{"name": "stop_loss", "values": [1.0, 2.0, 3.0, 4.0, 5.0]},
{"name": "take_profit", "values": [2.0, 3.0, 4.0, 5.0, 6.0]}
],
"collectField": "result.sharpe_ratio",
"rankingField": "sharpe_ratio",
"rankingMode": "max",
"prodMode": "always_run",
"sessionLabel": "daily_optimization",
"maxIterations": 0,
"continueOnError": true
}

Key detail: prodMode is set to always_run. This means the full sweep runs every single time the workflow triggers — daily in this case. The sweep re-evaluates all parameter combinations against the latest market data.

Step 5: Telegram Notification​

Add a Telegram Notify worker connected to after the Parameter Loop. This worker reads the sweep results and sends you a concise summary.

Configuration:

Message template:
📊 DAILY OPTIMIZATION COMPLETE
━━━━━━━━━━━━━━━━━━
Strategy: Gold & EURUSD Swing
Date: {{trigger_1.now}}

Best Parameters:
• Stop Loss: {{parameter_loop_1.bestParameters.stop_loss}}%
• Take Profit: {{parameter_loop_1.bestParameters.take_profit}}%

Results:
• Sharpe Ratio: {{parameter_loop_1.bestValue}}
• Total Iterations: {{parameter_loop_1.totalIterations}}
• Successful: {{parameter_loop_1.successfulIterations}}
• Failed: {{parameter_loop_1.failedIterations}}

Best iteration #{{parameter_loop_1.bestIteration}}

What the Telegram message looks like:

📊 DAILY OPTIMIZATION COMPLETE ━━━━━━━━━━━━━━━━━━━━ Strategy: Gold & EURUSD Swing Date: June 13, 2026

Best Parameters: • Stop Loss: 2.5% • Take Profit: 4.0%

Results: • Sharpe Ratio: 1.87 • Total Iterations: 25 • Successful: 23 • Failed: 2

Best iteration #7

Step 6: (Optional) Auto-Apply Best Parameters​

If you want the workflow to automatically use the best parameters for the next run, the Parameter Loop's use_best mode combined with session saving handles this:

  1. The sweep runs (prodMode: always_run)
  2. Results save to session daily_optimization
  3. On the next day's run, if you switch to prodMode: use_best, it loads the previous day's best without re-sweeping

But for true auto-optimization, keep always_run and let the system re-evaluate daily.

Advanced: Multiple Notification Levels​

You can create a richer notification system by splitting the output:

[Parameter Loop] ─┬──▶ [Telegram: Summary]  (short, daily digest)
│
└──▶ [Condition] ──▶ [Telegram: Alert] (only if Sharpe dropped)

Condition Configuration​

Check if the best Sharpe ratio fell below a threshold:

Condition: {{parameter_loop_1.bestValue}} < 1.0

If true → send an alert: "⚠️ Strategy degrading — Sharpe dropped below 1.0. Consider reviewing parameters."

If false → send the normal daily summary.

Real-World Scenario​

Imagine it's June 2026. Gold has been trending strongly for weeks with low volatility. Your strategy was optimized with stop_loss: 2.5 and take_profit: 4.0.

Suddenly, volatility spikes. The Fed makes an unexpected announcement.

Your daily optimization run catches this immediately:

DayBest SLBest TPSharpe
June 102.5%4.0%1.87
June 113.5%4.0%1.65
June 124.0%5.0%1.42
June 134.0%6.0%1.38

Without daily optimization: Your strategy keeps using SL=2.5 in a high-volatility market, getting stopped out repeatedly.

With daily optimization: The system automatically widened the stop loss from 2.5% to 4.0%, adapting to the new regime. Your Telegram shows the progression daily.

Production Considerations​

Rate Limiting​

Daily sweeps (25 iterations) on 1h data consume minimal compute. If you're optimizing every hour, consider reducing the grid size or increasing maxIterations as a safety cap.

Session Storage​

Each daily run saves a new session. After a year, you'll have 365 sessions — useful for trend analysis. You can clean old sessions from the Sessions tab.

Telegram Bot Setup​

If you haven't set up Telegram notifications:

  1. Create a bot via @BotFather on Telegram
  2. Copy the bot token
  3. Get your chat ID by sending a message to the bot and visiting https://api.telegram.org/bot<TOKEN>/getUpdates
  4. Enter both in the Telegram Notify worker configuration

Summary​

ComponentPurpose
Schedule TriggerRuns daily at market close
Fetch PricesGets fresh OHLC data
Swing Finder + BacktestEvaluates strategy with current parameters
Parameter LoopSweeps all combos to find the best
Telegram NotifySends you the results in a formatted message

This workflow turns strategy optimization from a manual weekly chore into a fully automated daily process. Set it up once, and let the system keep your strategy aligned with changing market conditions.