Hello there,
Sorry for the late reply but your post was somehow lost in the jungle

Well, your idea is not really revolutionary

and it is most ^probably close to the "MartinGale" pattern. Therefore, I'm attaching a martin Gale example for your consideration and I recommend you to study it carefully in order to understand its functional behavior and technical build. Feel free to modify it for your own need.
Cheers !