Generative adversarial networks (GANs) are machine learning models that are used to estimate the underlying statistical structure of a given dataset and, as a result, can be used for a variety of tasks, such as image generation or anomaly detection. Despite their initial simplicity, designing an effective loss function for training GANs remains challenging, and various loss functions have been proposed, aiming to improve the performance and stability of generative models. In this study, loss function design for GANs is presented as an optimization problem solved using the Genetic Programming approach. Initial experiments were carried out using a small Deep Convolutional GAN model and the MNIST dataset in order to search experimentally for an improved loss function. The functions found were evaluated on CIFAR-10, with the best function, named GANetic loss, showing better performance and stability compared to the losses commonly used for GAN training. To further evaluate its general applicability to more challenging problems, GANetic loss was applied to two medical applications: image generation and anomaly detection. Experiments were performed with histopathological, gastrointestinal, and glaucoma images to evaluate the GANetic loss in medical image generation, resulting in improved image quality compared to the baseline models. The GANetic loss used for polyp and glaucoma images showed a strong improvement in the detection of anomalies. In summary, the GANetic loss function was evaluated on multiple datasets and applications, where it consistently outperformed alternative losses. Moreover, GANetic loss leads to stable training and reproducible results, a known weak spot of GANs. Code: https://github.com/ZKI-PH-ImageAnalysis/GANetic-Loss.