public void FillSettings(StrategySettings settings) { var udSettings = (SimpleStrategySettings)settings; udSettings.BuyThreshold = (double)numBuyThreshold.Value; udSettings.SellThreshold = -(double)numSellThreshold.Value; }
public void FillSettings(StrategySettings settings) { var emaSettings = (EMAStrategySettings)settings; emaSettings.BuyThreshold = (double)numBuyThreshold.Value; emaSettings.SellThreshold = -(double)numSellThreshold.Value; emaSettings.FastEMAPeriod = (int)numFastMAPeriod.Value; emaSettings.SlowEMAPeriod = (int)numSlowMAPeriod.Value; }
/// <summary> /// Saves settings into the object /// </summary> /// <param name="settings"></param> public void FillSettings(StrategySettings settings) { var macdSettings = (MACDStrategySettings)settings; macdSettings.BuyThreshold = (double)numBuyThreshold.Value; macdSettings.SellThreshold = -(double)numSellThreshold.Value; macdSettings.FastEMAPeriod = (int)numFastMAPeriod.Value; macdSettings.SlowEMAPeriod = (int)numSlowMAPeriod.Value; macdSettings.SignalPeriod = (int)numSignal.Value; }
public static VolumeStrategySettings FromSettings(StrategySettings settings) { return(new VolumeStrategySettings( (Market)settings.Get(MarketCaption), (Pair)settings.Get(PairCaption), (int)settings.Get(PeriodCaption), (int)settings.Get(BarCountCaption), (int)settings.Get(GrowingPercentageCaption) )); }
public PickController( ILogger <PickController> logger, IOptions <StrategySettings> settings, IPickStrategyFactory strategyFactory, IPredictorProxyService predictorProxy) { _logger = logger; _settings = settings.Value; _strategyFactory = strategyFactory; _predictorProxy = predictorProxy; }
/////////////// #endregion //PRIVATE_MEMBERS #region MONOBEHAVIOUR_METHODS protected virtual void Start() { mCamSettings = FindObjectOfType <CameraSettings>(); mTrackableSettings = FindObjectOfType <TrackableSettings>(); mMenuAnim = FindObjectOfType <MenuAnimator>(); //////////////// mStrtSettings = FindObjectOfType <StrategySettings>(); mToggleGroup = GetComponentInChildren <ToggleGroup>(); prev_tgl = mToggleGroup.ActiveToggles().FirstOrDefault(); /////////////// }
public StrategySettings ToSettings() { var result = new StrategySettings(); result.Add(MarketCaption, Market); result.Add(PairCaption, Pair); result.Add(PeriodCaption, PeriodMinute); result.Add(BarCountCaption, GrowingBarCount); result.Add(GrowingPercentageCaption, GrowingPercentage); return(result); }
private void DetermineStopLoss(object sender, ElapsedEventArgs e) { settings = AppSettings.GetStrategySettings2(_StategyName); //AppSettings.GetStrategySettings("macd"); 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()); if (LastBuyAtPrice == 0) { return; } var stopLossPercent = settings.stop_loss_percent; //Convert.ToDecimal(settings[0]["stop_loss_percent"].ToString()); var curPrice = contextVals.CurrentBufferedPrice; var curDiff = Math.Round(curPrice - LastBuyAtPrice, 4); var diffPercentage = Math.Round((curDiff / LastBuyAtPrice) * 100, 4); if (stopLossCounter % 3 == 0 || stopLossCounter == 0) { var msg = string.Format(_StategyName + ": Price change since last buy: {0}-{1} = {2} ({3}%)", Math.Round(curPrice, 4).ToString(), Math.Round(LastBuyAtPrice, 4).ToString(), curDiff.ToString(), diffPercentage.ToString()); Logger.WriteLog(msg); } stopLossCounter += 1; if (diffPercentage <= Math.Abs(stopLossPercent) * -1) { StopLossInEffect = true; if (stopLossCounter % 2 == 0 || stopLossCounter == 0) { Logger.WriteLog("Stop Loss in effect"); } Sell = true; Buy = false; } else { //Sell = false; //Buy = false; StopLossInEffect = false; } }
/// <summary> /// Initialises a new instance of the class /// </summary> /// <param name="settings">the strategy settings</param> /// <param name="tradingIndicator">The indicator to use</param> public BaseTradingStrategy(StrategySettings settings, ITradingIndicator tradingIndicator) { _settings = settings; _tradingIndicator = tradingIndicator; _pair = settings.Pair; Actions = new List <MarketAction>(); // Only do back testing trading for now _proxy = new FakeExchange(); if (_proxy is FakeExchange) { (_proxy as FakeExchange).Init(settings.InitialItem1Balance, settings.InitialItem2Balance, settings.BuyFee, settings.SellFee); } }
public TrainingSession(StockPortfolio portfolio, Stock stock, BestNetworkDTO dto, NeuralStockSettings settings) { _statisticsService = ApplicationHelper.CurrentCompositionContainer.GetExportedValue <IStatisticsService>(); Portfolio = portfolio; Stock = stock; TrainSamplePercentage = settings.PercentageTraining; NumberAnns = settings.NumberANNs; NumberHiddenLayers = settings.NumberHiddenLayers; NumberNeuronsPerHiddenLayer = settings.NumberNeuronsHiddenLayer; NumberDaysBetweenTransactions = settings.NumberDaysBetweenTransactions; BuyLevel = dto.BuyLevel; SellLevel = dto.SellLevel; var strategy = new StrategyI(StrategySettings.FromJson(dto.StrategySettings), settings) { TrainingMeansInput = dto.TrainingMeansInput?.ToArray(), TrainingStdDevsInput = dto.TrainingStdDevsInput?.ToArray(), TrainingMeansOutput = dto.TrainingMeansOutput?.ToArray(), TrainingStdDevsOutput = dto.TrainingStdDevsOutput?.ToArray() }; var tmpFileName = Path.GetTempFileName(); File.WriteAllBytes(tmpFileName, dto.BestNeuralNet); var net = new NeuralNet(tmpFileName); _cachedPredictions.Clear(); SplitTrainTestData(); var trainingTestingData = PrepareAnnData(strategy, false); var prediction = Predict(trainingTestingData, net, false); var profitLossCalculator = new ProfitLossCalculator(Portfolio.Reset(), this, prediction.Item1); _cachedPredictions.Add(new Prediction(profitLossCalculator, strategy, net, prediction.Item2, prediction.Item3)); }
public BitmexDOMListener(IBitmexApiSocketService svc, StrategySettings settings) { _svc = svc; _svc.Connect(); _svc.Subscribe(BitmetSocketSubscriptions.CreateOrderBookL2Subsription( msg => { foreach (var dto in msg.Data) { if (!string.Equals(dto.Symbol, settings.Instrument.Symbol, StringComparison.OrdinalIgnoreCase)) { continue; } var tmp = OnDOMChanged; if (tmp != null) { tmp(); } } } )); }
public OrderManager(IExecutionStrategy exec, StrategySettings settings) { _exec = exec; _settings = settings; _exec.DeleteAllOrders(_settings.Instrument).Wait(); }
private void UpdateMacdValues(object sender, EventArgs e) { Logger.WriteLog(String.Format("Udating {0} strategy values", _StategyName)); //if (StopLossInEffect) //{ // Logger.WriteLog("Stop loss in effect"); // return; //} var largeSmaDataPoints = BigSma.SmaDataPoints; var smallSmaDataPoints = SmallSma.SmaDataPoints; //var emaTest = MovingAverage.SharedRawExchangeData.Select((d) => (double)d.Close).ToList().EMA(500); //var fst = emaTest.First(); //var lst = emaTest.Last(); var smaDiff = from i in Enumerable.Range(0, Math.Max(largeSmaDataPoints.Count, smallSmaDataPoints.Count)) select smallSmaDataPoints.ElementAtOrDefault(i) - largeSmaDataPoints.ElementAtOrDefault(i); var curSmaDiff = Math.Round(smaDiff.First(), 4); settings = AppSettings.GetStrategySettings2(_StategyName); var largeSignal = settings.signal; //Convert.ToInt16(settings[0]["signal"].ToString()); var smallSignal = settings.my_sma; //Convert.ToInt16(settings[0]["my_sma"].ToString()); var L_SIGNAL_LEN = largeSignal; //14; var S_SIGNAL_LEN = smallSignal; //5; var bigSmaOfMacd = Math.Round(smaDiff.ToList().SMA(L_SIGNAL_LEN).First(), 4); var smallSmaOfMacd = Math.Round(smaDiff.ToList().SMA(S_SIGNAL_LEN).First(), 4); //todo: //Logger.WriteLog("current large ema " + MovingAverage.SharedRawExchangeData.Select((d) => (double)d.Close).ToList().EMA(100).First()); //Logger.WriteLog("current small ema " + MovingAverage.SharedRawExchangeData.Select((d) => (double)d.Close).ToList().EMA(15).First()); //largeSmaDataPoints.EMA(15)); Logger.WriteLog(string.Format("macd values: \n" + "\tcurent small sma: {0}\n" + "\tcurent large sma: {1}\n" + "\tsmall - large = macd: {2}\n" + "\tbig sma of macd: {3}\n" + "\tsmall sma of macd: {4}\n", Math.Round(smallSmaDataPoints.First(), 4), Math.Round(largeSmaDataPoints.First(), 4), curSmaDiff, bigSmaOfMacd, smallSmaOfMacd)); var useBothSma = settings.use_two_sma; //Convert.ToBoolean(settings[0]["use_two_sma"].ToString()); if (IsValuesToClose(curSmaDiff, smallSmaOfMacd)) { Logger.WriteLog("values to close to each other, skipping buy / sell. \n" + "macd: " + curSmaDiff.ToString() + " smallSmaMacd: " + smallSmaOfMacd.ToString()); return; } if (useBothSma) { if (curSmaDiff > bigSmaOfMacd && curSmaDiff > smallSmaOfMacd) { //if stop loss in effect -> no need to indicate to buy since stop loss already sold and graph suggests buy if (StopLossInEffect) { Logger.WriteLog("Stop Loss in effect (BUY = True), cant buy again now"); return; } //buy condition Logger.WriteLog("BUY = true"); Buy = true; Sell = false; } else { //if stop loss in effect (and graph saying sell)-> then turn it off and signal to sell if not already sold if (StopLossInEffect) { StopLossInEffect = false; //set last buy price (value will be overridden in buy func) to 0 //this stops dterimeStopLoss to return false and //so that stop loss does not get set to on again //AppSettings.SaveUpdateStrategySetting("macd", "last_buy_price", "0.01"); //update all strategies with last buy price to 0.01 var allStrategies = AppSettings.GetAllStrategies(); foreach (var s in allStrategies) { AppSettings.SaveUpdateStrategySetting(s.StrategyName, "last_buy_price", "0.01"); } Logger.WriteLog("Stop Loss in effect (SELL = True), resetting stoploss flag to false."); //reload the settings to get 0.00 for last_buy_price //which disables stopLoss flag AppSettings.Reloadsettings(); return; } //sell Logger.WriteLog("Sell = true"); Sell = true; Buy = false; } } else { if (curSmaDiff > smallSmaOfMacd) { //if stop loss in effect -> no need to indicate to buy since stop loss already sold and graph suggests buy if (StopLossInEffect) { Logger.WriteLog("Stop Loss in effect, cant buy again now"); return; } //buy condition Buy = true; Sell = false; } else { //if stop loss in effect (and graph saying sell)-> then turn it off and signal to sell if not already sold if (StopLossInEffect) { StopLossInEffect = false; //set last buy price (value will be overridden in buy func) to 0 //this stops dterimeStopLoss to return false and //so that stop loss does not get set to on again //AppSettings.SaveUpdateStrategySetting("macd", "last_buy_price", "0.00"); var allStrategies = AppSettings.GetAllStrategies(); foreach (var s in allStrategies) { AppSettings.SaveUpdateStrategySetting(s.StrategyName, "last_buy_price", "0.01"); } Logger.WriteLog("Stop Loss in effect, resetting stoploss flag to false."); //reload the settings to get 0.00 for last_buy_price //which disables stopLoss flag AppSettings.Reloadsettings(); return; } //sell Sell = true; Buy = false; } } //throw new NotImplementedException(); }
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); }
public VolumeStrategy(StrategySettings settings) { _settings = VolumeStrategySettings.FromSettings(settings); Updater.SetSettings(settings); }