Esempio n. 1
0
        //use big, medium or small sma to sell depending on market conditions
        public TradeStrategyE(ref ContextValues inputContextValues, IntervalValues intervalValues) : base(ref inputContextValues)
        {
            SetCurrentAction(inputContextValues.CurrentAction);
            LastBuyAtPrice  = inputContextValues.CurrentBufferedPrice;
            LastSellAtPrice = 0;



            BigIntervalSmaValues = new SmaValues("BigInterval", ref inputContextValues, intervalValues.LargeIntervalInMin,
                                                 intervalValues.LargeSmaSlices, intervalValues.MediumSmaSlice, intervalValues.SmallSmaSlices);
            SmallIntervalSmaValues = new SmaValues("SmallInterval", ref inputContextValues, intervalValues.MediumIntervalInMin,
                                                   intervalValues.LargeSmaSlices, intervalValues.MediumSmaSlice, intervalValues.SmallSmaSlices);
            TinyIntervalSmaValues = new SmaValues("TinyInterval", ref inputContextValues, intervalValues.SmallIntervalInMin,
                                                  intervalValues.LargeSmaSlices, intervalValues.MediumSmaSlice, intervalValues.SmallSmaSlices);


            inputContextValues.WaitTimeAfterBigSmaCrossInMin = intervalValues.LargeIntervalInMin;
            //LargeSmaGroup = new SmaGroup();
            //LargeSmaGroup.SetGroup(SmallIntervalSmaValues, BigIntervalSmaValues);

            //SmallSmaGroup = new SmaGroup();
            //SmallSmaGroup.SetGroup(TinyIntervalSmaValues, SmallIntervalSmaValues);

            try
            {
                SmallPriceIncreasedPercentage = Properties.Settings.Default.StrategyE_SmallPriceIncreasedPercent;
                BigPriceIncreasedPercentage   = Properties.Settings.Default.StrategyE_BigPriceIncreasedPercent;
            }
            catch (Exception)
            {
                Logger.WriteLog("Couldnt read strategy E big and samll price change percentage values, using default of .75 and 1.75");
                SmallPriceIncreasedPercentage = 0.75m;
                BigPriceIncreasedPercentage   = 1.75m;
            }
        }
Esempio n. 2
0
        public MacdStrategy(ref ContextValues inputContextValues, IntervalValues intervalValues) : base(ref inputContextValues)
        {
            //myMacdStrategy_Large = new Macd(ref inputContextValues, "macd_large");

            myMacdStrategy_Small = new Macd(ref inputContextValues, "macd_small");

            var genSettings = AppSettings.GetGeneralSettings();

            percent_for_using_smallmacd = genSettings.price_inc_percent_for_using_smallmacd;
        }
Esempio n. 3
0
 public TradeStrategyF(ref ContextValues inputContextValues, IntervalValues intervalValues) : base(ref inputContextValues, intervalValues)
 {
 }
Esempio n. 4
0
 public TradeStrategyBase(ref ContextValues inputContextValues)
 {
     CurrentValues = inputContextValues;
 }
