Пример #1
0
        public override bool OnIntervalClose()
        {
            if (Count == 1)
            {
                highestHigh = Bars.High[0];
                lowestLow   = Bars.Low[0];
            }
            else
            {
                // this goes higher while..
                highestHigh = Math.Max(highestHigh, Bars.High[0]);

                // lowest goes lower
                lowestLow = Math.Min(Bars.Low[0], lowestLow);

                // when the high rises high enough it becomes a new potential pivot.
                if (Bars.High[0] > Formula.Highest(Bars.High, 3, 1) &&
                    Bars.High[0] - lowestLow > minimumMove)
                {
                    highestHigh = Bars.High[0];
                    lowestLow   = Bars.Low[0];
                }

                // when low drops below highest far enough, it's a new pivot
                if (this[0] != highestHigh && highestHigh - Bars.Low[0] > minimumMove)
                {
                    this[0] = highestHigh;
                    pivots.Add((int)this[0]);
                }
            }
            return(true);
        }
        public void it_adds()
        {
            var expected = 4;
            var actual   = Integers.Add(2, 2);

            actual.Should().Be(expected);
        }
Пример #3
0
        //methods
        public void InputNumbers()
        {
            //take inputs until non-number input given
            bool properInput = true;

            while (properInput)
            {
                double input;
                Console.WriteLine("Write whole number or decimal. Non-number input exits input.");
                if (double.TryParse(Console.ReadLine(), out input))
                {
                    //Check for whole number
                    if ((input % 1) == 0)
                    {
                        //add to int list
                        Integers.Add(Convert.ToInt32(input));
                    }
                    else
                    {
                        //add to double list
                        Doubles.Add(input);
                    }
                }
                else
                {
                    properInput = false;
                }
            }
        }
Пример #4
0
        protected override void VisitChildren(PtNode node)
        {
            var children = reflect.Or(node).ToList();

            if (children.Count == 0)
            {
                for (var i = node.Span.Start; i < node.Span.Next; ++i)
                {
                    Set.Add(i);
                }
                if (node is PtArguments ||
                    node is PtParameters ||
                    node is PtLambdaParameters ||
                    node is PtLambdaTypeParameters ||
                    node is PtFields ||
                    node is PtMethods ||
                    node is PtUnit)
                {
                }
                else
                {
                    var text = node.Span.ToString();
                    Debug.Assert(!string.IsNullOrWhiteSpace(text));
                    Debug.Assert(text != "(-)");
                    //System.Console.WriteLine($"{text}");
                }
            }

            base.VisitChildren(node);
        }
Пример #5
0
        public override bool OnIntervalClose()
        {
            int newCode = lrGraph.Code;

//			switch( newCode) {
//				case 1: newCode = 0; break;
//				case 6: newCode = 7; break;
//			}
            stretch[0] = newCode;
            if (newCode != lastCode)
            {
                // Got a code change, close out the previous one.
                if (lastCodes.Count > 2)
                {
                    int       combinedCode = lastCodes[1] * 8 + lastCodes[0];
                    CodeStats codeStats;
                    if (codes.TryGetValue(combinedCode, out codeStats))
                    {
                        codeStats.Count++;
                        codeStats.CountBars  += (Bars.CurrentBar - lastBar);
                        codeStats.ProfitLoss += (Bars.Close[0] - lastPrices[0]);
                        codes[combinedCode]   = codeStats;
                    }
                    else
                    {
                        codeStats.Count      = 1;
                        codeStats.CountBars  = 1;
                        codeStats.ProfitLoss = 0;
                        codes[combinedCode]  = codeStats;
                    }
                }
                // Alright start the new code.
                lastCodes.Add(newCode);
                lastPrices.Add(Bars.Close[0]);
                if (lastCodes.Count > 2)
                {
                    int combinedCode = lastCodes[1] * 8 + lastCodes[0];
                    TradeDecision(combinedCode);
                }
                lastBar  = Bars.CurrentBar;
                lastCode = newCode;
            }
            else
            {
            }
//			switch( lrGraph.Code) {
//				case 0: TradeSignal.GoShort(); break;
//				case 1: TradeSignal.GoShort(); break;
//				case 2: TradeSignal.GoShort(); break;
//				case 3: TradeSignal.GoShort(); break;
//				case 4: TradeSignal.GoLong(); break;
//				case 5: TradeSignal.GoLong(); break;
//				case 6: TradeSignal.GoLong(); break;
//				case 7: TradeSignal.GoLong(); break;
//			}
            return(true);
        }
