public DollarTrailingStop(Position position, Spud <double> close, double stopLoss, string name, QREBridgeBase bridge) : base(position, name, STOP, close.manager) { this.close = close; this.stopLoss = stopLoss; this.bridge = bridge; tradePnl = close.transform(price => position.pnlNoSlippage(price, bridge.arguments().runInNativeCurrency, bridge.fxRate(position.symbol))); highWaterMark = dependsOn(new Max(tradePnl)); }
public FaderCloseObjective(QREBridgeBase bridge, Symbol symbol) : base(bridge, symbol) { //Set up raw moving average var maLength = parameter <int>("maLength"); switch (parameter <int>("maType")) { case 1: maRaw = new AggregatorSpud <double>(bars.close, average, maLength); break; case 2: maRaw = new KAMA(bars.close, 2, 30, maLength); break; default: Bomb.toss("Not valid maType"); break; } //Set up stdDev priceStDev = new AggregatorSpud <double>(bars.close, standardDeviation, parameter <int>("stDevLength")); //Set up regression regressionBars = parameter <int>("regressionBars"); Bomb.when((parameter <int>("LeadBars") < regressionBars), () => "LeadBars cannot be less than regressionBars." + arguments()); var count = new BarCounter(bars).transform(i => (double)i); projectionSpud = new QRegression(maRaw, count, regressionBars, false); regressionProjBars = parameter <int>("regressionProjectionBars"); levelProjection = projectionSpud.transform(barsRegression => barsRegression.predict(count + regressionProjBars)); //Set up other parameters zEntry = parameter <double>("ZEntry"); zExit = parameter <double>("ZExit"); minPnLMultTC = parameter <double>("minPnLMultTC"); stopMultiple = parameter <double>("stopMultiple"); riskDollars = parameter <double>("RiskDollars"); addToPlot(maRaw, "maRaw", Color.Blue); addToPlot(levelProjection, "Projection", Color.Red); addToPlot(priceStDev, "StDev", Color.Green, "Support"); }