Exemple #1
0
        public static void PlotPriceBid(string path, PriceSet price_set)
        {
            PlotLine2D line_plot_2d = new PlotLine2D();

            AddBid(line_plot_2d, price_set);
            ToolsPlotting.WriteToFile(path, line_plot_2d, SIZE_X, SIZE_Y);
        }
Exemple #2
0
        public static void PlotMarketResult(string path, MarketResult market_result)
        {
            PlotLine2D line_plot_2d = new PlotLine2D();

            AddBidAskTrades(line_plot_2d, market_result);
            ToolsPlotting.WriteToFile(path, line_plot_2d, SIZE_X, SIZE_Y);
        }
Exemple #3
0
        public static void AddCashEquity(PlotLine2D line_plot_2d, MarketResult market_result)
        {
            IReadOnlyList <double> time   = market_result.Ticks;
            IReadOnlyList <double> cash   = market_result.Cash;
            IReadOnlyList <double> equity = market_result.Equity;

            AddSignal(line_plot_2d, time, cash, COLOR_CASH);
            AddSignal(line_plot_2d, time, equity, COLOR_EQUITY);
        }
Exemple #4
0
        public static void PlotIndicatorResult(string path, PriceSet price_set, IIndicator indicator, IList <Color> color_list, IList <int> selected_subindicators, bool plot_bid = true)
        {
            PlotLine2D line_plot_2d = new PlotLine2D();

            AddIndicatorResult(line_plot_2d, price_set, indicator, color_list, selected_subindicators);
            if (plot_bid)
            {
                AddBid(line_plot_2d, price_set);
            }
            ToolsPlotting.WriteToFile(path, line_plot_2d, SIZE_X, SIZE_Y);
        }
Exemple #5
0
 public static void AddPrice(PlotLine2D line_plot_2d, PriceSet price_set, TimeScale time_scale, PriceType price_type, Color color)
 {
     if (time_scale == TimeScale.Spot)
     {
         AddPriceSpot(line_plot_2d, price_set, price_type, color);
     }
     else
     {
         AddPriceCandle(line_plot_2d, price_set, time_scale, price_type, color);
     }
 }
Exemple #6
0
        public static void AddPriceCandle(PlotLine2D line_plot_2d, PriceSet price_set, TimeScale time_scale, PriceType price_type, Color color)
        {
            IReadOnlyList <PriceCandle> candles = price_set.GetCandles(time_scale);
            IReadOnlyList <double>      time    = price_set.Ticks;

            double[] signal = new double[candles.Count];
            Parallel.For(0, candles.Count, index =>
            {
                signal[index] = candles[index].GetPrice(price_type);
            });
            AddSignal(line_plot_2d, time, signal, color);
        }
Exemple #7
0
        public static void AddPriceSpot(PlotLine2D line_plot_2d, PriceSet price_set, PriceType price_type, Color color)
        {
            IReadOnlyList <Price>  prices = price_set.Prices;
            IReadOnlyList <double> time   = price_set.Ticks;

            double[] signal = new double[prices.Count];
            Parallel.For(0, prices.Count, index =>
            {
                signal[index] = prices[index].GetPrice(price_type);
            });
            AddSignal(line_plot_2d, time, signal, color);
        }
Exemple #8
0
        private static void AddSignal(PlotLine2D line_plot_2d, double[] time, double[] signal, List <IList <int> > selections, Color color)
        {
            List <Tuple <double[], double[], Color> > series_list = new List <Tuple <double[], double[], Color> >();

            foreach (IList <int> selection in selections)
            {
                series_list.Add(new Tuple <double[], double[], Color>(
                                    time.Select(selection),
                                    signal.Select(selection),
                                    color));
            }

            line_plot_2d.AddSeries(series_list);
        }
