Example #1
0
        public static string GetTickListNamePrefix(TickSize tickSize)
        {
            switch (tickSize)
            {
            case TickSize.Raw:
                return("tick:");

                break;

            case TickSize.OneMinute:
                return("tick1m:");

                break;

            case TickSize.TenMinute:
                return("tick10m:");

                break;

            case TickSize.OneHour:
                return("tick1h:");

                break;

            default:
                throw new ArgumentOutOfRangeException("tickSize", tickSize, null);
            }
        }
Example #2
0
        public static int GetClearWhenSize(TickSize tickSize)
        {
            switch (tickSize)
            {
            case TickSize.Raw:
                return(CLEAR_HISTORY_WHEN_SIZE_RawTick);

                break;

            case TickSize.OneMinute:
                return(CLEAR_HISTORY_WHEN_SIZE_1mTick);

                break;

            case TickSize.TenMinute:
                return(CLEAR_HISTORY_WHEN_SIZE_10mTick);

                break;

            case TickSize.OneHour:
                return(CLEAR_HISTORY_WHEN_SIZE_1hTick);

                break;

            default:
                throw new ArgumentOutOfRangeException("tickSize", tickSize, null);
            }
        }
Example #3
0
        private void DC_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            Task.Run(() =>
            {
                var DC = sender as ViewModel;

                switch (e.PropertyName)
                {
                case "BaseFontSize": BaseFontSize = DC.BaseFontSize; break;

                case "FontBrush": FontBrush = DC.FontBrush; break;

                case "TickSize":
                    {
                        TickSize        = DC.TickSize;
                        TickPriceFormat = TickSize.ToString().Replace('1', '0').Replace(',', '.');
                        Digits          = TickPriceFormat.ToCharArray().Length - 2;
                    }
                    break;

                case "NewCandles":
                    {
                        if (DC.NewCandles != null && DC.NewCandles.Count > 0)
                        {
                            CandlesModule.NewCandles(DC.NewCandles);
                        }
                    }
                    break;
                }
            });
        }
Example #4
0
        public void SetTickSize(TickSize size)
        {
            TickSize = size;
            for (int i = 0; i < Children.Count; i++)
            {
                var pointer = Children[i];
                var angle   = Math.PI * 2 / 3 * i;

                pointer.Rotation = 360 / 3 * i + 90;
                pointer.Position = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)) * (float)size.Size() * 1.3f;
            }
        }
