Ejemplo n.º 1
0
        /// <summary>
        /// Computes the next value of this indicator from the given state
        /// </summary>
        /// <param name="input">The input given to the indicator</param>
        /// <returns> A new value for this indicator </returns>
        protected override decimal ComputeNextValue(IBaseDataBar input)
        {
            if (!IsReady)
            {
                Open.Update(input.Time, (input.Open + input.Close) / 2);
                Close.Update(input.Time, (input.Open + input.High + input.Low + input.Close) / 4);
                High.Update(input.Time, input.High);
                Low.Update(input.Time, input.Low);
            }
            else
            {
                Open.Update(input.Time, (Open + Close) / 2);
                Close.Update(input.Time, (input.Open + input.High + input.Low + input.Close) / 4);
                High.Update(input.Time, Math.Max(input.High, Math.Max(Open, Close)));
                Low.Update(input.Time, Math.Min(input.Low, Math.Min(Open, Close)));
            }

            var volume = 0.0m;

            if (input is TradeBar)
            {
                volume = ((TradeBar)input).Volume;
            }
            else if (input is RenkoBar)
            {
                volume = ((RenkoBar)input).Volume;
            }
            Volume.Update(input.Time, volume);

            return(Close);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            int pace = 0;
            int i    = 0;

            while (i < CurrentBar)
            {
                TimeSpan ts = Time[0] - Time[i];
                if (ts.TotalSeconds < period)
                {
                    pace += Bars.Period.Value;
                }
                else
                {
                    break;
                }
                ++i;
            }
            if (pace >= threshold)
            {
                High.Set(pace);
            }
            else
            {
                Normal.Set(pace);
            }
        }
Ejemplo n.º 3
0
        private async void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            try
            {
                dayPosition = await apiProcessor.GetDayPosition();

                if (dayPosition.data.positions.Any())
                {
                    double mtmVal = GetMTMValue(dayPosition);
                    SetHighLowMTM(mtmVal);
                    OnMTMChanged?.Invoke(new MTMDetail {
                        MTM = mtmVal.ToString(), High = High.ToString(), Low = Low.ToString()
                    });
                    if ((mtmVal >= TargerMTM || mtmVal <= MaxLossMTM) && !timerStop)
                    {
                        TimerStop();
                        apiProcessor.ExitOrderRetryCount = 3;
                        await apiProcessor.ExitAllOrders();

                        OnMTMTargetHit("Target hit");
                    }
                }
            }
            catch (Exception ex)
            {
                OnError?.Invoke(ex.Message);
            }
        }
Ejemplo n.º 4
0
 public override int GetHashCode()
 {
     unchecked
     {
         return((High.GetHashCode() * 397) ^ Low.GetHashCode());
     }
 }
Ejemplo n.º 5
0
        public IEnumerable <IDataPoint <TItem> > GenerateDataPoints(IEnumerable <TItem> items)
        {
            var data = items
                       .Select(d => new ListPoint <TItem>
            {
                X = XValue.Invoke(d),
                Y = new List <decimal?>
                {
                    Open.Invoke(d),
                    High.Invoke(d),
                    Low.Invoke(d),
                    Close.Invoke(d)
                },
                Items = new List <TItem> {
                    d
                }
            });

            if (OrderBy != null)
            {
                data = data.OrderBy(OrderBy);
            }
            else if (OrderByDescending != null)
            {
                data = data.OrderByDescending(OrderByDescending);
            }

            return(UpdateDataPoints(data, DataPointMutator));
        }
Ejemplo n.º 6
0
        /// <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 :)
                if (Date != null)
                {
                    hashCode = hashCode * 59 + Date.GetHashCode();
                }
                if (Symbol != null)
                {
                    hashCode = hashCode * 59 + Symbol.GetHashCode();
                }
                if (Exchange != null)
                {
                    hashCode = hashCode * 59 + Exchange.GetHashCode();
                }

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

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

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

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

                hashCode = hashCode * 59 + Volume.GetHashCode();
                return(hashCode);
            }
        }
