Beispiel #1
0
        public SerAuxTrend(IStreamReader reader, GraphRecordNumber id, ushort length)
            : base(reader, id, length)
        {
            // assert that the correct record type is instantiated
            Debug.Assert(this.Id == ID);

            // initialize class members from stream
            this.regt    = (TrendlineType)reader.ReadByte();
            this.ordUser = reader.ReadByte();

            //read the nullable double value (ChartNumNillable)
            var b = reader.ReadBytes(4);

            if (b[2] == 0xFF && b[3] == 0xFF)
            {
                this.numIntercept = null;
            }
            else
            {
                this.numIntercept = System.BitConverter.ToDouble(b, 0);
            }

            this.fEquation   = Utils.ByteToBool(reader.ReadByte());
            this.fRSquared   = Utils.ByteToBool(reader.ReadByte());
            this.numForecast = reader.ReadDouble();
            this.numBackcast = reader.ReadDouble();

            // assert that the correct number of bytes has been read from the stream
            Debug.Assert(this.Offset + this.Length == this.Reader.BaseStream.Position);
        }
Beispiel #2
0
 public void AssignProperties(DataItem item, double level, TrendlineType type, DataItem previousItem)
 {
     this.item = item;
     this.level = level;
     this.type = type;
     this.previousHit = previousItem;
 }
Beispiel #3
0
 //public TrendHit()
 //{
 //    Guid = System.Guid.NewGuid();
 //}
 //public TrendHit(Trendline trendline) : this()
 //{
 //    this.Trendline = trendline;
 //}
 public TrendHit(Trendline trendline, DataItem item, double crossPoint, TrendlineType type)
 {
     Guid = System.Guid.NewGuid();
     this.Trendline = trendline;
     this.Item = item;
     this.CrossLevel = crossPoint;
     this.Type = type;
 }
Beispiel #4
0
        public SerAuxTrend(IStreamReader reader, RecordType id, ushort length)
            : base(reader, id, length)
        {
            // assert that the correct record type is instantiated
            Debug.Assert(this.Id == ID);

            // initialize class members from stream
            this.regt    = (TrendlineType)reader.ReadByte();
            this.ordUser = reader.ReadByte();

            //read the nullable double value (ChartNumNillable)
            this.numIntercept = new ChartNumNillable(reader).value;

            this.fEquation   = Utils.ByteToBool(reader.ReadByte());
            this.fRSquared   = Utils.ByteToBool(reader.ReadByte());
            this.numForecast = reader.ReadDouble();
            this.numBackcast = reader.ReadDouble();

            // assert that the correct number of bytes has been read from the stream
            Debug.Assert(this.Offset + this.Length == this.Reader.BaseStream.Position);
        }
Beispiel #5
0
        public void Compare(DataItem item, double level, TrendlineType type, DataItem previousItem)
        {
            /* Zresetuj obiekt przed rozpoczęciem nowych obliczeń. */
            Reset();
            AssignProperties(item, level, type, previousItem);

            this.priceOverBreak = CalculatePriceOverBreak();

            /* Oblicz różnicę w dystansie. Jeżeli świeca leży daleko od linii trendu
             * jej punktacja wynosi 0 i funkcja od razu kończy działanie, żeby nie
             * marnować zasobów.
             * Świece leżące po złej stronie linii trendu otrzymują ocenę ujemną.
             * Świece leżące blisko linii trendu otrzymują ocenę dodatnią. */
            var priceScore = EvaluateScore();

            /* Najpierw sprawdza czy notowanie jest przełamaniem linii trendu
             * (czyli cena zamknięcia powyżej linii oporu lub poniżej linii wsparcia).
             * Jeżeli tak, obliczenia nie są kontynuowane.*/
            AnalyzeBreak(item, level, type);
            if (IsBreak()) return;
        }
