[MAS-tips] analyzer alternatives (macd histogram)
Brought to you by:
jcochrane
From: Jim C. <jt...@di...> - 2003-06-02 19:16:58
|
Paul - I couldn't resist trying out making an analyzer with the indicator we created yesterday, along with a couple alternatives. (I'm also sending this to the tips list in case others find it useful.) I've included the macl scripts for the indicators and analyzers I tried, below. The first script uses two indicators: the indicator we created yesterday and a line. It simply gives a signal if the "test1" (as I named it) indicator crosses over the line. (So it is detecting when the indicator goes from 0 to 1, rather than whenever its value is 1, as we were thinking of yesterday.) The 2nd script tries a different approach, using slope to detect the same change. (Hopefully the comments in the script are self-expalanatory.) The 3rd script is the indicator we created yesterday, which I'm including for completeness. If you try out the 1st and 2nd scripts, you'll notice that, although many signals are the same, some differ by a day and some (from script 1, I believe) are generated that don't exist in the other. This is because the slope analyzer used for the 2nd script approximates the slope by using 3 data points: last period's, the current period's, and the next period's (e.g., yesterday, today, and tomorrow). It does this so that it is not late in detecting -/+ and +/- slope changes. (I think, in general, not being late is a good thing for trading.) So sometimes its signals are earlier than those of the other analyzer. And sometimes the signals are just different - because of the approximation. You may find using slope detection like this is what you want for many of your analyzers. (There are more analyzers that use slope in the "market_analyzers" macl script file that comes with the mas release, if you want to study them a bit to learn more about how to use the slope.) I hope you find this helpful. Jim ----------------------------------------------------------------------------- # macl script that defines a market analyzer that detects when a "test1" # indicator (which is 1 if macd-hist[today] > macd-hist[yesterday] and 0 # otherwise) changes from 0 to 1. It does this by detecting if test1 # crosses over a horizontal line whose y value is 0.5, which is in between 0 # and 1. m c s t test1 y Line y 0.5 0 daily below-to-above n b test1: 0 -> 1 s - x ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- # macl script that defines a "Slope of MACD Histogram" indicator and a # "Slope of macd hist crossed above 0" market analyzer that uses the # "Slope of MACD Histogram" indicator. The market analyzer does its # job by detects if slope of macd hist. crosses over horizontal line # whose y value is 0. e c n ONE_VARIABLE_FUNCTION c Slope of MACD Histogram 2 MACD Histogram y SLOPE_ANALYZER c MACD Histogram y s - m c s t Slope of MACD Histogram y Line y 0 0 daily below-to-above n b test2: Slope of macd hist crossed above 0 s - x ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- # An indicator that is 1 if macd-hist[today] > macd-hist[yesterday] and 0 # otherwise e c n ONE_VARIABLE_FUNCTION c test1 MACD Histogram y NUMERIC_CONDITIONAL_COMMAND c GT_OPERATOR c BASIC_NUMERIC_COMMAND c SETTABLE_OFFSET_COMMAND c BASIC_NUMERIC_COMMAND c MACD Histogram y 1 NUMERIC_VALUE_COMMAND c 1 NUMERIC_VALUE_COMMAND c 0 s - x ----------------------------------------------------------------------------- |