Esempio n. 5
0
        public SmaValues(string groupName, ref ContextValues inputContextValues,
                         int CommonIntervalMin = 5,
                         int LargestSmaSlice   = 60,
                         int MediumSmaSlice    = 55,
                         int SmallestSmaSlice  = 28)
        {
            myContextValues = inputContextValues;

            smaGroupName = groupName;

            sellBufferFraction = 10; //default value
            logSmaValueUpdates = false;
            //int commonLargeIntervalMin = 5;
            smallestSmaPrice = 0;
            mediumSmaPrice   = 0;
            largestSmaPrice  = 0;

            BuyReason  = "";
            SellReason = "";

            amountOfServerDataToDownload = 10; //default value

            try
            {
                Properties.Settings.Default.Reload();

                sellBufferFraction = Properties.Settings.Default.SellBufferFraction;
                if (sellBufferFraction == 0)
                {
                    sellBufferFraction = 10;
                }

                logSmaValueUpdates = Properties.Settings.Default.LogSmaUpdates;

                amountOfServerDataToDownload = Properties.Settings.Default.AmountOfServerData;
            }
            catch (Exception)
            {
                Logger.WriteLog("Error loading settings value sellbufferFraction using default of 10");
            }

            LargestMa  = new MovingAverage(ref inputContextValues.CurrentTicker, inputContextValues.ProductName, CommonIntervalMin, LargestSmaSlice, amountOfServerDataToDownload);
            MediumMa   = new MovingAverage(ref inputContextValues.CurrentTicker, inputContextValues.ProductName, CommonIntervalMin, MediumSmaSlice, amountOfServerDataToDownload);
            SmallestMa = new MovingAverage(ref inputContextValues.CurrentTicker, inputContextValues.ProductName, CommonIntervalMin, SmallestSmaSlice, amountOfServerDataToDownload);

            CommonSmaInterval = CommonIntervalMin;
            LargeSmaSlice     = LargestSmaSlice;
            MedSmaSlice       = MediumSmaSlice;
            SmallSmaSlice     = SmallestSmaSlice;


            LargestMa.MovingAverageUpdatedEvent  += LargestSmaUpdatedHandler;
            MediumMa.MovingAverageUpdatedEvent   += MediumSmaUpdatedHandler;
            SmallestMa.MovingAverageUpdatedEvent += SmallestSmaUpdateHandler;


            largestSmaPrice  = LargestMa.CurrentSMAPrice;
            mediumSmaPrice   = MediumMa.CurrentSMAPrice;
            smallestSmaPrice = SmallestMa.CurrentSMAPrice;

            Buy  = false;
            Sell = false;


            //DetermineBuySell();
        }
Esempio n. 6
0
        private void InitManager(string ProductName, IntervalValues intervalValues)
        {
            //try to get ticker first



            //Logger.WriteLog("Init Manager Thread ID: " + Thread.CurrentThread.ManagedThreadId.ToString());

            try
            {
                Logger.WriteLog("Initializing ticker");
                ProductTickerClient = new TickerClient(ProductName);
            }
            catch (Exception ex)
            {
                Logger.WriteLog("Manager cant initialize ticker");
                return;
            }


            ProductTickerClient.PriceUpdated += ProductTickerClient_UpdateHandler;

            AvoidExchangeFees = true;

            ProductTickerClient.TickerConnectedEvent    += TickerConnectedHandler;
            ProductTickerClient.TickerDisconnectedEvent += TickerDisconnectedHandler;

            MyAuth             = new CBAuthenticationContainer(MyKey, MyPassphrase, MySecret);
            MyProductOrderBook = new MyOrderBook(MyAuth, ProductName, ref ProductTickerClient);
            MyProductOrderBook.OrderUpdateEvent += FillUpdateEventHandler;



            CurContextValues             = new ContextValues(ref MyProductOrderBook, ref ProductTickerClient);
            CurContextValues.ProductName = ProductName;

            CurContextValues.Auth = MyAuth;

            CurContextValues.AutoTradingStartEvent += autoTradeStartEventHandler;
            CurContextValues.AutoTradingStopEvent  += autoTradeStopEventHandler;

            ////update ui with initial prices
            ProductTickerClient_UpdateHandler(this, new TickerMessage(ProductTickerClient.CurrentPrice));


            CurrentDisplaySmaTimeInterval = intervalValues.LargeIntervalInMin;
            CurrentDisplaySmaSlices       = intervalValues.LargeSmaSlices; //default large sma slice value



            //SmaSmall = new MovingAverage(ref ProductTickerClient, ProductName, CurContextValues.CurrentSmallSmaTimeInterval, CurContextValues.CurrentSmallSmaSlices);
            //SmaSmall.MovingAverageUpdated += SmaSmallChangedEventHandler;

            Logger.WriteLog(string.Format("{0} manager started", ProductName));


            //currentTradeStrategy = new TradeStrategyA(ref CurContextValues);
            //currentTradeStrategy = new TradeStrategyB(ref CurContextValues);
            //currentTradeStrategy = new TradeStrategyC(ref CurContextValues);
            //currentTradeStrategy = new TradeStrategyB(ref CurContextValues);
            //currentTradeStrategy = new TradeStrategyD(ref CurContextValues);

            if (intervalValues == null)
            {
                intervalValues = new IntervalValues(30, 15, 5);//IntervalValues(5, 3, 1);
            }
            //currentTradeStrategy = new TradeStrategyE(ref CurContextValues, intervalValues);

            CreateUpdateStrategyInstance(intervalValues, true).Wait();

            currentTradeStrategy.CurrentActionChangedEvent += CUrrentActionChangeEventHandler;



            //save the interval values for later use
            //CurContextValues.CurrentIntervalValues = intervalValues;
            SetCurrentIntervalValues(intervalValues);


            DisplaySma = new MovingAverage(ref ProductTickerClient, ProductName, CurrentDisplaySmaTimeInterval, CurrentDisplaySmaSlices);
            DisplaySma.MovingAverageUpdatedEvent += DisplaySmaChangedEventHandler;

            UpdateDisplaySmaParameters(CurrentDisplaySmaTimeInterval, CurrentDisplaySmaSlices);

            UpdateBuySellAmount(0.01m); //default
            //UpdateBuySellBuffer(0.03m); //default


            try
            {
                UpdateFunds();
            }
            catch (Exception)
            {
                Logger.WriteLog("Error getting available funds details, please check your gdax credentials");
            }

            AppSettings.MajorSettingsChangEvent += MajorSettingsChangedEventHandler;

            //writeCurrentStrategySmaValues();



            //ShowGraph(gra);
        }
