Ejemplo n.º 1
0
        public override void Calculate(int index)
        {
            if (!IsLastBar)
            {
                return;
            }

            ChartObjects.DrawVerticalLine("vLine", index - Period, _colorLine);

            int    maxIndex = index;
            double max      = Source[index];

            for (int i = index - Period; i <= index; i++)
            {
                if (max >= Source[i])
                {
                    continue;
                }

                max      = Source[i];
                maxIndex = i;
            }

            var text   = "max " + max.ToString("0.0000");
            var top    = VerticalAlignment.Top;
            var center = HorizontalAlignment.Center;

            ChartObjects.DrawText("max", text, maxIndex, max + 0.0002, top, center, _colorText);
            ChartObjects.DrawLine("line", maxIndex, max, index, Source[index], _colorLine);
        }
Ejemplo n.º 2
0
        public override void Calculate(int index)
        {
            if (index - 1 < 0)
            {
                return;
            }

            DateTimeOffset CurrentDate  = TradeDate(MarketSeries.OpenTime[index]);
            DateTimeOffset PreviousDate = TradeDate(MarketSeries.OpenTime[index - 1]);

            int DateDifference = (int)(CurrentDate.Date - PreviousDate.Date).TotalDays;

            int myOffset = (int)(CurrentDate.Offset.Hours + 7);

            if (TimeFrame < TimeFrame.Hour12)
            {
//*** Dayend ***
                if ((CurrentDate.DayOfWeek != PreviousDate.DayOfWeek || DateDifference > 6) && PreviousDate.DayOfWeek != DayOfWeek.Sunday && CurrentDate.DayOfWeek != DayOfWeek.Saturday)
                {
                    if (!HideDayLabels)
                    {
                        ChartObjects.DrawText("DayLabel" + index, " " + CurrentDate.DayOfWeek + (myOffset > 0?" +":" ") + myOffset, index, MarketSeries.Low.Minimum(PeriodsPerDay), VerticalAlignment.Bottom, HorizontalAlignment.Right);
                    }

                    if (!HideDayDividers)
                    {
                        ChartObjects.DrawVerticalLine("Dayend" + index, index, Colors.Orange, 1, LineStyle.DotsRare);
                    }

                    Dayend[index] = MarketSeries.Median[index];
                    //Print("CurDayOfWeek:"+CurrentDate.DayOfWeek+" CurrDate:"+CurrentDate.Date+" Diff:"+DateDifference);
                }
            }

//*** Weekend ***
            if (TimeFrame < TimeFrame.Weekly)
            {
                if (CurrentDate.DayOfWeek < PreviousDate.DayOfWeek || DateDifference > 6)
                {
                    if (!HideWeekDividers)
                    {
                        ChartObjects.DrawVerticalLine("Weekend" + index, index, Colors.Red, 1, LineStyle.DotsRare);
                    }

                    Weekend[index] = MarketSeries.Median[index];
                }
            }
        }
Ejemplo n.º 3
0
 public override void Calculate(int index)
 {
     if (MarketSeries.OpenTime[index].Minute == 0)
     {
         if (MarketSeries.OpenTime[index].Hour == 6 && seen_frankfurt != MarketSeries.OpenTime[index].Day)
         {
             seen_frankfurt = MarketSeries.OpenTime[index].Day;
             ChartObjects.DrawVerticalLine("Frankfurt Open" + index, index, Colors.OrangeRed, 1);
         }
         if (MarketSeries.OpenTime[index].Hour == 7 && seen_london != MarketSeries.OpenTime[index].Day)
         {
             seen_london = MarketSeries.OpenTime[index].Day;
             ChartObjects.DrawVerticalLine("London Open" + index, index, Colors.Red, 1);
         }
     }
 }
