You need to put it in a sentence HAVING. You cannot filter the result of aggregates with WHERE.
MySQL allows you to reference column aliases in HAVING. You may need
SELECT
productid,
AVG(price/amount) AS avg ,
FROM stock
GROUP BY productid
HAVING avg>=$from AND avg<=$to
But I'm not sure what exactly you are trying to do with AVG(SUM(price)/SUM(amount)), can you show some example data?