Example #1
0
        public override void Init(string pParameters)
        {
            this.InitializeParameters(pParameters, "CCI:14;TCCI:6;MINUTES:5;");

            CCIPeriods  = (int)PParser.GetDouble("CCI", 0);
            TCCIPeriods = (int)PParser.GetDouble("TCCI", 0);
            Minutes     = (int)PParser.GetDouble("MINUTES", 0);

            CCI      = new iCCI(CCIPeriods);
            TCCI     = new iCCI(TCCIPeriods);
            CCISlope = new iDerivatives();

            CCIH  = new CQueue(CCIPeriods * 3);
            TCCIH = new CQueue(CCIPeriods * 3);

            // OPTIMIZATION PARAMETER CHECK
            // if parameters are erroneous (TurboCCI length > CCI)
            // do not register candle listeners
            // SystemTester will then not send us any ticks
            // and go to the next iteration
            // need 6 cci bars to determine trend

            if ((TCCIPeriods < CCIPeriods) || (CCIPeriods < 6))
            {
                cbx = new cCandleBuilder(Minutes, 10);
                Framework.TickServer.RegisterTickListener("cbx", "*", cbx);
                cbx.RegisterCandleListener("cbx", this);
                Framework.TickServer.RegisterTickListener("System", "*", this);

                Framework.WriteGraphLine("InTrade,Margin,C,CCI,CCIDelta,CCISpeed,TCCI,TypeOfTrade,Direction,BelowFifty,ZLR");
            }
        }
Example #2
0
        public static void TestCQueue()
        {
            Framework.Logger(2, "Circular Queue Test Started");

            CQueue cq = new CQueue(4);

            cq.Add("1");
            cq.Add("2");
            cq.Add("3");
            cq.Add("4");

            string s1;

            s1 = (string)cq.GetItem(4);
            s1 = (string)cq.GetItem(0);
            s1 = (string)cq.GetItem(3);

            cq.Add("5");
            cq.Add("6");
            cq.Add("7");

            s1 = (string)cq.GetItem(4);
            s1 = (string)cq.GetItem(0);
            s1 = (string)cq.GetItem(3);

            Framework.Logger(2, "Circular Queue Test Ended");
        }
Example #3
0
        public void 用两个栈实现队列()
        {
            CQueue obj = new CQueue();

            obj.AppendTail(2);
            int param_2 = obj.DeleteHead();
        }
Example #4
0
        public void Test()
        {
            CQueue obj     = new CQueue();
            int    param_0 = obj.DeleteHead();

            obj.AppendTail(5);
            obj.AppendTail(2);
            int param_1 = obj.DeleteHead();
            int param_2 = obj.DeleteHead();
        }
Example #5
0
        public void CQueueTest1()
        {
            CQueue <char> queue = new CQueue <char>();

            queue.AppendTail('a');
            queue.AppendTail('b');
            queue.AppendTail('c');

            char head = queue.DeleteHead();

            Assert.AreEqual(head, 'a');
        }
        public void InsertAndRemoveBeforePersist()
        {
            var l = new CQueue <int>();

            l.Enqueue(1);

            l.Dequeue();

            AttachAndPersist(l);

            Load().Count.ShouldBe(0);
        }
Example #7
0
        public void TestMethodQueueEnqueue()
        {
            CQueue <string> q = new CQueue <string>();

            Assert.AreEqual(q.Size, 0);
            q.Enqueue("a");
            Assert.AreEqual(q.Size, 1);
            Assert.AreEqual(q.First(), "a");
            q.Enqueue("b");
            Assert.AreEqual(q.Size, 2);
            Assert.AreEqual(q.First(), "a");
        }