Exemple #9
0
        public static void AddIndicatorResult(PlotLine2D line_plot_2d, PriceSet price_set, IIndicator indicator, IList <Color> color_list, IList <int> selected_subindicators)
        {
            MarketModelSimulation market = new MarketModelSimulation(10000, price_set);

            double[] time = new double[price_set.Prices.Count];
            for (int price_index = 0; price_index < price_set.Prices.Count; price_index++)
            {
                time[price_index] = price_set.Prices[price_index].Time.Ticks;
            }
            Tuple <double[, ], bool[]> tuple      = indicator.ComputeAll(market, price_set.Second1.Count);
            List <IList <int> >        selections = CreateSections(tuple.Item2);

            for (int index = 0; index < selected_subindicators.Count; index++)
            {
                double[] signal = tuple.Item1.Select1DIndex1(selected_subindicators[index]);
                AddSignal(line_plot_2d, time, signal, selections, color_list[index]);
            }
        }
        public void DoExperiment()
        {
            List <PriceCandle> all_data = ToolsPrice.GetPriceCandles();

            // new DateTime(2016, 9, 3)
            PlotLine2D line_plot_2d = new PlotLine2D();


            for (int month_index = 1; month_index < 9; month_index++)
            {
                DateTimeUTC nfp_date = null;// ToolsTradingCalendarEvent.GetNFPDatetime(2016, month_index);

                DateTimeUTC   nfp_date_begin = nfp_date.AddMinutes(-100);
                DateTimeUTC   nfp_date_end   = nfp_date.AddMinutes(100);
                List <double> nfp_time       = new List <double>();
                List <double> nfp_bid        = new List <double>();

                double candle_time = 0;
                double subtract    = 0;
                foreach (PriceCandle candle in all_data)
                {
                    if ((nfp_date_begin <= candle.OpenTime) && (candle.OpenTime < nfp_date_end))
                    {
                        if (candle_time == 0)
                        {
                            subtract = candle.OpenBid;
                        }
                        nfp_time.Add(candle_time);
                        nfp_time.Add(candle_time);
                        nfp_time.Add(candle_time);
                        nfp_time.Add(candle_time);
                        nfp_bid.Add(candle.OpenBid);
                        nfp_bid.Add(candle.LowBid);
                        nfp_bid.Add(candle.HighBid);
                        nfp_bid.Add(candle.CloseBid);
                        candle_time++;
                    }
                }
                line_plot_2d.AddSeries(nfp_time, nfp_bid, Color.Black);
            }
            ToolsPlotting.WriteToFile(ToolsTradingDataSet.GetPath() + "nfp.png", line_plot_2d, 800, 800);
        }
Exemple #11
0
        public static void AddTrades(PlotLine2D line_plot_2d, MarketResult market_result)
        {
            List <Tuple <double[], double[], Color> > series_list = new List <Tuple <double[], double[], Color> >();

            for (int orderIndex = 0; orderIndex < market_result.Market.ClosedOrders.Count; orderIndex++)
            {
                TradingOrder closed_order     = market_result.Market.ClosedOrders[orderIndex];
                double[]     open_close_time  = new double[] { closed_order.OpenDateTime.Ticks, closed_order.CloseDateTime.Ticks };
                double[]     open_close_price = new double[] { closed_order.OpenPrice, closed_order.ClosePrice };
                if (closed_order.OrderType == TradingOrderType.Long)
                {
                    series_list.Add(new Tuple <double[], double[], Color>(open_close_time, open_close_price, COLOR_LONG));
                }
                else
                {
                    series_list.Add(new Tuple <double[], double[], Color>(open_close_time, open_close_price, COLOR_SHORT));
                }
            }
            line_plot_2d.AddSeries(series_list);
        }