Ejemplo n.º 4
0
        public override void Calculate(int index)
        {
            if (index - 1 < 0)
            {
                return;
            }

            DateTime CurrentDate    = MarketSeries.OpenTime[index].AddHours(2);
            DateTime PreviousDate   = MarketSeries.OpenTime[index - 1].AddHours(2);
            int      DateDifference = (int)(CurrentDate.Date - PreviousDate.Date).TotalDays;

            //**Dayend
            if (CurrentDate.DayOfWeek != PreviousDate.DayOfWeek && PreviousDate.DayOfWeek != DayOfWeek.Sunday)
            {
                if (!HideDayLabels)
                {
                    ChartObjects.DrawText("DayLabel" + index, " " + Convert.ToString(CurrentDate.DayOfWeek), index, MarketSeries.Low.Minimum(PeriodsPerDay), VerticalAlignment.Bottom, HorizontalAlignment.Right);
                }
                if (!HideDayDividers)
                {
                    ChartObjects.DrawVerticalLine("Dayend" + index, index, Colors.Orange, 1, LineStyle.DotsRare);
                }
                Dayend[index] = MarketSeries.Median[index];
                //Print(CurrentDate.Date+" "+DateDifference);
            }

            //** Weekend

            //if(DateDifference>1)
            if (CurrentDate.DayOfWeek < PreviousDate.DayOfWeek || DateDifference > 6)
            {
                if (!HideWeekDividers)
                {
                    ChartObjects.DrawVerticalLine("Weekend" + index, index, Colors.Red, 1, LineStyle.DotsRare);
                }
                Weekend[index] = MarketSeries.Median[index];
                //Print(CurrentDate.Date+" "+DateDifference);
            }
        }
Ejemplo n.º 5
0
Archivo: NRE.cs Proyecto: mikewusg/nre
        private void DisplayPastNews(int index)
        {
            DateTime openTime = MarketSeries.OpenTime[index];

            //find all news released between candle open and close time
            List <DateTime> dateTimes = _groups.Keys.Where(x => x >= openTime && x <= openTime.AddMinutes(TimeFrameInMinutes)).ToList();

            foreach (var dateTime in dateTimes)
            {
                var newsGroup = _groups[dateTime];

                var timeId = dateTime.ToString("yyyyMMddHHmmss");

                var high = MarketSeries.High[index];
                var low  = MarketSeries.Low[index];

                var pips = Symbol.PipSize;

                const int padding = 20;

                const Colors textColor = Colors.Green;

                //base currency news are displayed above current price
                if (newsGroup.BaseCurrencyNews.NewsList.Any())
                {
                    ChartObjects.DrawVerticalLine("Pointer1" + timeId, openTime, Colors.SlateGray, 1, LineStyle.DotsVeryRare);
                    ChartObjects.DrawText("News1" + timeId, FormatForDisplay(newsGroup.BaseCurrencyNews.NewsList), index, high + padding * pips, VerticalAlignment.Top, HorizontalAlignment.Right, textColor);
                }

                //quote currency news are displayed below current price
                if (newsGroup.QuoteCurrencyNews.NewsList.Any())
                {
                    ChartObjects.DrawVerticalLine("Pointer1" + timeId, openTime, Colors.SlateGray, 1, LineStyle.DotsVeryRare);
                    ChartObjects.DrawText("News2" + timeId, FormatForDisplay(newsGroup.QuoteCurrencyNews.NewsList), index, low - padding * pips, VerticalAlignment.Bottom, HorizontalAlignment.Right, textColor);
                }
            }
        }
