Live Trading

Algorithm Control

Introduction

The algorithm control features on the live results page let you adjust your algorithm while it is executing live so that you can perform actions that are not written in the project files. The control features let you intervene in the execution of your algorithm and make adjustments. For instance, you can create security subscriptions, place trades, stop the algorithm, and update the algorithm.

Add Security Subscriptions

The live results page enables you to manually create security subscriptions for your algorithm instead of calling the AddsecurityType methods in your code files. If you add security subscriptions to your algorithm, you can place manual trades through the IDE without having to edit and redeploy the algorithm. Follow these steps to add security subscriptions:

  1. Open your algorithm's live results page.
  2. In the Holdings tab, click Add Security.
  3. Enter the symbol, security type, resolution, leverage, and market of the security you want to add.
  4. If you want the data for the security to be filled-forward, check the Fill Forward check box.
  5. If you want to subscribe to extended market hours for the security, check the Extended Market Hours check box.
  6. Click Add Security.

You can't manually remove security subscriptions from the IDE.

Place Manual Trades

The live results page lets you manually place orders instead of calling the automated methods in your project files. You can use any order type that is supported by the brokerage that you used when deploying the algorithm. To view the supported order types of your brokerage, see the Orders section of your brokerage guide. Some example situations where it may be helpful to place manual orders instead of stopping and redeploying the algorithm include the following:

  • Your brokerage account had holdings in it before you deployed your algorithm
  • Your algorithm had bugs in it that caused it to purchase the wrong security
  • You want to add a hedge to your portfolio without adjusting the algorithm code
  • You want to rebalance your portfolio before the rebalance date

Note that it's not currently possible to cancel manual orders.

Follow these steps to place manual orders:

  1. Open your algorithm's live results page.
  2. In the Holdings tab, if the security you want to trade isn't listed, click Show All Portfolio.
  3. If the security you want to trade still isn't listed, subscribe to the security.
  4. Click the security you want to trade.
  5. Click Create Order or Liquidate.
  6. If you clicked Create Order, enter an order quantity.
  7. Click the Type field and then click an order type from the drop-down menu.
  8. Click Submit Order.

Liquidate Positions

The live results page has a Liquidate button that acts as a "kill switch" to sell all of the non-Equity holdings in your portfolio at the current market price using market orders and then stop the algorithm. For instance, if your algorithm has a bug in it that caused it to purchase a lot of securities that you didn't want, you can liquidate your portfolio instead of placing many manual trades.

Follow these steps to liquidate your positions:

  1. Open your algorithm's live results page.
  2. Click Liquidate.
  3. Click Liquidate again.

Stop the Algorithm

The live trading results page has a Stop button to immediately stop your algorithm from executing. When you stop a live algorithm, your portfolio holdings are retained. Stop your algorithm if you want to perform any of the following actions:

  • Update your project's code files
  • Upgrade the live trading node
  • Update the settings you entered into the deployment wizard
  • Place manual orders through your brokerage account instead of the web IDE

Furthermore, if you receive new securities in your portfolio because of a reverse merger, you also need to stop and redeploy the algorithm.

Lean actively terminates live algorithms when it detects interference outside of the algorithm's control to avoid conflicting race conditions between the owner of the account and the algorithm, so avoid manipulating your brokerage account and placing manual orders while your algorithm is running. If you need to adjust your brokerage account holdings, stop the algorithm, manually place your trades, and then redeploy the algorithm.

Follow these steps to stop your algorithm:

  1. Open your algorithm's live results page.
  2. Click Stop.
  3. Click Stop again.

Update the Algorithm

If you need to adjust your algorithm's project files, stop your algorithm, make your changes, and then redeploy your algorithm. You can't adjust your algorithm's code while your algorithm executes. When you stop and redeploy a live algorithm, your project's live equity curve is retained between the deployments. To erase the equity curve history, clone the project and then redeploy the cloned version of the project.

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: