I want to use to different indicators in a trading system. Stochastics and MACD. I want to buy when stochastics under <20 and MACD minus signal turns >0.0. First Stochastics and then MACD. Not simultaneously. They follow each other.
If I understand this correct. When I use “AND” between to indicators, the to conditions has to happen simultaneously. This is not what I want. First one indicator and then the other, regardless of the time for the first one.
If I use Stochastic < 20 and Stochastic %K crosses over Stochastic %D and I use “AND” between them, the crossover has to happen when Stochastic under < 20. But if I want the crossover to happen but not necessarily Stochastic <20. How do I code that?
How much maximum bars in the past would you like to know if the stochastic was in the oversold area before your MACD condition happen?
For this purpose, we need to create a condition that will return “true” if the stochastic were at least 1 bar under level 20, X bars before now, but we have to define how much bars to lookback, otherwise we could fetch through the entire history! 🙂
Your C3 condition could look like this:
1
2
3
X=10//define how much bars in the past we look if the stochastic were under level 20
C3=summation[x](sto<20)>0
Where ‘sto’ is your stochastic variable of course. So if the stochastic was at least one bar under level 20 between now and 10 bars ago, C3 will be true. You can now easily adapt this code snippet to your stochastic %D and %K cross also.
To help us continually offer you the best experience on ProRealCode, we use cookies. By clicking on "Continue" you are agreeing to our use of them. You can also check our "privacy policy" page for more information.Continue