public override void OnBar(object sender, IStrategyOnBarArgument currentData) { for (int i = 0; i < currentData.FinishedBars.Count; i++) { if (currentData.FinishedBars[i].KLinePeriod.Equals(GetParameter(PARAMKEY_PRINTPERIOD))) { IStrategyOnBarInfo bar = currentData.FinishedBars[i]; Console.WriteLine(bar.KLinePeriod + ":" + bar.KLineBar); results.Add(bar.KLinePeriod + ":" + bar.KLineBar); } } }
public override void OnBar(Object sender, IStrategyOnBarArgument currentData) { IList <IStrategyOnBarInfo> bars = currentData.FinishedBars; for (int i = 0; i < bars.Count; i++) { IStrategyOnBarInfo barInfo = bars[i]; Console.WriteLine(barInfo.KLinePeriod + ":" + barInfo.KLineBar); printData.Add(barInfo.KLinePeriod + ":" + barInfo.KLineBar); } //Console.WriteLine("bar:" + currentData.CurrentData.GetKLineData(KLinePeriod.KLinePeriod_1Minute)); }
public StrategyOnBarArgument(ForwardOnBarArgument forwardOnBarArgument) : base(forwardOnBarArgument.AllFinishedBars, forwardOnBarArgument.DataForward_Code) { this.mainBar = new StrategyOnBarInfo((ForwardOnbar_Info)forwardOnBarArgument.MainBar); for (int i = 0; i < forwardOnBarArgument.AllFinishedBars.Count; i++) { this.finishedBars.Add(new StrategyOnBarInfo((ForwardOnbar_Info)forwardOnBarArgument.AllFinishedBars[i])); } //for (int i = 0; i < forwardOnBarArgument..Count; i++) //{ // this.finishedBars.Add(new StrategyOnBarInfo((ForwardOnbar_Info)forwardOnBarArgument.AllFinishedBars[i])); //} }
private double GetMa(IStrategyOnBarInfo barInfo, int period) { IKLineData klineData = barInfo.KLineData; int start = barInfo.BarPos - period; start = start < 0 ? 0 : start; double ma = 0; for (int i = start; i <= barInfo.BarPos; i++) { ma += klineData.Arr_End[i]; } return(ma / (barInfo.BarPos - start + 1)); }
public override void OnBar(object sender, IStrategyOnBarArgument argument) { IStrategyOnBarInfo bar = argument.GetFinishedBar(MainKLinePeriod); if (bar != null) { if (argument.Time == 20171221.2100) { int start = bar.BarPos - 250; int end = bar.BarPos; for (int i = start; i < end; i++) { zigzag.Loop(i); } } } }
private void RecordBars(IList <IStrategyOnBarInfo> bars) { for (int i = 0; i < bars.Count; i++) { IStrategyOnBarInfo barInfo = bars[i]; KLinePeriod period = barInfo.KLinePeriod; List <double> MaList; if (dic_Period_MA.ContainsKey(period)) { MaList = dic_Period_MA[period]; } else { MaList = new List <double>(); dic_Period_MA.Add(period, MaList); } MaList.Add(GetMa(barInfo, this.maPeriod)); } }
public override void OnBar(Object sender, IStrategyOnBarArgument argument) { IStrategyOnBarInfo bar = argument.GetFinishedBar(ZigzagPeriod); if (bar != null) { zigzag.Loop(bar.BarPos); } //if (argument.Time == 20171218.0900) //{ // int start = bar.BarPos - 500; // int end = bar.BarPos; // for (int i = start; i < end; i++) // { // zigzag.Loop(i); // } //} }
public override void OnBar(object sender, IStrategyOnBarArgument currentData) { if (isOpen) { return; } IStrategyOnBarInfo barInfo = currentData.MainBar; IKLineBar currentBar = barInfo.KLineBar; IKLineBar lastBar = barInfo.KLineData.GetBar(barInfo.BarPos - 1); //多头吞噬 if (currentBar.BlockHigh > lastBar.BlockHigh && currentBar.BlockLow < lastBar.BlockLow && currentBar.isRed() && currentBar.BlockHeight >= 20) { openPrice = currentBar.End; StrategyHelper.Trader.Open(currentData.Code, data.market.OrderSide.Buy, openPrice, 10); isOpen = true; strategyResult.AddRow(currentBar.Code, barInfo.KLineBar.Time, new object[] { currentBar.BlockHeight, lastBar.BlockHeight }); IStrategyDrawer_PriceRect drawer = StrategyHelper.Drawer.GetDrawer_KLine(barInfo.KLinePeriod); drawer.DrawPoint(new graphic.shape.PriceShape_Point(barInfo.BarPos, openPrice)); } }
public override void OnBar(object sender, IStrategyOnBarArgument currentData) { IStrategyOnBarInfo barInfo = currentData.MainBar; GenMa(barInfo.KLineData, barInfo.KLineData.BarPos, maList, maPeriod); }
/** * 查找高低点算法 * 1.找到疑似的高点低点 * 2.和之前的高低点进行比较,确认用之前的高低点还是现在的。 * 3. */ private void CalcTurnPoints(IStrategyOnBarInfo bar) { IKLineData klineData = bar.KLineData; int barPos = klineData.BarPos; // if (barPos < highLowLength) { return; } IList <float> arr_HighPrice = klineData.Arr_High; IList <float> arr_LowPrice = klineData.Arr_Low; //首先找到高低点 bool hasFindLowPoint = IsPreviousBarTheLowestBar(arr_LowPrice, barPos, turnLength, highLowLength); bool hasFindHighPoint = IsPreviousBarTheHighestBar(arr_HighPrice, barPos, turnLength, highLowLength); if (!hasFindLowPoint && !hasFindHighPoint) { return; } int lastPointType = GetLastPointType(barPos); int turnPointIndex = barPos - turnLength; if (turnPointIndex < 0) { return; } //发生在chart刚开始,之前还没有低点高点 if (lastPointType == LASTTYPE_UNKNOWN) { if (hasFindHighPoint) { AddHighPoint(arr_HighPrice, turnPointIndex); } else { AddLowPoint(arr_LowPrice, turnPointIndex); } } else if (lastPointType == LASTTYPE_HIGH) { if (hasFindHighPoint) { ReplaceHighPoint(arr_HighPrice, turnPointIndex); } else if (hasFindLowPoint) { AddLowPoint(arr_LowPrice, turnPointIndex); } } else { if (hasFindLowPoint) { ReplaceLowPoint(barPos, arr_HighPrice, arr_LowPrice, turnPointIndex); } else if (hasFindHighPoint) { AddHighPoint(arr_HighPrice, turnPointIndex); } } }