protected override void OnOrderExecution(IExecution execution)
        {
            DateTime ts_Ausstieg;

            // ts_Ausstieg = Reversal2NextBar_Indicator().GetTargetBar(Bars[-1].Timestamp);
            ts_Ausstieg = GlobalUtilities.GetTargetBar(Bars, Bars[0].Time, TimeFrame, 1);
            Print("Ausstieg: " + ts_Ausstieg + "Bars[-1].Time: " + Bars[-1].Time);

            ////todo this is not working in 1.9
            //foreach (Trade item in this.Root.Core.TradingManager.ActiveOpenedTrades)
            //{
            //    if (item.EntryOrder.Name == SignalNameEnter
            //     || item.EntryOrder.Name == SignalNameStop)
            //    {
            //        item.Expiration = ts_Ausstieg;
            //    }
            //}


            if (execution.PositionType == PositionType.Flat)
            {
                oStop  = null;   //den Stop zuerst
                oEnter = null;
            }
        }
示例#2
0
        public void drawTarget(IBars bars, int curbar)
        {
            if (this.DrawLinesOnChart && curbar == PopGunTriggerBar)
            {
                AddChartText(("PopGunSize" + curbar), (Math.Round((((bars[0].High - bars[0].Low) / bars[0].Close) * 100), 2)).ToString(), 0, bars.GetByIndex(PopGunTriggerBar).Low - TickSize * bars[0].Close, Color.Black);
            }

            if (curbar <= PopGunTarget &&
                curbar > PopGunTriggerBar &&
                curbar > 0)
            {
                DateTime lineend = GlobalUtilities.GetTargetBar(bars, bars.GetByIndex(PopGunTriggerBar).Time, TimeFrame, PopGunExpires);

                if (this.DrawLinesOnChart)
                {
                    string strPopGunLong  = "PopGunLong" + curbar;
                    string strPopGunShort = "PopGunShort" + curbar;

                    AddChartLine(strPopGunLong, true, bars.GetByIndex(PopGunTriggerBar).Time, PopGunTriggerLong, lineend, PopGunTriggerLong,
                                 Color.Green, Const.DefaultIndicatorDashStyle, Const.DefaultLineWidth_large);

                    AddChartLine(strPopGunShort, true, bars.GetByIndex(PopGunTriggerBar).Time, PopGunTriggerShort, lineend, PopGunTriggerShort,
                                 Color.Red, Const.DefaultIndicatorDashStyle, Const.DefaultLineWidth_large);
                }


                if (this.IsSnapshotActive && curbar == PopGunTarget)
                {
                    GlobalUtilities.SaveSnapShot("PopGun", bars.Instrument.Name, this.Root.Core.ChartManager.AllCharts, bars, TimeFrame);
                }
            }
        }
示例#3
0
        //todo -100 wird noch nicht zurückgegeben oder?
        public int calculate(IBars bars, int curbar)
        {
            int returnvalue = 0;

            //We need at least three bars
            if (curbar < 2)
            {
                return(0);
            }

            double TwoBarsAgo_High = bars[2].High;
            double TwoBarsAgo_Low  = bars[2].Low;

            double OneBarAgo_High = bars[1].High;
            double OneBarAgo_Low  = bars[1].Low;

            double CurrentBar_High = bars[0].High;
            double CurrentBar_Low  = bars[0].Low;

            // 2) Determine, if 1 Bar ago, there was an inside bar
            if (TwoBarsAgo_High > OneBarAgo_High &&
                TwoBarsAgo_Low < OneBarAgo_Low)
            {
                //One Bar ago was an inside bar, so lets check if current bar is outside bar
                if (TwoBarsAgo_High < CurrentBar_High &&
                    TwoBarsAgo_Low > CurrentBar_Low)
                {
                    // current bar is outside bar -> lets pop the gun
                    this.PopGunTarget         = curbar + this.PopGunExpires;
                    PopGunTriggerBar          = CurrentBar;
                    this.PopGunTriggerLong    = CurrentBar_High;
                    this.PopGunTriggerShort   = CurrentBar_Low;
                    this.PopGunTargetDateTime = GlobalUtilities.GetTargetBar(Bars, Bars[0].Time, TimeFrame, PopGunExpires);
                }
            }

            if (curbar < this.PopGunTarget)
            {
                if (bars[0].Close > this.PopGunTriggerLong)
                {
                    returnvalue = 100;
                }
                else if (bars[0].Close < this.PopGunTriggerShort)
                {
                    returnvalue = -100;
                }
            }

            drawTarget();
            evaluation();

            return(returnvalue);
        }
