Exemplo n.º 1
0
        protected override void OnCalculate()
        {
            _orb_indicator.calculate(this.Bars, this.Bars[0]);
            //Occurred.Set(returnvalue);
            //Entry.Set(Bars[0].Close);

            //If there was a breakout and the current bar is the same bar as the long/short breakout, then trigger signal.
            if (_orb_indicator.LongBreakout != null && _orb_indicator.LongBreakout.Time == Bars[0].Time)
            {
                //Long Signal
                Occurred.Set(1);
                //Entry.Set(Close[0]);
            }
            else if (_orb_indicator.ShortBreakout != null && _orb_indicator.ShortBreakout.Time == Bars[0].Time)
            {
                //Short Signal
                Occurred.Set(-1);
                //Entry.Set(Close[0]);
            }
            else
            {
                //No Signal
                Occurred.Set(0);
                //Entry.Set(Close[0]);
            }
        }
Exemplo n.º 2
0
        protected override void OnCalculate()
        {
            //Print("OnBarUpdate" + Bars[0].Timestamp.ToString());

            this.IsAutoConfirmOrder = this.Autopilot;

            //Reset Strategy for the next/first trading day
            //todo => Not perfect if we are using GMT+12 and other markets than local markets like DAX
            if (this.CurrentdayOfUpdate.Date < Bars[0].Time.Date)
            {
                this._orderenterlong    = null;
                this._orderentershort   = null;
                this.CurrentdayOfUpdate = Bars[0].Time.Date;

                ////send email
                //if (this.Send_email)
                //{
                //    this.SendEmail(Core.Settings.MailDefaultFromAddress, Core.PreferenceManager.DefaultEmailAddress,
                //        "Reset on Strategy: " + this.GetType().Name, "Strategy was restarted because a new trading day has arrived." + Environment.NewLine + "Instrument: " + this.Instrument.Name + " - Date: " + Bars[0].Timestamp);
                //}
            }

            //close manually the trades in the end of the trading day
            DateTime eod = this._orb_indicator.getDateTimeForClosingBeforeTradingDayEnds(this.Bars, this.Bars[0].GetTimestamp(), this.TimeFrame, this.CloseXCandlesBeforeEndOfTradingDay);

            if (this.CloseOrderBeforeEndOfTradingDay &&
                (this._orderenterlong != null || this._orderentershort != null) &&
                Bars[0].Time >= eod)
            {
                this.DoExitLong();
                this.DoExitShort();
            }

            //if it to late or one order already set stop execution of calculate
            // || Bars[0].Timestamp.TimeOfDay >= this._orb_indicator.getDateTimeForClosingBeforeTradingDayEnds(this.Bars, this.Bars[0].Timestamp, this.TimeFrame, this.CloseXCandlesBeforeEndOfTradingDay).TimeOfDay
            if (_orderenterlong != null || _orderentershort != null != Bars[0].Time >= eod)
            {
                return;
            }

            //Calulate data
            _orb_indicator.calculate(this.Bars, this.Bars[0]);

            //If there was a breakout and the current bar is the same bar as the long/short breakout, then trigger signal.
            if (_orb_indicator.LongBreakout != null && _orb_indicator.LongBreakout.GetTimestamp() == Bars[0].Time)
            {
                //Long Signal
                //Print("Enter Long" + Bars[0].Timestamp.ToString());
                DoEnterLong();
            }
            else if (_orb_indicator.ShortBreakout != null && _orb_indicator.ShortBreakout.GetTimestamp() == Bars[0].Time)
            {
                //Short Signal
                //Print("Enter Short" + Bars[0].Timestamp.ToString());
                DoEnterShort();
            }
            else
            {
                //nothing to do
            }
        }