Using MACDSeries Histogram
Author: dag
Creation Date: 8/18/2009 12:48 PM
profile picture


How can I write a code to back-test the idea of using the slope(between bars)of the MACD histogram to enter and exit long and short trades ?
profile picture


Then we need to start with how do you define the slope?
profile picture


This is an idea I have toyed with as well.

If JJJA is agreeable, I would propose toying with (sorry, not a programmer) -

1. a sliding variable SellSlope to input the target to trigger a sell;
2. a sliding variable BuySlope to input the target to trigger a buy;
3. a sliding variable entry SlopeBars to specify the number of bars such that, TodaysBars - SlopeBars would generate StartSlopeBar

SlopeMACDHistogram = [(TodaysBarsMACDHistogram - StartSlopeBarsMACDHistogram) * SlopeBars] / 250 <? is 250 the number of trading days in a year?>

profile picture


I don't think it makes a lot of sense to consider the slope of a 12/26-period MACD oscillator over 250 bars.

My take: smooth the historgram a little with a responsive filter, like Kalman, and take the 1 or 2-period difference -

Please log in to see this code.

profile picture


Thank you for your help. I wish I knew enough about this programing to understand all that you have told me. I will study and try to see if this answers my question. In answer to Eugene's question, a line connecting one day's bar to the next creates a line with slope relative to the zero line on the histogram. It seems that buying long from zero on the bottom and selling at zero on top would be a good strategy. But I don't know whether the stock price corollates very well or whether whipsawing will cause to much buying and selling.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).