Пример #6
0
 private void BeforeIntervalClose()
 {
     if (price.BarCount > 1 && avgPrice.Count > 1)
     {
         int currPrice = (int)(price[0] - avgPrice[0]);
         int lastPrice = (int)(price[1] - avgPrice[1]);
         int change    = currPrice - lastPrice;
         if (IsTrace)
         {
             Log.Trace(Name + ": price[0]=" + price[0] + ",avgPrice[0]=" + avgPrice[0] + ",price[1]=" + price[1] + ",avgPrice[1]=" + avgPrice[1]);
         }
         if (change > 0)
         {
             gain.Add(change);
             loss.Add(0);
             Log.Debug("gain.Add(" + change + ")");
             Log.Debug("loss.Add(0)");
         }
         else
         {
             gain.Add(0);
             loss.Add(-change);
             Log.Debug("gain.Add(0)");
             Log.Debug("loss.Add(" + (-change) + ")");
         }
     }
     else
     {
         gain.Add(0);
         loss.Add(0);
         if (IsTrace)
         {
             Log.Trace("gain.Add(0)");
         }
         if (IsTrace)
         {
             Log.Trace("loss.Add(0)");
         }
     }
 }
Пример #7
0
 private void CalcFTT(Bars bars)
 {
     if (highMaxVolume.Count == 0)
     {
         highMaxVolume.Add(0);
     }
     else
     {
         highMaxVolume.Add(highMaxVolume[0]);
     }
     if (lowMaxVolume.Count == 0)
     {
         lowMaxVolume.Add(0);
     }
     else
     {
         lowMaxVolume.Add(lowMaxVolume[0]);
     }
     if (bars.High[0] > fttHighestHigh && bars.High[0] > bars.High[1])
     {
         if (bars.Volume[0] > highMaxVolume[0])
         {
             highMaxVolume[0] = bars.Volume[0];
         }
         fttHighestHigh = bars.High[0];
     }
     if (bars.Low[0] < fttLowestLow && bars.Low[0] < bars.Low[1])
     {
         if (bars.Volume[0] > lowMaxVolume[0])
         {
             lowMaxVolume[0] = bars.Volume[0];
             log.Debug("Low Max Volume Set to " + lowMaxVolume[0]);
         }
         fttLowestLow = bars.Low[0];
     }
 }
Пример #8
0
        SimEvents StorePutter(Store <int> store, int putCount, int timeout)
        {
            Debug.Assert(putCount >= 0);
            Debug.Assert(timeout >= 0);
            for (var i = 0; i < putCount; ++i)
            {
                Integers.Add(i);
                yield return(store.Put(i));

                if (timeout > 0)
                {
                    yield return(Env.Timeout(timeout));
                }
            }
        }
Пример #9
0
        /// <summary>
        /// Initializes this instance, registers all Integers and Doubles
        /// </summary>
        protected void Init()
        {
            var t = GetType();

            if (MetricsExtensions.CachedMetricsDefinitions.ContainsKey(t.FullName))
            {
                MetricsExtensions.CachedMetricsDefinitions[t.FullName].SetTo(this);
                return;
            }



            PropertyInfo[] props = t.GetProperties(BindingFlags.Instance | BindingFlags.Public);
            props = props.ToList().OrderBy(x => x.Name).ToArray();

            foreach (var p in props)
            {
                if (p.hasAttribute(imbAttributeName.measure_excludeFromMetrics))
                {
                    IgnoreComputations.Add(p);
                    IgnoreComputationsDict.Add(p.Name, p);
                    continue;
                }

                if (p.GetIndexParameters().Length == 0)
                {
                    if (p.PropertyType == typeof(Int32))
                    {
                        Integers.Add(p);
                        IntegersDict.Add(p.Name, p);
                    }
                    else if (p.PropertyType == typeof(Double))
                    {
                        Doubles.Add(p);
                        DoublesDict.Add(p.Name, p);
                    }
                    else if (p.PropertyType == typeof(Decimal))
                    {
                        Decimals.Add(p);
                        DecimalsDict.Add(p.Name, p);
                    }
                }
            }

            MetricsExtensions.StoreMetricsDefinition(this);
        }
