//protected override void OnBarUpdate()
        //{
        //    //TODO: Write your owner OnBarUpdate handling


        //    //DrawArrowUp("Arrowup" + CurrentBar, true, Bars.GetTime(Count - 1), Bars.GetLow(CurrentBar) - 300 * TickSize, Color.Red);
        //    //DrawArrowDown("Arrowdown" + CurrentBar, true, Bars.GetTime(Count - 1), Bars.GetHigh(CurrentBar) + 300 * TickSize, Color.Green);

        //    //Occurred.Set(-1);
        //    //Entry.Set(Close[0]);

        //}

        protected override void OnBarUpdate()
        {
            //MyGap.Set(Input[0]);

            if (Bars != null && Bars.Count > 0)
            //             && TimeFrame.Periodicity == DatafeedHistoryPeriodicity.Minute
            //             && TimeFrame.PeriodicityValue == 15)
            {
            }
            else
            {
                return;
            }

            if (Bars.BarsSinceSession == 0)
            {
                sessionprocessed = false;
            }

            //08.00, 08.15, 08.30, 08.45, 09.00 sind abgeschlossen -> es ist 09.15)
            //                if(Bars.BarsSinceSession == 5)
            if (ToTime(Bars.GetTime(CurrentBar)) > 90000 && //größer 09.00 geht für 15M und 1Std (und 1Tag?)
                sessionprocessed == false)       //Tag noch nicht verarbeitet
            {
                sessionprocessed = true;
                GapTradeLong     = GapTradeShort = false;

                IBar   GapOpenBar = Bars.Where(x => x.Time.Date == Bars[0].Time.Date).FirstOrDefault(); //liefert erster kerze des tages
                double GapOpen    = GapOpenBar.Open;

                double   LastDayClose     = PriorDayOHLC().PriorClose[0];
                double   GapSize          = GapOpen - LastDayClose;
                DateTime LastDayCloseDate = Bars.GetTime(Count - 7);
                DateTime LastPeriod       = Time[1];

                if (LastDayClose != null &&
                    Math.Abs(LastDayClose - GapOpen) > _PunkteGapMin &&
                    Math.Abs(LastDayClose - GapOpen) < _PunkteGapMax)
                {  //Wenn Gap größer 50 und kleiner 100
                    existgap = true;


                    //Gap markieren (08.00 - 09.15)
                    string strMyRect    = "MyRect" + Count;
                    string strMyGapSize = "MyGapSize" + Count;


                    if (LastDayClose - GapOpen < 0)   //Long
                    {
                        //Long
                        //DrawRectangle(strMyRect, true, LastDayCloseDate, LastDayClose, LastPeriod, HighestHighPrice(5)[0], _col_gap, _col_gap, 70);
                        DrawText(strMyGapSize, true, Math.Round(GapSize, 1).ToString(), LastDayCloseDate, LastDayClose + 25, 9, Color.Black, new Font("Areal", 9), StringAlignment.Center, Color.Black, Color.Azure, 1);

                        // if (LinReg(5)[0] > GapOpen)
                        if (LinReg(Closes[0], 5)[0] > GapOpen)
                        {
                            //Chancenreicher SuccessTrade
                            string strArrowUp = "ArrowUp" + Bars.GetTime(CurrentBar);
                            DrawArrowUp(strArrowUp, true, Bars.GetTime(Count - 1), Bars.GetOpen(CurrentBar) - 300 * TickSize, Color.Green);
                            GapTradeLong = true;

                            Occurred.Set(1);
                            Entry.Set(Bars.GetOpen(CurrentBar));
                        }
                    }
                    else
                    {
                        //Short
                        //DrawRectangle(strMyRect, true, LastDayCloseDate, LastDayClose, LastPeriod, LowestLowPrice(5)[0], Color.Pink, Color.Pink, 70);
                        DrawText(strMyGapSize, true, Math.Round(GapSize, 1).ToString(), LastDayCloseDate, LastDayClose - 25, 9, Color.Black, new Font("Areal", 9), StringAlignment.Center, Color.Black, Color.Azure, 1);

                        if (LinReg(Closes[0], 5)[0] < GapOpen)
                        {
                            ////Chancenreicher SuccessTrade
                            string strArrowDown = "ArrowDown" + Bars.GetTime(CurrentBar);
                            DrawArrowDown(strArrowDown, true, Bars.GetTime(Count - 1), Bars.GetOpen(CurrentBar) + 300 * TickSize, Color.Red);
                            GapTradeShort = true;

                            Occurred.Set(-1);
                            Entry.Set(Bars.GetOpen(CurrentBar));
                        }
                    }

                    if (GapTradeShort == true || GapTradeLong == true)
                    {
                        Print("------------------" + Time[5] + "------------------");
                        Print("LineReg: " + Math.Round(LinReg(5)[0]), 1);
                        Print("Gap Open: " + GapOpen);
                    }
                }
                else
                {
                    existgap = false;
                }
            }

//09.15. - 09.30 Kerze
            else if (Bars.BarsSinceSession == 6 && existgap == true)
            {
                //Auswertung
                decimal GapTradeResult;
                Color   colorTextBox;

                GapTradeResult = (decimal)Bars.GetClose(CurrentBar - 1) - (decimal)Bars.GetOpen(CurrentBar - 1);
                if (GapTradeLong == true)
                {
                    //Long
                    GapTradeCounterLong    += 1;
                    GapTradeResultTotalLong = GapTradeResultTotalLong + GapTradeResult;


                    string strGapeTradeLong = "GapTradeLong" + CurrentBar;
                    string strTradeResultLong;

                    if (GapTradeResult < 0)
                    {
                        Print("FAAAAAAAAAAAAAAAIIIIIIIIIIIIIILLLLLLLLLL");
                        GapTradeFailCounterLong += 1;
                        strTradeResultLong       = "Fail " + GapTradeResult.ToString();
                        colorTextBox             = colFail;
                    }
                    else
                    {
                        GapTradeWinCounterLong += 1;
                        strTradeResultLong      = "Win " + GapTradeResult.ToString();
                        colorTextBox            = colWin;
                    }
                    DrawText(strGapeTradeLong, true, strTradeResultLong, Time[1], Bars.GetHigh(CurrentBar - 1) + 10, 9, Color.Black, new Font("Areal", 9), StringAlignment.Center, Color.Black, colorTextBox, 70);
                }
                else if (GapTradeShort == true)
                {
                    //Short
                    GapTradeCounterShort    += 1;
                    GapTradeResultTotalShort = GapTradeResultTotalShort - GapTradeResult;


                    string strGapeTradeShort = "GapTradeLong" + CurrentBar;
                    string strTradeResultShort;

                    if (GapTradeResult > 0)
                    {
                        Print("FAAAAAAAAAAAAAAAIIIIIIIIIIIIIILLLLLLLLLL");
                        GapTradeFailCounterShort += 1;
                        strTradeResultShort       = "Fail " + GapTradeResult.ToString();
                        colorTextBox              = colFail;
                    }
                    else
                    {
                        GapTradeWinCounterShort += 1;
                        strTradeResultShort      = "Win " + GapTradeResult.ToString();
                        colorTextBox             = colWin;
                    }
                    DrawText(strGapeTradeShort, true, strTradeResultShort, Time[1], Bars.GetLow(CurrentBar - 1) - 10, 9, Color.Black, new Font("Areal", 9), StringAlignment.Center, Color.Black, colorTextBox, 70);
                }

                Print("Gap Trade Result: " + GapTradeResult);
            }

            if (Count == Bars.Count - 1)
            {
                Print("Total Trades Long:  " + GapTradeCounterLong);
                Print("Wins Long: " + GapTradeWinCounterLong);
                Print("Fails Long: " + GapTradeFailCounterLong);

                Print("Total Trades Short: " + GapTradeCounterShort);
                Print("Wins Short: " + GapTradeWinCounterShort);
                Print("Fails Short: " + GapTradeFailCounterShort);

                if (GapTradeCounterLong > 0)
                {
                    Print("Avg Long: " + (GapTradeResultTotalLong / GapTradeCounterLong));
                }
                if (GapTradeCounterShort > 0)
                {
                    Print("Avg Short: " + (GapTradeResultTotalShort / GapTradeCounterShort));
                }
            }
        }
