Exemple #1
0
 public BackgroundSignal(TickerType tickerType, BarItemType barType, object dataStreamSource)
 {
     this.dataStreamSource    = dataStreamSource;
     this.tickerType          = tickerType;
     this.barType             = barType;
     this.registeredAnalytics = new List <AnalyticsItem>();
 }
Exemple #2
0
 public void Initialize(string identityCode, BarItemType barType, Guid cacheId, CacheTypeOption cacheType)
 {
     if (cacheMode == CacheModeOption.Read || cacheMode == CacheModeOption.ReadWrite)
     {
         cache = SharedCacheFactory.Instance.LoadTimeKeyedCache(identityCode, barType, cacheId, cacheType);
     }
 }
Exemple #3
0
 private void RaiseBarGapEvent(BarItemType barItemType, DateTime dateTime)
 {
     if (BarGap != null)
     {
         BarGap(barItemType, dateTime);
     }
 }
Exemple #4
0
        public BacktestSession CreateSession(Guid accountId, TickerType tickerType, BarItemType barType, string barDataFile, Guid cacheId)
        {
            if (backtestSessions == null)
            {
                backtestSessions = new Dictionary <Guid, BacktestSession>();
            }

            this.cacheId = cacheId;

            //this line should raise an exception if file is invalid
            BarItemFile.ValidateFile(barDataFile);

            BacktestSession backtestSession = new BacktestSession(accountId, tickerType, barDataFile, cacheId);

            //backtestSession.SignalClosePosition += OnSignalClosePosition;
            //backtestSession.SignalOpenPosition += OnSignalOpenPosition;

            backtestSession.StrategyClosePosition += OnStrategyClosePosition;
            backtestSession.StrategyOpenPosition  += OnStrategyOpenPosition;

            backtestSessions.Add(backtestSession.SessionId, backtestSession);

            brokerAccounts[accountId].Orders.Initialize(barType, backtestSession.SessionId);

            return(backtestSession);
        }
Exemple #5
0
        public void Initialize(int maxBars, int barsViewable, string cacheFolder, BarItemType barType, Guid cacheId, string strategyIdentityCode)
        {
            multiChart1.Initialize(maxBars, barsViewable);

            this.SelectedTimeframe = barType;

            pricebarCache = new PricebarCache(barType, cacheId, CacheModeOption.Read);

            this.strategyDataFrame = new StrategyDataFrame(strategyIdentityCode, 300, pricebarCache);

            timeNavigator1.Initialize(pricebarCache.StartBarDate, pricebarCache.EndBarDate);

            strategyFrameReader = strategyDataFrame.GetFrameReader(pricebarCache.StartBarDate);

            IPriceActionChart priceChart = this.PriceActionChart;

            priceChart.Show();
            priceChart.SetDataPoints(strategyFrameReader.PriceBars);

            List <ChartSignalItem> signalItems = new List <ChartSignalItem>();

            foreach (BarItem barItem in strategyFrameReader.PriceBars)
            {
                MarketOrderState marketOrderState = strategyFrameReader.Read(barItem.Time);
                if (marketOrderState != MarketOrderState.NoOrder)
                {
                    signalItems.Add(new ChartSignalItem(marketOrderState == MarketOrderState.Long ? SignalState.Long : marketOrderState == MarketOrderState.Short ? SignalState.Short : SignalState.NoSignal, barItem.Time));
                }
            }

            priceChart.PlotSignal(signalItems.ToArray());

            //foreach (IndicatorChartingInfo chartingInfo in strategyDataFrame.GetIndicatorChartingInfo())
            //{
            //    ChartIndicatorItem[] chartIndicators = strategyDataFrame.GetIndicators(chartingInfo.IdentityCode, chartingInfo.SeriesLabel);
            //    if (chartingInfo.ChartRange == ChartRangeOption.PriceActionRange)
            //    {
            //        priceChart.PlotIndicator(GetSeriesLabel(chartingInfo), chartIndicators, chartingInfo.ChartType);
            //    }
            //    else if (chartingInfo.ChartRange == ChartRangeOption.PositiveHundredRange)
            //    {
            //        if (!PercentageChart.Visible)
            //        {
            //            PercentageChart.Show();
            //        }

            //        PercentageChart.PlotIndicator(GetSeriesLabel(chartingInfo), chartIndicators, chartingInfo.ChartType);
            //    }
            //    else if (chartingInfo.ChartRange == ChartRangeOption.PipRange)
            //    {
            //        if (!OscillatorChart.Visible)
            //        {
            //            OscillatorChart.Show();
            //        }

            //        OscillatorChart.PlotIndicator(GetSeriesLabel(chartingInfo), chartIndicators, chartingInfo.ChartType);
            //    }

            //}
        }
