private double GetNearestPriceLevel(double currentPrice, CrossDirection direction)
        {
            double result   = Double.MaxValue;
            double tempDiff = 0.0;

            foreach (double priceLevel in priceHedgeLevels)
            {
                tempDiff = Math.Abs(currentPrice - priceLevel);

                if (direction == CrossDirection.UP)
                {
                    if (tempDiff < result && priceLevel >= guidePriceForCrossing)
                    {
                        result = priceLevel;
                    }
                }
                else
                {
                    if (tempDiff < result && priceLevel <= guidePriceForCrossing)
                    {
                        result = priceLevel;
                    }
                }
            }

            return(result);
        }
        private bool OnInput()
        {
            CrossDirection dir  = this.controller.GetDirection();
            CrossDirection menu = this.controller.GetMenuDirection();

            if (dir != CrossDirection.None)
            {
                if (this.capability == Capability.Both || this.capability == Capability.Color)
                {
                    this.image.ChangeColor(dir);
                    return(true);
                }
            }
            else if (menu != CrossDirection.None)
            {
                if (this.capability == Capability.Both || this.capability == Capability.Movement)
                {
                    this.rect.ChangePosition(menu);
                    return(true);
                }
            }
            else if (this.controller.Validate() == true)
            {
                this.onValidate.Invoke();
                return(true);
            }
            else if (this.controller.Cancel() == true)
            {
                this.onCancel.Invoke();
                return(true);
            }
            return(false);
        }
        public static void ChangePosition(this RectTransform rect, CrossDirection direction)
        {
            Vector3 currentPos = rect.anchoredPosition;

            switch (direction)
            {
            case CrossDirection.Up:
                currentPos.y         += 1F;
                rect.anchoredPosition = currentPos;
                break;

            case CrossDirection.Down:
                currentPos.y         -= 1F;
                rect.anchoredPosition = currentPos;
                break;

            case CrossDirection.Left:
                currentPos.x         -= 1F;
                rect.anchoredPosition = currentPos;
                break;

            case CrossDirection.Right:
                currentPos.x         += 1F;
                rect.anchoredPosition = currentPos;
                break;
            }
        }
 private void UpdateDirectionAnim(UnityEngine.Vector3 touchpos, UnityEngine.Vector3 lastpos, bool is_damaged)
 {
     if (m_CurDirectionAnimInfo == null)
     {
         CrossDirection cur_direction = GetDirection(touchpos, lastpos);
         if (m_DirectionAnims.TryGetValue(cur_direction, out m_CurDirectionAnimInfo))
         {
             m_CurDirectionAnimInfo.Start();
         }
     }
     else
     {
         if (m_CurDirectionAnimInfo.IsCrossOver())
         {
             m_CurDirectionAnimInfo.Stop();
             m_CurDirectionAnimInfo = null;
         }
     }
 }
        public static void ChangeColor(this Image image, CrossDirection direction)
        {
            Color current = image.color;

            switch (direction)
            {
            case CrossDirection.Up:
                image.color = new Color(Math.Min(1F, current.r + 0.02F), current.g, current.b);
                break;

            case CrossDirection.Down:
                image.color = new Color(Math.Max(0F, current.r - 0.02F), current.g, current.b);
                break;

            case CrossDirection.Right:
                image.color = new Color(current.r, Math.Min(1F, current.g + 0.02F), current.b);
                break;

            case CrossDirection.Left:
                image.color = new Color(current.r, Math.Max(0F, current.g - 0.02F), current.b);
                break;
            }
        }
        private CrossDirection CrossDirectionFromStr(string str)
        {
            CrossDirection result = CrossDirection.kUnknown;

            switch (str)
            {
            case "TopLeft":
                result = CrossDirection.kTopLeft;
                break;

            case "TopRight":
                result = CrossDirection.kTopRight;
                break;

            case "BottomLeft":
                result = CrossDirection.kBottomLeft;
                break;

            case "BottomRight":
                result = CrossDirection.kBottomRight;
                break;
            }
            return(result);
        }
        public ICustomData <double, bool> CreateOrUpdateCross(HistoricalData currentData, ICustomData <double, double> a, ReferenceSeries b, CrossDirection direction)
        {
            ICustomData <double, bool> result;
            string name       = direction == CrossDirection.Down ? a.Name + CrossPartialName + b.Name : b.Name + CrossPartialName + a.Name;
            int    findResult = CrossDataSeries.FindIndex(x => x.Name == name);

            if (findResult != -1)
            {
                CrossDataSeries[findResult].GetValue(b.Value);
                result = CrossDataSeries[findResult];
            }
            else
            {
                result = CreateAndFillCross(currentData, a, b, direction);
            }

            return(result);
        }
        private ICustomData <double, bool> CreateAndFillCross(HistoricalData currentData, ICustomData <double, double> a, ReferenceSeries b, CrossDirection direction)
        {
            CrossDataSeries.Insert(0, new CROSS(a, b.Name, direction));
            (CrossDataSeries[0] as DataSeries <double, bool>).GetHistoricalData(currentData);
            FillCross(currentData, a);
            CrossDataSeries[0].GetValue(b.Value);

            return(CrossDataSeries[0]);
        }
Beispiel #9
0
 public CROSS(ICustomData <double, double> series, string refName, CrossDirection direction)
     : base(direction == CrossDirection.Down? series.Name + "CROSS" + refName: refName + "CROSS" + series.Name)
 {
     Series    = series;
     Direction = direction;
 }