Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Using price and moving average to execute every 3% gain on initial position - long short... momentum... or is it mean reversion... lol

Hi!

I'm having some trouble, mostly because I am an inexperienced coder.

I'm trying to tell the computer a few things.

  1. Take a position and hold it - Do not compound a position - take an initial position and hold it until criteria is met to exit rather than continually buying/shorting if price is >/< MA.... without using a schedule function.
  2. Execute every time 3% profit target is met per trade - if unrealized gain for the position taken is 3%, exit.
  3. If the algo goes long, it should always exit before shorting vice versa

Your feedback would be highly appreciated.

4 responses

Can anyone help with this?

If not I'll just have to wait until the conference!

Hi Lovis.

Is this the one you are looking for?
To my surprise it survived slippage and commission charges for that period.
But it may not survive on longer period.

Vladimir,

Thank you for responding!

Looking over what you did, I'm trying to figure out which code limits the entering of positions. What keeps compounding from happening?
It looks like the schedule function is limiting the number of trades... it only allows trading every 30 minutes... rather than every 1 minute before.

From the looks of it using a schedule function doesn't solve the problem.
Looking at the logs it still shows, example, 7 days in a row where it shorts day after day rather than only shorting the first day and then holding through the next 6 days. This is what I'm trying to achieve, the ability to tell it to go long one day, hold that long position, without adding or taking away from it and then exiting when the pnl of the position reaches 3% profit target... not 3% on the account, 3% on the position. Then it would re-enter short or long, whichever criteria is met and go again. It would be a high frequency trading algo... ideally to execute on SPY, USO, and DJX at the same time.

Hopefully this clarifies a bit more.

Peace and thanks again!

After watching some Sentdex videos on youtube I've decided to go back to the drawing board in the research environment. My goal is to make an algorithm that trades based on the changing slope of a simple moving average, or exponential moving average. My theory is that slope of a moving average changes between positive and negative in a loop and is indicative of market direction.

I'm having difficulty showing this in the research environment. Is there someone in the Quantopian community who can help me with this? I am willing to share my source code for the algorithm that I have already written with whoever responds to this post.

Hopefully you're not a complete noob like me.

Regards,
Lovis