示例#4
0
        public void drawTarget()
        {
            if (CurrentBar <= PopGunTarget &&
                CurrentBar > PopGunTriggerBar &&
                CurrentBar > 0)
            {
                string strPopGunLong  = "PopGunLong" + CurrentBar;
                string strPopGunShort = "PopGunShort" + CurrentBar;

                DateTime lineend = GlobalUtilities.GetTargetBar(Bars, Bars.GetByIndex(PopGunTriggerBar).Time, TimeFrame, PopGunExpires);

                DrawLine(strPopGunLong, true, Bars.GetByIndex(PopGunTriggerBar).Time, PopGunTriggerLong, lineend, PopGunTriggerLong,
                         Color.Green, Const.DefaultIndicatorDashStyle, Const.DefaultLineWidth_large);

                DrawLine(strPopGunShort, true, Bars.GetByIndex(PopGunTriggerBar).Time, PopGunTriggerShort, lineend, PopGunTriggerShort,
                         Color.Red, Const.DefaultIndicatorDashStyle, Const.DefaultLineWidth_large);

                if (this.IsSnapshotActive && CurrentBar == PopGunTarget)
                {
                    GlobalUtilities.SaveSnapShot("PopGun", Instrument.Name, this.Root.Core.ChartManager.AllCharts, Bars, TimeFrame);
                }
            }
        }
        protected override void OnCalculate()
        {
            string strReversalTradeLong  = "ReversalTradeLong" + ProcessingBarIndex;
            string strReversalTradeShort = "ReversalTradeShort" + ProcessingBarIndex;
            string strTradeResultLong;
            string strTradeResultShort;
            Color  colorTextBox;

            // 1 umkehr fallend auf steigend
            //-1 umkehr steigend auf fallend

            if (IsReversalLongTrade() == true)
            {
                ReversalTradeStartTSLong = Bars[0].Time;
                //TargetBarTime = GetTargetBar(Bars[0].Time);
                TargetBarTime = GlobalUtilities.GetTargetBar(Bars, Bars[0].Time, TimeFrame, 1);
                OutSeries.Set(100);
                Reversal2NextBar.Set(100);
            }
            else if (IsReversalShortTrade() == true)
            {
                ReversalTradeStartTSShort = Bars[0].Time;
                //TargetBarTime = GetTargetBar(Bars[0].Time);
                TargetBarTime = GlobalUtilities.GetTargetBar(Bars, Bars[0].Time, TimeFrame, 1);
                OutSeries.Set(-100);
            }
            else
            {
                Reversal2NextBar.Set(0);
            }

            //TradingKerze ist fertig, Zeiteinheit ist abgelaufen
            if (Bars[0].Time == TargetBarTime)
            {
                ReversalTradeResult = (decimal)Bars.GetClose(ProcessingBarIndex) - (decimal)Bars.GetOpen(ProcessingBarIndex);
                TradeCounter       += 1;

                if (ReversalTradeStartTSLong > DateTime.MinValue)
                {
                    ReversalTradeResultTotalLong = ReversalTradeResultTotalLong + ReversalTradeResult;
                    if (ReversalTradeResult < 0)
                    {
                        strTradeResultLong    = "Fail " + ReversalTradeResult.ToString();
                        colorTextBox          = colFail;
                        TradeCounterLongFail += 1;
                    }
                    else
                    {
                        strTradeResultLong   = "Win " + ReversalTradeResult.ToString();
                        colorTextBox         = colWin;
                        TradeCounterLongWin += 1;
                    }
                    AddChartText(strReversalTradeLong, true, strTradeResultLong, Time[1], Bars.GetHigh(ProcessingBarIndex) + (100 * TickSize), 9, Color.Black, new Font("Arial", 9), StringAlignment.Center, Color.Black, colorTextBox, 70);
                }
                else if (ReversalTradeStartTSShort > DateTime.MinValue)
                {
                    ReversalTradeResultTotalShort = ReversalTradeResultTotalShort + ReversalTradeResult;
                    if (ReversalTradeResult < 0)
                    {
                        strTradeResultShort   = "Win " + ReversalTradeResult.ToString();
                        colorTextBox          = colWin;
                        TradeCounterShortWin += 1;
                    }
                    else
                    {
                        strTradeResultShort    = "Fail " + ReversalTradeResult.ToString();
                        colorTextBox           = colFail;
                        TradeCounterShortFail += 1;
                    }
                    AddChartText(strReversalTradeShort, true, strTradeResultShort, Time[1], Bars.GetHigh(ProcessingBarIndex) - (100 * TickSize), 9, Color.Black, new Font("Arial", 9), StringAlignment.Center, Color.Black, colorTextBox, 70);
                }

                //Variablen Resetten
                ReversalTradeStartTSLong  = DateTime.MinValue;
                ReversalTradeStartTSShort = DateTime.MinValue;
            }

            if (IsProcessingBarIndexLast)
            {
                //       Print("LongWin: " + TradeCounterLongWin + " LongFail: " + TradeCounterLongFail + " ShortWin: " + TradeCounterShortWin + " ShortFail: " + TradeCounterShortFail);
                //       Print(Instrument.Name + "Trades: " + TradeCounter + " LongPunkte: " + ReversalTradeResultTotalLong + " ShortPunkte: " + ReversalTradeResultTotalShort);
            }
        }