Example #5
0
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                Description             = @"The Value Area is the price range where 70% of yesterdays volume traded.  See Larry Levin www.secretsoftraders.com/ for more info";
                Name                    = "CalculateValueArea";
                Calculate               = Calculate.OnBarClose;
                IsOverlay               = true;
                DisplayInDataBox        = true;
                DrawOnPricePanel        = true;
                DrawHorizontalGridLines = true;
                DrawVerticalGridLines   = true;
                PaintPriceMarkers       = true;
                ScaleJustification      = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                //See Help Guide for additional information.
                IsSuspendedWhileInactive = true;
                InclWeekendVol           = false;
                ProfileType          = @"VWTPO";
                PctOfVolumeInVA      = 0.7;
                OpenHour             = 8;
                OpenMinute           = 30;
                SessionLengthInHours = 6.75;

                AddPlot(new Stroke(Brushes.Yellow, 1), PlotStyle.Dot, "VAt");
                AddPlot(new Stroke(Brushes.Pink, 1), PlotStyle.Dot, "VAb");
                AddPlot(new Stroke(Brushes.Green, 1), PlotStyle.Line, "POC");
            }
            else if (State == State.DataLoaded)
            {
                if (TickSize.ToString().Length <= 2)
                {
                    FormatString = "0";
                }
                if (TickSize.ToString().Length == 3)
                {
                    FormatString = "0.0";
                }
                if (TickSize.ToString().Length == 4)
                {
                    FormatString = "0.00";
                }
                if (TickSize.ToString().Length == 5)
                {
                    FormatString = "0.000";
                }
                if (TickSize.ToString().Length == 6)
                {
                    FormatString = "0.0000";
                }
            }
        }
        /// <summary>
        /// Gets the hash code
        /// </summary>
        /// <returns>Hash code</returns>
        public override int GetHashCode()
        {
            unchecked // Overflow is fine, just wrap
            {
                var hashCode = 41;
                // Suitable nullity checks etc, of course :)

                hashCode = hashCode * 59 + QuoteCurrency.GetHashCode();

                hashCode = hashCode * 59 + Kind.GetHashCode();
                if (TickSize != null)
                {
                    hashCode = hashCode * 59 + TickSize.GetHashCode();
                }
                if (ContractSize != null)
                {
                    hashCode = hashCode * 59 + ContractSize.GetHashCode();
                }
                if (IsActive != null)
                {
                    hashCode = hashCode * 59 + IsActive.GetHashCode();
                }

                hashCode = hashCode * 59 + OptionType.GetHashCode();
                if (MinTradeAmount != null)
                {
                    hashCode = hashCode * 59 + MinTradeAmount.GetHashCode();
                }
                if (InstrumentName != null)
                {
                    hashCode = hashCode * 59 + InstrumentName.GetHashCode();
                }

                hashCode = hashCode * 59 + SettlementPeriod.GetHashCode();
                if (Strike != null)
                {
                    hashCode = hashCode * 59 + Strike.GetHashCode();
                }

                hashCode = hashCode * 59 + BaseCurrency.GetHashCode();
                if (CreationTimestamp != null)
                {
                    hashCode = hashCode * 59 + CreationTimestamp.GetHashCode();
                }
                if (ExpirationTimestamp != null)
                {
                    hashCode = hashCode * 59 + ExpirationTimestamp.GetHashCode();
                }
                return(hashCode);
            }
        }
        public override int GetHashCode()
        {
            var hashCode = 1689275518;

            hashCode = hashCode * -1521134295 + Difference.GetHashCode();
            hashCode = hashCode * -1521134295 + IsCurrentPriceIncreasing.GetHashCode();
            hashCode = hashCode * -1521134295 + IsDifferencePositive.GetHashCode();
            hashCode = hashCode * -1521134295 + CurrentPriceBid.GetHashCode();
            hashCode = hashCode * -1521134295 + CurrentPriceAsk.GetHashCode();
            hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(CurrentPrice);

            hashCode = hashCode * -1521134295 + TickSize.GetHashCode();
            hashCode = hashCode * -1521134295 + Rounding.GetHashCode();
            return(hashCode);
        }
Example #8
0
 protected override void OnStartUp()
 {
     if (TickSize.ToString().Length <= 2)
     {
         FormatString = "0";
     }
     if (TickSize.ToString().Length == 3)
     {
         FormatString = "0.0";
     }
     if (TickSize.ToString().Length == 4)
     {
         FormatString = "0.00";
     }
     if (TickSize.ToString().Length == 5)
     {
         FormatString = "0.000";
     }
     if (TickSize.ToString().Length == 6)
     {
         FormatString = "0.0000";
     }
 }
Example #9
0
        public static bool IsTickEqual(DateTime t1, DateTime t2, TickSize tickSize)
        {
            switch (tickSize)
            {
            case TickSize.OneMinute:
                return(DateTimes.IsEqualDownToMinute(t1, t2));

                break;

            case TickSize.TenMinute:
                return(DateTimes.IsEqualDownTo10Minute(t1, t2));

                break;

            case TickSize.OneHour:
                return(DateTimes.IsEqualDownToHour(t1, t2));

                break;

            default:
                throw new ArgumentOutOfRangeException("tickSize", tickSize, null);
            }
        }
