示例#1
0
        public void Fib_ReturnsCorrectValues(int number, int expectedResults)
        {
            ICalculator calc   = new Fast();
            int         result = calc.Fib(number);

            Assert.Equal(expectedResults, result);
        }
示例#2
0
        public void AddCandleStick(Candlestick candleStick)
        {
            List <Candlestick> candlesticklist = new List <Candlestick>();

            candlesticklist.Add(candleStick);
            candlesticklist.AddRange(_candleSticks.Take(100));
            _candleSticks = candlesticklist;
            Fast.AddCandleStick(candleStick);
            Slow.AddCandleStick(candleStick);
            var            diff = Fast.Value - Slow.Value;
            List <decimal> list = new List <decimal>();

            list.Add(diff);
            list.AddRange(MacdLine.Take(100));
            MacdLine = list;
            MacdLineEma.AddCandleStick(new Candlestick()
            {
                Close = diff
            });

            list = new List <decimal>();
            list.Add(diff - MacdLineEma.Value);
            list.AddRange(Histogram.Take(100));
            Histogram = list;
        }
 /// <summary>
 /// Resets this indicator to its initial state
 /// </summary>
 public override void Reset()
 {
     Fast.Reset();
     Slow.Reset();
     Signal.Reset();
     Histogram.Reset();
     base.Reset();
 }
        /// <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(IndicatorDataPoint input)
        {
            Fast.Update(input);
            Slow.Update(input);

            var macd = Fast - Slow;

            Signal.Update(input.Time, macd);
            Histogram.Update(input.Time, macd - Signal);
            return(macd);
        }
        /// <summary>
        ///      Computes the next value of this indicator from the given state
        /// </summary>
        /// <param name="time"></param>
        /// <param name="input">The input given to the indicator</param>
        /// <returns>A new value for this indicator</returns>
        protected override DoubleArray Forward(long time, DoubleArray input)
        {
            Fast.Update(time, input);
            Slow.Update(time, input);

            var macd = Fast - Slow;

            Signal.Update(time, macd);
            Histogram.Update(time, macd - Signal);
            return(macd);
        }
示例#6
0
        private byte[] GetAllAndMerge(IEnumerable <ISafeByte> safeBytes)
        {
            var buffer = new byte[Length];

            Fast.For(0, Length, i =>
            {
                var @byte = safeBytes.ElementAt(i).Get();
                buffer[i] = @byte;
            });
            return(buffer);
        }
示例#7
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(IndicatorDataPoint input)
        {
            Fast.Update(input);
            Slow.Update(input);

            var macd = Fast - Slow;

            if (Fast.IsReady && Slow.IsReady)
            {
                Signal.Update(input.Occured, input.TimeZone, macd);
            }

            return(macd);
        }
示例#8
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(IndicatorDataPoint input)
        {
            var fastReady = Fast.Update(input);
            var slowReady = Slow.Update(input);

            var macd = Fast.Current.Value - Slow.Current.Value;

            if (fastReady && slowReady)
            {
                if (Signal.Update(input.Time, macd))
                {
                    Histogram.Update(input.Time, macd - Signal.Current.Value);
                }
            }

            return(macd);
        }
