/// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            // Checks to ensure all Bars objects contain enough bars before beginning
            if (CurrentBars[0] <= BarsRequired)
            {
                //Print(Time + " CurrentBars[0]: " + CurrentBars[0] + " CurrentBars[1]: " + CurrentBars[1] + " BarsRequired: " + BarsRequired);
                return;
            }

            // This should be true when the primary bar is being udpated
            if (BarsInProgress == 0)
            {
                if (!Bars.BarsType.IsIntraday)
                {
                    DrawTextFixed("error msg", "OpeningRangeBreakout only works on intraday intervals", TextPosition.BottomRight);
                    return;
                }

                if (Bars.FirstBarOfSession)
                {
                    // Get the True Range of from the Daily bars
                    atr = ATR(BarsArray[1], AtrPeriod)[0];
                    //Print(Time + " ATR: " + atr);
                    longStop     = Open[0] - (atr * 0.05);
                    shortStop    = Open[0] + (atr * 0.05);
                    longEntry    = longStop + (atr * 0.236);
                    shortEntry   = shortStop - (atr * 0.236);
                    longTarget1  = longStop + (atr * 0.5);
                    shortTarget1 = shortStop - (atr * 0.5);
                    longTarget2  = longStop + (atr * 0.764);
                    shortTarget2 = shortStop - (atr * 0.7654);
                }

                if (atr != 0)
                {
                    LongStop.Set(longStop);
                    ShortStop.Set(shortStop);
                    LongEntry.Set(longEntry);
                    ShortEntry.Set(shortEntry);
                    LongTarget1.Set(longTarget1);
                    ShortTarget1.Set(shortTarget1);
                    LongTarget2.Set(longTarget2);
                    ShortTarget2.Set(shortTarget2);

//					DrawLine("longTarget2L", -5, longTarget2, -50, longTarget2, Color.Blue);
//					DrawText("longTarget2T", "Exit Long Profit Target #2 ", -25, longTarget2+0.10, Color.Blue);
//
//					DrawLine("longTarget1L", -5, longTarget1, -50, longTarget1, Color.Green);
//					DrawText("longTarget1T", "Exit Long Profit Target #1 ", -25, longTarget1+0.10, Color.Green);
//
//					DrawLine("longEntryL", -5, longEntry, -50, longEntry, Color.Blue);
//					DrawText("longEntryT", "Entry Long signal ", -25, longEntry+0.10, Color.Blue);
//
//					DrawLine("longStopL", -5, longStop, -50, longStop, Color.Blue);
//					DrawText("longStopT", "Exit Long Stop ", -25, longStop+0.10, Color.Blue);
//
//					DrawLine("shortStopL", -5, shortStop, -50, shortStop, Color.Purple);
//					DrawText("shortStopT", "Exit Short Stop ", -25, shortStop+0.10, Color.Purple);
//
//					DrawLine("shortEntryL", -5, shortEntry, -50, shortEntry, Color.Purple);
//					DrawText("shortEntryT", "Entry Short signal ", -25, shortEntry+0.10, Color.Purple);
//
//					DrawLine("shortTarget1L", -5, shortTarget1, -50, shortTarget1, Color.Red);
//					DrawText("shortTarget1T", "Exit short Profit Target #1 ", -25, shortTarget1, Color.Red);
//
//					DrawLine("shortTarget2L", -5, shortTarget2, -50, shortTarget2, Color.Purple);
//					DrawText("shortTarget2T", "Exit short Profit Target #2 ", -25, shortTarget2, Color.Purple);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            FastLine.Set(Instrument.MasterInstrument.Round2TickSize(DonchianChannel(LengthFast)[0]));
            SlowLine.Set(Instrument.MasterInstrument.Round2TickSize(DonchianChannel(LengthSlow)[0]));
            TrailingStop.Set(EMA(eMA1Len)[0]);
            //TrendFilter.Set(EMA(eMA2Len)[0]);

            if (CrossAbove(FastLine, SlowLine, 1) &&
                crossedAboveBarNumber <= crossedBelowBarNumber)
            {
                crossedAboveBarNumber = CurrentBar;
                lookingLong           = true;
                lookingShort          = false;
            }
            else if (CrossBelow(FastLine, SlowLine, 1) &&
                     crossedAboveBarNumber >= crossedBelowBarNumber)
            {
                crossedBelowBarNumber = CurrentBar;
                lookingLong           = false;
                lookingShort          = true;
            }

            // Cancel trade under these conditions
            if (lookingLong && High[0] + entryOffsetTicks * TickSize < TrailingStop[0])
            {
                lookingLong = false;
            }
            if (lookingShort && Low[0] - entryOffsetTicks * TickSize > TrailingStop[0])
            {
                lookingShort = false;
            }

            //Print(Time + " " + CurrentBar + " " + crossedAboveBarNumber + " " + crossedBelowBarNumber);

            double barHeight = Range()[0];             //High[0] - Low[0];

            PlotColors[0][0] = Color.DarkBlue;
            PlotColors[1][0] = Color.DarkBlue;
            PlotColors[2][0] = Color.DarkBlue;
            PlotColors[3][0] = Color.DarkBlue;
            PlotColors[4][0] = Color.DarkBlue;
            PlotColors[5][0] = Color.DarkBlue;
            PlotColors[6][0] = Color.DarkBlue;
            PlotColors[7][0] = Color.DarkBlue;
            PlotColors[8][0] = Color.DarkBlue;
            PlotColors[9][0] = Color.DarkBlue;

            if (isLongSignal())
            {
                LongEntry.Set(High[0] + entryOffsetTicks * TickSize);
                LongStop.Set(Low[0] - stopOffsetTicks * TickSize);
                LongTgt1.Set(High[0] + Instrument.MasterInstrument.Round2TickSize(tgt1X * barHeight));
                LongTgt2.Set(High[0] + Instrument.MasterInstrument.Round2TickSize(tgt2X * barHeight));
                LongTgt3.Set(High[0] + Instrument.MasterInstrument.Round2TickSize(tgt3X * barHeight));
            }
            if (isShortSignal())
            {
                ShortEntry.Set(Low[0] - entryOffsetTicks * TickSize);
                ShortStop.Set(High[0] + stopOffsetTicks * TickSize);
                ShortTgt1.Set(Low[0] - Instrument.MasterInstrument.Round2TickSize(tgt1X * barHeight));
                ShortTgt2.Set(Low[0] - Instrument.MasterInstrument.Round2TickSize(tgt2X * barHeight));
                ShortTgt3.Set(Low[0] - Instrument.MasterInstrument.Round2TickSize(tgt3X * barHeight));
            }
        }