Example #10
0
        /// <summary>
        /// Returns true if Instrument instances are equal
        /// </summary>
        /// <param name="other">Instance of Instrument to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Instrument other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     QuoteCurrency == other.QuoteCurrency ||

                     QuoteCurrency.Equals(other.QuoteCurrency)
                     ) &&
                 (
                     Kind == other.Kind ||

                     Kind.Equals(other.Kind)
                 ) &&
                 (
                     TickSize == other.TickSize ||
                     TickSize != null &&
                     TickSize.Equals(other.TickSize)
                 ) &&
                 (
                     ContractSize == other.ContractSize ||
                     ContractSize != null &&
                     ContractSize.Equals(other.ContractSize)
                 ) &&
                 (
                     IsActive == other.IsActive ||
                     IsActive != null &&
                     IsActive.Equals(other.IsActive)
                 ) &&
                 (
                     OptionType == other.OptionType ||

                     OptionType.Equals(other.OptionType)
                 ) &&
                 (
                     MinTradeAmount == other.MinTradeAmount ||
                     MinTradeAmount != null &&
                     MinTradeAmount.Equals(other.MinTradeAmount)
                 ) &&
                 (
                     InstrumentName == other.InstrumentName ||
                     InstrumentName != null &&
                     InstrumentName.Equals(other.InstrumentName)
                 ) &&
                 (
                     SettlementPeriod == other.SettlementPeriod ||

                     SettlementPeriod.Equals(other.SettlementPeriod)
                 ) &&
                 (
                     Strike == other.Strike ||
                     Strike != null &&
                     Strike.Equals(other.Strike)
                 ) &&
                 (
                     BaseCurrency == other.BaseCurrency ||

                     BaseCurrency.Equals(other.BaseCurrency)
                 ) &&
                 (
                     CreationTimestamp == other.CreationTimestamp ||
                     CreationTimestamp != null &&
                     CreationTimestamp.Equals(other.CreationTimestamp)
                 ) &&
                 (
                     ExpirationTimestamp == other.ExpirationTimestamp ||
                     ExpirationTimestamp != null &&
                     ExpirationTimestamp.Equals(other.ExpirationTimestamp)
                 ));
        }