Пример #10
0
        public void CheckForConfirmedPivot()
        {
            if (drawHigh && Bars.Low[0] <= lastHighPrice - threshold)
            {
                if (zagBars.Count == 0 || lastHighBar > zagBars[0])
                {
                    zigBars.Add(lastHighBar);
                    zigHighs.Add(lastHighPrice);
                    drawHigh = false;
                    if (zagBars.Count > 0)
                    {
                        Chart.DrawLine(Drawing.Color, zagBars[0], lastLowPrice,
                                       zigBars[0], lastHighPrice, LineStyle.Solid);
//						DrawDownTrend();
//						DrawHorizontal(lastHighPrice-100);
                        LogNewHigh();
                        lastLowPrice = int.MaxValue;
                    }
                }
            }
            else if (!drawHigh && Bars.High[0] >= lastLowPrice + threshold)
            {
                if (zigBars.Count == 0 || lastLowBar > zigBars[0])
                {
                    zagBars.Add(lastLowBar);
                    zagLows.Add(lastLowPrice);
                    drawHigh = true;
                    if (zigBars.Count > 0)
                    {
                        Chart.DrawLine(Drawing.Color, zagBars[0], lastLowPrice,
                                       zigBars[0], lastHighPrice, LineStyle.Solid);
//						DrawUpTrend();
//						DrawHorizontal(lastLowPrice+100);
                        LogNewLow();
                        lastHighPrice = 0;
                    }
                }
            }
        }
Пример #11
0
        public override bool OnIntervalClose()
        {
            double currLow = Bars.Low[0];

            if (lowest == 0)
            {
                lowest = currLow;
            }
            else
            {
                if (currLow < lowest)
                {
                    lowest = currLow;
                }
            }
            // DO NOT DELETE : Turn to hidden instead if necessary.
            this[0] = lowest;

            pivot    = 0;
            pivotBar = 0;
            for (int mainLoop = rightStrength; mainLoop < length; mainLoop++)
            {
                pivotPassed = true;
                leftPassed  = true;
                pivotHigh   = Bars.High[mainLoop] + 1;

                for (int i = mainLoop - rightStrength; i < mainLoop; i++)
                {
                    if (pivotHigh < Bars.High[i])
                    {
                        pivotPassed = false;
                        break;
                    }
                }
                if (pivotPassed)
                {
                    for (int i = mainLoop + 1; i <= mainLoop + leftStrength; i++)
                    {
                        if (pivotHigh < Bars.High[i])
                        {
                            leftPassed = false;
                            break;
                        }
                    }
                }

                if (leftPassed && pivotPassed)
                {
                    pivot    = pivotHigh;
                    pivotBar = mainLoop;
                    break;
                }
            }
            if (leftPassed && pivotPassed && (pivotHighs.Count == 0 || pivot != pivotHighs[0]))
            {
                if (pivot > this[pivotBar])
                {
                    lowest = pivot;
                    pivotHighs.Add(pivot);
                    int bar = Bars.CurrentBar - pivotBar;
                    pivotBars.Add(bar);
                    Elapsed elapsed = default(Elapsed);
                    if (pivotBars.Count > 1)
                    {
                        elapsed = Bars.Time[pivotBar] - Bars.Time[Bars.CurrentBar - pivotBars[1]];
                    }
                    if (!disableBoxes)
                    {
                        Chart.DrawBox(Drawing.Color, bar, pivot);
                        if (pivotBars.Count > 1)
                        {
                            Log.Debug("|Pivot High," + Bars.Time[pivotBar] + "," + elapsed.TotalSeconds +
                                      "," + Bars.Time[pivotBar] + "," + Bars.Time[Bars.CurrentBar - pivotBars[1]]);
                        }
                    }
                }
            }

            return(true);
        }
Пример #12
0
        /// <summary>
        /// Adds or updates storage content.
        /// </summary>
        /// <param name="type">The type of the storage content.</param>
        /// <param name="name">The name of the storage content.</param>
        /// <param name="newContent">The new storage content.</param>
        public static void SetObject(string type, string name, object newContent)
        {
            switch (type.ToLower())
            {
            case "pokemon":
                if (Pokemons.ContainsKey(name))
                {
                    Pokemons[name] = (BasePokemon)newContent;
                }
                else
                {
                    Pokemons.Add(name, (BasePokemon)newContent);
                }
                break;

            case "string":
            case "str":
                if (Strings.ContainsKey(name))
                {
                    Strings[name] = Convert.ToString(newContent);
                }
                else
                {
                    Strings.Add(name, Convert.ToString(newContent));
                }
                break;

            case "integer":
            case "int":
                if (Integers.ContainsKey(name))
                {
                    Integers[name] = @int(newContent);
                }
                else
                {
                    Integers.Add(name, @int(newContent));
                }
                break;

            case "boolean":
            case "bool":
                if (Booleans.ContainsKey(name))
                {
                    Booleans[name] = Convert.ToBoolean(newContent);
                }
                else
                {
                    Booleans.Add(name, Convert.ToBoolean(newContent));
                }
                break;

            case "item":
                if (Items.ContainsKey(name))
                {
                    Items[name] = (BaseItem)newContent;
                }
                else
                {
                    Items.Add(name, (BaseItem)newContent);
                }
                break;

            case "single":
            case "sng":
                if (Singles.ContainsKey(name))
                {
                    Singles[name] = sng(newContent);
                }
                else
                {
                    Singles.Add(name, sng(newContent));
                }
                break;

            case "double":
            case "dbl":
                if (Doubles.ContainsKey(name))
                {
                    Doubles[name] = dbl(newContent);
                }
                else
                {
                    Doubles.Add(name, dbl(newContent));
                }
                break;
            }
        }