Esempio n. 7
0
        public Macd(ref ContextValues inputContextValues, string macdStrategyName)
        {
            Buy  = false;
            Sell = false;

            stopLossCounter = 0;

            StopLossInEffect = false;

            _StategyName = macdStrategyName;

            settings = AppSettings.GetStrategySettings2(_StategyName);



            if (settings == null)
            {
                throw new Exception("CantInitSettingsError");
            }

            Logger.WriteLog("macd settings found: ");
            AppSettings.PrintStrategySetting(settings.StrategyName);


            LastBuyAtPrice  = settings.last_buy_price;  //Convert.ToDecimal(settings[0]["last_buy_price"].ToString());
            LastSellAtPrice = settings.last_sell_price; //Convert.ToDecimal(settings[0]["last_sell_price"].ToString());

            CommonINTERVAL = settings.time_interval;    //30;//30; //min
            int largeSmaLENGTH = settings.slow_sma;     //100;
            int smallSmaLENGTH = settings.fast_sma;     //15;

            updateInterval = CommonINTERVAL;            //update values every 1 min to keep sma data updated

            BigSma   = new MovingAverage(ref inputContextValues.CurrentTicker, inputContextValues.ProductName, CommonINTERVAL, largeSmaLENGTH);
            SmallSma = new MovingAverage(ref inputContextValues.CurrentTicker, inputContextValues.ProductName, CommonINTERVAL, smallSmaLENGTH);


            contextVals = inputContextValues;

            //if (aTimer != null) //timer already in place
            //{
            //    aTimer.Elapsed -= UpdateMacdValues;
            //    aTimer.Stop();
            //    aTimer = null;
            //}


            //aTimer = new System.Timers.Timer();
            //aTimer.Elapsed += UpdateMacdValues;
            //aTimer.Interval = updateInterval * 60 * 1000;
            //aTimer.Enabled = true;
            //aTimer.Start();



            BigSma.MovingAverageUpdatedEvent += UpdateMacdValues;


            UpdateMacdValues(this, null);



            if (StopLossTimer != null) //timer already in place
            {
                StopLossTimer.Elapsed -= DetermineStopLoss;
                StopLossTimer.Stop();
                StopLossTimer = null;
            }
            StopLossTimer          = new System.Timers.Timer();
            StopLossTimer.Elapsed += DetermineStopLoss;
            StopLossTimer.Interval = 1 * 60 * 1000; //every minute check the stop loss condition
            StopLossTimer.Enabled  = true;
            StopLossTimer.Start();


            DetermineStopLoss(this, null);
        }