Example #11
0
 /// <summary>
 /// TickSize event invocator
 /// </summary>
 protected virtual void OnTickSize(TickSizeEventArgs e)
 {
     TickSize?.Invoke(this, e);
 }
 public virtual void tickSize(int tickerId, int field, int size)
 {
     TickSize?.Invoke(this, new TickSizeArgs(tickerId, field, size));
 }
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                Description             = @"Enter the description for your new custom Indicator here.";
                Name                    = "SqaureOfNine";
                Calculate               = Calculate.OnBarClose;
                IsOverlay               = true;
                DisplayInDataBox        = true;
                DrawOnPricePanel        = true;
                DrawHorizontalGridLines = true;
                DrawVerticalGridLines   = true;
                PaintPriceMarkers       = true;
                ScaleJustification      = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                //See Help Guide for additional information.
                IsSuspendedWhileInactive = true;

                MultiplierForPriceScale = 1;
                InitialPrice            = 1;

                pOrT = PriceOrTime.Price;

                DisplayCountDown = true;

                //NT7, when you set the Date, it will default to midnight, while NT8 will reflect that date plus the current time..
                //Thus, the NT7 version of this indicator will have its time plots drawn slightly off from the NT8 one.

                //The line below forces the time associated with the date entered, to midnight.  Using this to conform to NT7 figures.
                //Might be best to be able to specify a time as well as date.
                ZuluTime = DateTime.Now.AddMinutes(-DateTime.Now.Minute).AddHours(-DateTime.Now.Hour).AddSeconds(-DateTime.Now.Second);

                Angle000Flag = true;
                Angle090Flag = true;
                Angle180Flag = true;
                Angle270Flag = true;

                xColor0x   = xColor0.Red;
                xColor90x  = xColor90.Blue;
                xColor180x = xColor180.Lime;
                xColor270x = xColor270.Purple;

                NumberOfLines = 10;
            }
            else if (State == State.Configure)
            {
                ZuluBar = -1;
                ;
            }
            else if (State == State.DataLoaded)
            {
                PriceDigits = Math.Max(0, TickSize.ToString().Length - 2);

                #region xColor0xSwitch
                switch (xColor0x)
                {
                case xColor0.Blue:
                {
                    Color0 = (SolidColorBrush)Brushes.Blue;
                    break;
                }

                case xColor0.Red:
                {
                    Color0 = (SolidColorBrush)Brushes.Red;
                    break;
                }

                case xColor0.Yellow:
                {
                    Color0 = (SolidColorBrush)Brushes.Yellow;
                    break;
                }

                case xColor0.Lime:
                {
                    Color0 = (SolidColorBrush)Brushes.Lime;
                    break;
                }

                case xColor0.Orange:
                {
                    Color0 = (SolidColorBrush)Brushes.Orange;
                    break;
                }

                case xColor0.Purple:
                {
                    Color0 = (SolidColorBrush)Brushes.Purple;
                    break;
                }

                case xColor0.Gray:
                {
                    Color0 = (SolidColorBrush)Brushes.Gray;
                    break;
                }
                }

                #endregion

                #region xColor90xSwitch
                switch (xColor90x)
                {
                case xColor90.Blue:
                {
                    Color90 = (SolidColorBrush)Brushes.Blue;
                    break;
                }

                case xColor90.Red:
                {
                    Color90 = (SolidColorBrush)Brushes.Red;
                    break;
                }

                case xColor90.Yellow:
                {
                    Print("Picked Yellow");

                    Color90 = (SolidColorBrush)Brushes.Yellow;
                    break;
                }

                case xColor90.Lime:
                {
                    Color90 = (SolidColorBrush)Brushes.Lime;
                    break;
                }

                case xColor90.Orange:
                {
                    Color90 = (SolidColorBrush)Brushes.Orange;
                    break;
                }

                case xColor90.Purple:
                {
                    Color90 = (SolidColorBrush)Brushes.Purple;
                    break;
                }

                case xColor90.Gray:
                {
                    Color90 = (SolidColorBrush)Brushes.Gray;
                    break;
                }
                }

                #endregion

                #region xColor180xSwitch

                switch (xColor180x)
                {
                case xColor180.Blue:
                {
                    Color180 = (SolidColorBrush)Brushes.Blue;
                    break;
                }

                case xColor180.Red:
                {
                    Color180 = (SolidColorBrush)Brushes.Red;
                    break;
                }

                case xColor180.Yellow:
                {
                    Color180 = (SolidColorBrush)Brushes.Yellow;
                    break;
                }

                case xColor180.Lime:
                {
                    Color180 = (SolidColorBrush)Brushes.Lime;
                    break;
                }

                case xColor180.Orange:
                {
                    Color180 = (SolidColorBrush)Brushes.Orange;
                    break;
                }

                case xColor180.Purple:
                {
                    Color180 = (SolidColorBrush)Brushes.Purple;
                    break;
                }

                case xColor180.Gray:
                {
                    Color180 = (SolidColorBrush)Brushes.Gray;
                    break;
                }
                }

                #endregion

                #region xColor270xSwitch
                switch (xColor270x)
                {
                case xColor270.Blue:
                {
                    Color270 = (SolidColorBrush)Brushes.Blue;
                    break;
                }

                case xColor270.Red:
                {
                    Color270 = (SolidColorBrush)Brushes.Red;
                    break;
                }

                case xColor270.Yellow:
                {
                    Color270 = (SolidColorBrush)Brushes.Yellow;
                    break;
                }

                case xColor270.Lime:
                {
                    Color270 = (SolidColorBrush)Brushes.Lime;
                    break;
                }

                case xColor270.Orange:
                {
                    Color270 = (SolidColorBrush)Brushes.Orange;
                    break;
                }

                case xColor270.Purple:
                {
                    Color270 = (SolidColorBrush)Brushes.Purple;
                    break;
                }

                case xColor270.Gray:
                {
                    Color270 = (SolidColorBrush)Brushes.Gray;
                    break;
                }
                }
                #endregion
            }
        }