Ejemplo n.º 7
0
 /// <summary>Returns a string that represents the current object.</summary>
 /// <returns>A string that represents the current object.</returns>
 /// <filterpriority>2</filterpriority>
 public override string ToString()
 {
     return($"O: {Open.SmartRounding()} " +
            $"H: {High.SmartRounding()} " +
            $"L: {Low.SmartRounding()} " +
            $"C: {Close.SmartRounding()}");
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Serialize to a JSON object
        /// </summary>
        public new void SerializeJson(Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true)
        {
            if (includeStartObject)
            {
                writer.WriteStartObject();
            }
            ((fhirCsR4.Models.Element) this).SerializeJson(writer, options, false);

            if (Low != null)
            {
                writer.WritePropertyName("low");
                Low.SerializeJson(writer, options);
            }

            if (High != null)
            {
                writer.WritePropertyName("high");
                High.SerializeJson(writer, options);
            }

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
        public override double Get(double x, double y, double z, double w)
        {
            double value     = Source.Get(x, y, z, w);
            double falloff   = Falloff.Get(x, y, z, w);
            double threshold = Threshold.Get(x, y, z, w);

            if (falloff > 0.0)
            {
                if (value < (threshold - falloff)) // Lies outside of falloff area below threshold, return first source
                {
                    return(Low.Get(x, y, z, w));
                }
                if (value > (threshold + falloff)) // Lies outside of falloff area above threshold, return second source
                {
                    return(High.Get(x, y, z, w));
                }

                // Lies within falloff area.
                double lower = threshold - falloff;
                double upper = threshold + falloff;
                double blend = Utilities.QuinticBlend((value - lower) / (upper - lower));
                return(Utilities.Lerp(blend, Low.Get(x, y, z, w), High.Get(x, y, z, w)));
            }

            return(value < threshold?Low.Get(x, y, z, w) : High.Get(x, y, z, w));
        }
Ejemplo n.º 10
0
        void ChartControl_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            if (!_fDragging)
            {
                return;
            }

            _iBarEnd = BarFromX((int)e.GetPosition(ChartPanel).X);

            if (!High.IsValidDataPoint(_iBarEnd) || !Low.IsValidDataPoint(_iBarEnd))
            {
                return;
            }

            if (_fDrawAB)
            {
                _priceEnd = swingDir > 0 ? High[_iBarEnd] : Low[_iBarEnd];
                lineAB    = UDrawLine("dDwABLine");
            }
            else
            {
                _priceEnd = swingDir < 0 ? High[_iBarEnd] : Low[_iBarEnd];
                lineBC    = UDrawLine("dDwBCLine");
            }

            ChartControl.InvalidateVisual();
        }
Ejemplo n.º 11
0
 /// <summary>
 /// >=1 means added
 /// 0 means last element updated
 /// -1 means nothing changed
 /// </summary>
 /// <param name="t"></param>
 /// <param name="o"></param>
 /// <param name="h"></param>
 /// <param name="l"></param>
 /// <param name="c"></param>
 /// <param name="v"></param>
 /// <param name="isTriggerDataAdded"></param>
 /// <returns></returns>
 public int AddUpdate(long t, double o, double h, double l, double c, double v, bool isTriggerDataAdded = false)
 {
     if (this.Count == 0 || t > this.LastTime)
     {
         Open.Add(o);
         High.Add(h);
         Low.Add(l);
         Close.Add(c);
         Volume.Add(v);
         Time.Add(t);
         if (isTriggerDataAdded)
         {
             OnDataAddedOrUpdated?.Invoke(this, this, 1);
         }
         return(1);
     }
     else if (t == this.LastTime)
     {
         Open[this.Count - 1]   = o;
         High[this.Count - 1]   = h;
         Low[this.Count - 1]    = l;
         Close[this.Count - 1]  = c;
         Volume[this.Count - 1] = v;
         if (isTriggerDataAdded)
         {
             OnDataAddedOrUpdated?.Invoke(this, this, 0);
         }
         return(0);
     }
     return(-1);
 }
Ejemplo n.º 12
0
            public override IDeepCopyable CopyTo(IDeepCopyable other)
            {
                var dest = other as ObservationReferenceRangeComponent;

                if (dest != null)
                {
                    base.CopyTo(dest);
                    if (Low != null)
                    {
                        dest.Low = (Hl7.Fhir.Model.SimpleQuantity)Low.DeepCopy();
                    }
                    if (High != null)
                    {
                        dest.High = (Hl7.Fhir.Model.SimpleQuantity)High.DeepCopy();
                    }
                    if (Meaning != null)
                    {
                        dest.Meaning = (Hl7.Fhir.Model.CodeableConcept)Meaning.DeepCopy();
                    }
                    if (Age != null)
                    {
                        dest.Age = (Hl7.Fhir.Model.Range)Age.DeepCopy();
                    }
                    if (TextElement != null)
                    {
                        dest.TextElement = (Hl7.Fhir.Model.FhirString)TextElement.DeepCopy();
                    }
                    return(dest);
                }
                else
                {
                    throw new ArgumentException("Can only copy to an object of the same type", "other");
                }
            }
Ejemplo n.º 13
0
 /// <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 :)
         if (Low != null)
         {
             hashCode = hashCode * 59 + Low.GetHashCode();
         }
         if (High != null)
         {
             hashCode = hashCode * 59 + High.GetHashCode();
         }
         if (Morning != null)
         {
             hashCode = hashCode * 59 + Morning.GetHashCode();
         }
         if (Day != null)
         {
             hashCode = hashCode * 59 + Day.GetHashCode();
         }
         if (Evening != null)
         {
             hashCode = hashCode * 59 + Evening.GetHashCode();
         }
         if (Night != null)
         {
             hashCode = hashCode * 59 + Night.GetHashCode();
         }
         return(hashCode);
     }
 }
