protected override void OnStart() { bb=Indicators.BollingerBands(MarketSeries.Close,bbperiod,bbotcl, MovingAverageType.Simple); rsi=Indicators.RelativeStrengthIndex(MarketSeries.Close,rsiperiod); psar=Indicators.ParabolicSAR(SARstep,SARmax); frc=Indicators.FractalChaosBands(5); }
public static void Main(string[] args) { DataLoader dataLoader = new DataLoader(); IndicatorTester tester = new IndicatorTester(); dataLoader.UserFilesFolder = @"C:\Program Files\Forex Strategy Builder Pro\User Files"; // Set Data Source name, symbol, and period IDataSet dataSet = dataLoader.LoadDataSet("FSB Demo Data", "EURUSD", DataPeriod.D1); if (dataSet == null) { Console.WriteLine("Data file is not loaded!"); Console.WriteLine("Press a key to continue!"); Console.ReadKey(); return; } // Create an indicator for testing IIndicator indicator = new BollingerBands(); indicator.Initialize(SlotTypes.Open); indicator.Calculate(dataSet); // Print first values PrintFirstValues(indicator, 0, 50); // Calculate indicator with random parameters for all available slots. // tester.CalculateIndicatorWithRandomParameters(indicator, dataSet, 25); Console.WriteLine("Test completed without errors."); Console.WriteLine("Press a key to continue!"); Console.ReadKey(); }
protected override void OnStart() { BB = Indicators.BollingerBands(BBSource, BBPeriods, BBStDev, BBMAType); ActiveGrids = new List <Grid>(); UnitTradingCost = RoundLotCost / Symbol.LotSize; KellyParameters = new Dictionary <string, double[]> { { "WinningTrades", new double[GridLevelCount] }, { "LosingTrades", new double[GridLevelCount] }, { "Profit", new double[GridLevelCount] }, { "Loss", new double[GridLevelCount] } }; firstIndex = Convert.ToInt32(EntryAfterConfirmation); Positions.Closed += OnPositionClosed; }
public static BollingerBands BollingerBands(CandleStickCollection candleSticks, int period = 14, double multiplier = 2, PriceSource priceSource = PriceSource.Close) { BollingerBands bollingerBands = new BollingerBands(candleSticks, period, multiplier, priceSource); return(bollingerBands); }
protected override void Initialize() { Result = CreateDataSeries(); iMACD = Indicators.MacdCrossOver(26, 12, 9); iBands = Indicators.BollingerBands(MarketSeries.Close, 20, 2, MovingAverageType.Simple); }
public override void ResetsProperly() { var bb = new BollingerBands(2, 2m); bb.Update(DateTime.Today, 1m); Assert.IsFalse(bb.IsReady); bb.Update(DateTime.Today.AddSeconds(1), 2m); Assert.IsTrue(bb.IsReady); Assert.IsTrue(bb.StandardDeviation.IsReady); Assert.IsTrue(bb.LowerBand.IsReady); Assert.IsTrue(bb.MiddleBand.IsReady); Assert.IsTrue(bb.UpperBand.IsReady); Assert.IsTrue(bb.BandWidth.IsReady); Assert.IsTrue(bb.PercentB.IsReady); bb.Reset(); TestHelper.AssertIndicatorIsInDefaultState(bb); TestHelper.AssertIndicatorIsInDefaultState(bb.StandardDeviation); TestHelper.AssertIndicatorIsInDefaultState(bb.LowerBand); TestHelper.AssertIndicatorIsInDefaultState(bb.MiddleBand); TestHelper.AssertIndicatorIsInDefaultState(bb.UpperBand); TestHelper.AssertIndicatorIsInDefaultState(bb.BandWidth); TestHelper.AssertIndicatorIsInDefaultState(bb.PercentB); }
public Indicator AnalyzeData(DataState state) { double[] closePrices = _analyseRepo.LoadClosePriceBySymbol(state.Symbol, true).ToArray(); List <BollingerBandsData> bBDataValues = BollingerBandsCalculator.CalculateBollingerBands( BollingerBandsCalculator.Period, BollingerBandsCalculator.DeviationUp, BollingerBandsCalculator.DeviationDown, closePrices); if (bBDataValues.Count == 0) { return(null); } var lastBB = AlgorithmHelper.TakeLast <BollingerBandsData>(bBDataValues, 1).FirstOrDefault(); if (lastBB == null) { return(null); } BollingerBands value = new BollingerBands(); value.Symbol = state.Symbol; value.Date = state.Last.Value; value.Upper = lastBB.Upper; value.Middle = lastBB.Middle; value.Lower = lastBB.Lower; value.ChannelHight = value.Upper - value.Lower; value.ChannelPercent = value.ChannelHight * 100 / value.Middle; return(value.ToIndicator()); }
protected override void OnStart() { bb = Indicators.BollingerBands(MarketSeries.Close, bbperiod, bbotcl, MovingAverageType.Simple); rsi = Indicators.RelativeStrengthIndex(MarketSeries.Close, rsiperiod); psar = Indicators.ParabolicSAR(SARstep, SARmax); frc = Indicators.FractalChaosBands(5); }
public Strategy(IStatistics st) { ema = new EMA(); bands = st.Base > 1 && st.Sigma > 0 && st.Percent > 0 && st.Max > 0 ? true : false; days = st.ShortDayPeriod > 1 && st.LongDayPeriod > 2 ? true : false; count = st.Quantity + 1; Headway = st.Time; if (bands) { over = new BollingerBands(st.Sigma * 0.1, st.Base, st.Percent, st.Max); baseTick = new List <double>(2097152); } if (days) { shortDay = new List <double>(512); longDay = new List <double>(512); } shortTick = new List <double>(2097152); longTick = new List <double>(2097152); Send += Analysis; this.st = st; GetChart(); Send -= Analysis; api = ConnectAPI.Get(); api.SendDatum += Analysis; balance = Balance.Get(); SendLiquidate += balance.OnReceiveLiquidate; }
protected override void OnStart() { i_Bollinger_Bands = Indicators.BollingerBands(MarketSeries.Close, 20, 2, MovingAverageType.Simple); i_Bollinger_Bands_1 = Indicators.BollingerBands(MarketSeries.Close, 20, 2, MovingAverageType.Simple); i_Bollinger_Bands_2 = Indicators.BollingerBands(MarketSeries.Close, 20, 2, MovingAverageType.Simple); i_Bollinger_Bands_3 = Indicators.BollingerBands(MarketSeries.Close, 20, 2, MovingAverageType.Simple); }
protected override void OnStart() { Print("START gyBolliBanBreak: {0}", Server.Time.ToLocalTime()); bbnd1 = Indicators.BollingerBands(srcBB, prdBB, devBB1, matBB); bbnd2 = Indicators.BollingerBands(srcBB, prdBB, devBB2, matBB); sma1 = Indicators.SimpleMovingAverage(srcSMA, prdSMA); }
/// <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); }
protected override void Initialize() { MA1 = Indicators.MovingAverage(MarketSeries.High, Keltner_Period, MovingAverageType.Simple); MA2 = Indicators.MovingAverage(MarketSeries.Low, Keltner_Period, MovingAverageType.Simple); MA3 = Indicators.MovingAverage(MarketSeries.Typical, Keltner_Period, MovingAverageType.Simple); iBand = iBand = Indicators.BollingerBands(MarketSeries.Close, Boll_Period, Boll_Dev, MovingAverageType.Simple); }
protected override void Initialize() { _rsi = Indicators.RelativeStrengthIndex(Source, RsiPeriod); _bollingerBands = Indicators.BollingerBands(_rsi.Result, Volatility, StDev, MovingAverageType.Simple); _price = Indicators.MovingAverage(_rsi.Result, PricePeriod, PriceMaType); _signal = Indicators.MovingAverage(_rsi.Result, SignalPeriod, SignalMaType); }
public Analysize(Remaining remaining, IStrategy st) { ema = new EMA(); bands = st.Base > 1 && st.Sigma > 0 && st.Percent > 0 && st.Max > 0 ? true : false; days = st.ShortDayPeriod > 1 && st.LongDayPeriod > 2 ? true : false; count = st.Quantity + 1; Headway = st.Time; if (bands) { over = new BollingerBands(st.Sigma * 0.1, st.Base, st.Percent, st.Max); baseTick = new List <double>(2097152); } if (days) { shortDay = new List <double>(512); longDay = new List <double>(512); } shortTick = new List <double>(2097152); longTick = new List <double>(2097152); Send += Analysis; this.st = st; info = new Information(st); this.remaining = remaining; GetChart(); info.Log(); }
/// <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); }
protected override void Initialize() { BB = Indicators.BollingerBands(Source, Periods, Std_Deviation, MA_Type); FireSoundAlarm = true; theCount = MarketSeries.Close.Count; }
/// <summary> /// Closes the trade if price crosses the upper/lower bollinger band. /// </summary> /// <param name="candles">candle history</param> /// <param name="bar">currentcandle</param> /// <param name="tradeManager">tradeManager</param> private void CloseTradeIfPossible(List <MarketCandle> candles, int bar, ITradeManager tradeManager) { var candle = candles[bar]; var bbands = new BollingerBands(candles, bar); // for long we close the trade if price gets above the upper bollinger bands if (_trade.TradeType == TradeType.Long && candle.HighPrice > bbands.Upper) { if (tradeManager.Close(_trade, candle.HighPrice)) { _state = StrategyState.Scanning; _trade = null; return; } } // for short we close the trade if price gets below the lowe bollinger bands if (_trade.TradeType == TradeType.Short && candle.LowPrice < bbands.Lower) { if (tradeManager.Close(_trade, candle.LowPrice)) { _state = StrategyState.Scanning; _trade = null; return; } } }
/// <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); }
protected override void OnStart() { Positions.Opened += OnPositionOpened; bollingerBands = Indicators.BollingerBands(Source, Periods, Deviation, MAType); //BandHeight = (bollingerBands.Top.LastValue - bollingerBands.Bottom.LastValue) / 3; //DeltaBollinger = BandHeight / 5; }
//--- protected override void OnStart() { //--- エントリーイベント Positions.Opened += OnPositionOpened; //--- BB bol = Indicators.BollingerBands(MarketSeries.Close, Period1, SD1, MovingAverageType.Simple); slowBol = Indicators.BollingerBands(MarketSeries.Close, Period2, SD2, MovingAverageType.Simple); }
protected override void OnStart() { fastMa = Indicators.MovingAverage(SourceSeries, FastPeriods, MAType); mediumMa = Indicators.MovingAverage(SourceSeries, mediumPeriods, MAType); slowMa = Indicators.MovingAverage(SourceSeries, SlowPeriods, MAType); atr = Indicators.AverageTrueRange(atrPeriod, MAType); bBand = Indicators.BollingerBands(SourceSeries, bBandPeriods, bBandDeviations, MAType); }
/// <summary> /// CALLED WHEN THE ROBOT FIRST STARTS, IT IS ONLY CALLED ONCE. /// </summary> protected override void OnStart() { // TRADE MANAGER DECLERATION tm = new TradeManager(this); // INDICATOR DECLERATIONS IndIchi = Indicators.IchimokuKinkoHyo(TenkanSen, KijunSen, SenkouSpanB); IndBoll = Indicators.BollingerBands(BollDS, BollPeriod, BollSD, BollMAT); }
/// <summary> /// Creates a new BollingerBands indicator which will compute the MiddleBand, UpperBand, LowerBand, and StandardDeviation /// </summary> /// <param name="symbol">The symbol whose BollingerBands we seek</param> /// <param name="period">The period of the standard deviation and moving average (middle band)</param> /// <param name="k">The number of standard deviations specifying the distance between the middle band and upper or lower bands</param> /// <param name="movingAverageType">The type of moving average to be used</param> /// <param name="resolution">The resolution</param> /// <param name="selector">Selects a value from the BaseData to send into the indicator, if null defaults to the Value property of BaseData (x => x.Value)</param> /// <returns>A BollingerBands configured with the specied period</returns> public BollingerBands BB(string symbol, int period, decimal k, MovingAverageType movingAverageType = MovingAverageType.Simple, Resolution?resolution = null, Func <BaseData, decimal> selector = null) { var name = CreateIndicatorName(symbol, string.Format("BB({0},{1})", period, k), resolution); var bb = new BollingerBands(name, period, k, movingAverageType); RegisterIndicator(symbol, bb, resolution, selector); return(bb); }
static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.Gray; //Console.ResetColor() is not working :( Console.CancelKeyPress += Console_CancelKeyPress; var ticker = string.Empty; string indicator = string.Empty; HandleArgs(args, ref ticker, ref indicator); Console.WriteLine($"Fetching trade data for {ticker.ToUpper()}..."); //on the next version, it's gonna be an interface RSI RSITrades = null; CCI CCITrades = null; BollingerBands BBandTrades = null; var bfxReader = new Core.Exchanges.Bitfinex.TickerReader(); TickerHandler tickerHndl = null; //getting the 14 last minutes history var hist = new Core.Exchanges.Bitfinex.TickerCandlesReader(); if (indicator.ToUpper() == "RSI") { RSICalc(out RSITrades, bfxReader, out tickerHndl, hist); } else if (indicator.ToUpper() == "CCI") { CCICalc(out CCITrades, bfxReader, out tickerHndl, hist); } else if (indicator.ToUpper() == "BBANDS") { BBandCalc(out BBandTrades, bfxReader, out tickerHndl, hist); } else { Console.WriteLine("Invalid Parameter"); return; } tickerHndl.OnError += tickerHndl_OnError; bfxReader.Enabled = true; Task.Run(async() => { await bfxReader.Start(ticker.ToUpper()); }); while (enabled) { ; } Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine($"Program ended."); }
protected override void OnStart() { bollingerBands = Indicators.BollingerBands(Source, Periods, Deviations, MAType); delayCounter = ExecutionDelay; qtdPositionLoss = 0; lastStopLoss = Server.Time; Positions.Closed += OnPositionClosed; }
public TickerHandler(IExchangeTickerReader tickerReader, BollingerBands trades) { _tickerReader = tickerReader; _tickerReader.PoolingInterval = Consts.PoolingInterval; _tickerReader.TickerReady += _tickerReader_TickerReady; _tickerReader.OnError += _tickerReader_OnError; _bband = trades; _bband.IndicatorReady += _bband_IndicatorReady; }
protected override void Init() { _psInd = GetIndicator <ParabolicSar>(Instrument.Id, Timeframe); _psInd.CoefStep = 0.01; _maInd = GetIndicator <MovingAverage>(Instrument.Id, Timeframe); _maInd.Period = 26; _macdInd = GetIndicator <MovingAverageConvergenceDivergence>(Instrument.Id, Timeframe); _bbInd = GetIndicator <BollingerBands>(Instrument.Id, Timeframe); }
protected override void OnStart() { //fastMa = Indicators.MovingAverage(SourceSeries, FastPeriods, MAType); //mediumMa = Indicators.MovingAverage(SourceSeries, mediumPeriods, MAType); //slowMa = Indicators.MovingAverage(SourceSeries, SlowPeriods, MAType); atr = Indicators.AverageTrueRange(atrPeriod, MAType); bBand = Indicators.BollingerBands(SourceSeries, bBandPeriods, bBandDeviations, MAType); _kama = Indicators.GetIndicator <KAMASignal>(Source, Fast, Slow, Period); }
/// <summary> /// Initializes the algorithm with fake VIX data /// </summary> public override void Initialize() { SetStartDate(2013, 10, 7); SetEndDate(2013, 10, 11); SetCash(100000); _vix = AddData <IncrementallyGeneratedCustomData>("VIX", Resolution.Daily).Symbol; _bb = BB(_vix, 30, 2, MovingAverageType.Simple, Resolution.Daily); }
protected override void OnStart() { rsi = Indicators.RelativeStrengthIndex(Source, Period0); bol = Indicators.BollingerBands(Source, Period1, stdev, MovingAverageType.Simple); //obtain high and low of initial start bar double max = MarketSeries.High.LastValue; double min = MarketSeries.Low.LastValue; }
protected override void OnStart() { if (Symbol.Code != "EURUSD" || TimeFrame != TimeFrame.Minute5) { Print("This robot can be run only on EURUSD Minute5"); Stop(); return; } _bb = Indicators.BollingerBands(MarketSeries.High, Period, StandardDeviation, MAType); }
protected override void OnStart() { sma=Indicators.MovingAverage(MarketSeries.Close,Period_MA_Long,MovingAverageType.Simple); bb=Indicators.BollingerBands(MarketSeries.Close,Period_BB,Deviation, MovingAverageType.Simple); }
protected override void OnStart() { _botName = ToString(); _instanceLabel = string.Format("{0}-{1}-{2}-{3}", _botName, _botVersion, Symbol.Code, TimeFrame.ToString()); Positions.Opened += OnPositionOpened; bb = Indicators.BollingerBands(Source, Periods, Deviation, MAType); }
protected override void Initialize() { _bband = Indicators.BollingerBands(Source, Period, StDeviation, MAType); }
protected override void Initialize() { _bollingerBands = Indicators.BollingerBands(Source, Period, K, MaType); }
protected override void Initialize() { rsi = Indicators.RelativeStrengthIndex(Source, Period); bbands = Indicators.BollingerBands(rsi.Result, Period, stdDev, MAType); }
protected override void OnStart() { bollingerBands = Indicators.BollingerBands(Source, Periods, Deviations, MAType); }
protected override void Initialize() { bb = Indicators.BollingerBands(Source, Period, std, matype); }