Example #14
0
        private static void UpdateRedisTick(IRedisTypedClient <Tick> redisTickClient, int secId, DateTime dtAyondoNow, IList <Quote> quotes, TickSize tickSize)
        {
            //redis tick list
            var list = redisTickClient.Lists[Ticks.GetTickListNamePrefix(tickSize) + secId];

            if (quotes.Count == 0) //fill in non-changing ticks
            {
                if (list.Count > 0)
                {
                    var last = list[list.Count - 1];

                    //redis last tick is newer
                    if (last.T >= dtAyondoNow)
                    {
                        return;//impossible
                    }

                    //update last tick in redis
                    if (Ticks.IsTickEqual(last.T, dtAyondoNow, tickSize))
                    {
                        //do nothing
                    }
                    else //append new tick with the same price as redis last
                    {
                        list.Add(new Tick()
                        {
                            P = last.P, T = dtAyondoNow
                        });
                    }
                }
            }
            else
            {
                var lastQuote = quotes.OrderByDescending(o => o.Time).First();
                var newTick   = new Tick {
                    P = Quotes.GetLastPrice(lastQuote), T = dtAyondoNow
                };

                if (list.Count == 0) //new products coming
                {
                    list.Add(newTick);
                    return;
                }

                var last = list[list.Count - 1];

                //redis last tick is newer
                if (last.T >= dtAyondoNow)
                {
                    return;//impossible
                }

                //update last tick in redis
                if (Ticks.IsTickEqual(last.T, dtAyondoNow, tickSize))
                {
                    ////last price dominate
                    //list[list.Count - 1] = newTick;

                    //first price dominate
                    //do nothing
                }
                else //append new last tick
                {
                    list.Add(newTick);
                }
            }

            //clear history/prevent data increasing for good
            var clearWhenSize = Ticks.GetClearWhenSize(tickSize);
            var clearToSize   = Ticks.GetClearToSize(tickSize);

            if (list.Count > clearWhenSize) //data count at most possible size (in x days )
            {
                YJYGlobal.LogLine("Tick " + tickSize + " " + secId + " Clearing data from " + list.Count + " to " + clearToSize);
                var ticks    = list.GetAll();
                var newTicks = ticks.Skip(ticks.Count - clearToSize);
                list.RemoveAll();
                list.AddRange(newTicks);
            }
        }
 public void tickSize(int tickerId, int field, int size)
 {
     TickSize.RaiseEvent(this, new TickSizeEventArgs(tickerId, field, size));
 }
Example #16
0
 void IEWrapper.TickSize(int tickerId, int field, int size)
 {
     TickSize?.Invoke(new TickSizeMessage(tickerId, field, size));
 }
Example #17
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            int    j;
            String beginMessage = Instrument.FullName + " - Ray Line Price Triggered on ";

            // Determine the Period Value
            switch (BarsPeriod.Id)
            {
            case PeriodType.Minute:
                beginMessage += BarsPeriod.Value + "M Timeframe @ ";
                break;

            case PeriodType.Day:
                beginMessage += BarsPeriod.Value + "D Timeframe @ ";
                break;

            case PeriodType.Week:
                beginMessage += BarsPeriod.Value + "W Timeframe @ ";
                break;

            case PeriodType.Month:
                beginMessage += BarsPeriod.Value + "MO Timeframe @ ";
                break;

            case PeriodType.Year:
                beginMessage += BarsPeriod.Value + "Y Timeframe @ ";
                break;

            case PeriodType.Tick:
                beginMessage += BarsPeriod.Value + "Tick Bar @ ";
                break;

            case PeriodType.Range:
                beginMessage += BarsPeriod.Value + "Range Bar @ ";
                break;

            case PeriodType.Volume:
                beginMessage += BarsPeriod.Value + "Volume Bar @ ";
                break;
            }

            // Use this method for calculating your indicator values. Assign a value to each
            // plot below by replacing 'Close[0]' with your own formula.
            if (!_init)
            {
                _init = true;
                int Digits = 0;
                if (TickSize.ToString().StartsWith("1E-"))
                {
                    Digits = Convert.ToInt32(TickSize.ToString().Substring(3));
                }
                else if (TickSize.ToString().IndexOf(".") > 0)
                {
                    Digits = TickSize.ToString().Substring(TickSize.ToString().IndexOf("."), TickSize.ToString().Length - 1).Length - 1;
                }
                _priceFormat = string.Format("F{0}", Digits);

                // Build a larger font size
                largerFont = new Font(ChartControl.Font.Name, fontSize, FontStyle.Bold);
            }

            // Check to see if Alerts are enabled
            if (enableAlert)
            {
                // Step through each one of the lines
                for (j = 0; j < lineInfoArray.Count; j++)
                {
                    LineInfo lineInfo = (LineInfo)lineInfoArray[j];

                    if (Historical || lineInfo.lineTriggered)
                    {
                        continue;
                    }

                    if ((lineInfo.lineGreaterThan && Input[0] >= lineInfo.linePrice - (TickSize * 0.5)) ||
                        (!lineInfo.lineGreaterThan && Input[0] <= lineInfo.linePrice + (TickSize * 0.5)))
                    {
                        lineInfo.lineTriggered = true;

                        Alert(DateTime.Now.Millisecond.ToString(), NinjaTrader.Cbi.Priority.Medium, beginMessage + lineInfo.linePrice.ToString(_priceFormat), Cbi.Core.InstallDir + @"\sounds\" + alertFileName, 0, Color.Yellow, Color.Black);

                        lineInfoArray[j] = lineInfo;
                    }
                }
            }
        }
