Question about bot

I wanna mix reverse marting gale with regular martin gale. How do i make it so the bot resets the amount every 4 operations, and that if there is a loss, it increases the series capital by the gale amount, and after winning that, resets the operation amount back to the base amount? Thanks.