Exemple #6
0
        public SequenceKeyedCaching LoadSequenceKeyedCache(string identityCode, BarItemType barType, Guid cacheId, CacheTypeOption cacheType)
        {
            CacheHeaderInfo header = cacheReader.RequestHeader(identityCode, barType, cacheId, cacheType);

            cacheReader.RegisterHeader(header);
            return(new SequenceKeyedCaching(header, cacheWriter, cacheReader));
        }
Exemple #7
0
 protected override void OutPosition(PriceBars priceBar, BarItemType barType)
 {
     if (bouncedOff)
     {
         if (lastPosition == PositionMode.Short)
         {
             Enter(PositionMode.Long);
         }
         else
         {
             Enter(PositionMode.Short);
         }
     }
     else
     {
         if (IsLongSetup(priceBar))
         {
             Enter(PositionMode.Long);
         }
         else if (IsShortSetup(priceBar))
         {
             Enter(PositionMode.Short);
         }
     }
 }
Exemple #8
0
 public MACD(BarItemType barType, int fastEMAPeriod, int slowEMAPeriod, int signalLinePeriod) : base(barType)
 {
     this.fastEMAPeriod    = fastEMAPeriod;
     this.slowEMAPeriod    = slowEMAPeriod;
     this.signalLinePeriod = signalLinePeriod;
     this.barType          = barType;
 }
Exemple #9
0
        public SignalCharting(ISignalChart chartControl, TickerType tickerType, BarItemType barType, object dataStreamSource)
        {
            this.dataStreamSource    = dataStreamSource;
            this.tickerType          = tickerType;
            this.barType             = barType;
            this.chartControl        = chartControl;
            this.registeredAnalytics = new List <AnalyticsItem>();

            SharedCacheFactory.Instance.CacheWriter = new FileCacheWriter("cache");
            SharedCacheFactory.Instance.CacheReader = new FileCacheReader("cache");

            if (dataStreamSource is string)
            {
                FileInfo    file        = new FileInfo(dataStreamSource.ToString());
                long        fileHash    = file.Attributes.GetHashCode() ^ file.CreationTime.Ticks ^ file.LastWriteTime.Ticks ^ file.Length;
                CacheConfig cacheConfig = new CacheConfig("cache");
                cacheConfig.Initialize();
                cacheConfig.Open(CachingModeOption.Reading);
                CacheRow row = cacheConfig.Read(fileHash);
                cacheConfig.Close();

                if (row == null)
                {
                    cacheConfig.Open(CachingModeOption.Writing);
                    cacheId = Guid.NewGuid();
                    cacheConfig.Append(fileHash, cacheId, SessionModeOption.Backtesting);
                    cacheConfig.Close();
                }
                else
                {
                    cacheId = new Guid((byte[])row["SessionId"]);
                }
            }
        }
Exemple #10
0
 public void ReceivePriceAction(BarItemType barType, PriceBars priceAction)
 {
     foreach (CoreIndicator indicator in indicators[barType.Code].CoreIndicators.Values)
     {
         RecurseCalculationDependencies(indicator, priceAction);
     }
 }
Exemple #11
0
 public StrategyDataFrame(string strategyIdentityCode, int frameSize, PricebarCache pricebarCache)
 {
     this.pricebarCache = pricebarCache;
     this.frameSize     = frameSize;
     this.barType       = pricebarCache.BarType;
     this.cacheId       = pricebarCache.CacheId;
     this.strategyCache = new StrategyCache(strategyIdentityCode, this.barType, this.cacheId);
 }
Exemple #12
0
 public MarketOrderCache(BarItemType barType, Guid sessionId, Guid cacheId)
     : base(CacheModeOption.Write)
 {
     this.identityCode = sessionId.ToString();
     this.barType      = barType;
     this.cacheId      = cacheId;
     this.cacheMode    = CacheModeOption.Write;
 }
Exemple #13
0
 private void OnNewBar(BarItemType barItemType, BarItem barItem)
 {
     barCount++;
     if (barCount == barsPause)
     {
         backtestSession.Pause();
     }
 }
Exemple #14
0
 //Full stochastics
 private StochasticsCore(BarItemType barItemType, int periods, int smoothedPercentKPeriods, int smoothedPercentDPeriods, PriceChangeCore priceChangeCore, HighsAndLowsCore highsAndLowsCore, IndicatorDelegates.CalculationCompletedHandler onCalculationCompleted = null)
     : base(DISPLAY_NAME, SHORT_NAME, DESCRIPTION, barItemType)
 {
     this.smoothedPercentK        = true;
     this.smoothedPercentKPeriods = smoothedPercentKPeriods;
     this.smoothedPercentDPeriods = smoothedPercentDPeriods;
     Init(barItemType, periods, priceChangeCore, highsAndLowsCore, onCalculationCompleted);
 }
 public BarItems(BarItemType type, int quantity, string itemName, double price)
     : base(itemName, price) // This is the overloaded constractor of the BarItems with the values below.
 {
     this.type     = type;
     this.ItemName = itemName;
     this.Price    = price;
     this.quantity = quantity;
 }
