There is no trade script. It's entries in the EDB: core_buildings give a additional, individual trading bonus and a global trading bonus deduction, example (from RotK):
Code:
large_stone_wall requires factions { barbarian, middle_eastern, [ snip ]
{
capability
{
wall_level 2
[ snip ]
trade_base_income_bonus bonus 6 requires factions { all, } ; individual, added bonus for settlement - Gig
}
faction_capability ; global deduction from all settlements - Gig
{
trade_base_income_bonus bonus -1 requires factions { all, }
}
If you do your math then you will realize that the trading bonus is cancelled with the sixth large_stone_wall core building (gets a bit more complicated when applied to all core_buildings in possible random numbers of settlement levels) , after that it will reduce the bonus from other buildings in the settlement until it reaches zero over all. All that's left then in the city is income from tax and merchants.
Your max score will be achieved by having a fixed number of settlements, with fixed levels - pyramid style:1x - huge stone wall
2x - large stone wall
3x - stone wall
etc
It also depends at what level the deduction starts, it requires a rethinking of tactics: have one or two cities at max levels to churn out high level units and let the rest generate the money for the upkeep\recruitment at lower city levels.