Now before asking questions, be sure to read those articles. Do some additional research on the topic. Then play around with this code to see how it may be able to do the job. I am providing three screenshots to help you see how the settings impact the signals. I will refer to those screenshots as I describe the settings. Each screenshot is numbered.
In screenshot ONE you see the settings. The comments point to specific settings. The first setting tells the code how many bars to allow between the Stochastic cross and the MACD cross. The rarely occur on the same bar. The next four settings are grouped in pairs. Each pair control the upper and lower range within which a Stochastic cross will be counted as valid. (you will likely want to experiment with different ranges after doing your research).
In screenshot TWO we see the custom study at the bottom, plotting green spikes. You see the Stochastic crossing above, within the range established by the default settings. Then you see the MACD cross above zero within 1-2 bars.
In screenshot THREE we see the same study at the bottom plotting red spikes. You see the Stochastic crossing below, within the range established by the default settings. Then you also see the MACD cross below zero within 1-2 bars.
The code is posted below. But I know many of you will be asking if we can make this into a scan. So immediately below the code I will show which lines to change in order to make this into a scan.
declare lower;
input signalBarsTolerance = 2;
input posX_RangeTop = 80;
input posX_RangeBottom = 50;
input negX_RangeTop = 50;
input negX_RangeBottom = 20;
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageTypeMACD = AverageType.EXPONENTIAL;
def Diff = MACD(fastLength, slowLength, MACDLength, averageTypeMACD).Diff;
input KPeriod = 10;
input DPeriod = 10;
input priceH = high;
input priceL = low;
input priceC = close;
input averageTypeStoch = AverageType.SIMPLE;
def SlowK = reference StochasticFull(80,20,KPeriod,DPeriod,priceH,priceL,priceC,3,averageTypeStoch).FullK;
def SlowD = reference StochasticFull(80,20,KPeriod,DPeriod,priceH,priceL,priceC,3,averageTypeStoch).FullD;
def histogramCrossesAbove = Diff[1] < 0 and Diff > 0;
def histogramCrossesBelow = Diff[1] > 0 and Diff < 0;
def slowKCrossesAboveSlowD = slowK[1] < slowD[1] and slowK > slowD;
def slowKCrossesBelowSlowD = slowK[1] > slowD[1] and slowK < slowD; def greenRange = slowD[1] > posX_RangeBottom and slowD[1] < posX_RangeTop;
def redRange = slowD[1] < negX_RangeTop and slowD[1] > negX_RangeBottom;
def greenSignal = (histogramCrossesAbove and Highest(slowKCrossesAboveSlowD, signalBarsTolerance) > 0 and greenRange) or (slowKCrossesAboveSlowD and Highest(histogramCrossesAbove, signalBarsTolerance) > 0 and greenRange);
def redSignal = (histogramCrossesBelow and Highest(slowKCrossesBelowSlowD, signalBarsTolerance) > 0 and redRange) or slowKCrossesBelowSlowD and Highest(histogramCrossesBelow, signalBarsTolerance) > 0 and redRange;
plot greenSpike = greenSignal;
greenSpike.SetDefaultColor(Color.GREEN);
plot redSpike = redSignal;
redSpike.SetDefaultColor(Color.RED);
Ok, this next bit is for those looking to use this as a scan. From the code listed above, delete the last four lines. Then add these new lines to build your scans.
# use this scan to find stocks with green spikes
plot scan = greenSignal;
# use this scan to find stock with red spikes
#plot scan = redSignal;
The prerequisite to building and using this as a custom scan is to watch a few of our videos on that topic. You can find them listed at the top of the page under the menus item titled “Free Tutorials”.
For those who would like to use workspace sharing I am providing a link. This link is for an entire chart grid, the StochMACD indicator is included. http://tos.mx/B7ebLF