For cardiac rhythm management, a combination of cardiac pacing and a noninvasive heart monitoring is proposed for the determination of a set of programmable pacing parameters hemodynamically beneficial to the patient. The apparatus incorporates a cardiac pacemaker and a thoracic electrical bioimpedance (TEB) heart monitor. This combination allows the creation of a closed-loop system that obtains pacing parameter settings providing hemodynamically beneficial pacing therapy to the patient as determined by measuring and recording of stroke volume (SV), cardiac output (CO), and other indices of ventricular performance by the heart monitor during an optimization cycle automatically employing different permutations of values of pacing parameters such as atrioventricular delays, inter-atrial delay, inter-ventricular delay, or heart rate, that are sequentially programmed to the pacemaker. The hemodynamically beneficial permutation of pacing parameter values is determined from all recordings and programmed to the pacemaker for permanent or temporary pacing therapy.