Example #8
0
        public void EnqueueAndDequeueFromCQueue()
        {
            var storage = new InMemoryStorageEngine();
            var os      = ObjectStore2.New(storage);

            var cQueue = new CQueue <string>();

            cQueue.Enqueue("hello");
            cQueue.Enqueue("world");
            cQueue.Enqueue("from here");

            os.Roots.Entangle(cQueue);

            os.Persist();
            os     = ObjectStore2.Load(storage);
            cQueue = os.Roots.Find <CQueue <string> >();

            cQueue.Count.ShouldBe(3);

            var dequeued = cQueue.Dequeue();

            dequeued.ShouldBe("hello");

            os.Persist();


            os     = ObjectStore2.Load(storage);
            cQueue = os.Roots.Find <CQueue <string> >();

            cQueue.Count.ShouldBe(2);

            cQueue.Dequeue().ShouldBe("world");
            cQueue.Dequeue().ShouldBe("from here");

            cQueue.Enqueue("hello");

            os.Persist();

            os     = ObjectStore2.Load(storage);
            cQueue = os.Roots.Find <CQueue <string> >();

            cQueue.Count.ShouldBe(1);
            cQueue.Dequeue().ShouldBe("hello");

            os.Persist();

            os     = ObjectStore2.Load(storage);
            cQueue = os.Roots.Find <CQueue <string> >();
            cQueue.Count.ShouldBe(0);
        }
        public void CQueue_Operation()
        {
            var cQueue = new CQueue();

            cQueue.DeleteHead().Should().Be(-1);

            cQueue.AppendTail(3);
            cQueue.AppendTail(4);
            cQueue.AppendTail(5);
            cQueue.DeleteHead().Should().Be(3);

            cQueue.AppendTail(6);
            cQueue.DeleteHead().Should().Be(4);
        }
        public void ElementsAddedAndRemovedAndSetToListAreAddedToStateMap()
        {
            var l = new CQueue <int>();

            l.Enqueue(0);
            l.Enqueue(1);

            AttachAndPersist(l);

            l.Dequeue();
            Persist();

            l = Load();
            l.Count.ShouldBe(1);
            l.Dequeue().ShouldBe(1);
        }
        public void InsertAndRemoveAgainAndAgain()
        {
            var l = new CQueue <int>();

            Attach(l);
            for (var i = 0; i < 50; i++)
            {
                l.Enqueue(i);
                Persist();
                l = Load();
                l.Dequeue().ShouldBe(i);
                Persist();
                l = Load();
                l.Count.ShouldBe(0);
            }
        }
        public void ElementsAddedToListAreAddedToStateMap()
        {
            var l = new CQueue <int>();

            l.Enqueue(0);
            l.Enqueue(1);

            AttachAndPersist(l);

            l = Load();

            l.Count.ShouldBe(2);
            var orderElements = l.OrderBy(_ => _).ToArray();

            orderElements[0].ShouldBe(0);
            orderElements[1].ShouldBe(1);
        }
Example #13
0
        public static async Task <Embed> GetEmbedQueue(LavaTrack track, CQueue <TrackInput> tracks
                                                       , LavaTrack ptrack)
        {
            EmbedBuilder Embed = new EmbedBuilder
            {
                Title       = "Playing Song",
                Description = $"[{track.Title}]({track.Url})"
            };

            Embed.AddField("Length", track.Duration.ToString(), true);
            Embed.AddField("Tracks in Queue", (tracks.Count).ToString(), true);
            Embed.AddField("Previous Track", ptrack.Title, true);
            Embed.AddField("Next Track", (tracks.Count == 0) ? "No tracks" : (tracks[0]).Track.Title, true);

            Embed.ImageUrl = await track.FetchArtworkAsync();

            return(Embed.Build());
        }
Example #14
0
        public void TestMethodQueueDequeue()
        {
            CQueue <string> q = new CQueue <string>();

            Assert.AreEqual(q.Size, 0);
            q.Enqueue("a");
            q.Enqueue("b");
            q.Enqueue("c");
            Assert.AreEqual(q.First(), "a");
            q.Dequeue();
            Assert.AreEqual(q.First(), "b");
            q.Dequeue();
            Assert.AreEqual(q.First(), "c");

            q.Dequeue();
            Assert.IsTrue(q.IsEmpty());
            Assert.ThrowsException <Exception>(() => q.First());
            Assert.ThrowsException <Exception>(() => q.Dequeue());
        }
Example #15
0
        public void CQueueTest6()
        {
            CQueue <char> queue = new CQueue <char>();

            queue.AppendTail('a');
            queue.AppendTail('b');
            queue.AppendTail('c');

            char head = queue.DeleteHead();

            head = queue.DeleteHead();

            queue.AppendTail('d');
            head = queue.DeleteHead();

            queue.AppendTail('e');
            head = queue.DeleteHead();
            head = queue.DeleteHead();
            head = queue.DeleteHead();
        }