Пример #13
0
        private void BuildDfaSets()
        {
            Debug.Assert(Grammar.ParseTable != null);

            var terminalSets = new List <Integers>();

            for (var stateNo = 0; stateNo < Grammar.ParseTable.NumberOfStates; ++stateNo)
            {
                var terminalSet = new Integers();

                for (var symNo = 0; symNo < Grammar.ParseTable.NumberOfTerminals; ++symNo)
                {
                    switch (Grammar.ParseTable[stateNo][symNo].Action)
                    {
                    case ParseAction.Accept:
                    case ParseAction.Shift:
                    case ParseAction.Reduce:
                        terminalSet.Add(symNo);
                        break;
                    }
                }

                Debug.Assert(!terminalSet.IsEmpty);
                terminalSets.Add(terminalSet);
            }

            var ts        = new List <(Terminal terminal, int index)>(Grammar.Terminals.Where(t => t.IsPid).Select((t, i) => (t, i)));
            var terminals = Grammar.Terminals.Where(t => t.IsPid).ToList();
            var tDfas     = Enumerable.Repeat(FA.None(), terminals.Count).ToArray();

            var result = Parallel.ForEach(ts, x =>
            {
                var terminal = x.terminal;
                var index    = x.index;
                var fa       = terminal.Raw.Expression.GetFA();
                fa           = fa.ToDfa();
                fa           = fa.Minimize();
                fa           = fa.RemoveDead();

                foreach (var state in fa.Finals)
                {
                    state.SetPayload(terminal.Id);
                }
                tDfas[index] = fa;
            });

            Debug.Assert(result.IsCompleted);

            var terminalDfas = tDfas.ToList();
            var already      = new Dictionary <Integers, int>();
            var stateDfas    = new List <int>();

            foreach (var terminalSet in terminalSets)
            {
                Debug.Assert(!terminalSet.IsEmpty);

                if (!already.TryGetValue(terminalSet, out var index))
                {
                    index = already.Count;

                    already.Add(terminalSet, already.Count);
                }

                stateDfas.Add(index);
            }

            var dfas = Enumerable.Repeat(FA.None(), already.Count).ToArray();

            result = Parallel.ForEach(already, kv =>
            {
                var terminalSet = kv.Key;
                var index       = kv.Value;

                FA dfa;
                if (terminalSet.Cardinality == 1)
                {
                    dfa = terminalDfas[terminalSet.Single()].Clone().RemoveDead();
                }
                else
                {
                    dfa = Combine(terminalSet.Select(i => terminalDfas[i]));
                }

                var finals  = dfa.Finals.Select(s => s.Payload).Distinct().OrderBy(p => p).ToList();
                var numbers = terminalSet.Distinct().OrderBy(p => p).ToList();
                Debug.Assert(finals.SequenceEqual(numbers));

                dfas[index] = dfa;
            });

            FA Combine(IEnumerable <FA> fas)
            {
                FA combined = fas.First().Clone();

                foreach (var fa in fas.Skip(1))
                {
                    combined = combined.Union(fa, true);
                }
                return(combined);
            }

            Debug.Assert(result.IsCompleted);
            Debug.Assert(Grammar.Table != null);
            Debug.Assert(stateDfas.Count == Grammar.Table.GetLength(0));

            Grammar.Dfas       = dfas.ToArray();
            Grammar.StateToDfa = stateDfas;
        }