Exemple #12
0
        internal void DoExperiment()
        {
            ToolsPrice.ComposeBinary(ToolsPrice.DefaultSymbolGBPUSD);
            PriceSet price_set = ToolsPrice.GetPriceSet(ToolsPrice.DefaultSymbolGBPUSD).SubSet(new DateTimeUTC(2016, 10, 17), new DateTimeUTC(2016, 10, 20));

            //PlotLine2D line_plot_2d_0 = new PlotLine2D();
            //ToolsTradingPlotting.AddPrice(line_plot_2d_0, price_set, TimeScale.Spot, PriceType.Bid, Color.Blue);
            //ToolsTradingPlotting.AddPrice(line_plot_2d_0, price_set, TimeScale.Spot, PriceType.Mean, Color.Green);
            //ToolsTradingPlotting.AddPrice(line_plot_2d_0, price_set, TimeScale.Spot, PriceType.Ask, Color.Red);
            //ToolsTradingPlotting.AddPrice(line_plot_2d_0, price_set, TimeScale.Day1, PriceType.Bid, Color.Black);
            //ToolsTradingPlotting.AddPrice(line_plot_2d_0, price_set, TimeScale.Day1, PriceType.Mean, Color.Green);
            //ToolsTradingPlotting.AddPrice(line_plot_2d_0, price_set, TimeScale.Day1, PriceType.Ask, Color.Red);
            //ToolsTradingPlotting.WriteToFile(ToolsTradingDataSet.GetPath() + "TestPlot0.png", line_plot_2d_0);

            IIndicator indicator      = new IndicatorMagicProfit(60);
            PlotLine2D line_plot_2d_1 = new PlotLine2D();

            ToolsTradingPlotting.AddIndicatorResult(line_plot_2d_1, price_set, indicator, new Color[] { Color.Red, Color.Green }, new int[] { 0, 1 });
            ToolsTradingPlotting.WriteToFile(ToolsTradingDataSet.GetPath() + "TestPlot3.png", line_plot_2d_1);



            //ToolsTradingPlotting.PlotPriceBid(ToolsTradingDataSet.GetPath() + "prices.png", prices);
            //ToolsTradingPlotting.PlotIndicatorResult(ToolsTradingDataSet.GetPath() + "indicator_0.png", prices, indicator_0, color_list, index_list, true);
            //ToolsTradingPlotting.PlotIndicatorResult(ToolsTradingDataSet.GetPath() + "indicator_1.png", prices, indicator_1, color_list, index_list, true);


            //IPolicyTemplate policy = new PolicyTemplateJaapBands();
            //MarketManagerSimulation exchange = new MarketManagerSimulation(10000, price_set);
            //MarketResult market_result = exchange.Run(policy.Instance());
            //Console.WriteLine(market_result.EndCash + " in: " + market_result.Market.ClosedOrders.Count);

            //PlotLine2D line_plot_2d_0 = new PlotLine2D();
            //ToolsTradingPlotting.AddBidAskTrades(line_plot_2d_0, market_result);
            //ToolsTradingPlotting.WriteToFile(ToolsTradingDataSet.GetPath() + "TestPlot0.png", line_plot_2d_0);


            //PlotLine2D line_plot_2d_1 = new PlotLine2D();
            //ToolsTradingPlotting.AddCashEquity(line_plot_2d_1, market_result);
            //ToolsTradingPlotting.WriteToFile(ToolsTradingDataSet.GetPath() + "TestPlot1.png", line_plot_2d_1);
        }
Exemple #13
0
 private static void AddSignal(PlotLine2D line_plot_2d, IReadOnlyList <double> time, IReadOnlyList <double> signal, Color color)
 {
     line_plot_2d.AddSeries(time, signal, color);
 }
Exemple #14
0
 public static void AddBidAsk(PlotLine2D line_plot_2d, PriceSet price_set)
 {
     AddBid(line_plot_2d, price_set);
     AddAsk(line_plot_2d, price_set);
 }
Exemple #15
0
 public static void AddBid(PlotLine2D line_plot_2d, PriceSet price_set)
 {
     AddPrice(line_plot_2d, price_set, TimeScale.Spot, PriceType.Bid, COLOR_BID);
 }
Exemple #16
0
 public static void AddAsk(PlotLine2D line_plot_2d, PriceSet price_set)
 {
     AddPrice(line_plot_2d, price_set, TimeScale.Spot, PriceType.Ask, COLOR_ASK);
 }
Exemple #17
0
 public static void AddBidAskTrades(PlotLine2D line_plot_2d, MarketResult market_result)
 {
     AddBidAsk(line_plot_2d, market_result.PriceSet);
     AddTrades(line_plot_2d, market_result);
 }
Exemple #18
0
 public static void WriteToFile(string path, PlotLine2D line_plot_2d)
 {
     ToolsPlotting.WriteToFile(path, line_plot_2d, SIZE_X, SIZE_Y);
 }