Example #16
0
        public void Update(Object stateinfo)
        {
            // Console.WriteLine(ctr);
            // ++ctr;

            // Process queue
            if (this.CQueue.Count > 0)
            {
                var item = CQueue.FirstOrDefault();
                item.Progress     += 10;
                this.QueueProgress = item.Progress;
                if (item.Progress >= 100)
                {
                    // this.Inventory.Add(item.Etype,item.Amount);
                    this.Inventory.Craft(item.Etype, item.Amount);
                    this.CQueue.Remove(item);
                    this.QueueProgress = 0;
                }
            }


            // Process Productions
            foreach (var item in this.Inventory.Items)
            {
                if (item.Production > 0)
                {
                    item.Progress += item.Speed;
                    if (item.Progress >= 100)
                    {
                        this.Inventory.Craft(item.Etype, item.Production);
                        item.Progress = 0;
                    }
                }
            }


            Updated?.Invoke(this, new GenericEventArgs("done"));
        }
        // initialization routine, called once before ticks are sent
        // if multiple tick sources are used, will get called several times
        // during the lifetime of the object, once per tick source change
        public override void Init(string pParameters)
        {
            this.InitializeParameters(pParameters, "PERIODS:17;MINUTES:10;");

            // get periods to use for the indicator(s)
            Periods     = (int)PParser.GetDouble("PERIODS", 0);
            Derivatives = new iDerivatives();
            HMA         = new iHMA(Periods);
            HMAD1       = new CQueue(Periods);
            FMA         = new iFMA(Periods);
            Deriv1      = new CQueue(Periods);
            Deriv2      = new CQueue(Periods);
            BBands      = new iBollingerBands(Periods, -1);
            StochRSI    = new iStochRSI(Periods);
            CCI         = new iCCI(Periods);

            // instantiate candlebuilder with desired timeframe
            Minutes = (int)PParser.GetDouble("MINUTES", 0);
            //			cbx = new cCandleBuilder(Minutes,PeriodsLong+PeriodsShort+1);
            cbx = new cCandleBuilder(Minutes, Periods);

            // register candlebuilder as a tick listener, name unimportant
            Framework.TickServer.RegisterTickListener("cbx", "*", cbx);
            // register this object as a candle listener
            // the candle name is important since we might receive
            // several candles with same period.
            cbx.RegisterCandleListener("cbx", this);
            // multiple candlebuilders can be setup by using previous 4 lines.

            // register this object as a tick listener, name unimportant
            // this is an optional step to receive ticks in between candles
            Framework.TickServer.RegisterTickListener("System", "*", this);

            // start header line of numerical output file
            Framework.WriteGraphLine("InTrade,Margin,C,TP,FMA,HMA,Deriv1,Deriv2,SMA,BBand1,BBand2,%b,Bandwidth,StochRSI,CCI");
        }
Example #18
0
 public iCCI(int pPeriods)
 {
     periods = pPeriods;
     TPSMA   = new iSMA(pPeriods);
     History = new CQueue(pPeriods);
 }
