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); // } //} }
public void OpenOrder(DateTime time, MarketOrderState orderState, double openingBidPrice, double openingAskPrice, DateTime openingBarTime) { this.orderTime = time; this.orderState = orderState; this.openingBidPrice = openingBidPrice; this.openingAskPrice = openingAskPrice; this.openingBarTime = openingBarTime; this.position = (PositionMode)Enum.Parse(typeof(PositionMode), Enum.GetName(typeof(MarketOrderState), orderState)); }
private void RefreshChart(DateTime currentDateTime) { multiChart1.Clear(); strategyFrameReader = strategyDataFrame.GetFrameReader(currentDateTime); //Get strategies. //Basic SDK can execute only one strategy. Expert SDK can execute multiple strategies. //PlotStrategies(this.strategyDataFrame.Strategies); 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) // { // ((IPriceActionChart)multiChart1).PlotIndicator(GetSeriesLabel(chartingInfo), chartIndicators, chartingInfo.ChartType); // } // else if (chartingInfo.ChartRange == ChartRangeOption.PositiveHundredRange) // { // if (!((IPercentageChart)multiChart1).Visible) // { // ((IPercentageChart)multiChart1).Show(); // } // ((IPercentageChart)multiChart1).PlotIndicator(GetSeriesLabel(chartingInfo), chartIndicators, chartingInfo.ChartType); // } // else if (chartingInfo.ChartRange == ChartRangeOption.PipRange) // { // if (!((IOscillatorChart)multiChart1).Visible) // { // ((IOscillatorChart)multiChart1).Show(); // } // ((IOscillatorChart)multiChart1).PlotIndicator(GetSeriesLabel(chartingInfo), chartIndicators, chartingInfo.ChartType); // } //} }
public MarketOrderState Read(DateTime time) { MarketOrderState strategy = MarketOrderState.NoOrder; if (strategyIndex.ContainsKey(time)) { int strategyPosition = strategyIndex[time]; //Check if position is Closed if (dataFrameItems[strategyPosition].Position == PositionMode.Closed) { //Check for reversal int nextPosition = strategyPosition + 1; if (nextPosition < dataFrameItems.Length && dataFrameItems[nextPosition].ClosingBarTime == time) { if (dataFrameItems[nextPosition].Position == PositionMode.Long) { strategy = MarketOrderState.LongReversal; } else if (dataFrameItems[nextPosition].Position == PositionMode.Short) { strategy = MarketOrderState.ShortReversal; } else { strategy = MarketOrderState.Closed; } } else { strategy = MarketOrderState.Closed; } } else if (dataFrameItems[strategyPosition].Position == PositionMode.Long) { strategy = MarketOrderState.Long; } else if (dataFrameItems[strategyPosition].Position == PositionMode.Short) { strategy = MarketOrderState.Short; } else if (dataFrameItems[strategyPosition].HasOrderUpdate) { strategy = MarketOrderState.OrderUpdate; } } return(strategy); }
public Guid CreateMarketOrder(DateTime time, TickerType tickerType, MarketOrderState orderState, double bidPrice, double askPrice, BarItem barItem) { Guid marketOrderId = Guid.NewGuid(); MarketOrder marketOrder = new MarketOrder(tickerType); marketOrder.OpenOrder(time, orderState, bidPrice, askPrice, barItem.Time); marketOrders.Add(marketOrderId, marketOrder); if (lastTickerOrder.ContainsKey(tickerType.Symbol)) { lastTickerOrder[tickerType.Symbol] = marketOrderId; } else { lastTickerOrder.Add(tickerType.Symbol, marketOrderId); } return(marketOrderId); }
private void OnSignalOpenPosition(Guid accountId, TickerType tickerType, MarketOrderState position, double bidPrice, double askPrice, BarItem barItem) { brokerAccounts[accountId].Orders.CreateMarketOrder(DateTime.Now, tickerType, position, bidPrice, askPrice, barItem); }
private void OnStrategyOpenPosition(Guid accountId, TickerType tickerType, PositionMode position, double bidPrice, double askPrice, BarItem barItem) { MarketOrderState marketOrderState = (MarketOrderState)Enum.Parse(typeof(MarketOrderState), Enum.GetName(typeof(PositionMode), position)); brokerAccounts[accountId].Orders.CreateMarketOrder(DateTime.Now, tickerType, marketOrderState, bidPrice, askPrice, barItem); }