Troubleshooting
This guide covers common issues and their solutions.
Backtest Failed
If your backtest shows failed status, check these common causes:
File Not Named agent.py
Problem: Your file has a different name (e.g., my_agent.py, strategy.py).
Solution: Rename your file to exactly agent.py.
Class Not Named Agent
Problem: Your class has a different name.
# Wrong
class MyStrategy(bt.Strategy):
pass
# Correct
class Agent(bt.Strategy):
pass
Solution: Rename your class to exactly Agent.
Missing Required Methods
Problem: Your agent is missing __init__(), prenext(), or next().
Solution: Implement all required methods:
class Agent(bt.Strategy):
def __init__(self):
pass # Initialize indicators here
def prenext(self):
self.next() # Required to start trading early
def next(self):
pass # Your trading logic here
Missing prenext() Method
Problem: Without prenext(), Backtrader waits for all indicator data before calling next(). This can cause issues with multi-symbol agents.
Solution: Add the prenext() method that calls next():
def prenext(self):
self.next()
Syntax Errors
Problem: Python syntax error in your code.
Solution: Check for:
- Missing colons after
def,if,else,for,while - Incorrect indentation (use 4 spaces, not tabs)
- Unclosed parentheses, brackets, or quotes
- Typos in variable or function names
Run your code locally with python agent.py to catch syntax errors before uploading.
Import Errors
Problem: Importing a module that’s not available.
Solution: We provide these pre-installed libraries:
backtraderpandasnumpytorch/pytorchtransformers(Hugging Face)
If you need a library that’s not available, contact support.
Indicator Data Not Ready
Problem: Using indicator values before they’re calculated.
Solution: Check data length before using indicators:
def next(self):
# Check if SMA has enough data
if len(self.sma) < self.p.period:
return
# Now safe to use
if self.data.close[0] > self.sma[0]:
self.buy()
Or use prenext() with careful null checking:
def prenext(self):
self.next()
def next(self):
try:
sma_value = self.sma[0]
except IndexError:
return # Not enough data yet
Account Creation Issues
Stuck on registering_account
Problem: Status stays at registering_account for more than a few minutes.
Causes:
- Alpaca API temporary issues
- Network connectivity problems
Solution:
- Refresh the page to check for updates
- Wait 5 minutes and check again
- If still stuck, contact support@spookylabs.io with your agent ID
Deployment Issues
deployment_failed Status
Problem: Your agent failed to deploy to paper trading.
Checklist:
- ✅ Backtest status is
success - ✅ Account is
fundedorfunded_pending - ✅ No pending orders or processes
Solution:
- Verify the checklist above
- Try clicking “Begin Paper Trading” again
- If it fails again, contact support with your agent ID
Agent Not Trading
Problem: Agent shows trading status but isn’t making trades.
Causes:
- Markets closed — Equities trade 9:30 AM - 4:00 PM ET, weekdays only
- No signals — Your agent’s conditions aren’t being met
- Data issue — Agent isn’t receiving market data
Solution:
- Check if markets are currently open
- Review your agent’s logic—maybe it’s working correctly but conditions aren’t met
- Simplify your agent to generate more frequent signals for testing
- Contact support if you believe there’s a data issue
Common Code Mistakes
Forgetting to Check Position
# Problem: Keeps buying even when already in position
def next(self):
if self.data.close[0] > self.sma[0]:
self.buy() # Will place order every bar!
# Solution: Check position first
def next(self):
if not self.position:
if self.data.close[0] > self.sma[0]:
self.buy()
Using Wrong Index for Current Data
# Problem: Using [-1] instead of [0] for current bar
def next(self):
current = self.data.close[-1] # Wrong! This is previous bar
# Solution: Use [0] for current bar
def next(self):
current = self.data.close[0] # Correct
Not Handling Order State
# Problem: Placing multiple orders before first one fills
def next(self):
if self.buy_signal():
self.buy() # May create duplicate orders
# Solution: Track order state
def __init__(self):
self.order = None
def notify_order(self, order):
if order.status in [order.Completed, order.Canceled, order.Rejected]:
self.order = None
def next(self):
if self.order:
return # Skip if order pending
if self.buy_signal():
self.order = self.buy()
Getting Help
If you can’t resolve your issue:
- Check the docs — Review Writing Agents for correct patterns
- Simplify your code — Isolate the problem by removing complexity
- Contact support — Email support@spookylabs.io with:
- Your agent ID
- Description of the problem
- Any error messages you’ve seen