Warning: session_start(): open(/var/lib/php/sessions/sess_9ph5dcja7qi8m0rvci8omi4l1r, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
persistable class Position extends G22TradingStrategy.Position {
settable AbstractJuicer juicer;
}
srecord ProfitBeforeLeverageJuiceable(Position p) is Juiceable {
public double juiceValue() { ret p.profitBeforeLeverage(); }
}
void juiceStrategy_price(double price) {
if (currentPrice == price) ret;
currentPrice = price;
afterwards { change(); }
for (p : cloneList(openPositions())) {
cast p to Position;
if (p.juicer != null) {
var signals = p.juicer.calculateCloseSignals();
var strongest = highestBy(signals, s -> s.strength());
if (strongest != null && strongest.isTrigger()) {
p.close(strongest);
}
}
}
}
Position openShort() { ret openPosition(-1); }
Position openLong() { ret openPosition(1); }
Position openPosition(int direction, O openReason default null) {
new Position p;
p.marginToUse = marginPerPosition;
addJuicer(p);
ret openPosition(p, direction, openReason);
}
void addJuicer(Position p) {
p.juicer(makeJuicer());
p.juicer.juiceable(new ProfitBeforeLeverageJuiceable(p));
}
void recreateJuicersForExistingPositions() {
for (p : cloneList(openPositions())) {
cast p to Position;
addJuicer(p);
}
}