protected override void onNewBar() { //Remove this code later if (parabolicStop != null) { if (parabolicStop.positionClosed()) { parabolicStop = null; } else { stopIndicator.set(parabolicStop); } } if (parabolicStop == null) { stopIndicator.set(bars[0].close); } //***************************************************************** //Setup from prior bar, now in confirm if (inConfirm) { confirmBarCount++; if (confirmBarCount <= entryBarWindow) { placeEntryOrders(); } else { inConfirm = false; } } if (inConfirm) { return; } //Not in confirm from prior bar, so check for setup setup = tradeSetup(); if (!hasPosition() && (setup != null)) { tradeSize = (long)Math.Max(Math.Round(riskDollars / ((nATRStopStart * atr) * bigPointValue()), 0), 1); atrAtEntry = atr; longEntryPrice = entryLowestLow[1] + atr * nATREntry; shortEntryPrice = entryHighestHigh[1] - atr * nATREntry; placeEntryOrders(); inConfirm = true; confirmBarCount = 1; } //Currently in position, submit exit orders if (hasPosition()) { placeExitOrders(); } }
protected override void onClose(Dictionary <Symbol, Bar> current) { var leftClose = current[pair.left].close; var leftCarry = (leftPrior[0].close - leftClose) / 3.0; var rightClose = current[pair.right].close; var rightCarry = (rightPrior[0].close - rightClose) / 3.0; payoutRatio.set((leftCarry - rightCarry) / (vol * Math.Sqrt(22))); var wantOut = Math.Abs(payoutRatio) <= cutoff; var wantLong = payoutRatio > 0; if (wantOut) { placeExits(leftClose, rightClose); return; } if (hasPosition() && wantLong == position(pair.left).direction().isLong()) { return; } placeExits(leftClose, rightClose); if (wantLong) { placeOrders(pair.buy("long payout achieved", limit(leftClose), limit(rightClose), 1000, oneBar())); } else { placeOrders(pair.sell("short payout achieved", limit(leftClose), limit(rightClose), 1000, oneBar())); } }
protected override double exitLevel() { Bomb.when(position.isClosed(), () => "position closed without cleaning up parabolic stop!"); if (numBars == 0) { return(initialStopPrice); } if (maxExtreme.changed()) { af.set(Math.Min(af[1] + afStep, afMax)); } return(capped(this[1] + af * (extreme - this[1]))); }
protected override double calculate() { if (values.count() > 1) { noise.set(Math.Abs(values[0] - values[1])); } if (values.count() <= calcBars) { return(values[0]); } var signal = Math.Abs(values[0] - values[calcBars]); var efficiencyRatio = signal / noiseSum; var smoothingCoefficient = Math.Pow(efficiencyRatio * (decayFast - decaySlow) + decaySlow, 2); return(this[1] + smoothingCoefficient * (values[0] - this[1])); }
public ParabolicStop( Position position, BarSpud bars, double initialStopPrice, double afStep, double afMax, int lookbackBars, string name ) : base(position, name, PROTECTIVE_STOP, bars.manager) { this.initialStopPrice = initialStopPrice; this.afStep = afStep; this.afMax = afMax; this.bars = bars; af = dependsOn(new RootSpud <double>(manager)); af.set(afStep); extreme = dependsOn(position.longShort(bars.high, bars.low)); var extremeSide = position.longShort(MinMax <double> .MAX, MinMax <double> .MIN); maxExtreme = dependsOn(extreme.minMax(extremeSide)); opposite = position.direction().isLong() ? bars.low : bars.high; recentOppositeExtreme = dependsOn(position.direction().isLong() ? opposite.lowest(lookbackBars) : opposite.highest(lookbackBars)); numBars = dependsOn(new BarCounter(bars)); }
protected override double calculate() { if (values.count() == 1) { return(double.NaN); } var changes = values[0] - values[1]; upChanges.set(Math.Max(0.0, changes)); dnChanges.set(-Math.Min(0.0, changes)); double rs; if (dnAverage == 0) { rs = 1000000.0; } else { rs = upAverage / dnAverage; } return(100.0 - (100.0 / (1.0 + rs))); }
protected void addPoint(SOURCE newInput) { manager.newBar(); values.set(newInput); }
protected void addPoint(double newY, double newX, double newSlope) { addPoint(newY, newX); slope.set(newSlope); }
protected void addPoint(double newY, double newX) { addPoint(newY); x.set(newX); }