// calculate profit in percent for a position // direction = 1 for long, -1 for short static double calculatePositionProfit(double openingPrice, double closingPrice, int direction, int leverage) { ret (closingPrice-openingPrice)*direction/openingPrice*leverage*100; }