Watch the Writing Melodies on top of Harmony online guitar lesson by Matthieu Brandt from Songwriting on Guitar
The melodies you write need to take the background chords into account. The feel a melody has, it's openness or closedness, the mood you set with it, it's emotional effect; this all depends on top of which harmony you play/sing the melody. Targeting specific tones in your melody and using others as passing tones is a good way to get a grip on the flow of a certain melody. Some notes will have tension on a background chord, others will feel stable. Depending on if you want to underline a certain lyrical statement or contradict it, you can chose your melody to 'feel' a certain way. A good solid memorable melody creates and resolves tension. The unstable notes will want to resolve to stable notes.