示例#6
0
        private void evaluation(IBars bars, int curbar)
        {
            if (IsEvaluationActive == false)
            {
                return;
            }
            if (curbar != PopGunTarget ||
                curbar == 0)
            {
                return;
            }


            bool   LongTrade = false;
            double PunkteLongTrade;
            bool   ShortTrade = false;
            double PunkteShortTrade;
            int    i;

            Statistic statistic = new Statistic("PopGun");

            #region LongAuswertung
            i = PopGunExpires - 1; //weil 0-Index
            do
            {
                if (bars[i].Close > PopGunTriggerLong)
                {
                    LongTrade = true;
                    statistic.EntryDateTime  = bars[i].Time;
                    statistic.TradeDirection = PositionType.Long;
                    statistic.EntryPrice     = PopGunTriggerLong;
                    statistic.StopPrice      = PopGunTriggerShort;
                    break;
                }

                i--;
            } while (i >= 1);
            #endregion

            #region ShortAuswertung
            i = PopGunExpires - 1;
            do
            {
                if (bars[i].Close < PopGunTriggerShort &&
                    ShortTrade == false)
                {
                    ShortTrade = true;
                    statistic.EntryDateTime  = bars[i].Time;
                    statistic.EntryPrice     = PopGunTriggerShort;
                    statistic.StopPrice      = PopGunTriggerLong;
                    statistic.TradeDirection = PositionType.Short;
                    break;
                }

                i--;
            } while (i >= 1);
            #endregion


            if (LongTrade == true && ShortTrade == true)
            {
                //     DoubleBreakOut = true;
            }
            else if (LongTrade == true)
            {
                PunkteLongTrade = bars[0].Close - PopGunTriggerLong;
                if (PunkteLongTrade > 0)
                {
                    PopGunTradeWinCounterLong += 1;
                }
                else
                {
                    PopGunTradeFailCounterLong += 1;
                }
                PopGunTradeCounterLong    += 1;
                PopGunTradeResultTotalLong = PopGunTradeResultTotalLong + (decimal)PunkteLongTrade;
            }
            else if (ShortTrade == true)
            {
                PunkteShortTrade = bars[0].Close - PopGunTriggerShort;
                if (PunkteShortTrade < 0)
                {
                    PopGunTradeWinCounterShort += 1;
                }
                else
                {
                    PopGunTradeFailCounterShort += 1;
                }
                PopGunTradeCounterShort    += 1;
                PopGunTradeResultTotalShort = PopGunTradeResultTotalShort + (decimal)PunkteShortTrade;
            }


            if (statistic.EntryDateTime > DateTime.MinValue)
            {
                statistic.TimeFrame    = TimeFrame.PeriodicityValue.ToString() + TimeFrame.Periodicity.ToString();
                statistic.ExitDateTime = GlobalUtilities.GetTargetBar(bars, bars[0].Time, TimeFrame, 1);
                statistic.Instrument   = bars.Instrument.Symbol.ToString();
                statistic.ExitPrice    = bars[0].Close;
                statistic.ExitReason   = "Expired (" + _PopGunExpires + " Bars)";

                //    Print(statistic.getCSVData());
                statistic.AppendToFile();
            }
        }
