Exemplo n.º 1
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            //			this.signalDataGrid.CurrentCell = null;
            using (DBUtils.OpenThreadConnection()) {
                int index = 0;
                this.signalDataGrid.CommitEdit(DataGridViewDataErrorContexts.Commit);
                foreach (var pattern in patterns)
                {
                    var cells = this.signalDataGrid.Rows[index].Cells;
                    cells["pattern"].Value = pattern.TradeCondition.GetCheckDescription();

                    Signal signal;
                    bool   isMatch = false;

                    TradeContext tradeContext = new TradeContext()
                    {
                        Instrument = pattern.TradeOrders[0].Instrument,
                        Date       = DateTime.Today
                    };

                    cells["trade"].Value = pattern.TradeOrders.GetTradeDescription(tradeContext);
                    if (pattern.TradeCondition.IsMatch(out signal, tradeContext))
                    {
                        pattern.TradeOrders.DoTrade(tradeContext);
                        if (tradeContext.Profit > 0f)
                        {
                            cells["trade"].Style.BackColor = Color.LightPink;
                        }
                        else
                        {
                            cells["trade"].Style.BackColor = pattern.TradeOrders.IsInTradeTime ? Color.Red : Color.Yellow;
                        }
                        isMatch = true;
                    }
                    else
                    {
                        cells["trade"].Style.BackColor = Color.White;
                        isMatch = false;
                    }

                    if (signal != null)
                    {
                        if (isMatch)
                        {
                            cells["match"].Value           = "Matched!" + signal.GetCheckResultDescription();
                            cells["match"].Style.BackColor = Color.Yellow;
                            var isAutoTrade = cells["autoTrade"].Value;
                            if (isAutoTrade != null && (bool)isAutoTrade)
                            {
                                DoTrade(pattern.TradeOrders);
                            }
                        }
                        else
                        {
                            if (signal.IsCheckFinished)
                            {
                                cells["match"].Style.BackColor = Color.LightGray;
                            }
                            cells["match"].Value = "Not Match " + signal.GetCheckResultDescription();
                        }
                    }
                    else
                    {
                        cells["match"].Value = "Not Match";
                    }
                    index++;
                }
                this.signalDataGrid.AutoResizeColumn(0);
                this.signalDataGrid.AutoResizeColumn(1);
                this.signalDataGrid.AutoResizeColumn(2);
            }
        }
Exemplo n.º 2
0
        private void 急変戻り戻り_Click(object sender, EventArgs e)
        {
            RunTask(sender, (report) => {
                using (DBUtils.OpenThreadConnection()) {
                    report.Version         = 1;
                    report.IsForceOverride = true;
                    report.Comment         = "";
                    report.SetHeader("t", "upc1", "upc2", "uptotal", "downc1", "downc2", "downtotal");

                    var candles = new CandlesticksGetter()
                    {
                        Granularity = "M1",
                        Start       = DateTime.Today.AddYears(-5),
                        End         = DateTime.Today
                    }.Execute().ToList();

                    List <int> indexList = GetOverMoveCandles(candles).ToList();

                    foreach (var t in Fibs().Take(20))
                    {
                        int upc1      = 0;
                        int upc2      = 0;
                        int uptotal   = 0;
                        int downc1    = 0;
                        int downc2    = 0;
                        int downtotal = 0;
                        foreach (var i in indexList)
                        {
                            if (i + t + 15 >= candles.Count())
                            {
                                break;
                            }
                            var candleOrg     = candles[i];
                            var candleArter15 = candles[i + t];
                            var candleArter30 = candles[i + t + 15];
                            if (candleOrg.IsNull || candleArter15.IsNull || candleArter30.IsNull)
                            {
                                continue;
                            }
                            if (candleOrg.IsUp())
                            {
                                if (candleOrg.Close > candleArter15.Close)
                                {
                                    upc1++;
                                    if (candleArter15.Close < candleArter30.Close)
                                    {
                                        upc2++;
                                    }
                                }
                                uptotal++;
                            }
                            else
                            {
                                if (candleOrg.Close < candleArter15.Close)
                                {
                                    downc1++;
                                    if (candleArter15.Close > candleArter30.Close)
                                    {
                                        downc2++;
                                    }
                                }
                                downtotal++;
                            }
                        }
                        report.WriteLine(t, upc1, upc2, uptotal, downc1, downc2, downtotal);
                    }
                }
            });
        }
