/// <summary> /// Returns if the conditions for a rebuy are met. /// </summary> /// <returns><c>true</c>, if rebuy is possible, <c>false</c> otherwise.</returns> /// <param name="candles">candle history</param> /// <param name="bar">currentcandle</param> private bool CanRebuy(List <MarketCandle> candles, int bar) { var bbands = new BollingerBands(candles, bar); var stoch = new Stochastics(candles, bar); var candle = candles[bar]; // for long we do a rebuy when price closes under the lower bollinger bands and both stochastics are below 20 // and price is 1.75% below the previous buy if (_trade.TradeType == TradeType.Long && candle.ClosePrice < bbands.Lower && stoch.K < 20 && stoch.D < 20) { var price = _trade.OpenPrice * RebuyPercentage; if (_trade.Rebuys.Count > 0) { price = _trade.Rebuys.Last().Price *RebuyPercentage; } return(candle.ClosePrice < price); } // for short we do a rebuy when price closes above the upper bollinger bands and both stochastics are above 80 // and price is 1.75% above the previous sell if (_trade.TradeType == TradeType.Short && candle.ClosePrice > bbands.Upper && stoch.K > 80 && stoch.D > 80) { var factor = 1m + (1m - RebuyPercentage); var price = _trade.OpenPrice * factor; if (_trade.Rebuys.Count > 0) { price = _trade.Rebuys.Last().Price *factor; } return(candle.ClosePrice > price); } return(false); }
private TrendDirection Get15MinuteDirection() { EMA fastEMA = EMA(EMAFastPeriod); EMA slowEMA = EMA(EMASlowPeriod); Stochastics stoch = Stochastics(StochPeriodD, StochPeriodK, StochSmooth); RSI rsi = RSI(RSIPeriod, RSISmooth); MACD macd = MACD(MACDFast, MACDSlow, MACDSmooth); // long if (CrossAbove(slowEMA, fastEMA[0], CrossoverLookbackPeriod) && rsi[0] > RSIUpper && Rising(stoch) && stoch[0] < StochUpper && (CrossAbove(0, macd.Diff, CrossoverLookbackPeriod) || (macd.Diff[0] < 0 && Rising(macd.Diff)))) // macd.diff should be just starting to rise { return(TrendDirection.Long); } // short if (CrossBelow(slowEMA, fastEMA[0], CrossoverLookbackPeriod) && rsi[0] < RSIUpper && Falling(stoch) && stoch[0] > StochLower && (CrossBelow(0, macd.Diff, CrossoverLookbackPeriod) || (macd.Diff[0] > 0 && Falling(macd.Diff)))) // macd.diff should be just starting to fall { return(TrendDirection.Short); } return(TrendDirection.Neutral); }
// Cycle Counter Vars #endregion /// <summary> /// This method is used to configure the strategy and is called once before any strategy method is called. /// </summary> protected override void Initialize() { pitColor = PitColor(Color.Black, 80000, 25, 161500); Add(pitColor); stoc = Stochastics(stocD, stocK, stocS); Add(stoc); stoc.Plots[0].Pen.Color = Color.Blue; // D color stoc.Plots[1].Pen.Color = Color.Black; // K color stoc.Plots[0].Pen.Width = 2; // D color stoc.Plots[1].Pen.Width = 1; // K color stoc.Lines[0].Pen.Color = Color.Black; // Lower stoc.Lines[1].Pen.Color = Color.Black; // Upper stoc.Lines[0].Pen.DashStyle = DashStyle.Dot; // Lower stoc.Lines[1].Pen.DashStyle = DashStyle.Dot; // Upper stoc.Lines[0].Pen.Width = 2; // Lower stoc.Lines[1].Pen.Width = 2; // Upper stoc.Lines[0].Value = 20; // Lower stoc.Lines[1].Value = 80; // Upper constantLines = ConstantLines(45, 55, 0, 0); constantLines.Panel = 1; // specifying to use the first indicator's panel Add(constantLines); constantLines.Plots[0].Pen.Color = Color.Red; constantLines.Plots[1].Pen.Color = Color.Red; CalculateOnBarClose = true; }
private TrendDirection Get4HDirection() { // check the 4h chart EMA fastEMA = EMA(BarsArray[1], EMAFastPeriod); EMA slowEMA = EMA(BarsArray[1], EMASlowPeriod); Stochastics stoch = Stochastics(BarsArray[1], StochPeriodD, StochPeriodK, StochSmooth); RSI rsi = RSI(BarsArray[1], RSIPeriod, RSISmooth); // long if (fastEMA[0] > slowEMA[0] && Rising(fastEMA) && rsi[0] > RSIUpper && Rising(stoch) && stoch[0] < StochUpper) { // BackColor = Color.LightGreen; return(TrendDirection.Long); } // short if (fastEMA[0] < slowEMA[0] && Falling(fastEMA) && rsi[0] < RSIUpper && Falling(stoch) && stoch[0] > StochLower) { // BackColor = Color.Pink; return(TrendDirection.Short); } return(TrendDirection.Neutral); }
/// <summary> /// Checks if a valid entry appeard /// </summary> /// <returns><c>true</c>, if valid entry was found, <c>false</c> otherwise.</returns> /// <param name="candles">History of candles</param> /// <param name="bar">The current candle</param> /// <param name="tradeType">returns trade type.</param> public bool IsValidEntry(List <MarketCandle> candles, int bar, out TradeType tradeType) { var candle = candles[bar]; var bbands = new BollingerBands(candles, bar); var stoch = new Stochastics(candles, bar); tradeType = TradeType.Long; // is bolling bands width > 2% if (bbands.Bandwidth >= 2m) { if (candle.ClosePrice < bbands.Lower && stoch.K < 20 && stoch.D < 20) { // open buy order when price closes below lower bollinger bands // and stochastics K & D are both below 20 tradeType = TradeType.Long; return(true); } else if (candle.ClosePrice > bbands.Upper && stoch.K > 80 && stoch.D > 80 && AllowShorting) { // open sell order when price closes above upper bollinger bands // and stochastics K & D are both above 80 tradeType = TradeType.Short; return(true); } } return(false); }
/// <summary> /// This method is used to configure the strategy and is called once before any strategy method is called. /// </summary> protected override void Initialize() { Add(PitColor(Color.Black, 83000, 25, 161500)); Add(EMA(EmaPeriod)); EMA(EmaPeriod).Plots[0].Pen.Color = Color.Gray; //Add(SMARick(SmaPeriod)); Add(HMARick(HmaPeriod, 75)); //SMARick(SmaPeriod).Plots[0].Pen.Color = Color.Red; //Add(SMARick(SmaPeriod * 3)); // Add(StochasticsCycles(stocD, stocK, MAType.HMA, false, false, stocS, 75, 3, HmaPeriod)); stoc = Stochastics(stocD, stocK, stocS); Add(stoc); stoc.Plots[0].Pen.Color = Color.Blue; // D color stoc.Plots[1].Pen.Color = Color.Black; // K color stoc.Plots[0].Pen.Width = 2; // D color stoc.Plots[1].Pen.Width = 1; // K color stoc.Lines[0].Pen.Color = Color.Black; // Lower stoc.Lines[1].Pen.Color = Color.Black; // Upper stoc.Lines[0].Pen.DashStyle = DashStyle.Dot; // Lower stoc.Lines[1].Pen.DashStyle = DashStyle.Dot; // Upper stoc.Lines[0].Pen.Width = 2; // Lower stoc.Lines[1].Pen.Width = 2; // Upper stoc.Lines[0].Value = 20; // Lower stoc.Lines[1].Value = 80; // Upper ConstantLines(45, 55, 0, 0).Panel = 1; // specifying to use the first indicator's panel Add(ConstantLines(45, 55, 0, 0)); ConstantLines(45, 55, 0, 0).Plots[0].Pen.Color = Color.Red; ConstantLines(45, 55, 0, 0).Plots[1].Pen.Color = Color.Red; macd = MACDrick(macdFast, macdSlow, macdSmooth); Add(macd); //Add(MACDRick2(Color.Green, Color.Red, true, macdFast, 20, macdSlow,macdSmooth)); // Add(MACD(macdFast,macdSlow,macdSmooth)); // MACD(macdFast,macdSlow,macdSmooth).CalculateOnBarClose = true; // MACD(macdFast,macdSlow,macdSmooth).Plots[0].Pen.Color = Color.Black; // Macd // MACD(macdFast,macdSlow,macdSmooth).Plots[1].Pen.Color = Color.Blue; // Avg // MACD(macdFast,macdSlow,macdSmooth).Plots[2].Pen.Color = Color.Red; //downBard // // MACD(macdFast,macdSlow,macdSmooth).Plots[3].Pen.Color = Color.Transparent; // Diff // MACD(macdFast,macdSlow,macdSmooth).Plots[0].Pen.Width = 2; // MACD(macdFast,macdSlow,macdSmooth).Plots[1].Pen.Width = 3; // MACD(macdFast,macdSlow,macdSmooth).Plots[0].PlotStyle = PlotStyle.Bar; //SetProfitTarget("", CalculationMode.Ticks, 205); //SetTrailStop("", CalculationMode.Ticks, 5, false); //SetStopLoss("", CalculationMode.Ticks, 200, false); CalculateOnBarClose = true; ClearOutputWindow(); TimeInForce = Cbi.TimeInForce.Day; ExitOnClose = true; ExitOnCloseSeconds = 3600; // 60 min before session close }
/// <summary> /// Checks if a valid entry appeard /// </summary> /// <returns><c>true</c>, if valid entry was found, <c>false</c> otherwise.</returns> /// <param name="candles">History of candles</param> /// <param name="bar">The current candle</param> /// <param name="tradeType">returns trade type.</param> /// <param name="bandwidth">returns BB bandwidth.</param> public bool IsValidEntry(List <MarketCandle> candles, int bar, out TradeType tradeType, out decimal bandwidth) { tradeType = TradeType.Long; bandwidth = 0m; if (candles.Count < bar + 20) { return(false); } var candle = candles[bar]; var bbands = new BollingerBands(candles, bar); var stoch = new Stochastics(candles, bar); // more then 5 flat candles in last 15 candles ? var flatCandles = 0; for (int i = 0; i < _settings.MaxFlatCandleCount; ++i) { var candleStick = candles[bar + i]; if (candleStick.BaseCurrencyVolume <= 0) { flatCandles++; } } if (flatCandles > _settings.MaxFlatCandles) { return(false); } // check for panic var panic = (double)((candle.ClosePrice / candle.OpenPrice) * 100m); if (panic < (100 - _settings.MaxPanic) || panic > (100 + _settings.MaxPanic)) { // more then 5% panic return(false); } bandwidth = bbands.Bandwidth; // is bolling bands width > 2% if (bbands.Bandwidth >= (decimal)_settings.MinBollingerBandWidth) { if (candle.ClosePrice < bbands.Lower && stoch.K < 20 && stoch.D < 20) { // open buy order when price closes below lower bollinger bands // and stochastics K & D are both below 20 tradeType = TradeType.Long; return(true); } else if (candle.ClosePrice > bbands.Upper && stoch.K > 80 && stoch.D > 80 && _settings.AllowShorts) { // open sell order when price closes above upper bollinger bands // and stochastics K & D are both above 80 tradeType = TradeType.Short; return(true); } } return(false); }
public StochasticLinesCrossover(BarItemType barType) { this.barType = barType; this.identityCode = string.Format("{0}({1})", IDENTITY_CODE, barType.Code); stoch = new Stochastics(barType, 14, 3, 3); Register(stoch); }
private static void ExportFeaturesAndLabel(string code) { string filePath = (Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX) ? Environment.GetEnvironmentVariable("HOME") : Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%"); filePath += "\\indicatorOutput.txt"; DateTime targetDate = IndicatorService.LastDate(code); int numberOfData = 4000; var data = IndicatorService.GetData(code, targetDate, new string[] { "Tarih", "Kapanis" }, numberOfData + 1); double[] sma = MovingAverage.Simple(code, targetDate, 14, numberOfData); double[] wma = MovingAverage.Weighted(code, targetDate, 14, numberOfData); double[] ema = MovingAverage.Exponential(code, targetDate, 14, numberOfData); MovingAverageConvergenceDivergence macd = new MovingAverageConvergenceDivergence(code, targetDate, 12, 26, 9, numberOfData); double[] rsi = RelativeStrengthIndex.Rsi(code, targetDate, 14, numberOfData); double[] williams = WilliamsR.Wsr(code, targetDate, 14, numberOfData); Stochastics stochastics = new Stochastics(code, targetDate, 14, 3, 3, numberOfData); double[] closesOut = IndicatorDataPreprocessor.GetClosesOut(numberOfData, data); double[] smaOut = IndicatorDataPreprocessor.GetSMAOut(sma); double[] wmaOut = IndicatorDataPreprocessor.GetWMAOut(wma); double[] emaOut = IndicatorDataPreprocessor.GetEMAOut(ema); double[] macdOut = IndicatorDataPreprocessor.GetMACDOut(macd); double[] rsiOut = IndicatorDataPreprocessor.GetRSIOut(rsi); double[] williamsROut = IndicatorDataPreprocessor.GetWilliamsROut(williams); double[] stochasticsOut = IndicatorDataPreprocessor.GetStochasticsOut(stochastics); int minRowCount; minRowCount = smaOut.Length; minRowCount = minRowCount < wmaOut.Length ? minRowCount : wmaOut.Length; minRowCount = minRowCount < emaOut.Length ? minRowCount : emaOut.Length; minRowCount = minRowCount < macdOut.Length ? minRowCount : macdOut.Length; minRowCount = minRowCount < rsiOut.Length ? minRowCount : rsiOut.Length; minRowCount = minRowCount < williamsROut.Length ? minRowCount : williamsROut.Length; minRowCount = minRowCount < stochasticsOut.Length ? minRowCount : stochasticsOut.Length; minRowCount = minRowCount < closesOut.Length ? minRowCount : closesOut.Length; FeatureVector vector = new FeatureVector(); vector.AddColumn("SMA", smaOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); vector.AddColumn("WMA", wmaOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); vector.AddColumn("EMA", emaOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); vector.AddColumn("MACD", macdOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); vector.AddColumn("RSI", rsiOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); vector.AddColumn("WilliamsR", williamsROut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); vector.AddColumn("Stochastics", stochasticsOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); vector.AddColumn("label", closesOut.Select(p => (object)string.Format("{0:0.0}", p).ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); new CSVExporter(vector).Export(filePath); Console.WriteLine("Operations completed."); }
public TeodosiSimpleSystem(BarItemType barType) { this.barType = barType; this.identityCode = string.Format("{0}({1})", IDENTITY_CODE, barType.Code); rsi = new RSI(barType, 7); stoch = new Stochastics(barType, 5, 3, 3); Register(rsi, stoch); }
public DoubleStochastic(BarItemType barType) { this.barType = barType; this.identityCode = string.Format("{0}({1})", IDENTITY_CODE, barType.Code); stochMajor = new Stochastics(barType, 26, 14, 14); stochRetrace = new Stochastics(barType, 14, 3, 3); Register(stochMajor, stochRetrace); }
public ArsalanStochasticAndEMA(BarItemType barType) { this.barType = barType; this.identityCode = string.Format("{0}({1})", IDENTITY_CODE, barType.Code); ema2 = new EMA(barType, 2); ema4 = new EMA(barType, 4); stoch = new Stochastics(barType, 5, true); Register(ema2, ema4, stoch); }
public PSARandStochastic(BarItemType barType) { this.barType = barType; this.identityCode = string.Format("{0}({1})", IDENTITY_CODE, barType.Code); psar = new ParabolicSAR(barType, 5); stoc = new Stochastics(barType, 14); ema = new EMA(barType, 100); Register(psar, stoc, ema); }
/// <summary> /// This method is used to configure the strategy and is called once before any strategy method is called. /// </summary> protected override void Initialize() { pitColor = PitColor(Color.Black, 80000, 25, 161500); Add(pitColor); ema = EMA(EmaPeriod); Add(ema); ema.Plots[0].Pen.Color = Color.Gray; sma = SMARick(SmaPeriod); Add(sma); //sma.Plots[0].Pen.Color = Color.Red; stoc = Stochastics(stocD, stocK, stocS); Add(stoc); stoc.Plots[0].Pen.Color = Color.Blue; // D color stoc.Plots[1].Pen.Color = Color.Black; // K color stoc.Plots[0].Pen.Width = 2; // D color stoc.Plots[1].Pen.Width = 1; // K color stoc.Lines[0].Pen.Color = Color.Black; // Lower stoc.Lines[1].Pen.Color = Color.Black; // Upper stoc.Lines[0].Pen.DashStyle = DashStyle.Dot; // Lower stoc.Lines[1].Pen.DashStyle = DashStyle.Dot; // Upper stoc.Lines[0].Pen.Width = 2; // Lower stoc.Lines[1].Pen.Width = 2; // Upper stoc.Lines[0].Value = 20; // Lower stoc.Lines[1].Value = 80; // Upper constantLines = ConstantLines(45, 55, 0, 0); constantLines.Panel = 1; // specifying to use the first indicator's panel Add(constantLines); constantLines.Plots[0].Pen.Color = Color.Red; constantLines.Plots[1].Pen.Color = Color.Red; macd = MACD(macdFast, macdSlow, macdSmooth); Add(macd); macd.CalculateOnBarClose = true; macd.Plots[0].Pen.Color = Color.Black; // Macd macd.Plots[1].Pen.Color = Color.Blue; // Avg macd.Plots[2].Pen.Color = Color.Transparent; //downBar //macd.Plots[3].Pen.Color = Color.Transparent; // Diff macd.Plots[0].Pen.Width = 2; macd.Plots[1].Pen.Width = 3; macd.Plots[0].PlotStyle = PlotStyle.Bar; SetProfitTarget("", CalculationMode.Ticks, ProfitTarget); SetStopLoss("", CalculationMode.Ticks, StopLoss, false); SetTrailStop("", CalculationMode.Ticks, TrailingStop, false); CalculateOnBarClose = true; }
public SimpleBalancedSystem(BarItemType barType) { this.barType = barType; this.identityCode = string.Format("{0}({1})", IDENTITY_CODE, barType.Code); ema5 = new EMA(barType, 5); ema10 = new EMA(barType, 10); stoch = new Stochastics(barType, 14, 3, 3); rsi = new RSI(barType, 14); Register(ema5, ema10, stoch, rsi); }
public ThoseFourIndicators(BarItemType barType) { this.barType = barType; this.identityCode = string.Format("{0}({1})", IDENTITY_CODE, barType.Code); cci = new CCI(barType, 14); stoch = new Stochastics(barType, 14, 2, 2); macd = new MACD(barType, 8, 40, 8); adx = new ADX(barType, 14); Register(cci, stoch, macd, adx); }
/// <summary> /// Called on every new bar of data. /// </summary> /// <param name="currentBar">The current bar of the simulation</param> protected override void OnBarUpdate(int currentBar) { base.OnBarUpdate(currentBar); Stochastics ind = (Stochastics)Dependents[0]; if (DataSeries.IsAbove(ind.D, 80, currentBar, 0) != -1) { if (DataSeries.IsAboutToCrossBelow(ind.K, ind.D, currentBar) == true) { WasFound[currentBar] = true; } } }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { stddev = this.StdDev(Bars, StdDevCount); Stochastics sto = Stochastics(Bars, 9, 10, 3); double stdDev1 = stddev.Value[0] * 1; double stdDev2 = stddev.Value[0] * 2; double stdDev3 = stddev.Value[0] * 3; double currentSMA = sma.Value[0]; double lastSMA = sma.Value[1]; string shortName = "BuyShort1"; string longName = "BuyLong1"; if (lastbarcount < Bars.Count) { if (sto.D[0] < 80 && sto.D[1] > 80) { if (Position.MarketPosition == MarketPosition.Long) // get out of a long. { SetStopLoss(longName, CalculationMode.Price, GetCurrentBid(), false); } // Get in a Short SetStopLoss(shortName, CalculationMode.Price, Bollinger(bollingerDeviations, StdDevCount).Upper[0] + stdDev2, false); EnterShort(0, GetQuantityToPurchase(), shortName); } if (sto.D[0] > 20 && sto.D[1] < 20) { if (Position.MarketPosition == MarketPosition.Short) // get out of a Short. { SetStopLoss(shortName, CalculationMode.Price, GetCurrentAsk(), false); } // Get in a Long SetStopLoss(longName, CalculationMode.Price, Bollinger(bollingerDeviations, StdDevCount).Lower[0] - stdDev2, false); EnterLong(0, GetQuantityToPurchase(), longName); } } lastbarcount = Bars.Count; }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { stoc = Stochastics(stocD, stocK, stocS); int currentTrend = Rising(SMA(SmaPeriod)) ? 1: -1; MarkCycleHigh(); MarkCycleLow(); if ((trend <= 0 && currentTrend == 1) || (trend >= 0 && currentTrend == -1)) { // reset trend trend = currentTrend; trendStartBar = CurrentBar; } /* * uptrend conditions * 1 - new * 2 - cross above 45, look for cycle high * 3 - cross above 55 * 4 - cross below 55, stop cycle high search */ if (currentTrend == 1) { switch (trend) { case 1: if (stoc.D[0] > 45) { trend = 2; } if (stoc.D[0] > 55) { trend = 3; } break; case 2: if (stoc.D[0] > 55) { trend = 3; } if (CrossBelow(stoc.D, 45, 1)) { trend = 1; } break; case 3: if (CrossBelow(stoc.D, 55, 1)) { trend = 4; } break; default: break; } } if (currentTrend == -1) { switch (trend) { case -1: if (stoc.D[0] < 55) { trend = -2; } if (stoc.D[0] < 45) { trend = -3; } break; case -2: if (stoc.D[0] < 45) { trend = -3; } if (CrossAbove(stoc.D, 55, 1)) { trend = -1; } break; case -3: if (CrossAbove(stoc.D, 55, 1)) { trend = -4; } break; default: break; } } if (trend >= 1) { cycleHigh = HighestBar(High, CurrentBar - trendStartBar); } if (trend <= -1) { cycleLow = LowestBar(Low, CurrentBar - trendStartBar); } if (trend < 0) { //DrawDot("Low" + CurrentBar, false, 0, Low[cycleLow], Color.Black); } if (trend > 0) { //DrawDot("High" + CurrentBar, false, 0, High[cycleHigh], Color.Black); Print(Time + " cycleHigh: " + cycleHigh); if (stoc.D[2] > stoc.D[1] && stoc.D[1] < stoc.D[0] ) { DrawArrowUp("My up arrow" + CurrentBar, false, 0, Low[0], Color.Black); if (Position.MarketPosition == MarketPosition.Flat) { EnterLongStop(High[0] + 1 * TickSize); } } } }
/// <summary> /// If the runnable has already been created, returns that object. If not then /// returns an new runnable object based on the name and the instrument. /// </summary> /// <param name="nameAndParameters">Name of the runnable</param> /// <returns>The runnable object</returns> public Runnable GetRunnable(string nameAndParameters) { Runnable requestedItem = null; // The name can have parameters to pass to the runnable construtor // and are separated by commas. // Ex: Rsi,11,3 would create the Rsi and pass the numbers to it in a // list. Its up to the indicator to do what it will with each number. string[] splitParams = nameAndParameters.Split(','); string runnableName = splitParams[0]; string[] runnableParams = splitParams.Skip(1).Take(splitParams.Length - 1).ToArray(); // See if the runnable is created already and return that object if it is. int key = nameAndParameters.GetHashCode(); if (_createdItems.ContainsKey(key)) { requestedItem = _createdItems[key]; } else { switch (runnableName) { // Indicators. case "Bollinger": requestedItem = new Bollinger(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "BressertDss": requestedItem = new BressertDss(_tickerData, this, runnableParams); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "BressertTimingBands": requestedItem = new BressertTimingBands(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "BearBeltHold": requestedItem = new BearBeltHold(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "BearEngulfing": requestedItem = new BearEngulfing(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "BearHarami": requestedItem = new BearHarami(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "BearHaramiCross": requestedItem = new BearHaramiCross(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "BullBeltHold": requestedItem = new BullBeltHold(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "BullEngulfing": requestedItem = new BullEngulfing(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "BullHarami": requestedItem = new BullHarami(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "BullHaramiCross": requestedItem = new BullHaramiCross(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "Cci14": requestedItem = new Cci(_tickerData, this, 14); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "DarkCloudCover": requestedItem = new DarkCloudCover(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "Doji": requestedItem = new Doji(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "BearDoji": requestedItem = new BearDoji(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "DownsideTasukiGap": requestedItem = new DownsideTasukiGap(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "EaseOfMovement": requestedItem = new EaseOfMovement(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "EveningStar": requestedItem = new EveningStar(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "FallingThreeMethods": requestedItem = new FallingThreeMethods(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "Hammer": requestedItem = new Hammer(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "HangingMan": requestedItem = new HangingMan(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "InvertedHammer": requestedItem = new InvertedHammer(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "KeltnerChannel": requestedItem = new KeltnerChannel(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "Macd": requestedItem = new Macd(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "Momentum14": requestedItem = new Momentum(_tickerData, this, 14); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "MorningStar": requestedItem = new MorningStar(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "PiercingLine": requestedItem = new PiercingLine(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "PriceOscillator": requestedItem = new PriceOscillator(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "RisingThreeMethods": requestedItem = new RisingThreeMethods(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "Rsi": requestedItem = new Rsi(_tickerData, this, runnableParams); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "Rsi3m3": requestedItem = new Rsi3m3(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "ShootingStar": requestedItem = new ShootingStar(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "Sma": requestedItem = new Sma(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "StickSandwitch": requestedItem = new StickSandwitch(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "StochasticsFast": requestedItem = new StochasticsFast(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "Stochastics": requestedItem = new Stochastics(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "StochRsi": requestedItem = new StochRsi(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "Trend": requestedItem = new Trend(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "ThreeBlackCrows": requestedItem = new ThreeBlackCrows(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "ThreeWhiteSoldiers": requestedItem = new ThreeWhiteSoldiers(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "Trix": requestedItem = new Trix(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "UpsideGapTwoCrows": requestedItem = new UpsideGapTwoCrows(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "UpsideTasukiGap": requestedItem = new UpsideTasukiGap(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "WilliamsR": requestedItem = new WilliamsR(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "Dmi": requestedItem = new Dmi(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "DtOscillator": requestedItem = new DtOscillator(_tickerData, this, runnableParams); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "FibonacciZones": requestedItem = new FibonacciZones(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "ElliotWaves": requestedItem = new ElliotWaves(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "ZigZag": requestedItem = new ZigZag(_tickerData, this, runnableParams); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; ///////////////////////////// Strategies //////////////////////////// case "BestOfRootStrategies": requestedItem = new BestOfRootStrategies(_tickerData, this); break; case "ComboStrategy": requestedItem = new ComboStrategy(_tickerData, this); break; case "BressertApproach": requestedItem = new BressertApproach(_tickerData, this); break; case "BressertComboStrategy": requestedItem = new BressertComboStrategy(_tickerData, this); break; case "FibonacciRsi3m3": requestedItem = new FibonacciRsi3m3(_tickerData, this); break; case "FibonacciDtOscillator": requestedItem = new FibonacciDtOscillator(_tickerData, this); break; case "ElliotWavesStrategy": requestedItem = new ElliotWavesStrategy(_tickerData, this); break; // // Bull // case "BullBollingerExtended": requestedItem = new BullBollingerExtended(_tickerData, this); break; case "BullBeltHoldFound": requestedItem = new BullBeltHoldFound(_tickerData, this); break; case "BullEngulfingFound": requestedItem = new BullEngulfingFound(_tickerData, this); break; case "BullHaramiFound": requestedItem = new BullHaramiFound(_tickerData, this); break; case "BullHaramiCrossFound": requestedItem = new BullHaramiCrossFound(_tickerData, this); break; case "BullCciCrossover": requestedItem = new BullCciCrossover(_tickerData, this); break; case "BullEaseOfMovement": requestedItem = new BullEaseOfMovement(_tickerData, this); break; case "BullDojiFound": requestedItem = new BullDojiFound(_tickerData, this); break; case "HammerFound": requestedItem = new HammerFound(_tickerData, this); break; case "BullKeltnerExtended": requestedItem = new BullKeltnerExtended(_tickerData, this); break; case "BullMacdCrossover": requestedItem = new BullMacdCrossover(_tickerData, this); break; case "BullMacdMomentum": requestedItem = new BullMacdMomentum(_tickerData, this); break; case "BullMomentumCrossover": requestedItem = new BullMomentumCrossover(_tickerData, this); break; case "MorningStarFound": requestedItem = new MorningStarFound(_tickerData, this); break; case "PiercingLineFound": requestedItem = new PiercingLineFound(_tickerData, this); break; case "RisingThreeMethodsFound": requestedItem = new RisingThreeMethodsFound(_tickerData, this); break; case "BullRsiCrossover": requestedItem = new BullRsiCrossover(_tickerData, this); break; case "BullSmaCrossover": requestedItem = new BullSmaCrossover(_tickerData, this); break; case "StickSandwitchFound": requestedItem = new StickSandwitchFound(_tickerData, this); break; case "BullStochasticsFastCrossover": requestedItem = new BullStochasticsFastCrossover(_tickerData, this); break; case "BullStochasticsCrossover": requestedItem = new BullStochasticsCrossover(_tickerData, this); break; case "BullStochRsiCrossover": requestedItem = new BullStochRsiCrossover(_tickerData, this); break; case "ThreeWhiteSoldiersFound": requestedItem = new ThreeWhiteSoldiersFound(_tickerData, this); break; case "BullTrendStart": requestedItem = new BullTrendStart(_tickerData, this); break; case "BullTrixSignalCrossover": requestedItem = new BullTrixSignalCrossover(_tickerData, this); break; case "BullTrixZeroCrossover": requestedItem = new BullTrixZeroCrossover(_tickerData, this); break; case "UpsideTasukiGapFound": requestedItem = new UpsideTasukiGapFound(_tickerData, this); break; case "BullWilliamsRCrossover": requestedItem = new BullWilliamsRCrossover(_tickerData, this); break; case "BullPriceOscillator": requestedItem = new BullPriceOscillator(_tickerData, this); break; case "BullDmi": requestedItem = new BullDmi(_tickerData, this); break; case "BullBressertDss": requestedItem = new BullBressertDss(_tickerData, this, runnableParams); break; case "BullRsi3m3": requestedItem = new BullRsi3m3(_tickerData, this); break; case "BullDtOscillator": requestedItem = new BullDtOscillator(_tickerData, this); break; //////////// Predicted bull strategies /////////// case "BullCciCrossoverPredicted": requestedItem = new BullCciCrossoverPredicted(_tickerData, this); break; case "BullDmiPredicted": requestedItem = new BullDmiPredicted(_tickerData, this); break; case "BullEaseOfMovementPredicted": requestedItem = new BullEaseOfMovementPredicted(_tickerData, this); break; case "BullKeltnerExtendedPredicted": requestedItem = new BullKeltnerExtendedPredicted(_tickerData, this); break; case "BullMacdCrossoverPredicted": requestedItem = new BullMacdCrossoverPredicted(_tickerData, this); break; case "BullMomentumCrossoverPredicted": requestedItem = new BullMomentumCrossoverPredicted(_tickerData, this); break; case "BullPriceOscillatorPredicted": requestedItem = new BullPriceOscillatorPredicted(_tickerData, this); break; case "BullRsiCrossoverPredicted": requestedItem = new BullRsiCrossoverPredicted(_tickerData, this); break; case "BullSmaCrossoverPredicted": requestedItem = new BullSmaCrossoverPredicted(_tickerData, this); break; case "BullStochasticsCrossoverPredicted": requestedItem = new BullStochasticsCrossoverPredicted(_tickerData, this); break; case "BullStochasticsFastCrossoverPredicted": requestedItem = new BullStochasticsFastCrossoverPredicted(_tickerData, this); break; case "BullStochRsiCrossoverPredicted": requestedItem = new BullStochRsiCrossoverPredicted(_tickerData, this); break; case "BullTrixSignalCrossoverPredicted": requestedItem = new BullTrixSignalCrossoverPredicted(_tickerData, this); break; case "BullTrixZeroCrossoverPredicted": requestedItem = new BullTrixZeroCrossoverPredicted(_tickerData, this); break; case "BullWilliamsRCrossoverPredicted": requestedItem = new BullWilliamsRCrossoverPredicted(_tickerData, this); break; // // Bear // case "BearBollingerExtended": requestedItem = new BearBollingerExtended(_tickerData, this); break; case "BearCciCrossover": requestedItem = new BearCciCrossover(_tickerData, this); break; case "BearEaseOfMovement": requestedItem = new BearEaseOfMovement(_tickerData, this); break; case "BearDojiFound": requestedItem = new BearDojiFound(_tickerData, this); break; case "BearKeltnerExtended": requestedItem = new BearKeltnerExtended(_tickerData, this); break; case "BearMacdMomentum": requestedItem = new BearMacdMomentum(_tickerData, this); break; case "BearMacdCrossover": requestedItem = new BearMacdCrossover(_tickerData, this); break; case "BearMomentumCrossover": requestedItem = new BearMomentumCrossover(_tickerData, this); break; case "BearRsiCrossover": requestedItem = new BearRsiCrossover(_tickerData, this); break; case "BearSmaCrossover": requestedItem = new BearSmaCrossover(_tickerData, this); break; case "BearStochasticsCrossover": requestedItem = new BearStochasticsCrossover(_tickerData, this); break; case "BearStochasticsFastCrossover": requestedItem = new BearStochasticsFastCrossover(_tickerData, this); break; case "BearStochRsiCrossover": requestedItem = new BearStochRsiCrossover(_tickerData, this); break; case "BearTrendStart": requestedItem = new BearTrendStart(_tickerData, this); break; case "BearTrixSignalCrossover": requestedItem = new BearTrixSignalCrossover(_tickerData, this); break; case "BearTrixZeroCrossover": requestedItem = new BearTrixZeroCrossover(_tickerData, this); break; case "BearWilliamsRCrossover": requestedItem = new BearWilliamsRCrossover(_tickerData, this); break; case "BearBeltHoldFound": requestedItem = new BearBeltHoldFound(_tickerData, this); break; case "BearEngulfingFound": requestedItem = new BearEngulfingFound(_tickerData, this); break; case "BearHaramiFound": requestedItem = new BearHaramiFound(_tickerData, this); break; case "BearHaramiCrossFound": requestedItem = new BearHaramiCrossFound(_tickerData, this); break; case "DarkCloudCoverFound": requestedItem = new DarkCloudCoverFound(_tickerData, this); break; case "DownsideTasukiGapFound": requestedItem = new DownsideTasukiGapFound(_tickerData, this); break; case "EveningStarFound": requestedItem = new EveningStarFound(_tickerData, this); break; case "FallingThreeMethodsFound": requestedItem = new FallingThreeMethodsFound(_tickerData, this); break; case "HangingManFound": requestedItem = new HangingManFound(_tickerData, this); break; case "InvertedHammerFound": requestedItem = new InvertedHammerFound(_tickerData, this); break; case "ShootingStarFound": requestedItem = new ShootingStarFound(_tickerData, this); break; case "ThreeBlackCrowsFound": requestedItem = new ThreeBlackCrowsFound(_tickerData, this); break; case "UpsideGapTwoCrowsFound": requestedItem = new UpsideGapTwoCrowsFound(_tickerData, this); break; case "BearPriceOscillator": requestedItem = new BearPriceOscillator(_tickerData, this); break; case "BearDmi": requestedItem = new BearDmi(_tickerData, this); break; case "BearBressertDss": requestedItem = new BearBressertDss(_tickerData, this, runnableParams); break; case "BearRsi3m3": requestedItem = new BearRsi3m3(_tickerData, this); break; case "BearDtOscillator": requestedItem = new BearDtOscillator(_tickerData, this); break; //////////// Predicted bear strategies /////////// case "BearCciCrossoverPredicted": requestedItem = new BearCciCrossoverPredicted(_tickerData, this); break; case "BearDmiPredicted": requestedItem = new BearDmiPredicted(_tickerData, this); break; case "BearEaseOfMovementPredicted": requestedItem = new BearEaseOfMovementPredicted(_tickerData, this); break; case "BearKeltnerExtendedPredicted": requestedItem = new BearKeltnerExtendedPredicted(_tickerData, this); break; case "BearMacdCrossoverPredicted": requestedItem = new BearMacdCrossoverPredicted(_tickerData, this); break; case "BearMomentumCrossoverPredicted": requestedItem = new BearMomentumCrossoverPredicted(_tickerData, this); break; case "BearPriceOscillatorPredicted": requestedItem = new BearPriceOscillatorPredicted(_tickerData, this); break; case "BearRsiCrossoverPredicted": requestedItem = new BearRsiCrossoverPredicted(_tickerData, this); break; case "BearSmaCrossoverPredicted": requestedItem = new BearSmaCrossoverPredicted(_tickerData, this); break; case "BearStochasticsCrossoverPredicted": requestedItem = new BearStochasticsCrossoverPredicted(_tickerData, this); break; case "BearStochasticsFastCrossoverPredicted": requestedItem = new BearStochasticsFastCrossoverPredicted(_tickerData, this); break; case "BearStochRsiCrossoverPredicted": requestedItem = new BearStochRsiCrossoverPredicted(_tickerData, this); break; case "BearTrixSignalCrossoverPredicted": requestedItem = new BearTrixSignalCrossoverPredicted(_tickerData, this); break; case "BearTrixZeroCrossoverPredicted": requestedItem = new BearTrixZeroCrossoverPredicted(_tickerData, this); break; case "BearWilliamsRCrossoverPredicted": requestedItem = new BearWilliamsRCrossoverPredicted(_tickerData, this); break; default: throw new Exception(nameAndParameters + " doesn't exist"); } _createdItems[key] = requestedItem; } return(requestedItem); }
private static void RunFeatureSelector(int mlAlgorithm, bool isCrossValidationEnabled, double trainingSetPercentage) { string code = "AKBNK"; DateTime targetDate = new DateTime(2018, 11, 1).ToLocalTime(); int numberOfData = 4000; var data = IndicatorService.GetData(code, targetDate, new string[] { "Tarih", "Kapanis" }, numberOfData + 1); double[] sma = MovingAverage.Simple(code, targetDate, 14, numberOfData); double[] wma = MovingAverage.Weighted(code, targetDate, 14, numberOfData); double[] ema = MovingAverage.Exponential(code, targetDate, 14, numberOfData); MovingAverageConvergenceDivergence macd = new MovingAverageConvergenceDivergence(code, targetDate, 12, 26, 9, numberOfData); double[] rsi = RelativeStrengthIndex.Rsi(code, targetDate, 14, numberOfData); double[] williams = WilliamsR.Wsr(code, targetDate, 14, numberOfData); Stochastics stochastics = new Stochastics(code, targetDate, 14, 3, 3, numberOfData); double[] closesOut = IndicatorDataPreprocessor.GetClosesOut(numberOfData, data); double[] smaOut = IndicatorDataPreprocessor.GetSMAOut(sma); double[] wmaOut = IndicatorDataPreprocessor.GetWMAOut(wma); double[] emaOut = IndicatorDataPreprocessor.GetEMAOut(ema); double[] macdOut = IndicatorDataPreprocessor.GetMACDOut(macd); double[] rsiOut = IndicatorDataPreprocessor.GetRSIOut(rsi, false); double[] williamsROut = IndicatorDataPreprocessor.GetWilliamsROut(williams, false); double[] stochasticsOut = IndicatorDataPreprocessor.GetStochasticsOut(stochastics, false); int minRowCount; minRowCount = smaOut.Length; minRowCount = minRowCount < wmaOut.Length ? minRowCount : wmaOut.Length; minRowCount = minRowCount < emaOut.Length ? minRowCount : emaOut.Length; minRowCount = minRowCount < macdOut.Length ? minRowCount : macdOut.Length; minRowCount = minRowCount < rsiOut.Length ? minRowCount : rsiOut.Length; minRowCount = minRowCount < williamsROut.Length ? minRowCount : williamsROut.Length; minRowCount = minRowCount < stochasticsOut.Length ? minRowCount : stochasticsOut.Length; minRowCount = minRowCount < closesOut.Length ? minRowCount : closesOut.Length; int numberOfIndicators = IndicatorService.indicators.Length; int numberOfCombinations = (int)Math.Pow(2, numberOfIndicators) - 1; for (int i = 1; i <= numberOfCombinations; i++) { int tmp = i; List <int> indicators = new List <int>(); for (int j = 0; j < numberOfIndicators; j++) { if ((tmp & 1) == 1) { indicators.Add(IndicatorService.indicators[j]); } tmp >>= 1; } double accuracy = CalculateAccuracy(indicators, mlAlgorithm, isCrossValidationEnabled, minRowCount, trainingSetPercentage, smaOut, wmaOut, emaOut, macdOut, rsiOut, williamsROut, stochasticsOut, closesOut); if (indicators.Contains(IndicatorService.SMA)) { Console.Write("SMA "); } if (indicators.Contains(IndicatorService.WMA)) { Console.Write("WMA "); } if (indicators.Contains(IndicatorService.EMA)) { Console.Write("EMA "); } if (indicators.Contains(IndicatorService.MACD)) { Console.Write("MACD "); } if (indicators.Contains(IndicatorService.RSI)) { Console.Write("RSI "); } if (indicators.Contains(IndicatorService.WilliamsR)) { Console.Write("WilliamsR "); } if (indicators.Contains(IndicatorService.Stochastics)) { Console.Write("Stochastics "); } Console.WriteLine("=>\t" + accuracy); } }
private static void RunConsoleApplication() { string filePath = (Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX) ? Environment.GetEnvironmentVariable("HOME") : Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%"); filePath += "\\indicatorOutput.txt"; string code = "AKBNK"; DateTime targetDate = new DateTime(2018, 11, 1).ToLocalTime(); int numberOfData = 1000; var data = IndicatorService.GetData(code, targetDate, new string[] { "Tarih", "Kapanis" }, numberOfData + 1); double[] sma = MovingAverage.Simple(code, targetDate, 14, numberOfData); double[] wma = MovingAverage.Weighted(code, targetDate, 14, numberOfData); double[] ema = MovingAverage.Exponential(code, targetDate, 14, numberOfData); MovingAverageConvergenceDivergence macd = new MovingAverageConvergenceDivergence(code, targetDate, 12, 26, 9, numberOfData); double[] rsi = RelativeStrengthIndex.Rsi(code, targetDate, 14, numberOfData); double[] williams = WilliamsR.Wsr(code, targetDate, 14, numberOfData); Stochastics stochastics = new Stochastics(code, targetDate, 14, 3, 3, numberOfData); double[] closesOut = IndicatorDataPreprocessor.GetClosesOut(numberOfData, data); double[] smaOut = IndicatorDataPreprocessor.GetSMAOut(sma); double[] wmaOut = IndicatorDataPreprocessor.GetWMAOut(wma); double[] emaOut = IndicatorDataPreprocessor.GetEMAOut(ema); double[] macdOut = IndicatorDataPreprocessor.GetMACDOut(macd); double[] rsiOut = IndicatorDataPreprocessor.GetRSIOut(rsi); double[] williamsROut = IndicatorDataPreprocessor.GetWilliamsROut(williams); double[] stochasticsOut = IndicatorDataPreprocessor.GetStochasticsOut(stochastics); int minRowCount; minRowCount = smaOut.Length; minRowCount = minRowCount < wmaOut.Length ? minRowCount : wmaOut.Length; minRowCount = minRowCount < emaOut.Length ? minRowCount : emaOut.Length; minRowCount = minRowCount < macdOut.Length ? minRowCount : macdOut.Length; minRowCount = minRowCount < rsiOut.Length ? minRowCount : rsiOut.Length; minRowCount = minRowCount < williamsROut.Length ? minRowCount : williamsROut.Length; minRowCount = minRowCount < stochasticsOut.Length ? minRowCount : stochasticsOut.Length; minRowCount = minRowCount < closesOut.Length ? minRowCount : closesOut.Length; FeatureVector vector = new FeatureVector(); vector.AddColumn("SMA", smaOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); vector.AddColumn("WMA", wmaOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); vector.AddColumn("EMA", emaOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); vector.AddColumn("MACD", macdOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); vector.AddColumn("RSI", rsiOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); vector.AddColumn("WilliamsR", williamsROut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); vector.AddColumn("Stochastics", stochasticsOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); vector.AddColumn("label", closesOut.Select(p => (object)string.Format("{0:0.0}", p).ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); new LabeledPointExporter(vector).Export(filePath); int count = vector.Values[0].Length; FeatureVector training = new FeatureVector(); for (int i = 0; i < vector.ColumnName.Count; i++) { training.AddColumn(vector.ColumnName[i], vector.Values[i].Take(count / 2).ToArray()); } FeatureVector test = new FeatureVector(); for (int i = 0; i < vector.ColumnName.Count; i++) { test.AddColumn(vector.ColumnName[i], vector.Values[i].Skip(count / 2).Take(count / 2).ToArray()); } //TestNaiveBayes(training, test); //TestNaiveBayesUsingCrossValidation(training, test); //TestLinearRegression(training, test); //TestLinearRegressionUsingCrossValidation(training, test); //TestLogisticRegression(training, test); //TestLogisticRegressionUsingCrossValidation(training, test); }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { /// Lines with comments like these were commented out to help read a cleaner chart // Checks to make sure we have at least 20 or more bars if (CurrentBar < 30) { return; } // dad = macd.Avg // mom = macd.Mom macdTrend = 0; if (macd.Mom[0] > 0 && macd.Avg[0] > 0) { macdTrend = 1; if (BackgroundColorEnabled) { BackColorAll = Color.FromArgb(Opacity, BackgroundLongColor); } } else if (macd.Mom[0] < 0 && macd.Avg[0] < 0) { macdTrend = -1; if (BackgroundColorEnabled) { BackColorAll = Color.FromArgb(Opacity, BackgroundShortColor); } } stoc = Stochastics(stocD, stocK, stocS); //stocX3 = Stochastics(IDataSeries, stocD, stocK, stocS); //int currentTrend = Rising(SMARick(SmaPeriod)) ? RISING: FALLING; int currentTrend = Rising(HMARick(HmaPeriod, 75)) ? RISING: FALLING; // is SMA trend changing //if ((( Rising(SMARick(SmaPeriod))&& (SMARick(SmaPeriod)[1] - SMARick(SmaPeriod)[2]) < 0 )) // || (Falling(SMARick(SmaPeriod)) && (SMARick(SmaPeriod)[1] - SMARick(SmaPeriod)[2]) > 0)) //{ if (currentTrend != previousTrend) { //if (Rising(SMARick(SmaPeriod)) != Rising(SMARick(SmaPeriod))[1]) //{ //if (currentTrend > 0 && trend < 0 || // currentTrend < 0 && trend > 0) //|| (trend >= 0 && currentTrend == -1)) //{ // reset trend //trend = currentTrend; trendStartBar = CurrentBar; trendCount++; cycleHigh = int.MaxValue; cycleLow = int.MinValue; /// if (currentTrend == FALLING) /// DrawText(CurrentBar + " barCount", CurrentBar + " ", 0, 2 * (High[0] - Low[0]) + High[0], Color.DarkRed); /// if (currentTrend == RISING) /// DrawText(CurrentBar + " barCount", CurrentBar + " ", 0, 2 * (High[0] - Low[0]) + High[0], Color.DarkGreen); // cycleCount = 0; } //if (((SMARick(SmaPeriod)[0] - SMARick(SmaPeriod)[1]) > 0 && (SMARick(SmaPeriod)[1] - SMARick(SmaPeriod)[2]) < 0 ) // || ((SMARick(SmaPeriod)[0] - SMARick(SmaPeriod)[1]) < 0 && (SMARick(SmaPeriod)[1] - SMARick(SmaPeriod)[2]) > 0 )) //{ // cycleCount = 0; //} MarkCycleHigh(); MarkCycleLow(); IdentifySecondChance(); Scalp(); // In-Trend note: // multi-hook entry pattern provides a higher probability that we are making a cycle high or low, than a single hook. // even more so, is when the price falls with the hooks are going up (long entry) // example in doc on pg 24 is using Stoc D // for the example above, if it's down trend and you're short, it could signal time to exit /* * uptrend conditions * 1 - new * 2 - cross above 45, look for cycle high * 3 - cross above 55 * 4 - cross below 55, stop cycle high search */ if (currentTrend == 1) { switch (trend) { case 1: if (stoc.D[0] > 45) { trend = 2; } if (stoc.D[0] > 55) { trend = 3; } break; case 2: if (stoc.D[0] > 55) { trend = 3; } if (CrossBelow(stoc.D, 45, 1)) { trend = 1; } break; case 3: if (CrossBelow(stoc.D, 55, 1)) { trend = 4; } break; default: break; } } if (currentTrend == -1) { switch (trend) { case -1: if (stoc.D[0] < 55) { trend = -2; } if (stoc.D[0] < 45) { trend = -3; } break; case -2: if (stoc.D[0] < 45) { trend = -3; } if (CrossAbove(stoc.D, 55, 1)) { trend = -1; } break; case -3: if (CrossAbove(stoc.D, 55, 1)) { trend = -4; } break; default: break; } } if (trend >= 1) { cycleHigh = HighestBar(High, CurrentBar - trendStartBar); } if (trend <= -1) { cycleLow = LowestBar(Low, CurrentBar - trendStartBar); } if (trend < 0) { //DrawDot("Low" + CurrentBar, false, 0, Low[cycleLow], Color.Black); } if (trend > 0) { //DrawDot("High" + CurrentBar, false, 0, High[cycleHigh], Color.Black); // Print(Time + " cycleHigh: " + cycleHigh); if (stoc.D[2] > stoc.D[1] && stoc.D[1] < stoc.D[0] ) { //DrawDot(CurrentBar + "ELx", false, 1, High[0] + 1 * TickSize, Color.Magenta); //DrawArrowUp("My up arrow" + CurrentBar, false, 0, Low[0], Color.Lime); if (Position.MarketPosition == MarketPosition.Flat) { //DrawDot(CurrentBar + "EL", false, 0, High[0] + 1 * TickSize, Color.Black); //EnterLongStop(High[0] + 1 * TickSize); } } } previousTrend = currentTrend; }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { double stopPrice = 0; double limitPrice = 0; int qty = 1; if (BarsPeriod.Id != PeriodType.Range) { DrawTextFixed("error msg", "This Strategy only works on Intraday Range Bars", TextPosition.BottomRight); return; } if (Bars.BarsSinceSession == 1) { ResetTrade(); } RcMACD macd = RcMACD(12, 26, 9); RSI rsi = RSI(7, 3); Stochastics stoc = Stochastics(3, 5, 2); Bollinger bollinger = Bollinger(2, 12); if (UseRSIFilter == 1) { if (rsi[0] > 70) { this.DrawTriangleUp(CurrentBar + "Up", false, 0, Low[0] - 2 * TickSize, Color.Green); } else if (rsi[0] < 30) { DrawTriangleDown(CurrentBar + "Down", false, 0, High[0] + 2 * TickSize, Color.Red); } } else { if (stoc.D[0] > 80) { DrawTriangleUp(CurrentBar + "Up", false, 0, Low[0] - 2 * TickSize, Color.Green); } else if (stoc.D[0] < 20) { DrawTriangleDown(CurrentBar + "Down", false, 0, High[0] + 2 * TickSize, Color.Red); } } if (Position.MarketPosition == MarketPosition.Flat) { if (entryOrderLong != null) { CancelOrder(entryOrderLong); entryOrderLong = null; } else // Long Entry Conditions if (longTrades && entryOrderLong == null && macd.Mom[0] > 0 && macd.Mom[0] > macd.Avg[0] && ((UseRSIFilter == 1 && rsi[0] > 70) || (UseRSIFilter == 0 && stoc.D[0] < 20)) && Rising(bollinger.Upper) && Close[0] > (bollinger.Upper[0] - 2 * TickSize) //&& Time[0].DayOfWeek != DayOfWeek.Friday //&& (ToTime(Time[0]) >= 83000 && ToTime(Time[0]) <= 103000) ) { DrawArrowUp(CurrentBar + "Long", false, 0, Low[0] - 8 * TickSize, Color.Green); if (Close[0] == High[0]) { //DrawDot(CurrentBar + "marketPrice", false, 1, Close[0], Color.Gray); if (!reverseTrades) { entryOrderLong = SubmitOrder(0, OrderAction.Buy, OrderType.Market, qty, limitPrice, stopPrice, orderPrefix + "ocoEnter", "Long"); } else { entryOrderLong = SubmitOrder(0, OrderAction.SellShort, OrderType.Market, qty, limitPrice, stopPrice, orderPrefix + "ocoEnter", "!Long"); } } else { stopPrice = Close[0] + 1 * TickSize; limitPrice = Close[0] + 1 * TickSize; //DrawDot(CurrentBar + "stopPrice", false, 1, stopPrice, Color.DarkGray); //DrawDot(CurrentBar + "limitPrice", false, 1, limitPrice, Color.Black); if (!reverseTrades) { entryOrderLong = SubmitOrder(0, OrderAction.Buy, OrderType.StopLimit, qty, limitPrice, stopPrice, orderPrefix + "ocoEnter", "Long"); } else { entryOrderLong = SubmitOrder(0, OrderAction.SellShort, OrderType.StopLimit, qty, limitPrice, stopPrice, orderPrefix + "ocoEnter", "!Long"); } } } // Short Entry Conditions if (shortTrades && entryOrderShort == null && macd.Mom[0] < 0 && macd.Mom[0] < macd.Avg[0] && ((UseRSIFilter == 1 && rsi[0] < 30) || (UseRSIFilter == 0 && stoc.D[0] > 80)) && Falling(bollinger.Lower) && Close[0] < (bollinger.Lower[0] + 2 * TickSize)) { DrawArrowDown(CurrentBar + "Short", false, 0, High[0] + 8 * TickSize, Color.Red); if (Close[0] == Low[0]) { //DrawDot(CurrentBar + "marketPrice", false, 1, Close[0], Color.Gray); if (!reverseTrades) { entryOrderShort = SubmitOrder(0, OrderAction.SellShort, OrderType.Market, qty, limitPrice, stopPrice, orderPrefix + "ocoEnter", "Short"); } else { entryOrderShort = SubmitOrder(0, OrderAction.Buy, OrderType.Market, qty, limitPrice, stopPrice, orderPrefix + "ocoEnter", "!Short"); } } else { stopPrice = Close[0] - 1 * TickSize; limitPrice = Close[0] - 1 * TickSize; //DrawDot(CurrentBar + "stopPrice", false, 1, stopPrice, Color.DarkGray); //DrawDot(CurrentBar + "limitPrice", false, 1, limitPrice, Color.Black); if (!reverseTrades) { entryOrderShort = SubmitOrder(0, OrderAction.SellShort, OrderType.StopLimit, qty, limitPrice, stopPrice, orderPrefix + "ocoEnter", "Short"); } else { entryOrderShort = SubmitOrder(0, OrderAction.Buy, OrderType.StopLimit, qty, limitPrice, stopPrice, orderPrefix + "ocoEnter", "!Short"); } } } } }
protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Strategy here."; Name = "Fastigium"; Calculate = Calculate.OnBarClose; EntriesPerDirection = 1; EntryHandling = EntryHandling.AllEntries; IsExitOnSessionCloseStrategy = true; ExitOnSessionCloseSeconds = 30; IsFillLimitOnTouch = false; MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix; OrderFillResolution = OrderFillResolution.Standard; Slippage = 0; StartBehavior = StartBehavior.WaitUntilFlat; TimeInForce = TimeInForce.Gtc; TraceOrders = false; RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose; StopTargetHandling = StopTargetHandling.PerEntryExecution; BarsRequiredToTrade = 20; RecordHistoricalTrades = false; TradingAccountId = 0; Quantity = 2; FireSns = false; Contrarian = false; StochasticsFilter = false; Conservative = true; StopLossTicks = 15; ProfitTakerTicks = 10; // Disable this property for performance gains in Strategy Analyzer optimizations // See the Help Guide for additional information IsInstantiatedOnEachOptimizationIteration = true; } else if (State == State.Configure) { shootingStarIndicator = GuerillaStickIndicator(GuerillaChartPattern.ShootingStar, false, false, false, 0); AddChartIndicator(shootingStarIndicator); hammerIndicator = GuerillaStickIndicator(GuerillaChartPattern.Hammer, false, false, false, 0); AddChartIndicator(hammerIndicator); dojiIndicator = GuerillaStickIndicator(GuerillaChartPattern.Doji, false, false, false, 0); AddChartIndicator(dojiIndicator); indecisionBarIndicator = GuerillaStickIndicator(GuerillaChartPattern.IndecisionBar, false, false, false, 0); AddChartIndicator(indecisionBarIndicator); bullishTrendBarIndicator = GuerillaStickIndicator(GuerillaChartPattern.BullishTrendBar, false, false, false, 0); AddChartIndicator(bullishTrendBarIndicator); bearishTrendBarIndicator = GuerillaStickIndicator(GuerillaChartPattern.BearishTrendBar, false, false, false, 0); AddChartIndicator(bearishTrendBarIndicator); greenBarIndicator = GuerillaStickIndicator(GuerillaChartPattern.GreenBar, false, false, false, 0); AddChartIndicator(greenBarIndicator); redBarIndicator = GuerillaStickIndicator(GuerillaChartPattern.RedBar, false, false, false, 0); AddChartIndicator(redBarIndicator); stochastics = Stochastics(7, 14, 3); AddChartIndicator(stochastics); disableManager.AddRange(DayOfWeek.Sunday, 13, 30, 24, 0); disableManager.AddRange(DayOfWeek.Monday, 13, 30, 16, 40); disableManager.AddRange(DayOfWeek.Tuesday, 13, 30, 16, 40); disableManager.AddRange(DayOfWeek.Wednesday, 13, 30, 16, 40); disableManager.AddRange(DayOfWeek.Thursday, 13, 30, 16, 40); disableManager.AddRange(DayOfWeek.Friday, 13, 30, 16, 40); } }
private void PreprocessIndicators() { var data = IndicatorService.GetData(code, targetDate, new string[] { "Tarih", "Kapanis" }, numberOfData + 1); double[] sma = null; double[] wma = null; double[] ema = null; MovingAverageConvergenceDivergence macd = null; double[] rsi = null; double[] williamsR = null; Stochastics stochastics = null; if (isSMA) { sma = MovingAverage.Simple(code, targetDate, 14, numberOfData); } if (isWMA) { wma = MovingAverage.Weighted(code, targetDate, 14, numberOfData); } if (isEMA) { ema = MovingAverage.Exponential(code, targetDate, 14, numberOfData); } if (isMACD) { macd = new MovingAverageConvergenceDivergence(code, targetDate, 12, 26, 9, numberOfData); } if (isRSI) { rsi = RelativeStrengthIndex.Rsi(code, targetDate, 14, numberOfData); } if (isWilliamsR) { williamsR = WilliamsR.Wsr(code, targetDate, 14, numberOfData); } if (isStochastics) { stochastics = new Stochastics(code, targetDate, 14, 3, 3, numberOfData); } double[] closesOut = IndicatorDataPreprocessor.GetClosesOut(numberOfData, data); double[] smaOut = null; double[] wmaOut = null; double[] emaOut = null; double[] macdOut = null; double[] rsiOut = null; double[] williamsROut = null; double[] stochasticsOut = null; if (isSMA) { smaOut = IndicatorDataPreprocessor.GetSMAOut(sma); } if (isWMA) { wmaOut = IndicatorDataPreprocessor.GetWMAOut(wma); } if (isEMA) { emaOut = IndicatorDataPreprocessor.GetEMAOut(ema); } if (isMACD) { macdOut = IndicatorDataPreprocessor.GetMACDOut(macd); } if (isRSI) { rsiOut = IndicatorDataPreprocessor.GetRSIOut(rsi, false); } if (isWilliamsR) { williamsROut = IndicatorDataPreprocessor.GetWilliamsROut(williamsR, false); } if (isStochastics) { stochasticsOut = IndicatorDataPreprocessor.GetStochasticsOut(stochastics, false); } minRowCount = closesOut.Length; if (isSMA) { minRowCount = minRowCount < smaOut.Length ? minRowCount : smaOut.Length; } if (isWMA) { minRowCount = minRowCount < wmaOut.Length ? minRowCount : wmaOut.Length; } if (isEMA) { minRowCount = minRowCount < emaOut.Length ? minRowCount : emaOut.Length; } if (isMACD) { minRowCount = minRowCount < macdOut.Length ? minRowCount : macdOut.Length; } if (isRSI) { minRowCount = minRowCount < rsiOut.Length ? minRowCount : rsiOut.Length; } if (isWilliamsR) { minRowCount = minRowCount < williamsROut.Length ? minRowCount : williamsROut.Length; } if (isStochastics) { minRowCount = minRowCount < stochasticsOut.Length ? minRowCount : stochasticsOut.Length; } FeatureVector featureVector = new FeatureVector(); if (isSMA) { featureVector.AddColumn("SMA", smaOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); } if (isWMA) { featureVector.AddColumn("WMA", wmaOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); } if (isEMA) { featureVector.AddColumn("EMA", emaOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); } if (isMACD) { featureVector.AddColumn("MACD", macdOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); } if (isRSI) { featureVector.AddColumn("RSI", rsiOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); } if (isWilliamsR) { featureVector.AddColumn("WilliamsR", williamsROut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); } if (isStochastics) { featureVector.AddColumn("Stochastics", stochasticsOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); } featureVector.AddColumn("label", closesOut.Select(p => (object)string.Format("{0:0.0}", p).ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); int count = featureVector.Values[0].Length; training = new FeatureVector(); test = new FeatureVector(); for (int i = 0; i < featureVector.ColumnName.Count; i++) { training.AddColumn(featureVector.ColumnName[i], featureVector.Values[i].Take((int)(count * trainingPercentage / 100.0)).ToArray()); test.AddColumn(featureVector.ColumnName[i], featureVector.Values[i].Skip((int)(count * trainingPercentage / 100.0)).Take(count).ToArray()); // Take(count) means take the rest of all elements, number of the rest of the elements is smaller than count. } }
private void stochasticsParameterNext_Click(object sender, EventArgs e) { stochasticsResultTitle.Text = Code + " için Stochastics sonucu"; FastKPeriod = (int)fastKPeriod.Value; FastDPeriod = (int)fastDPeriod.Value; SlowDPeriod = (int)slowDPeriod.Value; stochasticsCloseChart.Series.Clear(); stochasticsIndicatorChart.Series.Clear(); var closeSeries = new Series { Name = "Kapanış", Color = System.Drawing.Color.Black, ChartType = SeriesChartType.Line }; stochasticsCloseChart.Series.Add(closeSeries); var fastKSeries = new Series { Name = "Fast K", Color = System.Drawing.Color.Red, ChartType = SeriesChartType.Line }; var fastDSeries = new Series { Name = "Fast D", Color = System.Drawing.Color.Green, ChartType = SeriesChartType.Line }; var slowDSeries = new Series { Name = "Slow D", Color = System.Drawing.Color.Blue, ChartType = SeriesChartType.Line }; stochasticsIndicatorChart.Series.Add(fastKSeries); stochasticsIndicatorChart.Series.Add(fastDSeries); stochasticsIndicatorChart.Series.Add(slowDSeries); var closeData = IndicatorService.GetData(Code, TargetDate, new string[] { "Tarih", "Kapanis" }, NumberOfData); Stochastics stochastics; if (MapReduceAllowed) { stochastics = new Stochastics(Code, TargetDate, FastKPeriod, FastDPeriod, SlowDPeriod, NumberOfData, true); } else { stochastics = new Stochastics(Code, TargetDate, FastKPeriod, FastDPeriod, SlowDPeriod, NumberOfData, false); } int i; DateTime date; for (i = 0; i < stochastics.SlowD.Length; i++) { var close = closeData.ElementAt(i); date = close.GetElement("Tarih").Value.AsBsonDateTime.ToLocalTime(); fastKSeries.Points.AddXY(date, stochastics.FastK[i]); fastDSeries.Points.AddXY(date, stochastics.FastD[i]); slowDSeries.Points.AddXY(date, stochastics.SlowD[i]); closeSeries.Points.AddXY(date, close.GetElement("Kapanis").Value.ToDouble()); } for (; i < stochastics.FastD.Length; i++) { var close = closeData.ElementAt(i); date = close.GetElement("Tarih").Value.AsBsonDateTime.ToLocalTime(); fastKSeries.Points.AddXY(date, stochastics.FastK[i]); fastDSeries.Points.AddXY(date, stochastics.FastD[i]); closeSeries.Points.AddXY(date, close.GetElement("Kapanis").Value.ToDouble()); } for (; i < stochastics.FastK.Length; i++) { var close = closeData.ElementAt(i); date = close.GetElement("Tarih").Value.AsBsonDateTime.ToLocalTime(); fastKSeries.Points.AddXY(date, stochastics.FastK[i]); closeSeries.Points.AddXY(date, close.GetElement("Kapanis").Value.ToDouble()); } stochasticsCloseChart.ChartAreas[0].AxisY.Minimum = Math.Floor(closeData.Select(p => p.GetElement("Kapanis").Value.ToDouble()).Min()); stochasticsCloseChart.ChartAreas[0].AxisY.Maximum = Math.Ceiling(closeData.Select(p => p.GetElement("Kapanis").Value.ToDouble()).Max()); stochasticsIndicatorChart.ChartAreas[0].AxisY.Minimum = 0; stochasticsIndicatorChart.ChartAreas[0].AxisY.Maximum = 100; stochasticsCloseChart.Invalidate(); stochasticsIndicatorChart.Invalidate(); stochasticsResultPanel.BringToFront(); }
protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"RideTheTrendSkipTheBS"; Name = "RideTheTrendSkipTheBS"; Calculate = Calculate.OnBarClose; EntriesPerDirection = 1; EntryHandling = EntryHandling.AllEntries; IsExitOnSessionCloseStrategy = true; ExitOnSessionCloseSeconds = 30; IsFillLimitOnTouch = false; MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix; OrderFillResolution = OrderFillResolution.Standard; Slippage = 0; StartBehavior = StartBehavior.WaitUntilFlat; TimeInForce = TimeInForce.Gtc; TraceOrders = false; RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose; StopTargetHandling = StopTargetHandling.PerEntryExecution; BarsRequiredToTrade = 20; // Disable this property for performance gains in Strategy Analyzer optimizations // See the Help Guide for additional information IsInstantiatedOnEachOptimizationIteration = true; TradingAccountId = 0; ExitPeriod = 3; AdxPeriod = 14; MinAdx = 25; ExitSlopeThreshold = -15; UseBoundaryHours = true; StartHour = 7; StartMinute = 30; EndHour = 12; EndMinute = 30; LossExitTicks = 8; EnterPeriod = 3; EnterSlopeThreshold = 20; RecordHistoricalTrades = false; EnterBarsLength = 2; ExitBarsLength = 2; ExitStopBuffer = 2; ExitLimitBuffer = 2; Quantity = 1; FireSns = false; MinTrendLength = 1; BsWindowLength = 5; TargetDollars = 0; TrailingStopMinDollars = 0; TrailingStopDivisorDollars = 0; TrailingStopCushionDollars = 0; OverrideRealTimeOnly = false; } else if (State == State.Configure) { //SetOrderQuantity = SetOrderQuantity.DefaultQuantity; trailingStopEnabled = TrailingStopMinDollars > 0; if (trailingStopEnabled) { AddDataSeries(BarsPeriodType.Tick, 300); } stochastics = Stochastics(7, 14, 3); AddChartIndicator(stochastics); //tickCounter = TickCounter(true, false); //AddChartIndicator(tickCounter); fastMaIndicator = EMA(5); //AddChartIndicator(fastMaIndicator); slowMaIndicator = EMA(10); //AddChartIndicator(slowMaIndicator); rangeIndicator = MyRange(3, MinTickRange); //AddChartIndicator(rangeIndicator); adxIndicator = EnhancedADX(AdxPeriod, MinAdx); AddChartIndicator(adxIndicator); if (EnterPeriod > 1) { enterAdxSlopeIndicator = AdxSlope(AdxPeriod, EnterPeriod, EnterSlopeThreshold); //AddChartIndicator(enterAdxSlopeIndicator); } if (ExitPeriod > 1) { exitAdxSlopeIndicator = AdxSlope(AdxPeriod, ExitPeriod, ExitSlopeThreshold); //AddChartIndicator(exitAdxSlopeIndicator); } // disableManager.AddRange(DayOfWeek.Monday, 6, 25, 6, 50); // disableManager.AddRange(DayOfWeek.Tuesday, 6, 25, 6, 50); // disableManager.AddRange(DayOfWeek.Wednesday, 6, 25, 6, 50); // disableManager.AddRange(DayOfWeek.Thursday, 6, 25, 6, 50); // disableManager.AddRange(DayOfWeek.Friday, 6, 25, 6, 50); //disableManager.AddRange(DayOfWeek.Sunday, 13, 45, 24, 0); //disableManager.AddRange(DayOfWeek.Monday, 13, 45, 24, 0); //disableManager.AddRange(DayOfWeek.Tuesday, 13, 45, 24, 0); //disableManager.AddRange(DayOfWeek.Wednesday, 13, 45, 24, 0); //disableManager.AddRange(DayOfWeek.Thursday, 13, 45, 24, 0); //disableManager.AddRange(DayOfWeek.Friday, 13, 45, 24, 0); PrintTrade("Direction", "TickRange", "TickRangeBucket", "MaSlope", "MaSlopeBucket", "MaDiff", "MaDiffBucket", "Adx", "AdxBucket", "AdxSlope", "AdxSlopeBucket", "Hour", "Fifteen", "PL", "Win"); } else if (State == State.DataLoaded) { //fastMaIndicator.PlotBrushes[0][0] = Brushes.DodgerBlue; //slowMaIndicator.PlotBrushes[0][0] = Brushes.HotPink; } }