Exemplo n.º 1
0
        protected override void OnCalculate()
        {
            //for debugging reason only, just to get a hook in
            if (ProcessingBarIndex + 1 == 157)
            {
                int a = 1 + 1;
            }

            if (FirstOnBarUpdate == false)
            {
                Print("FirstOnBarUpdate " + Bars[0].Time + " Strat");
                FirstOnBarUpdate = true;
            }


            //Lets call the calculate method and save the result with the trade action
            ResultValue_DeepCorrection ResultValue = this._DeepCorrectionTrend_Indikator.calculate(Close, TrendSize, Bars[0], "Strat");

            //Entry
            if (ResultValue.Entry.HasValue)
            {
                switch (ResultValue.Entry)
                {
                case OrderDirection.Buy:
                    this.DoEnterLong(ResultValue.StopLoss, ResultValue.Target);
                    break;

                case OrderDirection.Sell:
                    //            this.DoEnterShort(ResultValue.StopLoss, ResultValue.Target);
                    break;
                }
            }
        }
        protected override void OnCalculate()
        {
            //for debugging reason only, just to get a hook in
            if (ProcessingBarIndex + 1 == 1051)
            {
                int a = 1 + 1;
            }

            if (ProcessingBarIndex < RequiredBarsCount)
            {
                return;
            }


            if (FirstOnBarUpdate == false)
            {
                Print("FirstOnBarUpdate " + Bars[0].Time + " Indi");
                FirstOnBarUpdate = true;
            }

            //Lets call the calculate method and save the result with the trade action
            ResultValue_DeepCorrection ResultValue = this.calculate(Close, TrendSize, Bars[0], "Indi");

            if (ResultValue.Entry.HasValue)
            {
                switch (ResultValue.Entry)
                {
                case OrderDirection.Buy:
                    Outputs[1].Set(1);
                    break;

                case OrderDirection.Sell:
                    //AddChartDiamond("ArrowShort_Entry" + Bars[0].Time.Ticks, true, Bars[0].Time, Bars[0].Open, Color.LightGreen);
                    Outputs[1].Set(-1);
                    break;
                }
            }
            else
            {
                //Value was null so nothing to do.
                Outputs[1].Set(0);
            }
        }
        public ResultValue_DeepCorrection calculate(IDataSeries InSeries, int TrendSize, IBar myBar, string caller)
        {
            if (FirstCalculate == false)
            {
                Print("FirstCalculate " + myBar.Time + caller);
                FirstCalculate = true;
            }

            //Create a return object
            ResultValue_DeepCorrection ResultValue = new ResultValue_DeepCorrection();

            if (MarketPhasesAdv(InSeries, TrendSize)[0] == MarketPhaseDeepCorrectionLong ||
                MarketPhasesAdv(InSeries, TrendSize)[0] == MarketPhaseDeepCorrectionWithTrendLong)
            {
                //Print(Bars[0].Time + " " + MarketPhasesAdv(InSeries, TrendSize)[0] + " tmp Pkt3 " + P123(Close, _trendSize).TempP3Price[0] + " valid Pkt3 " + P123(InSeries, _trendSize).ValidP3Price[0]);

                //try to get the temporary P3, if it does not exist, take the already validated P3
                if (P123(InSeries, _trendSize).TempP3Price[0] != 0)
                {
                    ResultValue.DeepCorrection = true;
                    ResultValue.Entry          = OrderDirection.Buy;
                    ResultValue.StopLoss       = P123(InSeries, _trendSize).TempP3Price[0];
                }
                else if (P123(InSeries, _trendSize).ValidP3Price[0] != 0)
                {
                    ResultValue.DeepCorrection = true;
                    ResultValue.Entry          = OrderDirection.Buy;
                    ResultValue.StopLoss       = P123(InSeries, _trendSize).ValidP3Price[0];
                }

                //Check, if current Price is lower than P2 (because we want to go long towards P2)
                if (InSeries[0] < P123(InSeries, _trendSize).P2Price[0])
                {
                    ResultValue.Target = P123(InSeries, _trendSize).P2Price[0];
                    Print("Indikator" + myBar.Time + " Long " + "Close: " + myBar.Close + " StopLoss: " + ResultValue.StopLoss + " Target: " + ResultValue.Target + " Marktphase: " + MarketPhasesAdv(InSeries, TrendSize)[0] + " BarsCount: " + InSeries.Count);
                }
                else
                {
                    ResultValue.Target = InSeries[0] * 1.005;
                    Print("Indikator" + myBar.Time + " Long " + "Close: " + myBar.Close + " StopLoss: " + ResultValue.StopLoss + " Target: " + ResultValue.Target + " Marktphase: " + MarketPhasesAdv(InSeries, TrendSize)[0] + " BarsCount: " + InSeries.Count);
                }
            }
            else if (MarketPhasesAdv(InSeries, TrendSize)[0] == MarketPhaseDeepCorrectionShort ||
                     MarketPhasesAdv(InSeries, TrendSize)[0] == MarketPhaseDeepCorrectionWithTrendShort)
            {
                //try to get the temporary P3, if it does not exist, take the already validated P3
                if (P123(InSeries, _trendSize).TempP3Price[0] != 0)
                {
                    ResultValue.DeepCorrection = true;
                    ResultValue.Entry          = OrderDirection.Sell;
                    ResultValue.StopLoss       = P123(InSeries, _trendSize).TempP3Price[0];
                    ResultValue.Target         = P123(InSeries, _trendSize).P2Price[0];
                }
                else if (P123(InSeries, _trendSize).ValidP3Price[0] != 0)
                {
                    ResultValue.DeepCorrection = true;
                    ResultValue.Entry          = OrderDirection.Sell;
                    ResultValue.StopLoss       = P123(InSeries, _trendSize).ValidP3Price[0];
                }
                //Check, if current Price is higher than P2 (because we want to go short towards P2)
                if (InSeries[0] > P123(InSeries, _trendSize).P2Price[0])
                {
                    ResultValue.Target = P123(InSeries, _trendSize).P2Price[0];
                }
                else
                {
                    ResultValue.Target = InSeries[0] / 1.005;
                }
            }
            return(ResultValue);
        }