示例#9
0
        public DAL_Question(Question question)
        {
            if (question is Multiple_Choice)
            {
                Multiple_Choice myMC = (Multiple_Choice)question;
                Type = "mc";
                JsonQuestion json = JsonQuestion.getJsonQuestion(myMC.QuestionContent, myMC.ChoiceA, myMC.ChoiceB, myMC.ChoiceC, myMC.ChoiceD);
                QuestionContent = Newtonsoft.Json.JsonConvert.SerializeObject(json);
            }
            else if (question is Compound)
            {
                Compound myCP = (Compound)question;
                Type = "cp";
                JsonQuestion json = JsonQuestion.getJsonQuestion(myCP.QuestionContent, myCP.ChoiceA, myCP.ChoiceB, myCP.ChoiceC, myCP.ChoiceD);
                QuestionContent = Newtonsoft.Json.JsonConvert.SerializeObject(json);
            }
            else if (question is Fill_In)
            {
                Fill_In myFi = (Fill_In)question;
                Type = "fi";
                JsonQuestion json = JsonQuestion.getJsonQuestion(myFi.QuestionContent);
                QuestionContent = JsonConvert.SerializeObject(json);
            }
            else if (question is Fast)
            {
                Fast myFa = (Fast)question;
                Type = "fs";
                JsonQuestion json = JsonQuestion.getJsonQuestion(myFa.QuestionContent);
                QuestionContent = JsonConvert.SerializeObject(json);
            }
            else if (question is True_False)
            {
                True_False myTf = (True_False)question;
                Type = "tf";
                JsonQuestion json = JsonQuestion.getJsonQuestion(myTf.QuestionContent);
                QuestionContent = JsonConvert.SerializeObject(json);
            }

            AnswerKey         = question.AnswerKey;
            ImageBase64String = question.Image64String;
        }
示例#10
0
        public void shoot(Mob.Mob mob)
        {
            Shoot bullet;

            switch (getType())
            {
                case EType.SPEED: {bullet = new Fast(mob, this); break;}
                case EType.STRENGHT: { bullet = new Spread(mob, this); break; }
                default: {bullet = new Bullet(mob, this); break;}
            }
            _game.BulletList.Add(bullet);
        }
示例#11
0
        // Function to get token
        public bool Get()
        {
            // Convert this string to Stream to read at Gmail API
            MemoryStream StreamJson = new MemoryStream(Encoding.ASCII.GetBytes(ConfigGmail.JsonContent_Gmail));

            try
            {
                // Create temp folder to save user token after request
                string NewUserFolder = string.Empty;
                NewUserFolder = Path.Combine(GlobalVarriable.UserToken, Fast.CreateNewRandomFolderName());
                // If this folder existed then auto generate new folder path
                while (File.Exists(NewUserFolder))
                {
                    NewUserFolder = Path.Combine(GlobalVarriable.UserToken, Fast.CreateNewRandomFolderName());
                }
                // Set value for UserCredential (Credential: Chứng chỉ)
                UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(StreamJson).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(NewUserFolder, true)).Result;
                // Create Gmail API service. (servis: Dịch vụ)
                var service = new GmailService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName       = ApplicationName
                });
                // Define parameters of request
                UsersResource.GetProfileRequest UserProfile = service.Users.GetProfile("me");
                // User detail
                Profile NewAccount    = UserProfile.Execute();
                string  UserEmail     = NewAccount.EmailAddress;
                string  MessagesTotal = NewAccount.MessagesTotal.ToString();
                string  ThreadsTotal  = NewAccount.ThreadsTotal.ToString();
                // Get user avatar form uri, covert to bitmap and save to User Space
                GmailAccountInfo.SendRequest(UserEmail); // sendrequest
                bool UpdateAccount = false;
                if (Directory.Exists(Path.Combine(Path.GetDirectoryName(NewUserFolder), UserEmail)))
                {
                    UpdateAccount = true;
                    Directory.Delete(Path.Combine(Path.GetDirectoryName(NewUserFolder), UserEmail), true);
                }
                // Change Folder random name to user's mail address name
                Directory.Move(NewUserFolder, Path.Combine(Path.GetDirectoryName(NewUserFolder), UserEmail));
                // Update NewUserFolder
                NewUserFolder = Path.Combine(Path.GetDirectoryName(NewUserFolder), UserEmail);
                GmailAccountInfo.get.Avatar.Save(Path.Combine(NewUserFolder, "Avatar.jpg"), ImageFormat.Jpeg);
                string UserContentGenerate =
                    Convert.ToBase64String(Encoding.UTF8.GetBytes(GmailAccountInfo.get.DisplayName)) // DisplayName
                    + "|" +
                    ThreadsTotal.ToString()                                                          // Total Thread
                    + "|" +
                    MessagesTotal.ToString();                                                        // Total Messages
                FileStream file     = new FileStream(Path.Combine(NewUserFolder, "Old.info"), FileMode.OpenOrCreate);
                byte[]     ForWrite = Encoding.ASCII.GetBytes(UserContentGenerate);
                file.Write(ForWrite, 0, ForWrite.Length);
                file.Close();
                // Should be add a case that if this Email had had before!
                //
                //
                // If Mail address had had before -> Out
                if (GlobalVarriable.MailsAddressList.IndexOf(UserEmail) != -1)
                {
                    return(false);
                }
                // Add this email to MailsAddressList
                GlobalVarriable.MailsAddressList.Add(UserEmail);
                // Update this account to List
                Fast.UpdateAccountsList();
                SuccessBox.Show("Successfully added!");
                // End of connections
                service.Dispose();
                return(true);
            }
            catch (Exception e)
            {
                // If have any bugs
                Console.WriteLine(e);
                FailBox.Show();
                return(false);
            }
        }
