RSI Flag when RSI crosses any value

Im initializing a variable , suppose ‘rs_flag’ as 1 at the start. Now whenever RSI cross 40 from below, want to change the ‘rs_flag’ value to 2, which I will be using it in set conditions. Anybody help me in this?