> For the complete documentation index, see [llms.txt](https://docs.tradesurge.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tradesurge.co/platform/strategies/upload-python.md).

# Upload a Python strategy

Write your strategy as one pure Python function that turns candles into signals, then upload it.

Python strategies use the TradeSurge Strategy API. It is one small interface: candles and parameters in, signals out. If you can describe your entries and exits in terms of candles, you can write it.

## What you need

* A strategy you can express from candle data alone: open, high, low, close and volume.
* A Python file that implements `generate_signals(candles)`.
* Any settings you want to tune, declared as parameters.

## Upload it

{% stepper %}
{% step %}

### Write the function

Implement `generate_signals` so it returns signals from the candles it receives. The only signals are `enter_long`, `enter_short`, `exit_long` and `exit_short`.
{% endstep %}

{% step %}

### Declare your parameters

List each tunable setting with its type and range. Parameters can be true or false, whole numbers, decimals or short text.
{% endstep %}

{% step %}

### Upload the file

Open Strategies and upload. TradeSurge checks the code and creates a new version.
{% endstep %}

{% step %}

### Run a backtest

Open the version and start a backtest to see how it would have performed.
{% endstep %}
{% endstepper %}

{% hint style="warning" %}
The most common rejection is code that reaches outside the candles. Network calls, file access, the system clock and random numbers are all refused, because they make results impossible to repeat.
{% endhint %}

## Good to know

* Signals are evaluated when a candle closes, never mid-candle.
* Any signal outside the four allowed actions fails closed.
* Uploaded code runs in a restricted sandbox.

## Next steps

<table data-view="cards"><thead><tr><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><strong>Backtest a strategy</strong></td><td>Read results in R.</td><td><a href="/platform/strategies/backtest.md">Backtest a strategy</a></td></tr><tr><td><strong>Upload a Pine Script strategy</strong></td><td>Bring a TradingView script instead.</td><td><a href="/platform/strategies/upload-pine.md">Upload a Pine Script strategy</a></td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.tradesurge.co/platform/strategies/upload-python.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
