Simple trade algorithm in C