Example #18
0
        void EWrapper.tickSize(int tickerId, int tickType, int size)
        {
            ShowDebugMessage(tickerId, TickType.getField(tickType), size);

            TickSize?.Invoke(tickerId, tickType, size);
        }
Example #19
0
        protected override void OnStartUp()
        {
            if (ChartControl == null)
            {
                return;
            }

            if (m1 == null)
            {
                m1 = new ToolStripMenuItem("Start from here");
            }
            if (m2 == null)
            {
                m2 = new ToolStripMenuItem("Finish here");
            }
            if (mSeparator == null)
            {
                mSeparator = new ToolStripSeparator();
            }

            m1.Name         = "Start from here";
            m2.Name         = "Finish here";
            m1.Click       += OnStartMenu;
            m2.Click       += OnFinishMenu;
            mSeparator.Name = "MySeparatorName";

            ChartControl.ChartPanel.MouseDown += OnMouseClick;

            if (!ChartControl.ContextMenuStrip.Items.ContainsKey("MySeparatorName"))
            {
                ChartControl.ContextMenuStrip.Items.Insert(0, mSeparator);
            }
            if (!ChartControl.ContextMenuStrip.Items.ContainsKey("Finish here"))
            {
                ChartControl.ContextMenuStrip.Items.Insert(0, m2);
            }
            if (!ChartControl.ContextMenuStrip.Items.ContainsKey("Start from here"))
            {
                ChartControl.ContextMenuStrip.Items.Insert(0, m1);
            }

            for (int i = 0; i < Plots.Length; i++)
            {
                pens[i] = Plots[i].Pen;
                if (showlabels)
                {
                    brushes[i] = new SolidBrush(Plots[i].Pen.Color);
                }
            }

            prices = new [] { price1, price2, price3, price4, price5, price6, price7, price8, price9, price10,
                              price11, price12, price13, price14, price15, price16, price17, price18, price19, price20 };

            Levels = new double[20];

            if (TickSize.ToString("0.#########").Length <= 2)
            {
                fs = "0";
            }
            else
            {
                switch (TickSize.ToString("0.#########").Length)
                {
                case 3:       fs = "0.0";                     break;

                case 4:       fs = "0.00";            break;

                case 5:       fs = "0.000";           break;

                case 6:       fs = "0.0000";          break;

                case 7:       fs = "0.00000";         break;

                default:       fs = "0.000000";        break;
                }
            }
        }
Example #20
0
 void EWrapper.tickSize(int tickerId, int field, int size)
 {
     TickSize?.Invoke(tickerId, field, size);
 }
Example #21
0
 public void tickSize(int tickerId, int field, int size)
 {
     TickSize?.Invoke(new TickSizeMessage(tickerId, field, size));
 }