Solenoid firing

I’m having a coding issue and I’m sure its an easy fix but I can’t figure it out. I’m using an accelerometer to detect an angle and then pull a solenoid for 300ms then let go. However, I want it to do this only one time when an angle > 20deg is read. With my code now, it keeps pulling until it reads an angle < 20deg. How can I change my code to make that happen?

ydegrees=((analogRead(ypin)-345)*1.304);

if (ydegrees < -20 or ydegrees > 20) {
digitalWrite(Solenoid, HIGH);
delay(300);
digitalWrite(Solenoid, LOW);

}
else
digitalWrite(Solenoid, LOW);
ydegrees=0;

Have a variable that is set when >20 and reset when <20.
Test this variable, if it is reset and >20 fire the solenoid and set the variable.

Would anyone be able to help me out with the above coding suggestion? I still cant figure it out and I know its so simple :stuck_out_tongue_closed_eyes:

Example StateChangeDetection in 02.Digital.