Many directions to take this question, I'll bite with the most theoretical, lest practical of them.
Short Answer: Kinda. Rebalancing from 'riskier' investments into 'safer' investments. i.e rebalancing equity gains into your bond allocation (Remember when that used to happen frequently?) Bonds obviously are not risk free, the shorter the duration the less theoretical risk.
Long Answer: No. Bonds are not this risk-free investment that every seems to think. (Not risk free in the sense of duration and interest rates, everyone here seems to get that. I'm talking default, or complete monetization of treasuries). Not saying it will happen in my lifetime or ever, but it is not 100% impossible. In such a scenario no paper asset would be worth anything. So even if you think you cash would be king it would not be, not if treasuries are defaulted upon. In which case hard assets are they key. Gold & silver & land. Except in such a scenario where treasuries are worthless these could and probably would be confiscated. In such a scenario your only shot as they say is guns, ammo, and food, hardly what I would call locking in gains. Remember a Federal Reserve Note is not worth the amount printed on all four corners, rather it is worth what another party is willing to accept it for. So no you can never truly 100% lock in gains it is simply impossible.
Best Answer: Yes. One can lock in gains by living a great life. Having friends, possibly a significant other, maybe kids, family etc. Sharing memories with these individuals or maybe just making memories by yourself. Go to the top of the Empire State Building, go see the lights of Paris, go climb Machu Picchu, drink some beers and kiss The Blarney Stone. Volunteer every so often, feed someone who doesn't have food, lend an ear to an elder in need of companionship and teach an underprivileged kid to read. That is how you lock in gains that no government, no economic cycle, inflation, deflation or standing army can take from you. Lock in gains by trading Federal Reserve Notes for things you will remember on your death bed, the moment your life flashes before your eyes, or just when you are lying in bed at night.