示例#7
0
        //todo -100 wird noch nicht zur�ckgegeben oder?
        public int calculate(IBars bars, int curbar, PopGunType popguntype)
        {
            bool noPopGunTrigger = false;
            int  returnvalue     = 0;

            //We need at least three bars
            if (curbar < 2)
            {
                return(0);
            }

            double TwoBarsAgo_High = bars[2].High;
            double TwoBarsAgo_Low  = bars[2].Low;

            double OneBarAgo_High = bars[1].High;
            double OneBarAgo_Low  = bars[1].Low;

            double CurrentHigh = bars[0].High;
            double CurrentLow  = bars[0].Low;

            if (this.PopGunType == UserCode.PopGunType.Classic)
            {
                // 2) Determine, if 1 Bar ago, there was an inside bar
                if (TwoBarsAgo_High > OneBarAgo_High &&
                    TwoBarsAgo_Low < OneBarAgo_Low)
                {
                    //One Bar ago was an inside bar, so lets check if current bar is outside bar
                    if (TwoBarsAgo_High < CurrentHigh &&
                        TwoBarsAgo_Low > CurrentLow)
                    {
                        // current bar is outside bar -> lets pop the gun
                        this.PopGunTargetDateTime = GlobalUtilities.GetTargetBar(bars, bars[0].Time, TimeFrame, PopGunExpires);

                        //check, if target bar would be on the following day, and therefor a risks of gap is given
                        if (Filter_NoTriggerEOD &&
                            PopGunTargetDateTime.Date > bars[0].Time.Date)
                        {
                            //reject current PopGun Trigger and reset TargetDateTime
                            PopGunTargetDateTime = DateTime.MinValue;
                            noPopGunTrigger      = true;
                        }

                        if (noPopGunTrigger == false)
                        {
                            this.PopGunTarget       = curbar + this.PopGunExpires;
                            PopGunTriggerBar        = ProcessingBarIndex;
                            this.PopGunTriggerLong  = CurrentHigh;
                            this.PopGunTriggerShort = CurrentLow;
                        }
                    }
                }

                if (curbar < this.PopGunTarget)
                {
                    if (bars[0].Close > this.PopGunTriggerLong)
                    {
                        returnvalue = 100;
                    }
                    else if (bars[0].Close < this.PopGunTriggerShort)
                    {
                        returnvalue = -100;
                    }
                }

                drawTarget(bars, curbar);
                evaluation(bars, curbar);
            }
            else if (this.PopGunType == UserCode.PopGunType.ThreeBarReversal)
            {
                if (bars[2].IsFalling && bars[1].IsFalling && TwoBarsAgo_Low > OneBarAgo_Low && bars[0].Close > TwoBarsAgo_High && bars[0].Close > OneBarAgo_High)
                {
                    returnvalue = 100;
                    if (this.DrawLinesOnChart)
                    {
                        AddChartLine("high_" + bars[0].Time.Ticks.ToString(), true, bars[0].Time, bars[0].Close, bars[0].Time.AddDays(5), bars[0].Close, Color.Green, Const.DefaultIndicatorDashStyle, Const.DefaultLineWidth_large);

                        AddChartLine("low_" + bars[0].Time.Ticks.ToString(), true, bars[0].Time, bars[1].Close, bars[0].Time.AddDays(5), bars[1].Close, Color.Red, Const.DefaultIndicatorDashStyle, Const.DefaultLineWidth_large);
                    }
                }
                else if (bars[2].IsGrowing && bars[1].IsGrowing && TwoBarsAgo_High < OneBarAgo_High && bars[0].Close < TwoBarsAgo_Low && bars[0].Close < OneBarAgo_Low)
                {
                    returnvalue = -100;

                    if (this.DrawLinesOnChart)
                    {
                        AddChartLine("high_" + bars[0].Time.Ticks.ToString(), true, bars[0].Time, bars[0].Close, bars[0].Time.AddDays(5), bars[0].Close, Color.Red, Const.DefaultIndicatorDashStyle, Const.DefaultLineWidth_large);

                        AddChartLine("low_" + bars[0].Time.Ticks.ToString(), true, bars[0].Time, bars[1].Close, bars[0].Time.AddDays(5), bars[1].Close, Color.Green, Const.DefaultIndicatorDashStyle, Const.DefaultLineWidth_large);
                    }
                }
            }
            else
            {
                throw new NotImplementedException();
            }

            return(returnvalue);
        }