programming question?

 
suppose I want to enter a trade when one condition just occured and another occured in the last 4 bars. how do I code that? for example, if I want to buy if stochastic crosses above 20, and RSI crossed 30 in the last 3 bars, do I need to define RSI for the last 3 bars and then code that? can I use a for loop instead? but I don't know how to code the boolean logic using the for loop.
 

test for the stochastic if it is above 20 test the RSI in a for loop. Use the shift parameter in iRSI() with the for loop.

kinda like this

if(iStocs >20)

{for(i=0 .. etc

 {if(iRSI(parameters,i) >30) 

  {bool flag=true;

}}} 

 
Thanks! one more thing-what if I need a crossover? For example, if stochastic crossed with its signal line in the last 3 bars, we wont enter a buy.
 
1mathboy1: what if ...
Code it.