Trade script code for following

2 period rsi crossed above 60 or
2period rsi crossed belowe 40

For the above given condition

RSI(CLOSE,2)>60 OR RSI(CLOSE,2)<40

i wanna crossed over code means if 2period rsi crosses 60 then only signal should be genrated but by above code a signal are generated even if rsi already aboce 60 or below 40

can you help me to make a EA?