Ejemplo n.º 14
0
        protected override void OnBarUpdate()
        {
            if (BarsArray == null || BarsArray.Length == 0)
            {
                return;
            }

            if (supportsRange)
            {
                double high        = High.GetValueAt(Bars.Count - 1 - (Calculate == NinjaTrader.NinjaScript.Calculate.OnBarClose ? 1 : 0));
                double low         = Low.GetValueAt(Bars.Count - 1 - (Calculate == NinjaTrader.NinjaScript.Calculate.OnBarClose ? 1 : 0));
                double close       = Close.GetValueAt(Bars.Count - 1 - (Calculate == NinjaTrader.NinjaScript.Calculate.OnBarClose ? 1 : 0));
                int    actualRange = (int)Math.Round(Math.Max(close - low, high - close) / Bars.Instrument.MasterInstrument.TickSize);
                double rangeCount  = CountDown ? (isAdvancedType ? BarsPeriod.BaseBarsPeriodValue : BarsPeriod.Value) - actualRange : actualRange;

                rangeString = CountDown ? string.Format(NinjaTrader.Custom.Resource.RangeCounterRemaing, rangeCount) :
                              string.Format(NinjaTrader.Custom.Resource.RangerCounterCount, rangeCount);
            }
            else
            {
                rangeString = NinjaTrader.Custom.Resource.RangeCounterBarError;
            }

            Draw.TextFixed(this, "NinjaScriptInfo", rangeString, TextPosition.BottomRight);
        }
Ejemplo n.º 15
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (Timestamp.Length != 0)
            {
                hash ^= Timestamp.GetHashCode();
            }
            if (Open != 0)
            {
                hash ^= Open.GetHashCode();
            }
            if (Close != 0)
            {
                hash ^= Close.GetHashCode();
            }
            if (High != 0)
            {
                hash ^= High.GetHashCode();
            }
            if (Low != 0)
            {
                hash ^= Low.GetHashCode();
            }
            return(hash);
        }
Ejemplo n.º 16
0
            // --- External Behaviours:

            /// <summary>
            /// Determines quintile group of individual with given population index.
            /// </summary>
            public Group FindQuintile(int populationIndex)
            {
                if (Median.IsMember(populationIndex))
                {
                    return(Group.median);
                }                                                                    // NOTE: returns Median for 0-index 0-population case
                else
                {
                    if (Top.IsMember(populationIndex))
                    {
                        return(Group.top);
                    }
                    else
                    {
                        if (High.IsMember(populationIndex))
                        {
                            return(Group.high);
                        }
                        else
                        {
                            if (Low.IsMember(populationIndex))
                            {
                                return(Group.low);
                            }
                            else
                            {
                                return(Group.bottom);
                            }
                        }
                    }
                }
            }
