Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
MACD signal with Volume MA signal

Hello everyone,

This is my first attempt at a strategy all by myself.

The idea is to take the MACD example for buy/sell signals but add a volume MA component that allows the strategy to hold still when the volume hasn't gone above the MA for the past 12 days.

My rationale is that usually MACD can go above or below 0 for small changes, however that does not necessarily mean anything. In my (very limited) experience, the MACD signal is strongest when coupled with a volume reading. If the MACD signal is triggered and also the volume for that day turns out to be much greater than the previous day's volume (thus the volume MA signal), then we can argue that something is happening and we get in or out.

However, my issue now is that apparently I'm heavily leveraged because even when trading with 10K USD my cash goes down to almost -50K USD.

How can I limit this such that I only buy when I have the sufficient amount of cash in hand? i.e. if the triggers tell me to buy 4K USD of security X and I only have 2K, it should not buy (or maybe better, buy only what's available).

Any ideas and comments are greatly appreciated. Also, any analysis on why this is working/not working is welcomed as well.

Thanks!

3 responses

Using talib.MACD() now, besides talib.KAMA(), and had fun tossing a few ideas around.

This is great Gary, thanks a mil! exactly the sort of thing I Was looking for.

I played around a bit with the securities, and because I always loved MMM and KO for their stability I tried them and also a few more (Which I consider relatively stable) andI Got nice results. Even going back as far as 2009 there's still a nice Sharpe ratio and although returns are below SPY performance, I think it's quite low in risk, or so it seems.

The strategy seems to be less sensitive to big changes in volatility, so you can even spot a few plateaus were there is not much action.

If you move the start date for the backtest to 2010, 2011, 2012, 2013 and even 2014 we can see similar results.

I kinda like this!

I tweaked things a bit and now tried the following:

If MACD < signal and volume > volume_KAMA then we buy

If MACD > signal and volume > volume_KAMA then we sell.

I also changed the Vol KAMA period to 7 days. For some reason that's the value that works the best. Even better than 12 day period.

What I don't understand and maybe you could explain :) is that MACD < signal -> but seems counterintuitive. I mean, if MACD goes above the signal and also the volume goes up sharply (above KAMA) then that means long sentiment is strong, and same for the opposite. If I do it in the "intuitive" way (i.e. buy when MACD > signal) returns and sharpe is much lower. I have no idea why.

And finally I changed the leveraged amount so instead of buying up to 5X of the portfolio value, it only goes up to 1X (i.e. 100% at most such that there is never borrowing).

I'm starting to like this even better!