Code two indicators conditions one before the other one

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #20387 quote
    Nufstad
    Participant
    Junior

    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?

    #20403 quote
    Nicolas
    Keymaster
    Master

    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.

    #20436 quote
    Nufstad
    Participant
    Junior

    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.

    Code.jpg Code.jpg
    #20546 quote
    Nicolas
    Keymaster
    Master

    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?

    #20708 quote
    Nufstad
    Participant
    Junior

    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?

    #20715 quote
    Nicolas
    Keymaster
    Master

    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.

    #20718 quote
    Nufstad
    Participant
    Junior

    Thanks. I will test it.

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.

Code two indicators conditions one before the other one


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Nufstad @nufstad Participant
Summary

This topic contains 6 replies,
has 2 voices, and was last updated by Nufstad
9 years, 1 month ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 01/10/2017
Status: Active
Attachments: No files
Logo Logo
Loading...