Hi everyone, 

I'm a newbie here and I'm not an expert coder, so apologies if my question sounds silly. 

I'm trying to implement a strategy that I usually use manually that enters a trade with a LONG position when the following conditions are met:

  1. Both Stochastic %K and %D lines cross from below the oversold threshold (20)
  2. It waits until the RSI indicator crosses from below the 50 threshold
  3. It confirms the uptrend with the MACD histogram being positive (Fast line above Signal)


Now… where I'm struggling is that I don't know how to tell the algo to “wait until”. I tried with some loops but I can't seem to find something that works. 

Can anyone help me with that. I am attaching te partial code I have at the moment but it doesn't generate a backtest because the loop (clearly wrong) takes more than 10 min to run. 

Thanks in advance for the help and apologies for the question that I know will be silly.