Ejemplo n.º 17
0
        public override string ToString()
        {
            var date  = OpenTime.ToDefaultString();
            var chars = 8;
            var vol   = Volume > 0 ? $" [v:{Volume.ToString().PadLeft(chars)}]" : "";

            return($"{date} o:{Open.ToString().PadRight(chars, '0')} h:{High.ToString().PadRight(chars, '0')} l:{Low.ToString().PadRight(chars, '0')} c:{Close.ToString().PadRight(chars, '0')}{vol}");
        }
Ejemplo n.º 18
0
        public override string ToString()
        {
            var array = new string[] { Date.ToString(), Open.ToString(),
                High.ToString(), Low.ToString(),
                Close.ToString(), AdjClose.ToString(), Volume.ToString() };

            return(string.Join(",", array));
        }
Ejemplo n.º 19
0
        public override int GetHashCode()
        {
            int hash = 13;

            hash = (hash * 7) + High.GetHashCode();
            hash = (hash * 7) + Low.GetHashCode();
            return(hash);
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Resets this indicator to its initial state
 /// </summary>
 public override void Reset()
 {
     Open.Reset();
     High.Reset();
     Low.Reset();
     Close.Reset();
     base.Reset();
 }
Ejemplo n.º 21
0
        /// <summary>
        /// Gets a copy of this data from a date, to a date.
        /// </summary>
        /// <param name="start">Date to start from</param>
        /// <param name="end">Date to end at</param>
        /// <returns>New object with the data from the requested dates</returns>
        public TickerData SubSet(DateTime start, DateTime end)
        {
            TickerData copyData = new TickerData(TickerAndExchange);

            int copyStartIndex = -1;
            int copyEndIndex   = -1;

            for (int i = 0; i < Dates.Count; i++)
            {
                if (copyStartIndex == -1 && Dates[i] >= start)
                {
                    copyStartIndex = i;
                }
                if (copyEndIndex == -1 && Dates[i] >= end)
                {
                    copyEndIndex = i;
                }

                if (copyStartIndex > -1 && copyEndIndex > -1)
                {
                    break;
                }
            }

            if (copyStartIndex != -1)
            {
                if (copyEndIndex == -1 && end > Dates.Last())
                {
                    copyEndIndex = Dates.Count - 1;
                }

                int amountToCopy = (copyEndIndex - copyStartIndex) + 1;
                copyData.Dates.AddRange(Dates.GetRange(copyStartIndex, amountToCopy));
                copyData.Open.AddRange(Open.GetRange(copyStartIndex, amountToCopy));
                copyData.Close.AddRange(Close.GetRange(copyStartIndex, amountToCopy));
                copyData.High.AddRange(High.GetRange(copyStartIndex, amountToCopy));
                copyData.Low.AddRange(Low.GetRange(copyStartIndex, amountToCopy));
                copyData.Volume.AddRange(Volume.GetRange(copyStartIndex, amountToCopy));

                // Extras
                copyData.Typical.AddRange(Typical.GetRange(copyStartIndex, amountToCopy));
                copyData.Median.AddRange(Median.GetRange(copyStartIndex, amountToCopy));
                copyData.HigherTimeframeTrend.AddRange(HigherTimeframeTrend.GetRange(copyStartIndex, amountToCopy));

                for (int i = 0; i < HigherTimeframeValueStrings.Length; i++)
                {
                    string key = HigherTimeframeValueStrings[i];
                    copyData.HigherTimeframeValues[key].AddRange(HigherTimeframeValues[key].GetRange(copyStartIndex, amountToCopy));
                }

                copyData.Start   = copyData.Dates[0];
                copyData.End     = copyData.Dates[copyData.Dates.Count - 1];
                copyData.NumBars = copyData.Dates.Count;
                copyData.SaveDates();
            }

            return(copyData);
        }
Ejemplo n.º 22
0
        public override string ToString()
        {
            var chars   = 8;
            var padChar = ' ';
            //var padChar = '0';
            var vol = Volume > 0 ? $" [v:{Volume.ToString().PadLeft(chars)}]" : "";

            return($"o:{Open.ToString().PadRight(chars, padChar)} h:{High.ToString().PadRight(chars, padChar)} l:{Low.ToString().PadRight(chars, padChar)} c:{Close.ToString().PadRight(chars, padChar)}{vol}");
        }
Ejemplo n.º 23
0
        // public double OpenInterest { get; set; }

        /// <summary>
        /// override
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return(TimeStamp.ToString() + ',' +
                   Open.ToString() + ',' +
                   High.ToString() + ',' +
                   Low.ToString() + ',' +
                   Last.ToString() + ',' +
                   Volume.ToString());
        }