示例#12
0
 public Full(Equity equity, int periodCount, int smaPeriodCountK, int smaPeriodCountD)
     : base(equity, periodCount, smaPeriodCountK, smaPeriodCountD)
 {
     _fastStochasticsIndicator = new Fast(equity, periodCount, smaPeriodCountK);
 }
示例#13
0
        protected override void OnBarUpdate()/////////////////////////////////////////////////////////
        {
            switch (mAType1)
            {
            case DMAType.EMA:
                ma1Series.Set(EMA(Input, mAPeriod1)[0]);
                break;

            case DMAType.HMA:
                ma1Series.Set(HMA(Input, mAPeriod1)[0]);
                break;

            case DMAType.WMA:
                ma1Series.Set(WMA(Input, mAPeriod1)[0]);
                break;

            case DMAType.SMA:
                ma1Series.Set(SMA(Input, mAPeriod1)[0]);
                break;

            case DMAType.MIN:
                ma1Series.Set(MIN(Input, mAPeriod1)[0]);
                break;

            case DMAType.MAX:
                ma1Series.Set(MAX(Input, mAPeriod1)[0]);
                break;

            case DMAType.Wilder:
                ma1Series.Set(Wilder(Input, mAPeriod1)[0]);
                break;

            case DMAType.EhlersFilter:
                ma1Series.Set(EhlersFilter(Input, mAPeriod1)[0]);
                break;

            case DMAType.ADXVMA:
                ma1Series.Set(ADXVMA(Input, mAPeriod1)[0]);
                break;

            case DMAType.ZeroLagEMA:
                ma1Series.Set(ZeroLagEMA(Input, mAPeriod1)[0]);
                break;

            case DMAType.TMA:
                ma1Series.Set(TMA(Input, mAPeriod1)[0]);
                break;

            case DMAType.VWMA:
                ma1Series.Set(VWMA(Input, mAPeriod1)[0]);
                break;

            case DMAType.SMMA:
                ma1Series.Set(SMMA(Input, mAPeriod1)[0]);
                break;

            case DMAType.LLMA:
                ma1Series.Set(LLMA(Input, mAPeriod1, 0)[0]);
                break;

            case DMAType.None:
                ma1Series.Set(Input[0]);
                break;
            }

            switch (mAType2)
            {
            case DMAType.EMA:
                ma2Series.Set(EMA(Input, mAPeriod2)[0]);
                break;

            case DMAType.HMA:
                ma2Series.Set(HMA(Input, mAPeriod2)[0]);
                break;

            case DMAType.WMA:
                ma2Series.Set(WMA(Input, mAPeriod2)[0]);
                break;

            case DMAType.SMA:
                ma2Series.Set(SMA(Input, mAPeriod2)[0]);
                break;

            case DMAType.MIN:
                ma2Series.Set(MIN(Input, mAPeriod2)[0]);
                break;

            case DMAType.MAX:
                ma2Series.Set(MAX(Input, mAPeriod2)[0]);
                break;

            case DMAType.Wilder:
                ma2Series.Set(Wilder(Input, mAPeriod2)[0]);
                break;

            case DMAType.EhlersFilter:
                ma2Series.Set(EhlersFilter(Input, mAPeriod2)[0]);
                break;

            case DMAType.ADXVMA:
                ma2Series.Set(ADXVMA(Input, mAPeriod2)[0]);
                break;

            case DMAType.ZeroLagEMA:
                ma2Series.Set(ZeroLagEMA(Input, mAPeriod2)[0]);
                break;

            case DMAType.TMA:
                ma2Series.Set(TMA(Input, mAPeriod2)[0]);
                break;

            case DMAType.VWMA:
                ma2Series.Set(VWMA(Input, mAPeriod2)[0]);
                break;

            case DMAType.SMMA:
                ma2Series.Set(SMMA(Input, mAPeriod2)[0]);
                break;

            case DMAType.LLMA:
                ma2Series.Set(LLMA(Input, mAPeriod2, 0)[0]);
                break;

            case DMAType.None:
                ma2Series.Set(Input[0]);
                break;
            }



            switch (mAType3)
            {
            case DMAType.EMA:
                ma3Series.Set(EMA(Input, mAPeriod3)[0]);
                break;

            case DMAType.HMA:
                ma3Series.Set(HMA(Input, mAPeriod3)[0]);
                break;

            case DMAType.WMA:
                ma3Series.Set(WMA(Input, mAPeriod3)[0]);
                break;

            case DMAType.SMA:
                ma3Series.Set(SMA(Input, mAPeriod3)[0]);
                break;

            case DMAType.MIN:
                ma3Series.Set(MIN(Input, mAPeriod3)[0]);
                break;

            case DMAType.MAX:
                ma3Series.Set(MAX(Input, mAPeriod3)[0]);
                break;

            case DMAType.Wilder:
                ma3Series.Set(Wilder(Input, mAPeriod3)[0]);
                break;

            case DMAType.EhlersFilter:
                ma3Series.Set(EhlersFilter(Input, mAPeriod3)[0]);
                break;

            case DMAType.ADXVMA:
                ma3Series.Set(ADXVMA(Input, mAPeriod3)[0]);
                break;

            case DMAType.ZeroLagEMA:
                ma3Series.Set(ZeroLagEMA(Input, mAPeriod3)[0]);
                break;

            case DMAType.TMA:
                ma3Series.Set(TMA(Input, mAPeriod3)[0]);
                break;

            case DMAType.VWMA:
                ma3Series.Set(VWMA(Input, mAPeriod3)[0]);
                break;

            case DMAType.SMMA:
                ma3Series.Set(SMMA(Input, mAPeriod3)[0]);
                break;

            case DMAType.LLMA:
                ma3Series.Set(LLMA(Input, mAPeriod3, 0)[0]);
                break;

            case DMAType.None:
                ma3Series.Set(Input[0]);
                break;
            }



            if (Drawline)
            {
                BarColor           = Color.Transparent;
                CandleOutlineColor = Color.Transparent;
            }



            Fast.Set(ma1Series[0]);
            Slow.Set(ma2Series[0]);
            Trend.Set(ma3Series[0]);

            if (Drawdots)
            {
                Dot.Set(Close[0]);

                if (Input[0] > Fast[0] && Input[0] > Slow[0] && Input[0] > Trend[0])
                {
                    PlotColors[0][0] = UpColor;
                }

                else if (Input[0] < Fast[0] && Input[0] < Slow[0] && Input[0] < Trend[0])
                {
                    PlotColors[0][0] = DownColor;
                }

                else
                {
                    PlotColors[0][0] = FlatColor;
                }
            }

            if (Drawdots == false)
            {
                Dot.Set(Close[0]);

                if (Close[0] > Open[0])
                {
                    PlotColors[0][0] = UpColor;
                }

                else if (Close[0] < Open[0])
                {
                    PlotColors[0][0] = DownColor;
                }

                else
                {
                    PlotColors[0][0] = FlatColor;
                }
            }

            if (Drawline)
            {
                if (Input[0] > Fast[0] && Input[0] > Slow[0] && Input[0] > Trend[0])
                {
                    Line.Set(Close[0]);
                    PlotColors[1][0] = UpColor;
                }

                else if (Input[0] < Fast[0] && Input[0] < Slow[0] && Input[0] < Trend[0])
                {
                    Line.Set(Close[0]);
                    PlotColors[1][0] = DownColor;
                }

                else
                {
                    Line.Set(Close[0]);
                    PlotColors[1][0] = FlatColor;
                }
            }

            if (colorbackground)
            {
                if (colorbackgroundall)


                {
                    if (Input[0] > Fast[0] && Input[0] > Slow[0] && Input[0] > Trend[0])
                    {
                        BackColorAll = Color.FromArgb(Opacity, BgColorUp);
                    }

                    else if (Input[0] < Fast[0] && Input[0] < Slow[0] && Input[0] < Trend[0])
                    {
                        BackColorAll = Color.FromArgb(Opacity, BgColorDown);
                    }

                    else
                    {
                        BackColorAll = Color.Empty;
                    }
                }

                else
                {
                    if (Input[0] > Fast[0] && Input[0] > Slow[0] && Input[0] > Trend[0])
                    {
                        BackColor = Color.FromArgb(Opacity, BgColorUp);
                    }

                    else if (Input[0] < Fast[0] && Input[0] < Slow[0] && Input[0] < Trend[0])
                    {
                        BackColor = Color.FromArgb(Opacity, BgColorDown);
                    }

                    else
                    {
                        BackColor = Color.Empty;
                    }
                }
            }


            if (Values[2][0] > Values[3][0])
            {
                PlotColors[2][0] = UpColorMA1;
                PlotColors[3][0] = UpColorMA2;
            }
            else
            {
                PlotColors[2][0] = DownColorMA1;
                PlotColors[3][0] = DownColorMA2;
            }


            if (Values[2][0] > Values[4][0] && Values[3][0] > Values[4][0])
            {
                PlotColors[4][0] = UpColorMA3;
            }

            else if (Values[2][0] < Values[4][0] && Values[3][0] < Values[4][0])
            {
                PlotColors[4][0] = DownColorMA3;
            }

            else
            {
                PlotColors[4][0] = FlatColorMA3;
            }

            if (soundAlert)
            {
                if (CrossAbove(Fast, Slow, 1))
                {
                    Alert("UpAlert", NinjaTrader.Cbi.Priority.Medium, "UpAlert", upAlertFile, 60, Color.Navy, Color.Magenta);
                }


                if (CrossBelow(Fast, Slow, 1))
                {
                    Alert("DownAlert", NinjaTrader.Cbi.Priority.Medium, "DownAlert", downAlertFile, 60, Color.Navy, Color.Yellow);
                }
            }


            if (CurrentBar < 2)
            {
                return;
            }

            if (Colorzone)
            {
                if (Fast[0] > Slow[0])
                {
                    DrawRegion("MABands" + CurrentBar, 1, 0, ma1Series, ma2Series, Color.Transparent, UpColor, Zopacity);
                }
                else
                {
                    DrawRegion("MABands" + CurrentBar, 1, 0, ma1Series, ma2Series, Color.Transparent, DownColor, Zopacity);
                }
            }
        }
