Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
New to Programming in general need help figuring out logic

Hi Everyone,
I am relatively new to programming. I am actually 50% done the python course in code academy. I am really stuck figuring out the logic for what I want to do and was hoping someone would be kind as to point me in the right path. The strategy is using a single security, SSO, to find setups for intraday trades.
For going long I want to spot a setup in the SSO where the 20 day is greater than the 50 day moving average and the stochastics are < 25, there is a positive candle stick function (I only have built one into the current code at the moment), and the close of the signal candle is less than the high of the previous candle (t-3).
The stop will be= (1 * ATR) - low of entry bar
The target exit will be: (2 * ATR) + entry price
If nothing triggers I would like to close the position end of day.

I have included my most recent back test, and I am clearly well off the path. I've looked at a ton of examples but cannot seem to find anything that incorporates multiple variables and closing position daily then resetting next day if the setup presents itself. I'm sure its the fact that I do not understand the language enough yet, as a lot of the models are quite complicated, but any help is greatly appreciated!

Best
Dave

2 responses

A couple tips:

  • While you're working on your logic, use short backtests. It's a faster cycle time while you figure out your bugs.
  • Add logging. It helps you understand what's going on.

I added some logging to your backtest, and I found that it was cycling in and out of the stock every minute. That didn't seem right, so I studied your if/elif statement. What you did is set up your "if" to always be false if you have a position - so every time you enter a position, by definition you're exiting it the next minute. Put another way, your code has two modes: buy and sell. It needs a third mode, which is "hold."

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 Dan,
Thanks for your response, greatly appreciated! I will apply and retest.