public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { var tm = value as TradingMacro; if (tm != null) { var categories = TradingMacro.GetActiveSettings2(excludeNotStrategy, tm, (c, i) => new { c, i }, (n, v) => new { n, v }, (key, values) => new { key, values = values.ToArray() }).ToArray(); writer.WriteStartObject(); foreach (var category in categories.OrderBy(c => c.key.i).ThenBy(c => c.key.c)) { writer.WriteWhitespace("\r\n"); writer.WriteComment(category.key.c); foreach (var v in category.values.OrderBy(v => v.n)) { writer.WritePropertyName(v.n); serializer.Serialize(writer, v.v); } } writer.WriteEndObject(); } else { JToken t = JToken.FromObject(value); if (t.Type != JTokenType.Object) { t.WriteTo(writer); } } }
private static void SetCorrelations(TradingMacro tm, List <Rate> rates, CorridorStatistics csFirst, PriceBar[] priceBars) { var pbs = priceBars /*.Where(pb => pb.StartDate > csFirst.StartDate)*/.OrderBy(pb => pb.StartDate).Select(pb => pb.Power).ToArray(); var rs = rates /*.Where(r => r.StartDate > csFirst.StartDate)*/.Select(r => r.PriceAvg).ToArray(); tm.Correlation_P = global::alglib.pearsoncorrelation(pbs, rs); tm.Correlation_R = global::alglib.spearmancorr2(pbs, rs, Math.Min(pbs.Length, rs.Length)); }
protected PriceBar[] FetchPriceBars(TradingMacro tradingMacro, int rowOffset, bool reversePower, DateTime dateStart) { var isLong = dateStart == DateTime.MinValue; var rs = tradingMacro.UseRates(ra => ra.Where(r => r.StartDate >= dateStart).GroupTicksToRates()).Concat(); var ratesForDensity = (reversePower ? rs.OrderBarsDescending() : rs.OrderBars()).ToArray(); SetPriceBars(tradingMacro, isLong, ratesForDensity.GetPriceBars(TradesManager.GetPipSize(tradingMacro.Pair), rowOffset)); return(GetPriceBars(tradingMacro, isLong)); }
private static void OnCloseTradeLocal(IList<Trade> trades, TradingMacro tm) { tm.BuyCloseLevel.InManual = tm.SellCloseLevel.InManual = false; if(trades.Any(t => t.Pair == tm.Pair) && trades.Select(t => t.PL).DefaultIfEmpty().Sum() >= -tm.PriceSpreadAverage) { tm.BuyLevel.CanTradeEx = tm.SellLevel.CanTradeEx = false; if(!tm.IsInVirtualTrading && !tm.IsAutoStrategy) tm.IsTradingActive = false; } if(tm.CurrentGrossInPipTotal > 0) { tm.BuyLevel.CanTrade = tm.SellLevel.CanTrade = false; if(!tm.IsInVirtualTrading) tm.IsTradingActive = false; } }
void SyncStraddleHistoryT1(TradingMacro tm) { var zip = (from shs in UseStraddleHistory(straddleHistory => (from sh in straddleHistory orderby sh.time select new { bid = sh.bid, time = sh.time.ToLocalTime() } ).ToList()) from endDate in shs.BackwardsIterator().Take(1).Select(t => t.time.ToLocalTime()) from z in tm.UseRates(ra => ra.TakeWhile(r => r.StartDate <= endDate).Zip(r => r.StartDate, shs, sh => sh.time, (r, sh) => (r, sh)).ToArray()) from t in z select t ).ToArray(); zip.ForEach(t => SetVoltage(t.r, t.sh.bid)); }
protected void SetPriceBars(TradingMacro tradingMacro, bool isLong, PriceBar[] priceBars) { if (!priceBarsDictionary.ContainsKey(tradingMacro)) { priceBarsDictionary.Add(tradingMacro, new PriceBarsDuplex()); } if (isLong) { priceBarsDictionary[tradingMacro].Long = priceBars; } else { priceBarsDictionary[tradingMacro].Short = priceBars; } }
protected override IList <JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { IList <JsonProperty> properties = base.CreateProperties(type, memberSerialization); // only serializer properties that start with the specified character var saveAttrs = new Type[] { typeof(DataMemberAttribute), typeof(WwwSettingAttribute) }; Func <PropertyInfo, bool> ok = pi => { var attrs = pi.GetCustomAttributes().ToArray(); var should = (from a in attrs join sa in saveAttrs on a.GetType() equals sa select true); return(should.Any()); }; var activeSettings = TradingMacro.GetActiveProprties(true, (pi, category) => new { pi, category }); return((from s in activeSettings join p in properties on s.pi.Name equals p.PropertyName orderby s.category, s.pi.Name select p).ToList()); }
public CorridorStatistics(TradingMacro tm, List <Rate> rates, double stDev, double[] coeffs) { this.TradingMacro = tm; Init(rates, stDev, coeffs, stDev, stDev, stDev * 2, stDev * 2, 0, 0); }
protected void TradingMacrosCopy_Add(TradingMacro tm) { _tradingMacrosCopy.Add(tm); ResetTradingMacros(); }
public static IEnumerable <TOut> GetActiveSettings2 <TKey, TValue, TOut>(bool excludeNotStrategy, TradingMacro tm, Func <string, int, TKey> grouper, Func <string, object, TValue> valuer, Func <TKey, IEnumerable <TValue>, TOut> outer) { var gr = MonoidsCore.ToFunc("", 0, (Category, s) => new { Category, s }); var type = typeof(TradingMacro); var cat = type.GetPropertiesByAttibute(() => (CategoryAttribute)null, (c, pi) => new { c.Category, pi, s = 0 }); var dm = type.GetPropertiesByAttibute(() => (EdmScalarPropertyAttribute)null, (c, pi) => new { Category = "DataMember", pi, s = 1, key = c.EntityKeyProperty }) .Where(x => !x.key /*&& !IsMemberExcluded(x.pi.Name)*/) .Select(x => new { x.Category, x.pi, x.s }); var nonStrategy = GetNotStrategyActiveSettings(); return (from setting in cat.Concat(dm).Distinct(x => x.pi) join ns in nonStrategy on setting.pi.Name equals ns into gss where !excludeNotStrategy || gss.IsEmpty() where IsNotDnr(setting.pi) && (!excludeNotStrategy || IsStrategy(setting.pi)) group setting by grouper(setting.Category, setting.s) into gs select outer(gs.Key, gs.Select(v => valuer(v.pi.Name, v.pi.GetValue(tm, null)))) ); }
public static IEnumerable <string> GetActiveSettings(bool excludeNotStrategy, TradingMacro tm) { var type = typeof(TradingMacro); var cat = type.GetPropertiesByAttibute(() => (CategoryAttribute)null, (c, pi) => new { c.Category, pi, s = 0 }); var dm = type.GetPropertiesByAttibute(() => (EdmScalarPropertyAttribute)null, (c, pi) => new { Category = "DataMember", pi, s = 1, key = c.EntityKeyProperty }) .Where(x => !x.key /*&& !IsMemberExcluded(x.pi.Name)*/) .Select(x => new { x.Category, x.pi, x.s }); var nonStrategy = GetNotStrategyActiveSettings(); return (from setting in cat.Concat(dm).Distinct(x => x.pi) join ns in nonStrategy on setting.pi.Name equals ns into gss where !(excludeNotStrategy && gss.Any()) where IsNotDnr(setting.pi) && (!excludeNotStrategy || IsStrategy(setting.pi)) group setting by new { setting.Category, setting.s } into g orderby g.Key.s, g.Key.Category from g2 in new[] { "//{0}//".Formater(g.Key.Category) } .Concat(g .Select(p => new { p, v = p.pi.GetValue(tm, null) }) .Where(x => x.v != null) .Select(x => "{0}={1}".Formater(x.p.pi.Name, x.v)) .OrderBy(s => s)) .Concat(new[] { Lib.TestParametersRowDelimiter }) select g2); }
private static void BroadcastCloseAllTrades(TradingMacro tm, Action<TradingMacro> onClose) { GalaSoft.MvvmLight.Messaging.Messenger.Default.Send(new CloseAllTradesMessage<TradingMacro>(tm, onClose)); }
protected void TradingMacrosCopy_Delete(TradingMacro tm) { _tradingMacrosCopy.Remove(tm); ResetTradingMacros(); }
protected IEnumerable <TradingMacro> GetTradingMacrosByGroup(TradingMacro tm, Func <TradingMacro, bool> predicate) { return(GetTradingMacrosByGroup(tm).Where(predicate)); }
protected PriceBar[] GetPriceBars(TradingMacro tradingMacro, bool isLong) { return(priceBarsDictionary.ContainsKey(tradingMacro) ? priceBarsDictionary[tradingMacro].GetPriceBars(isLong) : new PriceBar[0]); }
protected PriceBar[] FetchPriceBars(TradingMacro tradingMacro, int rowOffset, bool reversePower) { return(FetchPriceBars(tradingMacro, rowOffset, reversePower, DateTime.MinValue)); }
protected IEnumerable <TradingMacro> GetTradingMacrosByGroup(TradingMacro tm) { return(TradingMacrosCopy.Where(tm1 => tm1.TradingGroup == tm.TradingGroup && tm.IsActive)); }