コード例 #1
0
        /// <summary>
        /// Register IDataBarHistoryProvider.
        /// </summary>
        protected bool AddElement(ComponentId id, Symbol symbol, TimeSpan period, IDataBarHistoryProvider provider)
        {
            if (id.IsEmpty || provider == null || symbol.IsEmpty)
            {
                SystemMonitor.Warning("Invalid Id, symbol or quote provider instance.");
                return(false);
            }

            lock (this)
            {
                if (_dataBarProviders.ContainsKey(id) && _dataBarProviders[id].ContainsKey(symbol) &&
                    _dataBarProviders[id][symbol].ContainsKey(period))
                {
                    SystemMonitor.Warning("Failed to add order execution provider, since already added with this Id.");
                    return(false);
                }

                if (_dataBarProviders.ContainsKey(id) == false)
                {
                    _dataBarProviders.Add(id, new Dictionary <Symbol, Dictionary <TimeSpan, IDataBarHistoryProvider> >());
                }

                if (_dataBarProviders[id].ContainsKey(symbol) == false)
                {
                    _dataBarProviders[id].Add(symbol, new Dictionary <TimeSpan, IDataBarHistoryProvider>());
                }

                _dataBarProviders[id][symbol].Add(period, provider);
            }

            return(true);
        }
コード例 #2
0
        void UpdateValues(int updateBarsCount)
        {
            IDataBarHistoryProvider provider = CurrentDataBarProvider;

            if (provider == null)
            {
                return;
            }

            lock (provider)
            {
                for (int i = provider.BarCount - 1; i >= 0 && i >= provider.BarCount - 1 - updateBarsCount; i--)
                {
                    DataBar bar    = provider.BarsUnsafe[i];
                    float   volume = (float)bar.Volume;

                    _minVolume = Math.Min(_minVolume, (float)volume);
                    _maxVolume = Math.Max(_maxVolume, (float)volume);

                    _maxValue = Math.Max((float)bar.High, _maxValue);
                    _minValue = Math.Min((float)bar.Low, _minValue);
                }
            }

            RaiseSeriesValuesUpdated(true);
        }
コード例 #3
0
 void DataBarHistory_DataBarHistoryUpdateEvent(IDataBarHistoryProvider provider, DataBarUpdateType updateType, int updatedBarsCount)
 {
     if (updateType == DataBarUpdateType.Initial)
     {// Only executes on initial adding of many items.
         WinFormsHelper.BeginFilteredManagedInvoke(this, new GeneralHelper.GenericDelegate <bool, bool>(chartControl.MasterPane.FitDrawingSpaceToScreen), true, true);
     }
 }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="period"></param>
        /// <returns></returns>
        public bool SetCurrentDataBarProvider(TimeSpan?period)
        {
            if (period.HasValue == false)
            {
                _dataBarProvider = null;
                if (CurrentDataBarProviderChangedEvent != null)
                {
                    CurrentDataBarProviderChangedEvent(this);
                }
                return(true);
            }

            lock (this)
            {
                if (_dataBarProviders.ContainsKey(period.Value) == false)
                {
                    SystemMonitor.OperationError("Period provider not available.");
                    return(false);
                }

                _dataBarProvider = _dataBarProviders[period.Value];
            }

            if (CurrentDataBarProviderChangedEvent != null)
            {
                CurrentDataBarProviderChangedEvent(this);
            }

            return(true);
        }
コード例 #5
0
 void DataBarHistory_DataBarHistoryUpdateEvent(IDataBarHistoryProvider provider, DataBarUpdateType updateType, int updatedBarsCount)
 {
     if (updateType != DataBarUpdateType.CurrentBarUpdate)
     {// Do the full update only on actual bar update.
         UpdateValues(updatedBarsCount);
     }
     else
     {
         RaiseSeriesValuesUpdated(true);
     }
 }
コード例 #6
0
        /// <summary>
        /// Since we are in back test delivery, it is possible to receive this before we are initialized,
        /// since the underlying data bar provider gets launched before this class does.
        /// </summary>
        void _sourceDataBarProvider_DataBarHistoryUpdateEvent(IDataBarHistoryProvider provider, DataBarUpdateType updateType, int updatedBarsCount)
        {
            SystemMonitor.CheckError(provider == _sourceDataBarProvider, "Data provider update not expected.");

            RestoreLastStep();

            if (_pendingSessionInfo.HasValue && _pendingRequest.HasValue)
            {// Executed only the first time.
                _pendingSessionInfo = null;
                _pendingRequest     = null;

                RequestDataHistoryUpdate(_pendingSessionInfo.Value, _pendingRequest.Value, false);
            }
        }