Exemplo n.º 3
0
        private void SignalForm_Load(object sender, EventArgs e)
        {
            using (DBUtils.OpenThreadConnection()) {
                // 81.56%
                patterns.Add(
                    new TradePattern()
                {
                    TradeCondition = new TradeConditionAnd()
                    {
                        TradeConditions = new TradeCondition[] {
                            new TimeOfDayPattern()
                            {
                                Instrument     = "USD_JPY",
                                CheckStartTime = new TimeSpan(0, 30, 0),
                                CheckEndTime   = new TimeSpan(4, 50, 0),
                                IsCheckUp      = false,
                            },
                            new TimeOfDayPattern()
                            {
                                Instrument     = "USD_JPY",
                                CheckStartTime = new TimeSpan(3, 20, 0),
                                CheckEndTime   = new TimeSpan(3, 30, 0),
                                IsCheckUp      = false,
                            },
                        },
                    },
                    TradeOrders = new TradeOrders(
                        new TimeTradeOrder()
                    {
                        Instrument = "USD_JPY",
                        TradeType  = TradeType.Ask,
                        Time       = new TimeSpan(4, 50, 0),
                    },
                        new TimeTradeOrder()
                    {
                        Instrument = "USD_JPY",
                        TradeType  = TradeType.Settle,
                        Time       = new TimeSpan(7, 10, 0),
                    }
                        )
                }
                    );

                // 83.08%
                patterns.Add(
                    new TradePattern()
                {
                    TradeCondition = new TradeConditionAnd()
                    {
                        TradeConditions = new TradeCondition[] {
                            new TimeOfDayPattern()
                            {
                                Instrument     = "USD_JPY",
                                CheckStartTime = new TimeSpan(1, 00, 0),
                                CheckEndTime   = new TimeSpan(3, 40, 0),
                                IsCheckUp      = false,
                            },
                            new TimeOfDayPattern()
                            {
                                Instrument     = "USD_JPY",
                                CheckStartTime = new TimeSpan(3, 50, 0),
                                CheckEndTime   = new TimeSpan(4, 20, 0),
                                IsCheckUp      = false,
                            },
                        },
                    },

                    TradeOrders = new TradeOrders(
                        new TimeTradeOrder()
                    {
                        Instrument = "USD_JPY",
                        TradeType  = TradeType.Ask,
                        Time       = new TimeSpan(4, 50, 0),
                    },
                        new TimeTradeOrder()
                    {
                        Instrument = "USD_JPY",
                        TradeType  = TradeType.Settle,
                        Time       = new TimeSpan(7, 10, 0),
                    }
                        )
                }
                    );

                //73.78%
                patterns.Add(
                    new TradePattern()
                {
                    TradeCondition = new TimeOfDayPattern()
                    {
                        Instrument     = "USD_JPY",
                        CheckStartTime = new TimeSpan(0, 20, 0),
                        CheckEndTime   = new TimeSpan(5, 40, 0),
                        IsCheckUp      = false,
                    },
                    TradeOrders = new TradeOrders(
                        new TimeTradeOrder()
                    {
                        Instrument = "USD_JPY",
                        TradeType  = TradeType.Ask,
                        Time       = new TimeSpan(5, 49, 0),
                    },
                        new TimeTradeOrder()
                    {
                        Instrument = "USD_JPY",
                        TradeType  = TradeType.Settle,
                        Time       = new TimeSpan(7, 10, 0),
                    }
                        )
                }
                    );


                /*
                 * patterns.Add(new TimeOfDayPattern() {
                 *      Instrument = "USD_JPY",
                 *      CheckStartTime = new TimeOfDayPattern.Time(5, 50),
                 *      CheckEndTime = new TimeOfDayPattern.Time(6, 00),
                 *      IsCheckUp = false,
                 *      TradeStartTime = new TimeOfDayPattern.Time(6, 00),
                 *      TradeEndTime = new TimeOfDayPattern.Time(6, 10),
                 *      TradeType = TradeType.Ask
                 * });*/

                // 64.19%
                patterns.Add(
                    new TradePattern()
                {
                    TradeCondition = new TimeOfDayPattern()
                    {
                        Instrument     = "USD_JPY",
                        CheckStartTime = new TimeSpan(7, 50, 0),
                        CheckEndTime   = new TimeSpan(8, 40, 0),
                        IsCheckUp      = true,
                    },
                    TradeOrders = new TradeOrders(
                        new TimeTradeOrder()
                    {
                        Instrument = "USD_JPY",
                        TradeType  = TradeType.Bid,
                        Time       = new TimeSpan(8, 50, 0),
                    },
                        new TimeTradeOrder()
                    {
                        Instrument = "USD_JPY",
                        TradeType  = TradeType.Settle,
                        Time       = new TimeSpan(11, 30, 0),
                    }
                        )
                }
                    );
                // 62.87%
                patterns.Add(
                    new TradePattern()
                {
                    TradeCondition = new TimeOfDayPattern()
                    {
                        Instrument     = "USD_JPY",
                        CheckStartTime = new TimeSpan(1, 30, 0),
                        CheckEndTime   = new TimeSpan(4, 20, 0),
                        IsCheckUp      = false,
                    },
                    TradeOrders = new TradeOrders(
                        new TimeTradeOrder()
                    {
                        Instrument = "USD_JPY",
                        TradeType  = TradeType.Bid,
                        Time       = new TimeSpan(9, 50, 0),
                    },
                        new TimeTradeOrder()
                    {
                        Instrument = "USD_JPY",
                        TradeType  = TradeType.Settle,
                        Time       = new TimeSpan(13, 10, 0),
                    }
                        )
                }
                    );

                // 64.54% ... A

                patterns.Add(
                    new TradePattern()
                {
                    TradeCondition = new TimeOfDayPattern()
                    {
                        Instrument     = "EUR_USD",
                        CheckStartTime = new TimeSpan(8, 50, 0),
                        CheckEndTime   = new TimeSpan(11, 00, 0),
                        IsCheckUp      = false,
                    },
                    TradeOrders = new TradeOrders(
                        new TimeTradeOrder()
                    {
                        Instrument = "EUR_USD",
                        TradeType  = TradeType.Ask,
                        Time       = new TimeSpan(11, 01, 0),
                    },
                        new TimeTradeOrder()
                    {
                        Instrument = "EUR_USD",
                        TradeType  = TradeType.Settle,
                        Time       = new TimeSpan(11, 40, 0),
                    }
                        )
                }
                    );

                /*
                 *
                 * //62.9% ... B
                 * patterns.Add(
                 *      new TradePattern() {
                 *              TradeCondition = new TimeOfDayPattern() {
                 *                      Instrument = "EUR_USD",
                 *                      CheckStartTime = new TimeSpan(6, 50, 0),
                 *                      CheckEndTime = new TimeSpan(7, 50, 0),
                 *                      IsCheckUp = true,
                 *              },
                 *              TradeOrders = new TradeOrders(
                 *                      new TimeTradeOrder() {
                 *                              Instrument = "EUR_USD",
                 *                              TradeType = TradeType.Ask,
                 *                              Time = new TimeSpan(11, 00, 0),
                 *                      },
                 *                      new TimeTradeOrder() {
                 *                              Instrument = "EUR_USD",
                 *                              TradeType = TradeType.Settle,
                 *                              Time = new TimeSpan(11, 30, 0),
                 *                      }
                 *              )
                 *      }
                 * );
                 */
                // 11:00-11:40の上昇確率
                // !A && !B => 42.86%
                // A && !B => 57.76%
                // !A && B => 53.82%
                // A && B => 68.81%

                patterns.Add(
                    new TradePattern()
                {
                    TradeCondition = new TradeConditionAnd()
                    {
                        TradeConditions = new TradeCondition[] {
                            new TimeOfDayPattern()
                            {
                                Instrument     = "EUR_USD",
                                CheckStartTime = new TimeSpan(6, 50, 0),
                                CheckEndTime   = new TimeSpan(7, 50, 0),
                                IsCheckUp      = true,
                            },
                            new TimeOfDayPattern()
                            {
                                Instrument     = "EUR_USD",
                                CheckStartTime = new TimeSpan(8, 50, 0),
                                CheckEndTime   = new TimeSpan(11, 00, 0),
                                IsCheckUp      = false,
                            },
                        },
                    },

                    TradeOrders = new TradeOrders(
                        new TimeTradeOrder()
                    {
                        Instrument = "EUR_USD",
                        TradeType  = TradeType.Ask,
                        Time       = new TimeSpan(11, 00, 0),
                    },
                        new TimeTradeOrder()
                    {
                        Instrument = "EUR_USD",
                        TradeType  = TradeType.Settle,
                        Time       = new TimeSpan(11, 40, 0),
                    }
                        )
                }
                    );



                //63.98%
                patterns.Add(
                    new TradePattern()
                {
                    TradeCondition = new TimeOfDayPattern()
                    {
                        Instrument     = "EUR_USD",
                        CheckStartTime = new TimeSpan(0, 50, 0),
                        CheckEndTime   = new TimeSpan(4, 00, 0),
                        IsCheckUp      = true,
                    },
                    TradeOrders = new TradeOrders(
                        new TimeTradeOrder()
                    {
                        Instrument = "EUR_USD",
                        TradeType  = TradeType.Bid,
                        Time       = new TimeSpan(6, 20, 0),
                    },
                        new TimeTradeOrder()
                    {
                        Instrument = "EUR_USD",
                        TradeType  = TradeType.Settle,
                        Time       = new TimeSpan(7, 40, 0),
                    }
                        )
                }
                    );


                this.signalDataGrid.Columns.Add("pattern", "パターン");
                this.signalDataGrid.Columns.Add("match", "マッチ状況");
                this.signalDataGrid.Columns.Add("trade", "トレード");

                this.signalDataGrid.Columns.Add(new DataGridViewCheckBoxColumn()
                {
                    Name       = "autoTrade",
                    HeaderText = "自動取引"
                });

                foreach (var pattern in patterns)
                {
                    this.signalDataGrid.Rows.Add();
                }
            }
        }