Throw back a few phalanxes on the flanks in reserve out of phalanx mode. Slant them slightly so they are protecting your flanks. Once you see cavalry coming just turn on phalanx mode and leave them there. Don't form your phalanx into a single line of advance, that's not wise against Dacians. Alternatively, form your phalanxes into a single line but hire some barbarian mercenaries and put them behind your main phalanx line. Also, do not counter charge your cavalry, but let your phalanxes and mercenaries absorb the shock so the enemy loses his charge bonus. THEN you counter charge. That way you minimise casualties drastically and completely screw up the enemy's morale, especially if you're not doing a frontal countercharge. Your cavalry are least effective when used on cav-cav melee with both sides charging. As Macedon, it is essential that you have a healthy force of melee mercenary infantry when in barbarian areas.
I once fought two Dacian armies with one Macedonian. I had 3 levies, 6 light lancers, 2 generals and 4 barbarians/bastarnae. I offered my 3 levies alone to the first army (the second had not yet arrived), which promptly dashed itself to pieces on my levies while my mercenaries absorbed the shock from the second army's cavalry and my cavalry destroyed the first, putting them in the perfect position to destroy the second army from the rear after my levies turned, just in time to meet the second army's infantry which promptly dashed itself to pieces on it. The trick is, when fighting with phalanx and melee infantry, leave your melees out of the line and put them behind, because the barbarian AI unfailingly chooses to charge melee infantry over phalanx.
And one a final note, you should NEVER enter barbarian territory without cavalry, no matter how many phalanxes you have. That is sheer folly, because the barbs have the best light cav in the game. If don't have any cavalry, your phalanxes can only have the fate of being flanked and annihilated.