Hello.
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.
Can anyone help me with the code?
Now I have;
IF C3 AND c4 THEN.
Replace AND?
You can refer to a past conditions with periods offset under bracket:
IF C3[2] AND C4 THEN
In this example, the C3 condition was met 2 bars ago and the C4 one, on the current candlestick.
Please let us know if you have any other questions about testing conditions in the past data.
It partially worked.
The code I am looking for is when one indicator is meet, for exampel Stochastic < 20 and regardless of the time, MACD minus signal is >0.
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?
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?
That’s the reason why I asked you this question:
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:
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.