Abstract. Most community detection algorithms from the literature work as optimization tools that minimize a given quality (or fitness) function, while assuming that each node belongs to a single community. Although several studies propose fitness functions for the detection of communities, the definition of what a community is is still vague. Therefore, each proposal of fitness function leads to communities that reflect the particular definition of community adopted by the authors. Besides, such communities not always correspond to the real partition observed in practice. This paper proposes a new flexible fitness function for community detection that allows the user to obtain communities that reflect distinct characteristics according to what is needed. This new fitness function was combined with an adapted version of the immune-inspired optimization algorithm named cob-aiNet[C] and applied to identify (both disjoint and overlapping) communities in a set of artificial and real-world complex networks. The results have shown that the partitions obtained with the optimization of this new metric are more coherent (when compared to the real, known, partitions) than those obtained with one of the most adopted function from the literature: modularity.