public TradeStrategy(List<Price> Prices, Parameter_General parameter, DateTime startPeriod, Triggers_Delegate Triggers, Triggers_Delegate Triggers2)
        {
            _p.StopLoss = parameter.StopLoss;
            _p.TakeProfit = parameter.TakeProfit;
            _Trigger = Triggers;
            _Trigger2 = Triggers2;
            _p.CloseEndofDay = parameter.CloseEndofDay;

            foreach (Price s in Prices)
            {
                if (s.TimeStamp >= startPeriod)
                {
                    TradeStrategy st = new TradeStrategy
                    {
                        TimeStamp = s.TimeStamp,
                        Price_Open = s.Open,
                        Price_Close = s.Close,
                        Price_High = s.High,
                        Price_Low = s.Low,
                        InstrumentName = s.InstrumentName
                    };
                    _ST.Add(st);
                }
            }
           // GetDynamicStopLoss(Prices, parameter.StoplossFactor ,parameter.TakeProfitFactor);
        }
        public static List<Trade> EmaScalp(Parameter_EMA_Scalp 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);

            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>();

        }
Esempio n. 3
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>());
        }
Esempio n. 4
0
        public TradeStrategy(List <Price> Prices, Parameter_General parameter, DateTime startPeriod, Triggers_Delegate Triggers, Triggers_Delegate Triggers2)
        {
            _p.StopLoss      = parameter.StopLoss;
            _p.TakeProfit    = parameter.TakeProfit;
            _Trigger         = Triggers;
            _Trigger2        = Triggers2;
            _p.CloseEndofDay = parameter.CloseEndofDay;

            foreach (Price s in Prices)
            {
                if (s.TimeStamp >= startPeriod)
                {
                    TradeStrategy st = new TradeStrategy
                    {
                        TimeStamp      = s.TimeStamp,
                        Price_Open     = s.Open,
                        Price_Close    = s.Close,
                        Price_High     = s.High,
                        Price_Low      = s.Low,
                        InstrumentName = s.InstrumentName
                    };
                    _ST.Add(st);
                }
            }
            // GetDynamicStopLoss(Prices, parameter.StoplossFactor ,parameter.TakeProfitFactor);
        }
Esempio n. 5
0
        private static int GetVolume(TradeStrategy T)
        {
            int vol = 0;

            if (T.ActualTrade != Trade.Trigger.None)
            {
                vol = 1;
            }
            return(vol);
        }
Esempio n. 6
0
        public static List <Trade> GetTradeData(bool TradesOnly)
        {
            List <Trade> trades = new List <Trade>();

            for (int x = 0; x < _T.Count; x++)
            {
                var t = new Trade()
                {
                    InstrumentName   = _T[x].InstrumentName,
                    BuyorSell        = TradeStrategy.GetBuySell(_T[x].ActualTrade),
                    CurrentDirection = _T[x].TradeDirection,
                    Position         = _T[x].Position,
                    RunningProfit    = _T[x].RunningProfit,
                    TimeStamp        = _T[x].TimeStamp,
                    TotalPL          = _T[x].TotalProfit,
                    TradedPrice      = _T[x].Price_Close,
                    Reason           = _T[x].ActualTrade,
                    CurrentPrice     = _T[x].Price_Close,
                    TradeVolume      = GetVolume(_T[x]),
                    IndicatorNotes   = "A1:" + Math.Round(A_1[x].Ema, 2) + "  A2:" + Math.Round(A_6[x].Ema, 2) + "  B1:" + Math.Round(B_1[x].Ema, 2) + "  B2:" + Math.Round(B_6[x].Ema, 2) + "  C:" + Math.Round(E1[x].Ema, 2)
                };

                if (TradesOnly)
                {
                    if (_T[x].ActualTrade != Trade.Trigger.None)
                    {
                        trades.Add(t);
                    }
                }
                else
                {
                    trades.Add(t);
                }

                // Debug.WriteLine(t.TimeStamp + "," + t.BuyorSell + "," + t.CurrentDirection + "," + _T[x].TradeTrigger + ","  + _T[x].ActualTrade  + "," + _T[x].TradedPrice );
            }

            Clear();
            return(trades);
        }
        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>();

        }
Esempio n. 8
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>());
        }
 private static int GetVolume(TradeStrategy T)
 {
     int vol = 0;
     if (T.ActualTrade != Trade.Trigger.None) vol = 1;
     return vol;
 }
Esempio n. 10
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("----------------------------------------------");
            }