コード例 #7
0
        public virtual void Dispose()
        {
            UnInitialize();

            _manager = null;

            _dataDelivery = null;

            _quote = null;

            _tickProvider = null;

            _dataBarProvider = null;

            ChangeOperationalState(OperationalStateEnum.Disposed);
        }
コード例 #8
0
        protected override void OnDataBarPeriodUpdate(IDataBarHistoryProvider provider, DataBarUpdateType updateType, int updatedBarsCount)
        {
            lock (this)
            {
                if (provider != null)
                {
                    //Console.WriteLine("Bars: {0}", provider.BarCount);

                    //Keep bars have no more limit than the quotes
                    if (provider.DataBarLimit > this.QuotesLimit)
                    {
                        provider.DataBarLimit = this.QuotesLimit;
                    }
                }
            }
        }
コード例 #9
0
        protected override float GetDrawingValueAt(int index, object tag)
        {
            if (_dataProvider == null)
            {
                return(0);
            }

            IDataBarHistoryProvider dataBarProvider = CurrentDataBarProvider;

            if (dataBarProvider == null)
            {
                return(0);
            }

            // The lock on the dataDelivery provider must already be on.
            return((float)dataBarProvider.BarsUnsafe[index].GetValue(_lineDrawingSource));
        }
コード例 #10
0
        /// <summary>
        /// Establish the total minimum value of any item in this interval.
        /// </summary>
        /// <param name="startIndex">Inclusive starting index.</param>
        /// <param name="endIndex">Exclusive ending index.</param>
        public override void GetTotalMinimumAndMaximum(int?startIndex, int?endIndex,
                                                       ref float minimum, ref float maximum)
        {
            if (_dataProvider == null)
            {
                return;
            }

            if (startIndex.HasValue == false && endIndex.HasValue == false)
            {// We can use the stored values to optimize performance in this case.
                minimum = _minValue;
                maximum = _maxValue;
                return;
            }

            if (startIndex.HasValue == false)
            {
                startIndex = 0;
            }

            IDataBarHistoryProvider dataBarProvider = CurrentDataBarProvider;

            if (dataBarProvider == null)
            {
                return;
            }

            if (endIndex.HasValue == false)
            {
                endIndex = dataBarProvider.BarCount;
            }

            lock (dataBarProvider)
            {
                for (int i = startIndex.Value; i < endIndex && i < dataBarProvider.BarCount; i++)
                {
                    if (dataBarProvider.BarsUnsafe[i].HasDataValues)
                    {
                        minimum = (float)Math.Min((float)dataBarProvider.BarsUnsafe[i].Low, minimum);
                        maximum = (float)Math.Max((float)dataBarProvider.BarsUnsafe[i].High, maximum);
                    }
                }
            }
        }
コード例 #11
0
        public virtual void UnInitialize()
        {
            lock (this)
            {
                if (_dataProvider != null)
                {
                    if (_dataProvider != null)
                    {
                        _dataProvider.DataBarHistoryUpdateEvent -= new DataBarHistoryUpdateDelegate(_dataProvider_DataBarHistoryUpdateEvent);
                    }
                    _dataProvider = null;
                }

                if (_parameters != null)
                {
                    _parameters.ParameterUpdatedValueEvent -= new IndicatorParameters.ParameterUpdatedValueDelegate(_parameters_ParameterUpdatedValueEvent);
                }
            }
        }
コード例 #12
0
        public override DateTime?GetTimeAtIndex(int index)
        {
            if (_dataProvider == null)
            {
                return(null);
            }

            IDataBarHistoryProvider dataBarProvider = CurrentDataBarProvider;

            if (dataBarProvider == null)
            {
                return(null);
            }

            lock (dataBarProvider)
            {
                return(dataBarProvider.BarsUnsafe[index].DateTime);
            }
        }
コード例 #13
0
    /// <summary>
    /// Quote dataDelivery was updated.
    /// </summary>
    protected override void OnDataBarPeriodUpdate(IDataBarHistoryProvider provider, DataBarUpdateType updateType, int updatedBarsCount)
    {
        //Indicator indicator = this.ObtainIndicator("Rsi");

        //if (indicator.Results.GetValueSetCurrentValue(0).HasValue == false
        //    || this.CanPlaceOrders == false)
        //{
        //    return;
        //}

        //Trace(indicator.Results.GetValueSetCurrentValue(0).Value.ToString());

        //if (this.CurrentPositionVolume == 0)
        //{

        //    // Get the value of the [0] index operationResult set of this indicator.
        //    // Each indicator can have many operationResult sets - each representing a "line" on the chart.
        //    if (indicator.Results.GetValueSetCurrentValue(0) > BuyValue)
        //    {// If the Rsi operationResult is above BuyValue, take some action.
        //        this.OpenBuyOrder(10000);
        //    }
        //    else if (indicator.Results.GetValueSetCurrentValue(0) < SellValue)
        //    {
        //        this.OpenSellOrder(10000);
        //    }
        //}
        //else
        //{// Maybe we need to close an open position.

        //    if (this.CurrentPositionVolume > 0
        //        && indicator.Results.GetValueSetCurrentValue(0) < ClosePositionValue)
        //    {// If the Rsi operationResult is below SellValue, close buy position.
        //        this.ClosePosition();
        //    }

        //    if (this.CurrentPositionVolume < 0
        //        && indicator.Results.GetValueSetCurrentValue(0) > ClosePositionValue)
        //    {// If the Rsi operationResult is above SellValue, close sell position.
        //        this.ClosePosition();
        //    }
        //}
    }