Ejemplo n.º 2
0
        private void printAuswertung()
        {
            decimal GapTradeResult;
            Color   colorTextBox;
            string  strResultDescr = "";

            GapTradeResult = (decimal)Bars.GetClose(ProcessingBarIndex - 1) - (decimal)Bars.GetOpen(ProcessingBarIndex - 1);
            if (GapTradeLong == true)
            {
                //Long
                GapTradeCounterLong    += 1;
                GapTradeResultTotalLong = GapTradeResultTotalLong + GapTradeResult;


                string strGapeTradeLong = "GapTradeLong" + ProcessingBarIndex;
                string strTradeResultLong;
                TradeDir = "Long";

                if (GapTradeResult < 0)
                {
                    if (_print_info == true)
                    {
                        Print("Fail");
                    }
                    GapTradeFailCounterLong += 1;
                    strResultDescr           = "Fail";
                    strTradeResultLong       = "Fail " + GapTradeResult.ToString();
                    colorTextBox             = colFail;
                }
                else
                {
                    GapTradeWinCounterLong += 1;
                    strResultDescr          = "Win";
                    strTradeResultLong      = "Win " + GapTradeResult.ToString();
                    colorTextBox            = colWin;
                }
                AddChartText(strGapeTradeLong, true, strTradeResultLong, Time[1], Bars.GetHigh(ProcessingBarIndex - 1) + (100 * TickSize), 9, Color.Black, new Font("Arial", 9), StringAlignment.Center, Color.Black, colorTextBox, 70);
            }
            else if (GapTradeShort == true)
            {
                //Short
                GapTradeCounterShort    += 1;
                GapTradeResultTotalShort = GapTradeResultTotalShort + GapTradeResult;


                string strGapeTradeShort = "GapTradeLong" + ProcessingBarIndex;
                string strTradeResultShort;
                TradeDir = "Short";

                if (GapTradeResult > 0)
                {
                    if (_print_info == true)
                    {
                        Print("Fail");
                    }
                    GapTradeFailCounterShort += 1;
                    strResultDescr            = "Fail";
                    strTradeResultShort       = "Fail " + GapTradeResult.ToString();
                    colorTextBox              = colFail;
                }
                else
                {
                    GapTradeWinCounterShort += 1;
                    strResultDescr           = "Win";
                    strTradeResultShort      = "Win " + GapTradeResult.ToString();
                    colorTextBox             = colWin;
                }
                AddChartText(strGapeTradeShort, true, strTradeResultShort, Time[1], Bars.GetLow(ProcessingBarIndex - 1) - (100 * TickSize), 9, Color.Black, new Font("Arial", 9), StringAlignment.Center, Color.Black, colorTextBox, 70);
            }
            if (_print_info == true)
            {
                Print("Gap Trade Result: " + GapTradeResult);
            }

            if (dev_mode == true)
            {
                Print(Instrument.Name + ";" + Math.Round(GapSize, 2) + ";" + GapTradeResult + ";" + strResultDescr + ";" + TradeDir);
            }
        }