You could try a service like tradingview (paid, but with free trial). They have alerts based on scripts (and a library of user made scripts) that run on historical data like price, volume, etc. You pay, in part, to access this data (with a little time lag--pay more for less lag).
As far as writing such a script, I'm not sure its possible. If you could determine when a price is high/low such that its an advantageous to sell/buy, so could others, and the price would fall/rise to account for that information. But not everyone agrees with me. See: https://en.wikipedia.org/wiki/Efficient-market_hypothesis So it may be possible :)