示例#1
0
        public static List <Trade> EmaSar(Parameter_EMA_SAR P, List <Price> price, bool tradeOnly)
        {
            A_1 = Factory_Indicator.createEMA(P.A_EMA1, price);
            A_6 = Factory_Indicator.createEMA(P.A_EMA2, price);
            B_1 = Factory_Indicator.createEMA(P.B_EMA1, price);
            B_6 = Factory_Indicator.createEMA(P.B_EMA2, price);
            E1  = Factory_Indicator.createEMA(P.C_EMA, price);
            SAR = Factory_Indicator.createSAR(P.SAR_STEP, P.SAR_MAXP, price);
            DateTime sd = E1[0].TimeStamp;

            CutToSize(sd);
            TradeStrategy _strategy = new TradeStrategy(price, P, B_6[0].TimeStamp, CalcTriggers, CalcTriggers2);

            _strategy.Calculate();
            _T = _strategy.getStrategyList();
            //for (int x = 0; x < _T.Count; x++) DP(x);


            // _strategy.ClearList(); //FOR SIMULATOR
            return(GetTradeData(tradeOnly)); // REAL TRADING

            //  Clear();//FOR SIMULATOR

            return(new List <Trade>());
        }
示例#2
0
        public static List <Trade> MAMAScalp(Parameter_MAMA P, List <Price> price, bool tradeOnly)
        {
            A_1 = Factory_Indicator.createEMA(P.A_EMA1, price);
            A_6 = Factory_Indicator.createEMA(P.A_EMA2, price);
            B_1 = Factory_Indicator.createEMA(P.B_EMA1, price);
            B_6 = Factory_Indicator.createEMA(P.B_EMA2, price);
            E1  = Factory_Indicator.createEMA(P.C_EMA, price);

            MA = Factory_Indicator.createAdaptiveMA_MAMA(P.Fast, P.Slow, price);

            //StreamWriter sr = new StreamWriter(@"d:\MAMA.txt");
            //foreach (var m in MA.Skip(1000))
            //{
            //    sr.WriteLine(m.TimeStamp + "," + m.Price_Close + "," + m.Mama + "," + m.Fama);//+","+E1.Where(z=>z.TimeStamp==m.TimeStamp).First().Ema );
            //}
            //sr.Close();

            //Environment.Exit(0);

            DateTime sd = E1[0].TimeStamp;

            CutToSize(sd);
            TradeStrategy _strategy = new TradeStrategy(price, P, B_6[0].TimeStamp, CalcTriggers, CalcTriggers2);

            _strategy.Calculate();
            _T = _strategy.getStrategyList();
            //for (int x = 0; x < _T.Count; x++) DP(x);


            // _strategy.ClearList(); //FOR SIMULATOR
            return(GetTradeData(tradeOnly)); // REAL TRADING

            //  Clear();//FOR SIMULATOR

            return(new List <Trade>());
        }
