public SwingMA(QREBridgeBase bridge, Symbol symbol) : base(bridge, symbol) { entryATRMargin = parameter <double>("EntryATRMargin"); exitATRMargin = 2 * entryATRMargin; stopATRs = parameter <int>("StopATRs"); riskDollars = parameter <double>("RiskDollars"); atr = new AverageTrueRangeEW(bars, parameter <int>("ATRLen")); maSlow = new Average(bars.close, parameter <int>("MASlow")); //Set up raw moving average switch (parameter <int>("MAType")) { case 1: maSlow = new Average(bars.close, parameter <int>("MASlow")); maFast = new Average(bars.close, parameter <int>("MAFast")); break; case 2: maSlow = new KAMA(bars.close, 2, 30, parameter <int>("MASlow")); maFast = new KAMA(bars.close, 2, 30, parameter <int>("MAFast")); break; default: Bomb.toss("Not valid MAType"); break; } addToPlot(maSlow, "maSlow", Color.Blue); addToPlot(maFast, "maFast", Color.Red); addToPlot(atr, "ATR", Color.Blue, "ATRPane"); }
public BollingerBand(Spud <double> values, int barsBack, double deviations) : base(values.manager) { this.barsBack = barsBack; this.deviations = deviations; mean = dependsOn(new Average(values, barsBack)); sd = dependsOn(new StdDeviationOfPopulation(values, barsBack)); }
public PlotDefinition(Spud <double> spud, string name, Color color, string pane) { this.spud = spud; this.name = name; this.color = color; this.pane = pane; }
protected double weightedSum(Spud <double> s) { var sum = 0.0; zeroTo(window, i => sum = sum + weights[window - i - 1] * s[i]); return(sum); }
public Fibonacci(BarSpud values, int nDays) : base(values.manager) { this.values = dependsOn(values); this.nDays = nDays; highestHigh = values.high.highest(this.nDays); lowestLow = values.low.lowest(this.nDays); }
protected double weightedSumBivariate(Spud <double> s1, Spud <double> s2) { var sum = 0.0; zeroTo(window, i => sum = sum + weights[window - i - 1] * (s1[i]) * (s2[i])); return(sum); }
public NBarFade(QREBridgeBase bridge, Symbol symbol) : base(bridge, symbol) { atrLen = parameter <int>("ATRLen"); nDays = parameter <int>("nDays"); nATREntry = parameter <double>("nATRentry"); stopAfStep = parameter <double>("stopAfStep"); stopAfMax = parameter <double>("stopAfMax"); entryBarWindow = parameter <double>("entryBarWindow"); closeBetter = parameter <bool>("closeBetter"); riskDollars = parameter <double>("riskDollars"); atr = new AverageTrueRangeEW(bars, atrLen); // this should be a daily spud nATRStopStart = nATREntry * parameter <double>("exitATRmultiple"); entryHighestHigh = bars.high.highest(nDays); entryLowestLow = bars.low.lowest(nDays); var halfNDays = (int)Math.Round(nDays * 0.5, 0); exitHighestHigh = bars.high.highest(halfNDays); exitLowestLow = bars.low.lowest(halfNDays); inConfirm = false; //Plot methods parabolicStop = null; stopIndicator = new RootSpud <double>(bars.manager); addToPlot(stopIndicator, "ParabolicStop", Color.Red); addToPlot(entryHighestHigh, "entryHighestHigh", Color.LightBlue); addToPlot(entryLowestLow, "entryLowestLow", Color.Blue); addToPlot(exitHighestHigh, "exitHighestHigh", Color.Pink); addToPlot(exitLowestLow, "exitLowestLow", Color.Salmon); addToPlot(bars.close, "price", Color.Purple); addToPlot(atr, "ATR", Color.Blue, "ATRPane"); }
// this class provides a hook for choosing a type of standard deviation based on a param. // if you know which you want, use the appropriate constructor directly. public static AggregatorSpud <double> maybeBiased(Spud <double> value, int windowSize, bool isBiased) { if (isBiased) { return(new StdDeviationOfPopulation(value, windowSize)); } return(new StdDeviationOfSample(value, windowSize)); }
static Dictionary <DateTime, double> dates(Spud <Bar> bars) { var i = 1.0; var result = new Dictionary <DateTime, double>(); Objects.each(bars.toArray(), bar => result[bar.time] = i++); return(result); }
public DoubleSpudGraphable(string name, Spud <double> doubles, BarSpud bars) { this.name = name; this.doubles = doubles; timeIndices = bars.timeLookup(); bars.valueSet += bar => timeIndices[bar.time] = 0; bars.pushedDown += () => timeIndices = bars.timeLookup(); }
public RSI(Spud <double> values, int halfLife) : base(values.manager) { this.values = dependsOn(values); upChanges = new RootSpud <double>(manager); dnChanges = new RootSpud <double>(manager); upAverage = new EWMA(upChanges, halfLife); dnAverage = new EWMA(dnChanges, halfLife); }
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 RandomWalkKalman(Spud <double> values, int freq, int window, bool useGoldenRatio) : base(values.manager) { this.values = dependsOn(values); this.window = window; this.freq = freq; this.useGoldenRatio = useGoldenRatio; sequence = Fibonacci.Sequence(2 * window); logValues = dependsOn(new LogSpud(values)); }
public KAMA(Spud <double> values, double maFastLength, double maSlowLength, int calcBars) : base(values.manager) { this.values = dependsOn(values); decayFast = 2 / (maFastLength + 1); decaySlow = 2 / (maSlowLength + 1); this.calcBars = calcBars; noise = new RootSpud <double>(values.manager); noiseSum = new AggregatorSpud <double>(noise, sum, calcBars); }
public FXCommodityClose(QREBridgeBase bridge, Symbol symbol) : base(bridge, symbol, bars => commoditySignal(bridge.arguments().parameters.get <int>("signal"), bars)) { maFX = new Average(bars.close, maDays); currencyReversed = symbol.name.StartsWith("USD"); maxBarsHeld = parameter <int>("MaxBarsHeld"); addToPlot(upperBand, "UpperBand", Color.Blue, "Commodity"); addToPlot(lowerBand, "LowerBand", Color.Blue, "Commodity"); addToPlot(ma, "commodMovingAverage", Color.Red, "Commodity"); }
public TDSequential(QREBridgeBase bridge, Symbol symbol) : base(bridge, symbol) { setupLength = parameter <int>("SetupLength"); version = parameter <int>("Version"); waitForFlip = parameter <int>("WaitForFlipOnEntry"); countdownLength = parameter <int>("CountdownLength"); setupCount = new TDSetup(bars); setupInPlace = 0; stopLevel = 0; tdCountdown = 0; bars.close.prepare(); }
bool isRecovered(Spud <int> barsSinceStopOut, long size) { var barsBack = Math.Min(barsSinceStopOut, recoveryPeriod); if (barsSinceStopOut > recoveryPeriod) { size = tradeSize(); } var pnl = symbol.pnl(size, bars[barsBack].close, bar.close); return(pnl > recoveryAmount); }
public FXCarry(QREBridgeBase bridge, Symbol symbol) : base(bridge, symbol) { payoutRatio = payoutRatioSymbol(symbol).doubles(bars); atr = new AverageTrueRange(bars, 100); tradeSizeParameter = parameter <double>("TradeSize"); recoveryAmount = parameter <double>("RecoveryAmount") * tradeSizeParameter; recoveryPeriod = parameter <int>("RecoveryPeriod"); trigger = parameter <double>("Trigger"); maxTrigger = parameter <double>("MaxTrigger"); triggerCushion = parameter <double>("TriggerCushion"); addToPlot(payoutRatio, "payoutRatio", Color.Red, "payoutRatio"); bars.close.prepare(); stoppedOut(); }
protected TrendingMABase(QREBridgeBase bridge, Symbol symbol, Converter <BarSpud, Spud <double> > signalSeries) : base(bridge, symbol) { maDays = parameter <int>("MADays"); riskDollars = parameter <double>("RiskDollars"); atr = new AverageTrueRange(bars, parameter <int>("ATRLen")); signal = signalSeries(bars); ma = new Average(signal, maDays); shortSum = new Sum(signal, maDays - 1); var numDeviations = parameter <double>("BollingerBandDeviations"); var barsBack = parameter <int>("BollingerBandBarsBack"); upperBand = new BollingerBand(ma, barsBack, numDeviations); lowerBand = new BollingerBand(ma, barsBack, -numDeviations); }
public CouponSwap(QREBridgeBase bridge, Symbol symbol) : base(bridge, symbol) { //Set up signal data string tickerHeader; if (symbol.name.Substring(symbol.name.Length - 3, 3) == "TRS") { tickerHeader = symbol.name.Substring(0, 5); } else if (Regex.IsMatch(symbol.name, @"....\.\d")) { var tickerParts = symbol.name.Split(Convert.ToChar(".")); tickerHeader = (tickerParts[0] == "FNCL" ? "F" : "D"); tickerHeader = tickerHeader + tickerParts[1] + tickerParts[2]; tickerHeader = tickerHeader + tickerParts[3] + tickerParts[4]; } else { throw Bomb.toss("Bad symbol name, not able to figure out the signal data."); } modelPrice = new Symbol(tickerHeader + "MDL").doubles(bars); actualPrice = new Symbol(tickerHeader + "ACT").doubles(bars); rollDecimal = new Symbol(tickerHeader + "WRL").doubles(bars); rollTicks = new Times(rollDecimal, rollDecimal.manager.constant(32.0)); tradeSize = parameter <long>("TradeSize"); maxSize = parameter <long>("MaxPyramid") * tradeSize; entryTicks = parameter <double>("EntryTicks"); stopTicks = parameter <double>("StopTicks"); richCheap = new RichCheapSpud(modelPrice, actualPrice); longEntryCross = new CrossOverSpud <double>(richCheap, entryTicks); shortEntryCross = new CrossOverSpud <double>(richCheap, -entryTicks); longExitCross = new CrossOverSpud <double>(richCheap, parameter <double>("ExitTicks")); shortExitCross = new CrossOverSpud <double>(richCheap, -parameter <double>("ExitTicks")); longMA = new EWMA(richCheap, parameter <double>("HalfLife")); rollCutOff = parameter <double>("RollCutOff"); rollCutOffMargin = parameter <double>("RollCutOff.Margin"); longRollCross = new CrossOverSpud <double>(rollDecimal, -(rollCutOff - rollCutOffMargin) / 32); shortRollCross = new CrossOverSpud <double>(rollDecimal, (rollCutOff - rollCutOffMargin) / 32); //Add Plots addToPlot(modelPrice, "Model Price", Color.Red, "Coupon Swap"); addToPlot(actualPrice, "Actual Price", Color.Blue, "Coupon Swap"); addToPlot(rollTicks, "Weighted Roll", Color.Green, "Roll"); }
public FaderClose(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 Average(bars.close, 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 StdDeviationOfSample(bars.close, 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"); rSqrScale = parameter <double>("rSqrScale"); Bomb.when((rSqrScale != 0), () => "rSquare parameter not implemented yet."); addToPlot(maRaw, "maRaw", Color.Blue); addToPlot(levelProjection, "Projection", Color.Red); addToPlot(priceStDev, "StDev", Color.Green, "Support"); }
// check to see if input has valid parameters needed to render a 25Live calendar public bool IsValidSpud() { if (!String.IsNullOrEmpty(Spud)) { if (Spud.Contains("webName") && Spud.Contains("spudType")) { return(true); } else { return(false); } } else { return(true); } }
protected NDayBreakBase(QREBridgeBase bridge, Symbol symbol, Converter <BarSpud, ComparableSpud <double> > high, Converter <BarSpud, ComparableSpud <double> > low ) : base(bridge, symbol) { atr = new AverageTrueRangeEW(bars, parameter <int>("ATRLen")); breakDays = parameter <int>("BreakDays") - 1; breakOutHigh = high(bars).highest(breakDays); breakOutLow = low(bars).lowest(breakDays); breakDownHigh = high(bars).highest(breakDays / 2); breakDownLow = low(bars).lowest(breakDays / 2); risk = parameter <double>("Risk"); addToPlot(breakOutHigh, "breakout high", Color.Red); addToPlot(breakOutLow, "breakout low", Color.Blue); addToPlot(breakDownHigh, "breakdown high", Color.DeepPink); addToPlot(breakDownLow, "breakdown low", Color.DeepSkyBlue); }
public QRegression(Spud <double> y, Spud <double> x, int window, bool noIntercept, double[] weights) : base(y.manager) { if (Equals(weights[0], double.NaN)) { var w = new double[window]; zeroTo(window, i => w[i] = 1); this.weights = w; } else { Bomb.when(weights.Length != window, () => "The number of weights is not equal to window size"); this.weights = weights; } this.y = dependsOn(y); this.x = dependsOn(x); this.window = window; this.noIntercept = noIntercept; weightSum = weightsSum(); }
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)); }
public FXCarryV2(QREBridgeBase bridge, Symbol symbol) : base(bridge, symbol) { payoutRatioLong = payoutRatioSymbol(symbol, "Long").doubles(bars).allowStaleTicks(); payoutRatioShort = payoutRatioSymbol(symbol, "Short").doubles(bars).allowStaleTicks(); nATR = parameter <int>("nATR"); atrLen = parameter <int>("ATRLen"); atr = new AverageTrueRange(bars, atrLen); riskDollars = parameter <double>("RiskDollars"); bollingerBandBarsBack = parameter <int>("BollingerBandBarsBack"); ma = new Average(bars.close, bollingerBandBarsBack); bollingerBandDeviations = parameter <double>("BollingerBandDeviations"); trigger = parameter <double>("Trigger"); maxTrigger = parameter <double>("MaxTrigger"); triggerCushion = parameter <double>("TriggerCushion"); addToPlot(payoutRatioLong, "payoutRatioLong", Color.Red, "payoutRatioLong"); addToPlot(payoutRatioShort, "payoutRatioShort", Color.Red, "payoutRatioShort"); upperBand = new BollingerBand(bars.close, bollingerBandBarsBack, bollingerBandDeviations); lowerBand = new BollingerBand(bars.close, bollingerBandBarsBack, -bollingerBandDeviations); addToPlot(upperBand, "upperBand", Color.Blue); addToPlot(lowerBand, "lowerBand", Color.Blue); bars.close.prepare(); stoppedOut = true; }
public StdDeviationOfPopulation(Spud <double> values) : this(values, Window.INFINITE) { }
public class StdDeviationOfPopulation : AggregatorSpud <double> { // long name so StdDeviation variations sort together public StdDeviationOfPopulation(Spud <double> values, int periods) : base(values, populationStandardDeviation, periods) { }
public LiveSpud(Spud <double> spud) : base(spud.manager) { dependsOn(spud); manager.onLive += delegate { state = true; thyselfBeDirty(); }; }
public TDSetup(Spud <Bar> bars) : base(bars.manager) { this.bars = dependsOn(bars); }