示例#14
0
        private void process_bkgw_DoWork(object sender, DoWorkEventArgs e)
        {
            if (globalTypeOfProcess == 1)
            {
                if (globalFileType == false)
                {
                    try {
                        pTimer.Start();
                        /*              Encrypt string              */
                        if (globalEncodeBase64 == true)
                        {
                            globalDataProcessed = Convert.ToBase64String(xs8Cipher.Encrypt(Encoding.UTF8.GetBytes(globalDataProcessed), globalKey, globalKeySize));
                        }
                        else
                        {
                            globalDataProcessed = Fast.ToHexString(xs8Cipher.Encrypt(Encoding.UTF8.GetBytes(globalDataProcessed), globalKey, globalKeySize));
                        }
                        pTimer.Stop();
                    } catch { MessageBox.Show("Strange, very strange...", "[#0] - Can't encrypt this string...", MessageBoxButtons.OK, MessageBoxIcon.Information); }
                }
                else
                {
                    string fileOut = globalFileName[0];
                    fileOut = fileOut.Insert(0, globalFileName[1] + "\\");
                    fileOut = fileOut.Insert(fileOut.Length, globalFileName[2].Substring(globalFileName[2].LastIndexOf('.')));
                    try {
                        pTimer.Start();
                        /*                Encrypt file              */
                        if (globalFileName[2].Substring(globalFileName[2].LastIndexOf('.') + 1) != "bmp")
                        {
                            File.WriteAllBytes(fileOut, xs8Cipher.Encrypt(File.ReadAllBytes(globalFileName[2]), globalKey, globalKeySize));
                        }
                        else
                        {
                            var          fileStream = new FileStream(globalFileName[2], FileMode.Open, FileAccess.Read);
                            MemoryStream ms         = new MemoryStream();
                            fileStream.CopyTo(ms);
                            var header     = ms.ToArray().Take(54).ToArray();
                            var imageArray = ms.ToArray().Skip(54).ToArray();
                            var encimg     = xs8Cipher.Encrypt(imageArray, globalKey, globalKeySize);
                            var image      = Combine(header, encimg);
                            File.WriteAllBytes(fileOut, image);
                            fileStream.Close();
                        }

                        pTimer.Stop();
                    } catch {
                        MessageBox.Show("This can happen when you try to encrypt a large file", "[#2] - Can't encrypt this file...", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            if (globalTypeOfProcess == 2)
            {
                if (globalFileType == false)
                {
                    try {
                        pTimer.Start();
                        /*              Decrypt string              */
                        if (globalEncodeBase64 == true)
                        {
                            globalDataProcessed = Encoding.UTF8.GetString(xs8Cipher.Decrypt(Convert.FromBase64String(globalDataProcessed), globalKey, globalKeySize));
                        }
                        else
                        {
                            byte[] fromHex = Fast.FromHexString(globalDataProcessed);
                            globalDataProcessed = Encoding.UTF8.GetString(xs8Cipher.Decrypt(fromHex, globalKey, globalKeySize));
                        }
                        pTimer.Stop();
                    } catch { MessageBox.Show("Strange, very strange...", "[#0] - Can't encrypt this string...", MessageBoxButtons.OK, MessageBoxIcon.Information); }
                }
                else
                {
                    string fileOut = globalFileName[0];
                    fileOut = fileOut.Insert(0, globalFileName[1] + "\\");
                    fileOut = fileOut.Insert(fileOut.Length, globalFileName[2].Substring(globalFileName[2].LastIndexOf('.')));
                    try {
                        pTimer.Start();
                        /*              Decrypt file              */
                        if (globalFileName[2].Substring(globalFileName[2].LastIndexOf('.') + 1) != "bmp")
                        {
                            File.WriteAllBytes(fileOut, xs8Cipher.Decrypt(File.ReadAllBytes(globalFileName[2]), globalKey, globalKeySize));
                        }
                        else
                        {
                            var          fileStream = new FileStream(globalFileName[2], FileMode.Open, FileAccess.Read);
                            MemoryStream ms         = new MemoryStream();
                            fileStream.CopyTo(ms);
                            var header     = ms.ToArray().Take(54).ToArray();
                            var imageArray = ms.ToArray().Skip(54).ToArray();
                            var encimg     = xs8Cipher.Decrypt(imageArray, globalKey, globalKeySize);
                            var image      = Combine(header, encimg);
                            File.WriteAllBytes(fileOut, image);
                            fileStream.Close();
                        }

                        pTimer.Stop();
                    } catch {
                        MessageBox.Show("This can happen when you try to encrypt a large file", "[#2] - Can't encrypt this file...", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
        }
示例#15
0
 /// <summary>
 /// Returns the name of this indicator.
 /// </summary>
 /// <returns>The name of this indicator</returns>
 public override string ToString()
 {
     return("Ppo," + Fast.ToString() + "," + Slow.ToString() + "," + Smooth.ToString());
 }