示例#3
0
        public static List <IndicatorBasket> CalcIndicators()
        {
            //   Console.WriteLine("Calculating Indicators...");
            var Indicators = new List <IndicatorBasket>();

            //Base Level Calcs
            var ohlc      = Trades.Select(z => z.OHLC);
            var OHLC_LIST = ohlc.ToList();
            var volume    = Trades.ToDictionary(x => x.TimeStamp, x => x.TradeVolume);
            var trigger   = Trades.ToDictionary(x => x.TimeStamp, x => x.TradeTrigger);
            var EM        = AlsiUtils.Factory_Indicator.createAdaptiveMA_MAMA(P.Mamapar1, P.Mamapar2, OHLC_LIST).ToDictionary(x => x.TimeStamp, x => x.Mama);
            var adx_DMI   = AlsiUtils.Factory_Indicator.createADX(P.ADX_period, OHLC_LIST);
            var RSI       = AlsiUtils.Factory_Indicator.createRSI(P.RSI_period, OHLC_LIST);


            //Second Level Clacs
            //EMA OF DMI+ and DMI-
            List <VariableIndicator> varDmiUP   = new List <VariableIndicator>();
            List <VariableIndicator> varDmiDOWN = new List <VariableIndicator>();

            foreach (var f in adx_DMI)
            {
                var vdown = new VariableIndicator()
                {
                    TimeStamp = f.TimeStamp,
                    Value     = f.DI_Down,
                };
                var vup = new VariableIndicator()
                {
                    TimeStamp = f.TimeStamp,
                    Value     = f.DI_Up,
                };

                varDmiUP.Add(vup);
                varDmiDOWN.Add(vdown);
            }

            var Dmi_Up_EMA   = Factory_Indicator.createEMA(P.Di_UP_avg_period, varDmiUP);
            var Dmi_Down_EMA = Factory_Indicator.createEMA(P.Di_DOWN_avg_period, varDmiDOWN);

            //EMA OF RSI
            List <VariableIndicator> varRsi = new List <VariableIndicator>();

            foreach (var r in RSI)
            {
                var rsi = new VariableIndicator()
                {
                    TimeStamp = r.TimeStamp,
                    Value     = r.RSI,
                };
                varRsi.Add(rsi);
            }

            var RSI_EMA = Factory_Indicator.createEMA(P.RSI_EMA, varRsi);

            //slope OF RSI
            var rsi_slope = Factory_Indicator.createRegression(P.RSI_Slope_period, varRsi);

            //CREATE DICTIONARY
            var DMI_UP_DIC   = Dmi_Up_EMA.ToDictionary(x => x.TimeStamp, x => x.Ema);
            var DMI_Down_DIC = Dmi_Down_EMA.ToDictionary(x => x.TimeStamp, x => x.Ema);
            var RSI_DIC      = RSI_EMA.ToDictionary(x => x.TimeStamp, x => x.Ema);
            var RSI_SLOPE    = rsi_slope.ToDictionary(x => x.TimeStamp, x => x.Slope);



            //  var sw = new StreamWriter(@"d:\Indicators.csv");
            // sw.WriteLine("Trade" + "," + "Stamp" + "," + "PriceClose" + "," + "MAMA" + "," + "DI-UP" + "," + "DI-DOWN" + "," + "VOL" + "," + "RSI" + "," + "RSI SLOPE" + "," + "extra 3" + "," + "extra 4");
            foreach (var r in adx_DMI)
            {
                double em = 0;
                EM.TryGetValue(r.TimeStamp, out em);

                double rs = 0;
                RSI_DIC.TryGetValue(r.TimeStamp, out rs);

                double rsslope = 0;
                RSI_SLOPE.TryGetValue(r.TimeStamp, out rsslope);

                int vol = 0;
                volume.TryGetValue(r.TimeStamp, out vol);

                double DI_up = 0;
                DMI_UP_DIC.TryGetValue(r.TimeStamp, out DI_up);

                double DI_Down = 0;
                DMI_Down_DIC.TryGetValue(r.TimeStamp, out DI_Down);

                Trade.Trigger Trig;
                trigger.TryGetValue(r.TimeStamp, out Trig);



                var topband = DI_up;
                var midband = em;
                var lowband = DI_Down;

                var b1     = rs;
                var adjVol = (vol == null) ? 0 : vol;
                var b2     = rsslope;;
                var b3     = 0;
                var b4     = 0;
                var trade  = Trig;

                var i = new IndicatorBasket()
                {
                    Action    = trade,
                    Timestamp = r.TimeStamp,
                    DI_DOWN   = DI_Down,
                    DI_UP     = DI_up,
                    Mama      = em,
                    RSI       = rs,
                    RSI_SLOPE = rsslope,
                    Price     = r.Price_Close,
                    Volume    = adjVol,
                };
                Indicators.Add(i);
                //   sw.WriteLine(trade + "," + r.TimeStamp + "," + r.Price_Close + "," + midband + "," + topband + "," + lowband + "," + adjVol + "," + b1 + "," + b2 + "," + b3 + "," + b4);
            }
            //   sw.Close();

            return(Indicators);
        }
示例#4
0
            private static void Apply_2nd_AlgoLayer(int EMA)
            {
                List <VariableIndicator> _st = new List <VariableIndicator>();

                foreach (var t in _ST)
                {
                    if (t.TotalProfit != 0)
                    {
                        VariableIndicator v = new VariableIndicator()
                        {
                            TimeStamp = t.TimeStamp,
                            Value     = t.TotalProfit,
                        };
                        _st.Add(v);
                    }
                }

                var           ema       = Factory_Indicator.createEMA(EMA, _st);
                double        newprof   = ema[0].CustomValue;
                TradeStrategy mt        = null;
                bool          cantradeA = false;
                bool          cantradeB = false;
                bool          closepos  = false;
                bool          first     = true;
                int           count     = 0;

                foreach (var v in ema)
                {
                    count++;
                    // if (count > 30) break;

                    if (first)
                    {
                        ;
                    }
                    mt = _ST.Where(z => z.TimeStamp == v.TimeStamp).First();

                    if (!first)
                    {
                        closepos = (mt.ActualTrade == Trade.Trigger.CloseShort || mt.ActualTrade == Trade.Trigger.CloseLong);
                    }
                    if (closepos && cantradeA)
                    {
                        cantradeB = true;
                    }
                    else
                    {
                        cantradeB = false;
                    }

                    cantradeA = (v.CustomValue > v.Ema);

                    if (!first && closepos && cantradeB)
                    {
                        newprof += mt.RunningProfit;
                    }

                    //Debug.WriteLine(((cantradeA) ? "**" : "") + ((cantradeB) ? "**" : "") + v.Timestamp + " " + v.CustomValue + " " + v.Ema +
                    //    " TradeA :" + cantradeA + "  TradeB :" + cantradeB + " Prof " + newprof +
                    //    "   " + ((!first && mt != null) ? mt.ActualTrade.ToString() : ""));



                    first = false;
                }

                Debug.WriteLine(EMA + "  " + newprof);
                Debug.WriteLine("----------------------------------------------");
            }