Hi Cstyle. A couple of thoughts:

When looking for help (in any forum), things like "The values being written" are too vague. Much better to also post the log or a snippet showing the values, bar where they occurred, etc., as well as why the values "don't seem right".

Re. the code, take a look at TradePriceClose vs. priceClose().

HTH.