Example #19
0
        private static void ConcurrentCollectionsExample()
        {
            CDictionary stock = new CDictionary();
            int         stockValue;

            //Try add
            var result = stock.TryAdd("Simpsons", 5);

            Console.WriteLine($"Tried to add 5 Simpsons tshirts with result:{result}");
            Console.WriteLine($"Add the same tshirt again");
            result = stock.TryAdd("Simpsons", 2);
            Console.WriteLine($"Tried to add 2 Simpsons tshirts with result:{result}");

            //Try Update
            result = stock.TryUpdate("Simpsons", 5, 6);
            Console.WriteLine($"Tried to update Simpsons tshirts (5 of stock), with a new value of 6 with result {result}");
            result = stock.TryUpdate("Simpsons", 7, 6);
            Console.WriteLine($"Tried to update Simpsons tshirts (5 of stock) sending 7 instead, with a new value of 6 with result {result}");

            //TryGet

            result = stock.TryGet("Simpsons", out stockValue);
            Console.WriteLine($"Get value for simpsons occured with result {result} and the value is {stockValue}");

            //Add or Update -> try to update the value, if key it's not present add it
            var updatedStock = stock.AddOrUpdate("Simpsons", 3);

            Console.WriteLine($"Tried to increment Simpsons tshirts (5 of stock) with a new value of {updatedStock}");
            updatedStock = stock.AddOrUpdate("Family Guy", 10);
            Console.WriteLine($"Tried to increment Simpsons tshirts (5 of stock) with a new value of {updatedStock}");

            //Get or Add -> try and get the value. if key not present add it

            stockValue = stock.GetOrAdd("Family Guy", 0);
            Console.WriteLine($"Get the value of {stockValue} for tshirt Family Guy");
            //Try Remove
            result = stock.TryRemove("Simpsons", out stockValue);
            Console.WriteLine($"Tried to remove remove Simpsons tshirts wich had {stockValue} of stock with result {result}");

            result = stock.TryRemove("Simpsons", out stockValue);
            Console.WriteLine($"Tried to remove remove Simpsons tshirts wich had {stockValue} of stock with result {result}");


            //Concurrent Queue
            CQueue queue = new CQueue();

            queue.Enqueue("Simpsons");
            queue.Enqueue("FamilyGuy");
            queue.Enqueue("StarWars");

            string shirt;

            result = queue.TryPeek(out shirt);
            if (result)
            {
                Console.WriteLine($"The item at the front of the queue is {shirt}");
            }
            else
            {
                Console.WriteLine($"Error peeking. Pervert?");
            }

            result = queue.TryDequeue(out shirt);

            if (result)
            {
                Console.WriteLine($"The item dequeued is {shirt}");
            }
            else
            {
                Console.WriteLine($"Error peeking. Pervert?");
            }

            result = queue.TryPeek(out shirt);
            if (result)
            {
                Console.WriteLine($"The item at the front of the queue (after dequeue) is {shirt}");
            }
            else
            {
                Console.WriteLine($"Error peeking. Pervert?");
            }


            //Concurrent Stack

            CStack stack = new CStack();

            stack.Push("Simpsons");
            stack.Push("FamilyGuy");
            stack.Push("StarWars");


            result = stack.TryPeek(out shirt);
            if (result)
            {
                Console.WriteLine($"The item at the Top of the stack is {shirt}");
            }
            else
            {
                Console.WriteLine($"Error peeking. Pervert?");
            }

            result = stack.TryPop(out shirt);

            if (result)
            {
                Console.WriteLine($"The item poped is {shirt}");
            }
            else
            {
                Console.WriteLine($"Error peeking. Pervert?");
            }

            result = stack.TryPeek(out shirt);
            if (result)
            {
                Console.WriteLine($"The item at the Top of the stack (after Pop) is {shirt}");
            }
            else
            {
                Console.WriteLine($"Error peeking. Pervert?");
            }


            //ConcurrentBag No garanties for the order of put and take. In single thread it tends to have the same beahaviour of stack. It is
            //used if the same thread does multiple add and remove. in that case it is more efficient.
            CBag bag = new CBag();

            bag.Push("Simpsons");
            bag.Push("FamilyGuy");
            bag.Push("StarWars");


            result = bag.TryPeek(out shirt);
            if (result)
            {
                Console.WriteLine($"The item peeked is {shirt}");
            }
            else
            {
                Console.WriteLine($"Error peeking. Pervert?");
            }

            result = bag.TryPop(out shirt);

            if (result)
            {
                Console.WriteLine($"The item poped is {shirt}");
            }
            else
            {
                Console.WriteLine($"Error peeking. Pervert?");
            }

            result = bag.TryPeek(out shirt);
            if (result)
            {
                Console.WriteLine($"The item at the Top of the stack (after Pop) is {shirt}");
            }
            else
            {
                Console.WriteLine($"Error peeking. Pervert?");
            }
        }
Example #20
0
        private void ShowQueueItem(CQueue<ModulePak> queue, string stringPrfx, bool writeDb)
        {
            int bsNomer = Convert.ToInt32(NoZero(FieldBsNo.Text));
            for (int i = queue.Count(); i > 0; i--)
            {
                ModulePak pak;
                queue.TryDequeue(out pak);

                byte[] bts = pak.Bytes;

                var sb = new StringBuilder(DateTime.Now.TimeOfDay.ToString());
                sb.Append(stringPrfx);

                if (FlagHexOut.Checked)
                {
                    foreach (var bt in bts)
                    {
                        sb.Append(bt.ToString("X") + " ");
                    }
                }
                else
                {
                    foreach (var bt in bts)
                    {
                        sb.Append(bt);
                        sb.Append(" ");
                    }
                }
                sb.AppendLine();
                _delegateSetTextSafe(FieldTerminal, sb.ToString());
                if (writeDb)
                {
                    WriteDb(pak, bsNomer);
                }
            }
        }
Example #21
0
 public iMinMax(int pPeriods)
 {
     periods = pPeriods;
     queue   = new CQueue(periods);
 }
Example #22
0
 public iDerivatives()
 {
     tickcount = 0;
     Values    = new CQueue(3);
 }
Example #23
0
 public iWMA(int pPeriods)
 {
     periods = pPeriods;
     values  = new CQueue(periods);
 }
Example #24
0
 public iSTDDEV(int pPeriods)
 {
     periods = pPeriods;
     SMA     = new iSMA(pPeriods);
     History = new CQueue(pPeriods);
 }
Example #25
0
 public iADX(int pPeriods)
 {
     periods = pPeriods;
     Prices  = new CQueue(periods);
 }