/// <summary> /// Write ctx to Json file /// </summary> /// <returns></returns> public void WriteCtxParaObj() { //Print(String.Format("ReadCtxPairSpd paraDict={0}, paraDict.Count={1}", ctxPairSpd, ctxPairSpd.Count)); // foreach(var ele in ctxPairSpd) // { // Print(string.Format("DateCtx.ele.Key={0}, ele.Value.ToString()={1}", ele.Key, ele.Value)); // foreach(CtxPairSpd ctxPS in ele.Value) { // Print(string.Format("ctxPS.Symbol={0}, ctxPS.TimeClose={1}", ctxPS.Symbol, ctxPS.TimeClose)); // } // } //if(IsInStrategyAnalyzer) //return; try{ string output = GConfig.Dictionary2JsonFile(this.CtxPairSpreadDaily.DictCtxPairSpd, GConfig.GetCTXOutputFilePath()); Print(string.Format("WriteCtxParaObj={0}", CtxPairSpreadDaily.DictCtxPairSpd.Count)); foreach (string key in CtxPairSpreadDaily.DictCtxPairSpd.Keys) { List <CtxPairSpd> cps = CtxPairSpreadDaily.DictCtxPairSpd[key]; if (cps != null && cps.Count > 0) { CtxPairSpd ctx = cps[0]; Print(string.Format("{0}\t{1}\t{2}", key, ctx.TimeSpdHigh, ctx.TimeSpdLow)); } } } catch (Exception ex) { Print(string.Format("{0}: WriteCtxParaObj exception {1}", CurrentBars[0], ex.Message)); } }
public void SetPairSpdCtx() { string key = BarsPeriod.BarsPeriodType == BarsPeriodType.Day? this.GetDateStrByDateTime(Times[0][0]):this.GetDateStrByDateTime(Times[0][1]); CtxPairSpd ctxps = new CtxPairSpd(); ctxps.Symbol = Instrument.MasterInstrument.Name; ctxps.TimeOpen = 830; ctxps.TimeClose = 1030; ctxps.TimeStart = 830; ctxps.TimeEnd = 1430; ctxps.PositionInBand = GetSpreadPosInBand().ToString(); ctxps.TrendDirection = GetSpreadTrend().ToString(); ctxps.PairATRRatio = PairATRRatio[0]; ctxps.PairSpdHigh = this.PairSpdHigh; ctxps.TimeSpdHigh = this.PairSpdHighTime; ctxps.PairSpdLow = this.PairSpdLow; ctxps.TimeSpdLow = this.PairSpdLowTime; //if()if(giSpdRs.IsSpreadFlat()) ; CtxPairSpreadDaily.AddDayCtx(key, new List <CtxPairSpd> { ctxps }); //Print(string.Format("{0}: SetPairSpdCtx={1}", CurrentBars[BarsInProgress], CtxPairSpreadDaily.DictCtxPairSpd.Count)); // Print(string.Format("{0}: SetPairSpdCtx Spread[0]={1}, Spread[1]={2}, PairSpdHigh={3}, PairSpdLow={4}, PairSpdHighTime={5}, PairSpdLowTime={6}", // CurrentBars[BarsInProgress], Spread[0], Spread[1], PairSpdHigh, PairSpdLow, PairSpdHighTime, PairSpdLowTime)); }
void OnEntryPositions(IndicatorEventArgs e) { //New entry with no poistions for both legs if (HasPosition(0) <= 0 && HasPosition(1) <= 0) { string key = ctxPairSpdDaily.KeyLastDay; //giSpdRs.GetDateStrByDateTime(Times[0][0]); // if (key == null) { Print(string.Format("ctxPairSpdDaily.KeyLastDay CurrentBars={0}, BarsInProgress={1}, Times[][0]={2}", CurrentBars[BarsInProgress], BarsInProgress, Times[BarsInProgress][0])); return; } CtxPairSpd ctxps = ctxPairSpdDaily.GetDayCtx(key); if (ctxps == null) { return; } else { int quant1 = base.GetTradeQuantity(0, CapRatio1); int quant2 = base.GetTradeQuantity(1, CapRatio2); string sig = e.IndSignal.SignalName; Print(String.Format("{0}:OnEntryPositions quant1={1}, quant2={2}: Spread={3}, Upper={4}, Lower={5}", CurrentBars[BarsInProgress], quant1, quant2, giSpdRs.Spread[0], giSpdRs.Upper[0], giSpdRs.Lower[0])); if (TrendDirection.Down.ToString().Equals(ctxps.TrendDirection) && PositionInBand.Lower.ToString().Equals(ctxps.PositionInBand) && sig == giSpdRs.SignalName_AboveStdDev) { if (MktPosition1 != MarketPosition.Long && MktPosition2 != MarketPosition.Short) { EnterShort(0, quant1, giSpdRs.SignalName_EntryShortLeg1); EnterLong(1, quant2, giSpdRs.SignalName_EntryLongLeg2); } } else if (TrendDirection.Up.ToString().Equals(ctxps.TrendDirection) && PositionInBand.Upper.ToString().Equals(ctxps.PositionInBand) && sig == giSpdRs.SignalName_BelowStdDev) { if (MktPosition1 != MarketPosition.Short && MktPosition2 != MarketPosition.Long) { EnterLong(0, quant1, giSpdRs.SignalName_EntryLongLeg1); EnterShort(1, quant2, giSpdRs.SignalName_EntryShortLeg2); } } } // if(MktPosition1 == MarketPosition.Long) { // EnterLong(0, quant1, giSpdRs.SignalName_EntryLongLeg1); // } else if(MktPosition1 == MarketPosition.Short) { // EnterShort(0, quant1, giSpdRs.SignalName_EntryShortLeg1); // } // if(MktPosition2 == MarketPosition.Long) { // EnterLong(1, quant2, giSpdRs.SignalName_EntryLongLeg2); // } else if(MktPosition2 == MarketPosition.Short) { // EnterShort(1, quant2, giSpdRs.SignalName_EntryShortLeg2); // } } }
private void GetPairSpdCtx() { //Is a new day if (Times[0][0].Day != Times[0][1].Day) { this.ctxPairSpdDaily.KeyLastDay = giSpdLadder.GetDateStrByDateTime(Times[0][1]); CtxPairSpd ctxps = this.ctxPairSpdDaily.GetDayCtx(this.ctxPairSpdDaily.KeyLastDay); CapRatio2 = 1; CapRatio1 = ctxps == null? Closes[1][0] / Closes[0][0] : ctxps.PairATRRatio; } }