コード例 #14
0
        public override void SaveToFile(string fileName)
        {
            if (_dataProvider == null)
            {
                return;
            }

            IDataBarHistoryProvider dataBarProvider = CurrentDataBarProvider;

            if (dataBarProvider == null)
            {
                return;
            }

            lock (dataBarProvider)
            {
                CSVDataBarReaderWriter reader = new CSVDataBarReaderWriter(fileName, CommonFinancial.CSVDataBarReaderWriter.DataFormat.CSVHistoricalFileDefault);
                reader.Write(dataBarProvider.BarsUnsafe);
            }
        }
コード例 #15
0
        public virtual bool Initialize(IDataBarHistoryProvider dataProvider)
        {
            SystemMonitor.CheckThrow(_dataProvider == null, "Data provider already assigned.");
            TracerHelper.Trace(this.Name);
            lock (this)
            {
                _dataProvider = dataProvider;
                if (_dataProvider != null)
                {
                    _dataProvider.DataBarHistoryUpdateEvent += new DataBarHistoryUpdateDelegate(_dataProvider_DataBarHistoryUpdateEvent);
                }

                if (_parameters != null)
                {
                    _parameters.ParameterUpdatedValueEvent += new IndicatorParameters.ParameterUpdatedValueDelegate(_parameters_ParameterUpdatedValueEvent);
                }
            }


            return(true);
        }
コード例 #16
0
        /// <summary>
        ///
        /// </summary>
        public virtual bool SetInitialParameters(ISourceManager manager, ComponentId sourceId, ExpertSession session)
        {
            _sessionInfo = session.Info;

            _manager = manager;

            _sourceId = sourceId;

            _dataDelivery = manager.ObtainDataDelivery(sourceId);

            _quote = manager.ObtainQuoteProvider(sourceId, _sessionInfo.Symbol);

            _tickProvider = manager.ObtainDataTickHistoryProvider(sourceId, _sessionInfo.Symbol);

            _dataBarProvider = null;

            bool result = _dataDelivery != null && _quote != null && _tickProvider != null;

            SystemMonitor.CheckError(result, "Failed to initialize data provider.");

            return(result);
        }
コード例 #17
0
        /// <summary>
        ///
        /// </summary>
        bool GetProviders(Symbol symbol, out IQuoteProvider quotes, out IDataBarHistoryProvider bars)
        {
            quotes = _manager.ObtainQuoteProvider(_dataDelivery.SourceId, symbol);
            RuntimeDataSessionInformation sessionInformation = _dataDelivery.GetSymbolRuntimeSessionInformation(symbol);

            if (sessionInformation.AvailableDataBarPeriods == null || sessionInformation.AvailableDataBarPeriods.Count == 0)
            {
                quotes = null;
                bars   = null;
                SystemMonitor.OperationError("Can not close order since no suitable data provider sessions found.");
                return(false);
            }

            bars = _manager.ObtainDataBarHistoryProvider(_dataDelivery.SourceId, symbol, sessionInformation.AvailableDataBarPeriods[0]);

            if (quotes == null || quotes.Ask.HasValue == false || bars == null)
            {
                return(false);
            }

            return(true);
        }