Ejemplo n.º 6
0
 protected void DrawVerticalLine(string objectName, DateTime date, Colors color, double thickness = 1.0, cAlgo.API.LineStyle style = cAlgo.API.LineStyle.Solid)
 {
     _addedAlgoChartObjects.Add(objectName);
     _chartObjects.DrawVerticalLine(objectName, date, color, thickness, style);
 }
        void Calc_And_Show_Chart()
        {
            //Variable
            _askNo = 0;
            _bidNo = 0;
            int    set_position         = 0;
            double fair_value           = 0;
            double total_time           = 0;
            double vwap_price           = 0;
            double twap_price           = 0;
            int    fair_value_index     = 0;
            double vwap_price_low       = 0;
            double vwap_price_high      = 0;
            double fairvalue_price      = 0;
            double fairvalue_volume     = 0;
            double cumulative_volume    = 0;
            double Check_Bid_Volume     = 0;
            double Check_Ask_Volume     = 0;
            double high_range_volume    = 0;
            double low_range_volume     = 0;
            double highlow_range_volume = 0;
            double symbol_point         = Symbol.PointSize;
            int    new_index            = MarketSeries.Close.Count - 1;
            int    CurrentDay           = MarketSeries.OpenTime[new_index].DayOfYear;

            /*
             * var marketSeries1440 = MarketData.GetSeries(TimeFrame.Daily);
             * int DailyTimeFrameCount = marketSeries1440.Close.Count - 1;
             * double today_high = marketSeries1440.High[DailyTimeFrameCount];
             * double today_low = marketSeries1440.Low[DailyTimeFrameCount];
             * double today_bid = marketSeries1440.Open[DailyTimeFrameCount];
             */

            foreach (var entry in _marketDepth.AskEntries)
            {
                if (entry.Price > today_high)
                {
                    today_high = entry.Price;
                }
            }

            foreach (var entry in _marketDepth.BidEntries)
            {
                if (entry.Price < today_low)
                {
                    today_low = entry.Price;
                }
            }

            double range              = ((today_high - today_low) / symbol_point);
            int    middle_of_range    = (int)Math.Round(range / 2);
            int    middle_of_array    = array_value_index / 2;
            int    start_set_ask      = middle_of_array + (int)Math.Round(((Symbol.Ask - today_bid) / symbol_point));
            int    start_set_bid      = middle_of_array + (int)Math.Round(((Symbol.Bid - today_bid) / symbol_point));
            int    start_volume_index = middle_of_array + (int)Math.Round(((today_low - today_bid) / symbol_point));
            int    start_index        = (new_index - (int)range);
            int    ask_value_index    = 0;
            int    bid_value_index    = 0;
            double middle_price       = ((today_high + today_low) / 2);

            current_time = MarketSeries.OpenTime[new_index].Year * MarketSeries.OpenTime[new_index].Day * MarketSeries.OpenTime[new_index].Hour * MarketSeries.OpenTime[new_index].Millisecond;

            //Clear array & indicator chart
            for (var i = new_index; i > 0; i--)
            {
                AskResult[i] = 0;
                BidResult[i] = 0;
            }

            /*
             * if (CurrentDay != old_day)
             * {
             *  for (var i = 0; i < array_value_index; i++)
             *  {
             *      aVolume[i] = 0;
             *  }
             *  today_high =0;
             *  today_low = 999999;
             *  today_bid = Symbol.Bid;
             *  CurrentDay = old_day;
             * }*/

            //Calc Array
            for (var bs = 0; bs < array_value_index; bs++)
            {
            }

            foreach (var entry in _marketDepth.AskEntries)
            {
                double entry_ask_volume = (entry.Volume / lot_size);
                if (Show_Delta_Volume == true)
                {
                    aVolume[start_set_ask + _askNo] = aVolume[start_set_ask + _askNo] + entry_ask_volume;
                }
                else
                {
                    aVolume[start_set_ask + _askNo] = entry_ask_volume;
                }
                vwap_price_high  = entry.Price;
                Check_Ask_Volume = Check_Ask_Volume + entry_ask_volume;
                _askNo++;
            }

            foreach (var entry in _marketDepth.BidEntries)
            {
                double entry_bid_volume = (entry.Volume / lot_size);
                if (Show_Delta_Volume == true)
                {
                    aVolume[start_set_bid - _bidNo] = aVolume[start_set_bid - _bidNo] - entry_bid_volume;
                }
                else
                {
                    aVolume[start_set_bid - _bidNo] = (entry_bid_volume * (-1));
                }
                Check_Bid_Volume = Check_Bid_Volume + entry_bid_volume;
                vwap_price_low   = entry.Price;
                _bidNo++;
            }

            //Indicator Chart
            if (Check_Ask_Volume <= 0)
            {
                ChartObjects.DrawText("No_Ask_Volume", "No Ask Pending Volume", ((((start_index + new_index) / 2) + new_index) / 2), 0, vAlignAskBid, hAlignAskBid, Colors.Magenta);
            }
            else
            {
                ChartObjects.RemoveObject("No_Ask_Volume");
            }
            if (Check_Bid_Volume <= 0)
            {
                ChartObjects.DrawText("No_Bid_Volume", "No Bid Pending Volume", ((((start_index + new_index) / 2) + start_index) / 2), 0, vAlignAskBid, hAlignAskBid, Colors.Magenta);
            }
            else
            {
                ChartObjects.RemoveObject("No_Bid_Volume");
            }

            if (Check_Ask_Volume > 0 && Check_Bid_Volume > 0)
            {
                for (int c = start_index; c < new_index; c++)
                {
                    double volume = aVolume[start_volume_index];

                    if (start_volume_index > middle_of_array)
                    {
                        highlow_range_volume = highlow_range_volume + Math.Abs(volume);
                    }
                    else
                    {
                        highlow_range_volume = highlow_range_volume - Math.Abs(volume);
                    }

                    if (volume > 0)
                    {
                        AskResult[c] = volume;
                        BidResult[c] = 0;
                    }
                    else
                    {
                        if (volume < 0)
                        {
                            AskResult[c] = 0;
                            BidResult[c] = (volume * (-1));
                        }
                        else
                        {
                            AskResult[c] = 0;
                            BidResult[c] = 0;
                        }
                    }
                    if (Math.Abs(volume) > fair_value)
                    {
                        fair_value_index = c;
                        fair_value       = Math.Abs(volume);
                        fairvalue_volume = volume;
                    }
                    start_volume_index++;
                }
            }

            //Calc for Object Chart Text
            ask_value_index = start_index + (int)((vwap_price_high - today_low) / symbol_point);
            bid_value_index = start_index + (int)((vwap_price_low - today_low) / symbol_point);

            ask_volume        = ask_volume + Check_Ask_Volume;
            bid_volume        = bid_volume + Check_Bid_Volume;
            total_volume      = ask_volume + bid_volume;
            set_position      = (int)Math.Round(fair_value / 10);
            cumulative_volume = bid_volume - ask_volume;
            fairvalue_price   = today_low + ((fair_value_index - start_index) * symbol_point);
            //VWAP
            total_pv  += (Check_Ask_Volume + Check_Bid_Volume) * ((vwap_price_high + vwap_price_low + ((Symbol.Bid + Symbol.Ask) / 2)) / 3);
            vwap_price = total_pv / total_volume;
            //TWAP i dont create to work calc in miliseconds to calc diference betwen update time

            /*if(old_time > 0 && old_askbid_middle > 0)
             * {
             *  total_pt += (current_time - old_time) * ((vwap_price_high + vwap_price_low + old_askbid_middle + ((Symbol.Bid + Symbol.Ask)/2)) /4);
             *  total_time = current_time - start_time;
             *  twap_price = total_pt / total_time;
             * }
             * old_askbid_middle = ((Symbol.Bid + Symbol.Ask)/2);
             * old_time = current_time;*/
            /*if(current_time > old_time)
             * {*/
            total_pt  += (current_time - old_time) * ((MarketSeries.Open[new_index - 1] + MarketSeries.High[new_index - 1] + MarketSeries.Low[new_index - 1] + MarketSeries.Close[new_index - 1]) / 4);
            total_time = current_time - start_time;
            if (total_time > 0)
            {
                twap_price = total_pt / total_time;
            }
            else
            {
                twap_price = 0;
            }
            //}
            old_time = current_time;

            //Indicator Object Chart Line
            ChartObjects.DrawVerticalLine("High", new_index, Colors.Magenta, 4, LineStyle.Solid);
            ChartObjects.DrawVerticalLine("Low", start_index, Colors.Green, 4, LineStyle.Solid);
            ChartObjects.DrawVerticalLine("Middle", ((start_index + new_index) / 2), Colors.PapayaWhip, 4, LineStyle.Solid);
            //ChartObjects.DrawVerticalLine("FairValue", fair_value_index, Colors.Yellow, 3, LineStyle.Solid);
            ChartObjects.DrawVerticalLine("Ask", ask_value_index, Colors.Yellow, 2, LineStyle.Solid);
            ChartObjects.DrawVerticalLine("Bid", bid_value_index, Colors.Yellow, 2, LineStyle.Solid);

            //Indicator Object Chart Text
            ChartObjects.DrawText("Sum_Volume", "Sum Volume " + total_volume, new_index + 10, fair_value, vAlignText, hAlignText, Colors.DimGray);
            ChartObjects.DrawText("Ask_Volume", "Ask Volume " + ask_volume, new_index + 10, (fair_value - set_position), vAlignText, hAlignText, Colors.DimGray);
            ChartObjects.DrawText("Bid_Volume", "Bid Volume " + bid_volume, new_index + 10, (fair_value - (set_position * 2)), vAlignText, hAlignText, Colors.DimGray);
            if (highlow_range_volume < 0)
            {
                ChartObjects.DrawText("MiddleRangeVolume", "Buyers & Sellers " + highlow_range_volume, new_index + 10, (fair_value - (set_position * 3)), vAlignText, hAlignText, Colors.RoyalBlue);
            }
            else
            {
                if (highlow_range_volume > 0)
                {
                    ChartObjects.DrawText("MiddleRangeVolume", "Buyers & Sellers " + highlow_range_volume, new_index + 10, (fair_value - (set_position * 3)), vAlignText, hAlignText, Colors.Red);
                }
                else
                {
                    ChartObjects.DrawText("MiddleRangeVolume", "Buyers & Sellers " + highlow_range_volume, new_index + 10, (fair_value - (set_position * 3)), vAlignText, hAlignText, Colors.DimGray);
                }
            }

            if (cumulative_volume < 0)
            {
                ChartObjects.DrawText("Cumulative_Volume", "Cumulative Volume " + cumulative_volume, new_index + 10, (fair_value - (set_position * 4)), vAlignText, hAlignText, Colors.RoyalBlue);
            }
            else
            {
                if (cumulative_volume > 0)
                {
                    ChartObjects.DrawText("Cumulative_Volume", "Cumulative Volume " + cumulative_volume, new_index + 10, (fair_value - (set_position * 4)), vAlignText, hAlignText, Colors.Red);
                }
                else
                {
                    ChartObjects.DrawText("Cumulative_Volume", "Cumulative Volume " + cumulative_volume, new_index + 10, (fair_value - (set_position * 4)), vAlignText, hAlignText, Colors.DimGray);
                }
            }
            if (fairvalue_volume > 0)
            {
                ChartObjects.DrawText("FairValue_Volume", "Fair Value Volume " + fairvalue_volume, new_index + 10, (fair_value - (set_position * 5)), vAlignText, hAlignText, Colors.RoyalBlue);
            }
            else
            {
                if (fairvalue_volume < 0)
                {
                    ChartObjects.DrawText("FairValue_Volume", "Fair Value Volume " + fairvalue_volume, new_index + 10, (fair_value - (set_position * 5)), vAlignText, hAlignText, Colors.Red);
                }
                else
                {
                    ChartObjects.DrawText("FairValue_Volume", "Fair Value Volume " + fairvalue_volume, new_index + 10, (fair_value - (set_position * 5)), vAlignText, hAlignText, Colors.DimGray);
                }
            }
            if (fairvalue_price < vwap_price)
            {
                ChartObjects.DrawText("FairValue_Price", "Fair Value Price @ " + fairvalue_price, new_index + 10, (fair_value - (set_position * 6)), vAlignText, hAlignText, Colors.RoyalBlue);
            }
            else
            {
                if (fairvalue_price > vwap_price)
                {
                    ChartObjects.DrawText("FairValue_Price", "Fair Value Price @ " + fairvalue_price, new_index + 10, (fair_value - (set_position * 6)), vAlignText, hAlignText, Colors.Red);
                }
                else
                {
                    ChartObjects.DrawText("FairValue_Price", "Fair Value Price @ " + fairvalue_price, new_index + 10, (fair_value - (set_position * 6)), vAlignText, hAlignText, Colors.DimGray);
                }
            }

            if (vwap_price > middle_price)
            {
                ChartObjects.DrawText("VWAP_Price", "VWAP Price @ " + vwap_price.ToString("0.#####"), new_index + 10, (fair_value - (set_position * 7)), vAlignText, hAlignText, Colors.RoyalBlue);
            }
            else
            {
                if (vwap_price < middle_price)
                {
                    ChartObjects.DrawText("VWAP_Price", "VWAP Price @ " + vwap_price.ToString("0.#####"), new_index + 10, (fair_value - (set_position * 7)), vAlignText, hAlignText, Colors.Red);
                }
                else
                {
                    ChartObjects.DrawText("VWAP_Price", "VWAP Price @ " + vwap_price.ToString("0.#####"), new_index + 10, (fair_value - (set_position * 7)), vAlignText, hAlignText, Colors.DimGray);
                }
            }

            //ChartObjects.DrawText("TWAP_Price", "TWAP Price @ "+twap_price.ToString("0.#####"), new_index+10, (fair_value-(set_position*7)), vAlignText, hAlignText, Colors.DimGray);
            ChartObjects.DrawText("High_Price", "High Price @ " + today_high, new_index + 10, (fair_value - (set_position * 8)), vAlignText, hAlignText, Colors.DimGray);
            ChartObjects.DrawText("Middle_Price", "Middle Price @ " + middle_price, new_index + 10, (fair_value - (set_position * 9)), vAlignText, hAlignText, Colors.DimGray);
            ChartObjects.DrawText("Low_Price", "Low Price @ " + today_low, new_index + 10, (fair_value - (set_position * 10)), vAlignText, hAlignText, Colors.DimGray);
        }