By increasing energy trading in a microgrid, we can reduce the energy burden of the main grid, generate surplus power, reduce transmission and distribution losses, and save electricity bill. One of the options for curbing surplus energy flow, which will help maintain a dynamic equilibrium in the power grid between supply and demand, is Peer to Peer energy trading. When players form a group to strengthen their position and increase their payoff in a game, they are referred to as coalitions. An optimal coalition is designed in this work using the Fractional Hedonic Games mechanism, in which a player’s utilities is the average of all the other players in a coalition. The objective of using FHG is to consider each player’s preference in the game, as other games in the literature do not consider preference relations. We argued that the proposed coalition is better than the grand coalition and proved optimal and stable with a better payoff.