コード例 #18
0
 /// <summary>
 ///
 /// </summary>
 private bool CheckStopLossInsideBar(IDataBarHistoryProvider provider, Order order)
 {
     if (provider.Current.HasValue)
     {//Check if we have reached the stoploss
         if ((order.IsBuy && order.StopLoss != 0 &&
              provider.Current.Value.Low < order.StopLoss) ||
             (!order.IsBuy && order.StopLoss != 0 &&
              !order.IsDelayed &&
              provider.Current.Value.High > order.StopLoss))
         {//StopLoss has been triggered inside bar
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
コード例 #19
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public IndicatorManager(IDataBarHistoryProvider dataProvider)
 {
     _dataBarProvider = dataProvider;
 }
コード例 #20
0
 public virtual void Dispose()
 {
     UnInitialize();
     _dataProvider = null;
 }
コード例 #21
0
 void _dataProvider_CurrentDataBarProviderChangedEvent(ISessionDataProvider dataProvider)
 {
     CurrentDataBarProvider = dataProvider.DataBars;
 }
コード例 #22
0
        public virtual void UnInitialize()
        {
            lock (this)
            {
                if (_dataProvider != null)
                {
                    if (_dataProvider != null)
                    {
                        _dataProvider.DataBarHistoryUpdateEvent -= new DataBarHistoryUpdateDelegate(_dataProvider_DataBarHistoryUpdateEvent);
                    }
                    _dataProvider = null;
                }

                if (_parameters != null)
                {
                    _parameters.ParameterUpdatedValueEvent -= new IndicatorParameters.ParameterUpdatedValueDelegate(_parameters_ParameterUpdatedValueEvent);
                }
            }
        }
コード例 #23
0
        /// <summary>
        /// 
        /// </summary>
        public virtual bool SetInitialParameters(ISourceManager manager, ComponentId sourceId, ExpertSession session)
        {
            _sessionInfo = session.Info;

            _manager = manager;

            _sourceId = sourceId;

            _dataDelivery = manager.ObtainDataDelivery(sourceId);

            _quote = manager.ObtainQuoteProvider(sourceId, _sessionInfo.Symbol);

            _tickProvider = manager.ObtainDataTickHistoryProvider(sourceId, _sessionInfo.Symbol);

            _dataBarProvider = null;

            bool result = _dataDelivery != null && _quote != null && _tickProvider != null;

            SystemMonitor.CheckError(result, "Failed to initialize data provider.");

            return result;
        }
コード例 #24
0
 public virtual void Dispose()
 {
     UnInitialize();
     _dataProvider = null;
 }
コード例 #25
0
        public virtual void Dispose()
        {
            UnInitialize();

            _manager = null;

            _dataDelivery = null;

            _quote = null;

            _tickProvider = null;

            _dataBarProvider = null;

            ChangeOperationalState(OperationalStateEnum.Disposed);
        }
コード例 #26
0
 void DataBarHistory_DataBarHistoryUpdateEvent(IDataBarHistoryProvider provider, DataBarUpdateType updateType, int updatedBarsCount)
 {
     OnDataBarPeriodUpdate(updateType, updatedBarsCount);
 }
コード例 #27
0
 void DataProvider_DataBarProviderCreatedEvent(ISessionDataProvider dataProvider, IDataBarHistoryProvider provider)
 {
     CurrentSession.DataProvider.DataBarProviderCreatedEvent -= new DataProviderBarProviderUpdateDelegate(DataProvider_DataBarProviderCreatedEvent);
     Start();
 }
コード例 #28
0
 protected virtual void OnDataBarPeriodUpdate(IDataBarHistoryProvider provider, DataBarUpdateType updateType, int updatedBarsCount)
 {
 }
コード例 #29
0
 void DataProvider_DataBarProviderCreatedEvent(ISessionDataProvider dataProvider, IDataBarHistoryProvider provider)
 {
     CurrentSession.DataProvider.DataBarProviderCreatedEvent -= new DataProviderBarProviderUpdateDelegate(DataProvider_DataBarProviderCreatedEvent);
     Start();
 }
コード例 #30
0
 void _dataProvider_DataBarHistoryUpdateEvent(IDataBarHistoryProvider provider, DataBarUpdateType updateType, int updatedBarsCount)
 {
     Calculate(false, updateType);
 }
コード例 #31
0
        /// <summary>
        /// Main drawing routine.
        /// </summary>
        public override void Draw(ChartPane managingPane, GraphicsWrapper g, int unitsUnification,
                                  RectangleF clippingRectangle, float itemWidth, float itemMargin)
        {
            //TracerHelper.Trace(TracerHelper.GetCallingMethod(2).Name);

            if (Visible == false)
            {
                return;
            }

            if (_dataProvider == null)
            {
                return;
            }

            IDataBarHistoryProvider dataBarProvider = CurrentDataBarProvider;

            if (dataBarProvider == null)
            {
                return;
            }

            lock (dataBarProvider)
            {
                base.Draw(g, dataBarProvider.BarsUnsafe, unitsUnification, clippingRectangle, itemWidth, itemMargin, _maxVolume, null);
            }

            // Draw ask/bid line.
            if (_dataProvider.OperationalState == CommonSupport.OperationalStateEnum.Operational && _dataProvider.Quotes != null &&
                _dataProvider.Quotes.Bid.HasValue && _dataProvider.Quotes.Ask.HasValue)
            {
                if (_showCurrentAskLine)
                {
                    float price = (float)_dataProvider.Quotes.Ask;
                    g.DrawLine(_priceLevelPen, clippingRectangle.X, price, clippingRectangle.X + clippingRectangle.Width, price);
                }

                if (_showCurrentBidLine)
                {
                    float price = (float)_dataProvider.Quotes.Bid;
                    g.DrawLine(_priceLevelPen, clippingRectangle.X, price, clippingRectangle.X + clippingRectangle.Width, price);
                }
            }

            List <Order> ordersOpening;

            // Draw orders locations on chart.
            lock (this)
            {
                if (_orderExecutionProvider == null)
                {
                    return;
                }
            }
            // Render orders.
            ordersOpening = new List <Order>();

            ITradeEntityManagement history = _orderExecutionProvider.TradeEntities;

            if (history != null && _dataProvider != null)
            {
                lock (history)
                {
                    ordersOpening.AddRange(history.GetOrdersBySymbol(_dataProvider.SessionInfo.Symbol));
                }
            }

            // Use for orders closes.
            List <Order> ordersClosing = new List <Order>();

            foreach (Order order in ordersOpening)
            {
                if (order.State == OrderStateEnum.Closed)
                {// Only add orders already closed.
                    ordersClosing.Add(order);
                }
            }

            // This is used later on, since ordersClosing is modified.
            List <Order> ordersClosed = new List <Order>(ordersClosing);

            // TradeEntities opening at current bar.
            List <Order> pendingOpeningOrders = new List <Order>();
            // Order closing at current bar.
            List <Order> pendingClosingOrders = new List <Order>();

            PointF drawingPoint = new PointF();
            int    startIndex, endIndex;

            GetDrawingRangeIndecesFromClippingRectange(clippingRectangle, drawingPoint, unitsUnification, out startIndex, out endIndex, itemWidth, itemMargin);

            lock (dataBarProvider)
            {
                float lastBarX = (itemMargin + itemWidth) * dataBarProvider.BarCount;
                for (int i = startIndex; i < endIndex && i < dataBarProvider.BarCount &&
                     (ordersOpening.Count > 0 || ordersClosing.Count > 0); i++)
                {         // Foreach bar, draw orders (and closeVolume).
                    while (ordersOpening.Count > 0)
                    {     // All orders before now.
                        if (ordersOpening[0].OpenTime < (dataBarProvider.BarsUnsafe[i].DateTime - Period))
                        { // Order before time period.
                            if ((ordersOpening[0].State == OrderStateEnum.Executed /*||
                                                                                    * ordersOpening[0].State == OrderInformation.OrderStateEnum.Submitted*/) &&
                                _showPendingOrdersTracing)
                            {// Since it is an open pending order, we shall also need to draw it as well.
                                pendingOpeningOrders.Add(ordersOpening[0]);
                            }
                            ordersOpening.RemoveAt(0);
                            continue;
                        }

                        if (ordersOpening[0].OpenTime > dataBarProvider.BarsUnsafe[i].DateTime)
                        {// Order after time period - look no further.
                            break;
                        }

                        // Order open is within the current period.
                        // Only if order is part of the current period - add to pending.
                        pendingOpeningOrders.Add(ordersOpening[0]);
                        ordersOpening.RemoveAt(0);
                    }

                    for (int j = ordersClosing.Count - 1; j >= 0; j--)
                    {
                        if (ordersClosing[j].CloseTime >= (dataBarProvider.BarsUnsafe[i].DateTime - dataBarProvider.Period) &&
                            ordersClosing[j].CloseTime <= dataBarProvider.BarsUnsafe[i].DateTime)
                        {// Order close is within the current period.
                            pendingClosingOrders.Add(ordersClosing[j]);
                            ordersClosing.RemoveAt(j);
                        }
                    }

                    drawingPoint.X = i * (itemMargin + itemWidth);
                    DrawOrders(g, i, drawingPoint, itemWidth, itemMargin, pendingOpeningOrders, pendingClosingOrders, dataBarProvider.BarsUnsafe[i], lastBarX);
                    pendingOpeningOrders.Clear();
                    pendingClosingOrders.Clear();
                }

                if (_showClosedOrdersTracing && dataBarProvider.BarCount > 0 && startIndex < dataBarProvider.BarCount)
                {// Since a closed order may be before or after (or during) the curren set of periods - make a special search and render for them.
                    endIndex = Math.Max(0, endIndex);
                    endIndex = Math.Min(dataBarProvider.BarCount - 1, endIndex);

                    foreach (Order order in ordersClosed)
                    {
                        if (order.OpenTime.HasValue &&
                            order.CloseTime.HasValue &&
                            order.OpenTime.Value <= dataBarProvider.BarsUnsafe[endIndex].DateTime &&
                            order.CloseTime.Value >= dataBarProvider.BarsUnsafe[startIndex].DateTime - dataBarProvider.Period)
                        {
                            int openIndex  = dataBarProvider.GetIndexAtTime(order.OpenTime.Value);
                            int closeIndex = dataBarProvider.GetIndexAtTime(order.CloseTime.Value);

                            Pen pen = _buyDashedPen;
                            if (order.IsBuy == false)
                            {
                                pen = _sellDashedPen;
                            }

                            Decimal?doubleOpenValue  = order.OpenPrice;
                            Decimal?doubleCloseValue = order.ClosePrice;

                            if (doubleOpenValue.HasValue == false)
                            {
                                SystemMonitor.Error("Invalid open price value for closed order to draw.");
                                continue;
                            }

                            if (doubleCloseValue.HasValue == false)
                            {
                                SystemMonitor.Error("Invalid close price value for closed order to draw.");
                                continue;
                            }

                            g.DrawLine(pen, new PointF(openIndex * (itemWidth + itemMargin), (float)doubleOpenValue),
                                       new PointF(closeIndex * (itemWidth + itemMargin), (float)doubleCloseValue));
                        }
                    }
                }
            } // Lock
        }
コード例 #32
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public IndicatorManager(IDataBarHistoryProvider dataProvider)
 {
     _dataBarProvider = dataProvider;
 }
コード例 #33
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="period"></param>
        /// <returns></returns>
        public bool SetCurrentDataBarProvider(TimeSpan? period)
        {
            if (period.HasValue == false)
            {
                _dataBarProvider = null;
                if (CurrentDataBarProviderChangedEvent != null)
                {
                    CurrentDataBarProviderChangedEvent(this);
                }
                return true;
            }

            lock(this)
            {
                if (_dataBarProviders.ContainsKey(period.Value) == false)
                {
                    SystemMonitor.OperationError("Period provider not available.");
                    return false;
                }

                _dataBarProvider = _dataBarProviders[period.Value];
            }

            if (CurrentDataBarProviderChangedEvent != null)
            {
                CurrentDataBarProviderChangedEvent(this);
            }

            return true;
        }
コード例 #34
0
        public void UnInitialize()
        {
            lock (this)
            {
                _ordersArrows.Clear();
                GeneralHelper.FireAndForget(SelectedOrderChangedEvent, _selectedOrder, null);
                _selectedOrder = null;

                CurrentDataBarProvider = null;
                if (_dataProvider != null)
                {
                    if (_dataProvider.Quotes != null)
                    {
                        _dataProvider.Quotes.QuoteUpdateEvent += new QuoteProviderUpdateDelegate(Quotes_QuoteUpdateEvent);
                    }

                    _dataProvider.CurrentDataBarProviderChangedEvent -= new DataProviderUpdateDelegate(_dataProvider_CurrentDataBarProviderChangedEvent);
                    _dataProvider = null;
                }

                if (_orderExecutionProvider != null)
                {
                    IOrderSink executor = _orderExecutionProvider;
                    ITradeEntityManagement management = _orderExecutionProvider.TradeEntities;

                    if (executor != null)
                    {
                        executor.OrdersUpdatedEvent -= new OrdersUpdateDelegate(executor_OrderUpdatedEvent);
                    }

                    if (management != null)
                    {
                        management.OrdersAddedEvent -= new OrderManagementOrdersUpdateDelegate(management_OrdersAddedEvent);
                        management.OrdersRemovedEvent -= new OrderManagementOrdersUpdateDelegate(management_OrdersRemovedEvent);
                        management.OrdersUpdatedEvent -= new OrderManagementOrdersUpdateTypeDelegate(management_OrderUpdatedEvent);
                    }

                    _orderExecutionProvider = null;
                }

                _buyDashedPen.Dispose();
                _sellDashedPen.Dispose();
            }
        }
コード例 #35
0
        public virtual bool Initialize(IDataBarHistoryProvider dataProvider)
        {
            SystemMonitor.CheckThrow(_dataProvider == null, "Data provider already assigned.");
            TracerHelper.Trace(this.Name);
            lock (this)
            {
                _dataProvider = dataProvider;
                if (_dataProvider != null)
                {
                    _dataProvider.DataBarHistoryUpdateEvent += new DataBarHistoryUpdateDelegate(_dataProvider_DataBarHistoryUpdateEvent);
                }

                if (_parameters != null)
                {
                    _parameters.ParameterUpdatedValueEvent += new IndicatorParameters.ParameterUpdatedValueDelegate(_parameters_ParameterUpdatedValueEvent);
                }
            }

            return true;
        }
コード例 #36
0
        /// <summary>
        /// 
        /// </summary>
        public void Initialize(ISessionDataProvider dataProvider, ISourceOrderExecution orderExecutionProvider)
        {
            if (dataProvider == null)
            {
                return;
            }

            lock (this)
            {
                _dataProvider = dataProvider;
                if (_dataProvider != null)
                {
                    _dataProvider.CurrentDataBarProviderChangedEvent += new DataProviderUpdateDelegate(_dataProvider_CurrentDataBarProviderChangedEvent);
                    CurrentDataBarProvider = _dataProvider.DataBars;

                    if (_dataProvider.Quotes != null)
                    {
                        _dataProvider.Quotes.QuoteUpdateEvent += new QuoteProviderUpdateDelegate(Quotes_QuoteUpdateEvent);
                    }
                }

                _orderExecutionProvider = orderExecutionProvider;
                if (_orderExecutionProvider != null)
                {
                    IOrderSink executor = _orderExecutionProvider;
                    if (executor != null)
                    {
                        executor.OrdersUpdatedEvent += new OrdersUpdateDelegate(executor_OrderUpdatedEvent);
                    }

                    ITradeEntityManagement management = _orderExecutionProvider.TradeEntities;
                    if (management != null)
                    {
                        management.OrdersAddedEvent += new OrderManagementOrdersUpdateDelegate(management_OrdersAddedEvent);
                        management.OrdersRemovedEvent += new OrderManagementOrdersUpdateDelegate(management_OrdersRemovedEvent);
                        management.OrdersUpdatedEvent += new OrderManagementOrdersUpdateTypeDelegate(management_OrderUpdatedEvent);
                    }
                }

                ComponentResourceManager resources = new ComponentResourceManager(typeof(ProviderTradeChartSeries));
                _imageDown = ((Image)(resources.GetObject("imageDown")));
                _imageUp = ((Image)(resources.GetObject("imageUp")));
                _imageCross = ((Image)(resources.GetObject("imageCross")));

                _buyDashedPen.DashPattern = new float[] { 5, 5 };
                _buyDashedPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;

                _priceLevelPen.DashPattern = new float[] { 3, 3 };
                _priceLevelPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;

                _sellDashedPen.DashPattern = new float[] { 5, 5 };
                _sellDashedPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;
            }
        }
コード例 #37
0
 void DataBarHistory_DataBarHistoryUpdateEvent(IDataBarHistoryProvider provider, DataBarUpdateType updateType, int updatedBarsCount)
 {
     if (updateType == DataBarUpdateType.Initial)
     {// Only executes on initial adding of many items.
         WinFormsHelper.BeginFilteredManagedInvoke(this, new GeneralHelper.GenericDelegate<bool, bool>(chartControl.MasterPane.FitDrawingSpaceToScreen), true, true);
     }
 }
コード例 #38
0
 void DataBarHistory_DataBarHistoryUpdateEvent(IDataBarHistoryProvider provider, DataBarUpdateType updateType, int updatedBarsCount)
 {
     if (updateType != DataBarUpdateType.CurrentBarUpdate)
     {// Do the full update only on actual bar update.
         UpdateValues(updatedBarsCount);
     }
     else
     {
         RaiseSeriesValuesUpdated(true);
     }
 }
コード例 #39
0
 void _dataProvider_DataBarHistoryUpdateEvent(IDataBarHistoryProvider provider, DataBarUpdateType updateType, int updatedBarsCount)
 {
     Calculate(false, updateType);
 }
コード例 #40
0
 /// <summary>
 /// 
 /// </summary>
 private bool CheckStopLossInsideBar(IDataBarHistoryProvider provider, Order order)
 {
     if (provider.Current.HasValue)
     {//Check if we have reached the stoploss
         if ((order.IsBuy && order.StopLoss != 0 &&
                provider.Current.Value.Low < order.StopLoss) ||
             (!order.IsBuy && order.StopLoss != 0 &&
                 !order.IsDelayed &&
             provider.Current.Value.High > order.StopLoss))
         {//StopLoss has been triggered inside bar
             return true;
         }
         else
         {
             return false;
         }
     }
     else
     {
         return false;
     }
 }
コード例 #41
0
        /// <summary>
        /// Register IDataBarHistoryProvider.
        /// </summary>
        protected bool AddElement(ComponentId id, Symbol symbol, TimeSpan period, IDataBarHistoryProvider provider)
        {
            if (id.IsEmpty || provider == null || symbol.IsEmpty)
            {
                SystemMonitor.Warning("Invalid Id, symbol or quote provider instance.");
                return false;
            }

            lock (this)
            {
                if (_dataBarProviders.ContainsKey(id) && _dataBarProviders[id].ContainsKey(symbol)
                    && _dataBarProviders[id][symbol].ContainsKey(period))
                {
                    SystemMonitor.Warning("Failed to add order execution provider, since already added with this Id.");
                    return false;
                }

                if (_dataBarProviders.ContainsKey(id) == false)
                {
                    _dataBarProviders.Add(id, new Dictionary<Symbol, Dictionary<TimeSpan, IDataBarHistoryProvider>>());
                }

                if (_dataBarProviders[id].ContainsKey(symbol) == false)
                {
                    _dataBarProviders[id].Add(symbol, new Dictionary<TimeSpan, IDataBarHistoryProvider>());
                }

                _dataBarProviders[id][symbol].Add(period, provider);
            }

            return true;
        }
コード例 #42
0
 void DataBarHistory_DataBarHistoryUpdateEvent(IDataBarHistoryProvider provider, DataBarUpdateType updateType, int updatedBarsCount)
 {
     OnDataBarPeriodUpdate(updateType, updatedBarsCount);
 }
コード例 #43
0
        /// <summary>
        /// 
        /// </summary>
        bool GetProviders(Symbol symbol, out IQuoteProvider quotes, out IDataBarHistoryProvider bars)
        {
            quotes = _manager.ObtainQuoteProvider(_dataDelivery.SourceId, symbol);
            RuntimeDataSessionInformation sessionInformation = _dataDelivery.GetSymbolRuntimeSessionInformation(symbol);

            if (sessionInformation.AvailableDataBarPeriods == null || sessionInformation.AvailableDataBarPeriods.Count == 0)
            {
                quotes = null;
                bars = null;
                SystemMonitor.OperationError("Can not close order since no suitable data provider sessions found.");
                return false;
            }

            bars = _manager.ObtainDataBarHistoryProvider(_dataDelivery.SourceId, symbol, sessionInformation.AvailableDataBarPeriods[0]);

            if (quotes == null || quotes.Ask.HasValue == false || bars == null)
            {
                return false;
            }

            return true;
        }
コード例 #44
0
        /// <summary>
        /// Since we are in back test delivery, it is possible to receive this before we are initialized, 
        /// since the underlying data bar provider gets launched before this class does.
        /// </summary>
        void _sourceDataBarProvider_DataBarHistoryUpdateEvent(IDataBarHistoryProvider provider, DataBarUpdateType updateType, int updatedBarsCount)
        {
            SystemMonitor.CheckError(provider == _sourceDataBarProvider, "Data provider update not expected.");

            RestoreLastStep();

            if (_pendingSessionInfo.HasValue && _pendingRequest.HasValue)
            {// Executed only the first time.
                _pendingSessionInfo = null;
                _pendingRequest = null;

                RequestDataHistoryUpdate(_pendingSessionInfo.Value, _pendingRequest.Value, false);
            }
        }
コード例 #45
0
        /// <summary>
        /// Obtain an array of input values, based in type of array name required from TaLib.
        /// </summary>
        double[] GetInputArrayValues(string valueArrayTypeName, int startingIndex, int indexCount)
        {
            IDataBarHistoryProvider provider = DataProvider;

            if (provider == null)
            {
                return(null);
            }

            double[] result = null;
            if (valueArrayTypeName == "inLow")
            {
                result = provider.GetValuesAsDouble(DataBar.DataValueEnum.Low, startingIndex, indexCount);
            }
            else if (valueArrayTypeName == "inHigh")
            {
                result = provider.GetValuesAsDouble(DataBar.DataValueEnum.High, startingIndex, indexCount);
            }
            else if (valueArrayTypeName == "inOpen")
            {
                result = provider.GetValuesAsDouble(DataBar.DataValueEnum.Open, startingIndex, indexCount);
            }
            else if (valueArrayTypeName == "inClose")
            {
                result = provider.GetValuesAsDouble(DataBar.DataValueEnum.Close, startingIndex, indexCount);
            }
            else if (valueArrayTypeName == "inVolume")
            {
                result = provider.GetValuesAsDouble(DataBar.DataValueEnum.Volume, startingIndex, indexCount);
            }
            else if (valueArrayTypeName == "inReal")
            {
                if (_realInputArraySource.HasValue)
                {
                    result = provider.GetValuesAsDouble(_realInputArraySource.Value, startingIndex, indexCount);
                }
                else
                {
                    SystemMonitor.Throw("inReal parameter not assigned.");
                }
            }
            else if (valueArrayTypeName == "inReal0")
            {
                if (_realInputArraySource.HasValue)
                {
                    result = provider.GetValuesAsDouble(_realInputArraySource.Value, startingIndex, indexCount);
                }
                else
                {
                    SystemMonitor.Throw("inReal parameter not assigned.");
                }
            }
            else if (valueArrayTypeName == "inReal1")
            {
                if (_real1InputArraySource.HasValue)
                {
                    result = provider.GetValuesAsDouble(_real1InputArraySource.Value, startingIndex, indexCount);
                }
                else
                {
                    SystemMonitor.Throw("inReal parameter not assigned.");
                }
            }
            else
            {
                SystemMonitor.Throw("Class operation logic error - array type name unknown.");
            }

            return(result);
        }