Many traders place importance on the crossing of two moving averages. Indeed, these are given the special names of: Golden Cross – when a shorter moving average crosses above a longer moving average Dead Cross – when a shorter moving average crosses below a longer moving average Now wouldn’t be useful to be able to have an indicator which provides the price at which two averages will cross on the current bar? Well, here it is: First of all, let us go through how this is calculated. Let us take a 5 period and 10 period moving average. At the price at which two averages cross quite obviously they equal each other. We know at that point that:
Average(close,5) = Average(close,10) Breaking that down we know that an average is calculated by summing the past “x” closes and dividing by “x.” So for a 5 period average we take today’s close plus the past 4 and divide by 5. For a 10 period average we take today’s close plus the past 9 and divide by 10. In this case we will not use “today’s close” but today’s “crossing price.” Also, to make the formula generic we’ll use P1 for the length of the short moving average and P2 for the long moving average. The common number to both is the crossing price. We know the rest. So we can rewrite the equation thus: (Sum(Close,P1-1)[1] + cross price ) / P1 = (Sum(Close,P2-1)[1]+ cross price ) / P2 Where the suffix [1] represents the value of the prior bar If we then bring this down we can derive: Cross Price = (Sum(Close,P2-1)[1] * P1 - Sum(Close,P1-1)[1] * P2 ) / (P2 - P1) The moving average cross rate is very easy to input into Chart Studio. Open this feature and open a new technique. Cut and paste the following into the area that appears:
indicator MvgAvgCrossRate2; input price = close, period1 = 5, Period2 = 20 ; draw MACR("MA Cross Rate") ; vars c(number), Sum1(series), Sum2(series), CR(series), i(number), b(number), f(number); begin f := front(price); b := back(price); Sum1 := Summation(price, period1 - 1) ; Sum2 := Summation(price, period2 - 1); for i := f + 1 to b do begin CR[i] := ( (Sum2[i-1] * Period1) - (Sum1[i-1] * Period2) ) / (Period2 - Period1) ; end; MACR := CR ; end.
Following this select “Build” and select “Verify Module” from the top menu bar You will be prompted to enter a name for this analysis technique. Write in “Mov Avg Cross Rate.” The Select “Build” again and this time you should see this succeed in the output window at the bottom of the studio. Then select “Build” again but this time choose “Install Module” The module will be installed into the User Modules. You will now be able to access Mov Avg Cross Rate in the charting application via the “set Up Indicators” icon at the top of the chart. The indicator may be plotted on top of the price chart or below in a sub chart. 
The image above has the MA Cross rate applied in both price chart and sub chart for comparison with the respective moving averages also plotted. Ian Copsey
|