# Bot Event Loops

## Bot Event Loops

Bots have safeguards and limits that alert you when an automation encounters an error. These safeguards were created to protect traders and require you to think critically about your trade setup from entry to exit.

Bot event loops typically occur in bots that run on event triggers. The error can happen if you’re not careful when using open position or close position actions inside an automation.

Bots have [position limits](https://optionalpha.com/help/position-limits) and [capital allocation limits](https://optionalpha.com/help/capital-warnings) for an important reason. The limits prevent the bot from entering a “looping” scenario where it opens and closes positions beyond the limits you’ve set in the bot’s global settings.<br>

“Position opened” triggers tell the bot to run an automation once instantly after the bot opens a position. “Position closed” triggers tell the bot to run an automation as soon as a position is closed.<br>

<figure><img src="https://2799944806-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MYjluAVRcRcfh1YL43z%2Fuploads%2FjWSIafme5haWO77SrzZz%2Fimage.png?alt=media&#x26;token=8e124b78-f361-41cb-b6ce-410508a0d7c3" alt=""><figcaption></figcaption></figure>

Event loops are a unique situation where positions are opened or closed because of related events and subsequently become stuck in a “loop.”

For example, an event could automatically open a position when another is closed. Closing the position could trigger another event that immediately opens a new position, thereby causing the bot to enter and exit positions in an endless loop.

The event loop will cause the bot to reach its daily and/or total position limit.

The bot event loop error is a specific, deliberate error you can encounter if you’re not careful setting up your event automation actions Be sure to always think through the process when creating your bots, and don’t forget to [test your automations](https://optionalpha.com/help/testing-automations) and paper trade to avoid these situations!

<br>


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.optionalpha.com/technical-documentation/troubleshooting/bot-event-loops.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
