sclass TradingCandle { // min, max, start and end prices settable double min; settable double max; settable double start; settable double end; settable Timestamp startTime; settable Timestamp endTime; settable bool ongoing; bool isGreen() { ret end > start; } bool isRed() { ret end < start; } bool isWhite() { ret end == start; } S colorText() { ret isGreen() ? "green" : isRed() ? "red" : "white"; } double durationInSeconds() { ret toSeconds(endTime.minus(startTime)); } void addValue(double price, Timestamp timestamp) { if (price < min) min = price; if (price > max) max = price; end = price; endTime = timestamp; if (startTime == null) { startTime = timestamp; start = price; } } S myType() { ret "candle"; } toString { S text = firstToUpper(colorText()) + " " + myType(); if (startTime != null) { text += " starting " + startTime + ", duration " + iround(toSeconds(endTime.minus(startTime))) + "s"; text += ", starting price " + start + ", end price " + end; } ret text; } double changeRatio() { ret doubleRatio(end, start); } public TradingCandle clone() { ret shallowClone(this); } }