Back to Community
Issues with Placing Orders Every Minute

Good evening,

Recently I developed an algorithm based on a RSI mean crossover which rebalanced every morning 30 minutes after the market opened. The results can be seen here: https://www.quantopian.com/posts/first-strategy-tested-rsi-weighted-mean-crossover

I wanted to transfer this strategy over to a minute calculation to capture changes more frequently in RSI and RSI average values to hopefully get into a position sooner. My results can be seen attached. However, there seems to be a problem with my code placing a new open order every minute that fills, which exceeds the initial capital I have invested. My questions are:

1.) Is there a way to control the number of open orders to 1 until it is completely filled, or until a signal is generated to switch the position, i.e. crossover detected?
2.) Do I have to close out my entire long/short position before initiating a new long/short position? Or can order_target_percent take care of that?
3.) Is there a way to make sure my position, either long or short, does not exceed the available cash in my account?

Thanks!

Brian

Clone Algorithm
6
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 578cec737f15150f8eb12288
There was a runtime error.
2 responses

Hi Brian,

A good way to handle all 3 of your issues would be to add the following line of code to the beginning of your handle_data function.

if get_open_order():  
    return  

This will ensure that you only order new securities whenever your current orders have been filled. This should clear up your over-leveraging as well.

Best,
Lotanna Ezenwa

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Hi Lotanna,

Thank you for your response. I added the following line of code to the beginning of my handle_data function.

if get_open_orders(context.stock):  
    return  

Checking my daily positions and gains, I am not replicating the same order until my current order is filled. Also my account is not being over-leveraged either.

It appears that using the RSI indicator with a EWMA crossover does not perform as well as I thought when calculated every minute. Might have to play with the sensitivity of the window length.

Thanks again!

Brian

Clone Algorithm
6
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 578e4e737334540f8d1a8407
There was a runtime error.