void CreateRow(DataGridView gw, TestResult_Order order) { DataGridViewRow row = new DataGridViewRow(); row.CreateCells(gw); row.Cells[0].Value = order.Action; row.Cells[1].Value = order.OpenDate; row.Cells[2].Value = order.OpenPrice; row.Cells[3].Value = order.CloseDate; row.Cells[4].Value = order.ClosePrice; row.Cells[5].Value = order.Pips; gw.Rows.Add(row); gw.Refresh(); }
public void Run(Instrument instrument) { List <Candle> ha_D_Candles = HA_D_Candles(instrument); TestResult_Order order = null; EMA ema50 = new EMA(50); EMA ema9 = new EMA(9); for (int i = 0; i < ha_D_Candles.Count; i++) { ema50.AddDataPoint(ha_D_Candles[i].Close); ema9.AddDataPoint(ha_D_Candles[i].Close); if (i > 50) { order = Results.GetResult_HA_EMAs(instrument, ha_D_Candles[i - 1], ha_D_Candles[i], ema50.Average, ema9.Average, order); if (order != null && order.Close == true) { GetResult(order); order = null; } } } }
public static TestResult_Order GetResult_HA_EMAs(Instrument instrument, Candle previous_HA_candle, Candle current_HA_candle, double ema50, double ema9, TestResult_Order order) { double currentPrice = current_HA_candle.Close; if ((current_HA_candle.HaColor == CandleColor.GREEN && previous_HA_candle.HaColor == CandleColor.RED)) { if (current_HA_candle.Close > ema50 && current_HA_candle.Close > ema9) { if (order == null) { order = new TestResult_Order(); order.OpenDate = current_HA_candle.Time; order.OpenPrice = current_HA_candle.Close; order.Action = Core.Constants.Action.BUY; order.Close = false; } } } else if (current_HA_candle.HaColor == CandleColor.RED && previous_HA_candle.HaColor == CandleColor.GREEN) { if (current_HA_candle.Close < ema50 && current_HA_candle.Close < ema9) { if (order == null) { order = new TestResult_Order(); order.OpenDate = current_HA_candle.Time; order.OpenPrice = current_HA_candle.Close; order.Action = Core.Constants.Action.SELL; order.Close = false; } } } if (order != null) { if (order.Action == Constants.Action.BUY) { if (current_HA_candle.HaColor == CandleColor.RED) { order.CloseDate = current_HA_candle.Time; order.ClosePrice = current_HA_candle.Close; order.Pips = order.ClosePrice - order.OpenPrice; order.Close = true; } } else if (order.Action == Constants.Action.SELL) { if (current_HA_candle.HaColor == CandleColor.GREEN) { order.CloseDate = current_HA_candle.Time; order.ClosePrice = current_HA_candle.Open; order.Pips = order.OpenPrice - order.ClosePrice; order.Close = true; } } } return(order); }
private void Strategy_GetResult(TestResult_Order result) { CreateRow(this.gwResults, result); }