Exemple #16
0
 public Stochastics(BarItemType barType, int periods, bool smoothedPercentK = false)
     : base(barType)
 {
     this.periods                 = periods;
     this.barType                 = barType;
     this.smoothedPercentK        = smoothedPercentK;
     this.smoothedPercentKPeriods = 3;
     this.smoothedPercentDPeriods = 3;
 }
Exemple #17
0
        public BarItemFile(string barItemFile, BarItemType timeFrame, TimeBarItemType bookmarkTimeFrame)
        {
            this.barItemFile       = barItemFile;
            this.bookmarkTimeFrame = bookmarkTimeFrame;
            this.bookmarkFile      = Path.Combine(Path.GetDirectoryName(barItemFile), Path.GetFileNameWithoutExtension(barItemFile) + ".bmk");
            this.bookMark          = new BookmarkFile(bookmarkFile, bookmarkTimeFrame);

            Initialize();
        }
Exemple #18
0
 public StrategyCache(object signalInstance, Guid cacheId)
     : base(CacheModeOption.Write)
 {
     this.barType        = ((IStrategy)signalInstance).BarType;
     this.identityCode   = ((IStrategy)signalInstance).IdentityCode;
     this.cacheId        = cacheId;
     this.signalInstance = signalInstance;
     this.cacheMode      = CacheModeOption.Write;
 }
Exemple #19
0
        public BollingerTopsAndBottoms(BarItemType barType)
        {
            this.barType = barType;

            this.identityCode = string.Format("{0}({1})", IDENTITY_CODE, barType.Code);

            sma = new SMA(barType, 30);

            Register(sma);
        }
Exemple #20
0
        public EMABreakthrough(BarItemType barType)
        {
            this.barType = barType;

            this.identityCode = string.Format("{0}({1})", IDENTITY_CODE, barType.Code);

            ema = new EMA(barType, 50);

            Register(ema);
        }
Exemple #21
0
        public MultiIndicator(string displayName, string shortName, string description, BarItemType barItemType)
            : base(new DateTimeKeyedMultiIndicator(), 300)
        {
            this.displayName = displayName;
            this.shortName   = shortName;
            this.description = description;
            this.barItemType = barItemType;

            dependencies = new Dictionary <string, CalculationDependencyItem>();
        }
Exemple #22
0
        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);
        }
Exemple #23
0
        public WhiteSoldiersBlackCrows(BarItemType barType)
        {
            this.barType = barType;

            this.identityCode = string.Format("{0}({1})", IDENTITY_CODE, barType.Code);

            bb = new BollingerBands(barType, 20);

            Register(bb);
        }
Exemple #24
0
        public StupidGuySystem(BarItemType barType)
        {
            this.barType = barType;

            this.identityCode = string.Format("{0}({1})", IDENTITY_CODE, barType.Code);

            macd = new MACD(barType, 35, 45, 30);

            Register(macd);
        }
Exemple #25
0
        public NewYorkBreakout(BarItemType barType)
        {
            this.barType = barType;

            this.identityCode = string.Format("{0}({1})", IDENTITY_CODE, barType.Code);

            sma = new SMA(barType, 30);

            Register(sma);
        }
Exemple #26
0
        public RSIHighLow(BarItemType barType)
        {
            this.barType = barType;

            this.identityCode = string.Format("{0}({1})", IDENTITY_CODE, barType.Code);

            rsi = new RSI(barType, 14);

            Register(rsi);
        }
Exemple #27
0
        public H4BollingerBandStrategy(BarItemType barType)
        {
            this.barType = barType;

            this.identityCode = string.Format("{0}({1})", IDENTITY_CODE, barType.Code);

            bb = new BollingerBands(barType, 20);

            Register(bb);
        }
Exemple #28
0
        public SwingRSIandMACd(BarItemType barType)
        {
            this.barType = barType;

            this.identityCode = string.Format("{0}({1})", IDENTITY_CODE, barType.Code);

            sma = new SMA(barType, 30);

            Register(sma);
        }
Exemple #29
0
        public SimpleSteppingIntoPosition(BarItemType barType)
        {
            this.barType = barType;

            this.identityCode = string.Format("{0}({1})", IDENTITY_CODE, barType.Code);

            sma = new SMA(barType, 30);

            Register(sma);
        }
Exemple #30
0
        public TradingOffDailyChart(BarItemType barType)
        {
            this.barType = barType;

            this.identityCode = string.Format("{0}({1})", IDENTITY_CODE, barType.Code);

            sma = new SMA(barType, 30);

            Register(sma);
        }