How to trigger based on history signal?

Suppose there is such a strategy, when fast sma cross slow sma, then does not trigger buy, wait until the price falls between slow sma and fast sma, then trigger buy, whether this strategy can be developed without for loop, what is the good way?

@enjoynova I think you should take a look at the Flip() function to keep the signal generated by moving averages cross and then trigger a Buy signal when your second condition occurs and the flip/flop signal is True.

3 Likes

This is very helpful, thank you for your answer!

@enjoynova,

why would you want to use Cross and Flip if you can achieve the same by just using single "Greater_than" operator?

If you walk on the street do you prefer going to looked for location using straight road or using multiple side streets, crossroads,.... taking more time?

Same here.

Instead of over-complicating things by using Cross() and Flip()

m1 = MA( Close, 20 ); // SMA1
m2 = MA( Close, 50 ); // SMA2

upcross = Cross(m1, m2);
dncross = Cross(m2, m1);
b_flp = Flip(upcross, dncross);

Buy = b_flp AND C > m2 AND C < m1; 

You can just leave out Cross and Flip by simply using upper mentioned ">" (greater-than) operator.

m1 = MA( Close, 20 ); // SMA1
m2 = MA( Close, 50 ); // SMA2

Buy = m1 > m2 AND C > m2 AND C < m1;

What you get is same signals for both ones but second one being the straight road to goal/location.
Note: no sell signal exists yet that's why you only see multiple buy signals.

5115

5 Likes

Yes, it's simpler. Thank you!