Пример #14
0
        public void LoadValues()
        {
            var typesBinder = new MappedTypesBinder {
                KnownTypes =
                {
                    { "String",    typeof(StringResource)    },
                    { "Integer",   typeof(IntegerResource)   },
                    { "Dimension", typeof(DimensionResource) },
                    { "Colour",    typeof(ColourResource)    }
                }
            };

            foreach (var file in ValueFiles)
            {
                var path = Path.Combine(config.Paths.Values, file);
                log.Verbose(Tag, "Deserialising '{0}'", path);

                var content = File.ReadAllText(path);

                var values = JsonConvert.DeserializeObject <Dictionary <string, IValueResource> >(content, new JsonSerializerSettings {
                    TypeNameHandling = TypeNameHandling.Objects,
                    Binder           = typesBinder,
                    Converters       = new JsonConverter[] {
                        new DimensionConverter(this),
                        new ColourConverter(this),
                        new StringConverter(this),
                        new IntegerConverter(this)
                    }
                });

                values.ForEach(p => {
                    var key      = p.Key;
                    var resource = p.Value;

                    if (resource is DimensionResource)
                    {
                        if (Dimensions.ContainsKey(key))
                        {
                            throw new DuplicateValueNameException("Dimension", key);
                        }

                        Dimensions.Add(key, (resource as DimensionResource).Value);
                    }
                    else if (resource is IntegerResource)
                    {
                        if (Integers.ContainsKey(key))
                        {
                            throw new DuplicateValueNameException("Integer", key);
                        }

                        Integers.Add(key, (resource as IntegerResource).Value);
                    }
                    else if (resource is StringResource)
                    {
                        if (Strings.ContainsKey(key))
                        {
                            throw new DuplicateValueNameException("String", key);
                        }

                        Strings.Add(key, (resource as StringResource).Value);
                    }
                    else if (resource is ColourResource)
                    {
                        if (Colours.ContainsKey(key))
                        {
                            throw new DuplicateValueNameException("Colour", key);
                        }

                        Colours.Add(key, (resource as ColourResource).Value);
                    }
                });
            }
        }
Пример #15
0
        public void Add(double value)
        {
            int x = (int)value;

            integers.Add(x);
        }
Пример #16
0
        public override bool OnIntervalClose()
        {
            double currHigh = Bars.High[0];

            if (highest == 0)
            {
                highest = currHigh;
            }
            else
            {
                if (currHigh > highest)
                {
                    highest = currHigh;
                }
            }
            // DO NOT DELETE. Turn to hidden instead if necessary.
            this[0] = highest;

            pivot = 0;
            for (int MAINLOOP = RSTREN; MAINLOOP < LENGTH; MAINLOOP++)
            {
                rightPassed = true;
                leftPassed  = true;
                SHBAR       = Bars.Low[MAINLOOP] - 1;

                for (int VALUE1 = MAINLOOP - RSTREN; VALUE1 <= MAINLOOP - 1; VALUE1++)
                {
                    if (SHBAR > Bars.Low[VALUE1])
                    {
                        rightPassed = false;
                        break;
                    }
                }

                if (rightPassed)
                {
                    for (int VALUE1 = MAINLOOP + 1; VALUE1 <= MAINLOOP + LSTREN; VALUE1++)
                    {
                        if (SHBAR > Bars.Low[VALUE1])
                        {
                            leftPassed = false;
                            break;
                        }
                    }
                }

                if (rightPassed && leftPassed)
                {
                    pivot    = SHBAR;
                    pivotBar = MAINLOOP;
                    break;
                }
            }

            if (leftPassed && rightPassed && (pivotLows.Count == 0 || pivot != pivotLows[0]))
            {
                if (pivot < this[pivotBar])
                {
                    highest = pivot;
                    pivotLows.Add(pivot);
                    int bar = Bars.CurrentBar - pivotBar;
                    pivotBars.Add(bar);
                    Elapsed elapsed = default(Elapsed);
                    if (pivotBars.Count > 1)
                    {
                        elapsed = Bars.Time[pivotBar] - Bars.Time[Bars.CurrentBar - pivotBars[1]];
                    }
                    if (!disableBoxes)
                    {
                        Chart.DrawBox(Drawing.Color, bar, pivot);
                        if (pivotBars.Count > 1)
                        {
                            Log.Debug("|Pivot Low," + Bars.Time[pivotBar] + "," + elapsed.TotalSeconds +
                                      "," + Bars.Time[pivotBar] + "," + Bars.Time[Bars.CurrentBar - pivotBars[1]]);
                        }
                    }
                }
            }

            return(true);
        }