Ejemplo n.º 24
0
 public L_High(int id, High v_High) : base(0, 1, id)
 {
     this.v_High = v_High;
     output[0]   = true;
     for (int i = 0; i < 0; i++)
     {
         this.input[i] = false;
     }
 }
Ejemplo n.º 25
0
 public override int GetHashCode()
 {
     return(Time.GetHashCode() ^
            Open.GetHashCode() ^
            Close.GetHashCode() ^
            High.GetHashCode() ^
            Low.GetHashCode() ^
            Volume.GetHashCode());
 }
 public void WriteXml(XmlWriter writer)
 {
     writer.WriteAttributeString("perLowLimit", PercentLowLimit.ToString(CultureInfo.InvariantCulture));
     writer.WriteAttributeString("perHighLimit", PercentHighLimit.ToString(CultureInfo.InvariantCulture));
     writer.WriteAttributeString("perOutSpec", PercentOutSpec.ToString(CultureInfo.InvariantCulture));
     writer.WriteAttributeString("low", Low.ToString(CultureInfo.InvariantCulture));
     writer.WriteAttributeString("high", High.ToString(CultureInfo.InvariantCulture));
     writer.WriteAttributeString("range", Range.ToString(CultureInfo.InvariantCulture));
     writer.WriteAttributeString("sigmaLevel", SigmaLevel);
 }
Ejemplo n.º 27
0
Archivo: Form1.cs Proyecto: tphuy/Snake
 private void newgame_Click(object sender, EventArgs e)
 {
     level1.Show();
     level2.Show();
     newgame.Hide();
     High.Hide();
     Exit_btn.Hide();
     btn_About.Hide();
     lbSnake.Hide();
 }
Ejemplo n.º 28
0
 /// <inheritdoc />
 public MovingRange(IIndicator <IPriceHL> source, int period)
 {
     Source         = source;
     Period         = period;
     High           = Source.Transform(p => p.High);
     Low            = Source.Transform(p => p.Low);
     Hhv            = High.HighestValue(Period);
     Llv            = Low.LowestValue(Period);
     Source.Update += SourceOnUpdate;
 }
Ejemplo n.º 29
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = High.GetHashCode();
         hashCode = (hashCode * 397) ^ Low.GetHashCode();
         hashCode = (hashCode * 397) ^ Average.GetHashCode();
         return(hashCode);
     }
 }
Ejemplo n.º 30
0
        public string ToString(int decimalPlaces)
        {
            var date = OpenTime.ToDefaultString();

            var padChar = ' ';
            //var padChar = '0';
            var vol = Volume > 0 ? $" [v:{Volume.ToString().PadLeft(decimalPlaces)}]" : "";

            return($"{date} o:{Open.ToString().PadRight(decimalPlaces, padChar)} h:{High.ToString().PadRight(decimalPlaces, padChar)} l:{Low.ToString().PadRight(decimalPlaces, padChar)} c:{Close.ToString().PadRight(decimalPlaces, padChar)}{vol}");
        }
Ejemplo n.º 31
0
 public JsonMtGOX()
 {
     high = new High();
     low = new Low();
     avg = new Avg();
     vwap = new Vwap();
     vol = new Vol();
     lastlocal = new LastLocal();
     lastorig = new LastOrig();
     lastall = new LastAll();
     last = new Last();
     buy = new Buy();
     sell = new Sell();
     rootobject = new RootObject();
     returnObject = new Return();
 }