sclass TradingPosition { settable S coin; settable bool isLong; settable int leverage; // How much we originally invest in USDT settable double marginInvestment; // How much USDT margin we end up with settable double margin; // How much crypto we bet on settable double amount; // Is position still open? settable bool ongoing; settable long openingTime; settable long closingTime; settable double openingPrice; // closing or current price settable double closingPrice; settable double openingFees; settable double closingFees; // Actual price movement during position settable TradingCandle candle; // Signal we acted on (optional) settable TradingSignal afterSignal; double openingFeePercentage() { ret doubleRatio(openingFees, margin*leverage); } double priceDifference() { ret closingPrice-openingPrice; } double leveragedPriceDifference() { ret priceDifference()*leverage; } // PNL = Profit & Loss double expectedPNL aka relativeValue() { ret (isLong() ? 1 : -1)*leveragedPriceDifference()*amount; } }