Beispiel #6
0
        public double ExtremumEvaluation(TrendlineType type)
        {
            var value = 0d;

            if (type == TrendlineType.Support)
            {
                value = Math.Max(TroughByClose, TroughByLow);
            }
            else if (type == TrendlineType.Resistance)
            {
                value = Math.Max(PeakByClose, PeakByHigh);
            }

            return Math.Max(value, PriceGap);
        }
Beispiel #7
0
 public double ProperValue(TrendlineType type)
 {
     if (type == TrendlineType.Resistance)
     {
         return High;
     }
     else
     {
         return Low;
     }
 }
 public void Compare(DataItem item, double level, TrendlineType type, DataItem previousItem)
 {
 }
Beispiel #9
0
 private void AnalyzeBreak(DataItem item, double level, TrendlineType type)
 {
     /* Sprawdź czy cena zamknięcia leży poniżej linii wsparcia lub powyżej linii oporu. */
     if (type == TrendlineType.Resistance && item.Quotation.Close > level ||
         type == TrendlineType.Support && item.Quotation.Close < level)
     {
         this.trendBreak = new TrendBreak
         {
             Item = item,
             TrendLevel = level
         };
     }
 }
Beispiel #10
0
 /* Covered with unit tests. */
 public double GetHighOrLowPrice(TrendlineType type)
 {
     return (type == TrendlineType.Support) ? Quotation.Low : Quotation.High;
 }
Beispiel #11
0
        public void setNewHit(DataItem item, double level, TrendlineType type)
        {
            TrendHit hit = new TrendHit(this, item, level, type, currentHit, currentBounce);
            TrendBounce bounce = new TrendBounce(this, hit);
            hit.BounceToNextHit = bounce;

            //Close current hit and bounce.
            if (currentHit != null)
            {
                currentHit.NextHit = hit;
                this.Hits.Add(currentHit);
            }
            if (currentBounce != null)
            {
                currentBounce.EndHit = hit;
                this.Bounces.Add(currentBounce);
            }

            currentHit = hit;
            currentBounce = bounce;

            //Calculate points.
            //hit.Calculate();
            //bounce.Calculate();
        }
Beispiel #12
0
 public TrendHit(Trendline trendline, DataItem item, double crossPoint, TrendlineType type, TrendHit prevHit, TrendBounce prevBounce)
     : this(trendline, item, crossPoint, type)
 {
     this.PreviousHit = prevHit;
     this.BounceFromPreviousHit = prevBounce;
 }
Beispiel #13
0
        public bool IsTrendlineBroken(double level, TrendlineType type)
        {
            if (type == TrendlineType.Resistance)
            {
                return Quotation.Close > level;
            }
            else if (type == TrendlineType.Support)
            {
                return Quotation.Close < level;
            }

            return false;
        }
Beispiel #14
0
        public bool IsExtremum(TrendlineType type)
        {
            if (this.Price != null)
            {
                return this.Price.IsExtremum(type);
            }

            return false;
        }
Beispiel #15
0
 /* Covered with unit tests. */
 public double GetOpenOrClosePrice(TrendlineType type)
 {
     return (type == TrendlineType.Support) ? Math.Min(Quotation.Open, Quotation.Close) : Math.Max(Quotation.Open, Quotation.Close);
 }
Beispiel #16
0
 public bool IsExtremum(TrendlineType type)
 {
     return type == TrendlineType.Resistance ? IsPeak() : IsTrough();
 }
Beispiel #17
0
 public bool IsMatch(TrendlineType type)
 {
     if (type == TrendlineType.Resistance)
     {
         return (PeakByClose > 0 || PeakByHigh > 0);
     }
     else if (type == TrendlineType.Support)
     {
         return (TroughByClose > 0 || TroughByLow > 0);
     }
     else
     {
         return true;
     }
 }
Beispiel #18
0
 /* Covered with unit tests. */
 public double GetClosestDistance(TrendlineType type, double level)
 {
     double closeDistance = Math.Abs(GetOpenOrClosePrice(type) - level);
     double exDistance = Math.Abs(GetHighOrLowPrice(type) - level);
     return Math.Min(closeDistance, exDistance);
 }