Example #1
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (BarsInProgress == 0)
            {
                double ibHigh       = 0;
                double ibLow        = 9999;
                double dailyHigh    = 0;
                double dailyLow     = 9999;
                double ibCummVolume = 0;



                if (Bars.BarsSinceSession == 0)
                {
                    recordFirstItemOnly = true;
                    recordFirstEODOnly  = true;
                    dailyOpen           = Open[0];
                }


                if (Time[0].TimeOfDay >= ib30Time && recordFirstItemOnly == true)
                {
                    ibBarSinceSession = Bars.BarsSinceSession;
                    Print(Time[0].ToString());
                    Print(Bars.BarsSinceSession);
                    datenum = Time[0];

                    ib30 = new InitialBalance()
                    {
                        IBStartTime = Time[Bars.BarsSinceSession],
                        IBEndTime   = Time[0],
                        IBClose     = Close[0],
                        IBOpen      = Open[Bars.BarsSinceSession],
                        IBDate      = datenum
                    };

                    for (int i = 0; i <= Bars.BarsSinceSession; i++)
                    {
                        ibHigh       = Math.Max(ibHigh, High[i]);
                        ibLow        = Math.Min(ibLow, Low[i]);
                        ibCummVolume = ibCummVolume + Volume[i];
                    }

                    ib30.IBLow    = ibLow;
                    ib30.IBHigh   = ibHigh;
                    ib30.IBVolume = ibCummVolume;


                    dIB30.Add(dayIndex, ib30);
                    dayIndex++;


                    recordFirstItemOnly = false;
                }


                if (Time[0].TimeOfDay >= dayEndTime && recordFirstEODOnly == true)
                {
                    for (int i = 0; i <= Bars.BarsSinceSession; i++)
                    {
                        dailyHigh = Math.Max(dailyHigh, High[i]);
                        dailyLow  = Math.Min(dailyLow, Low[i]);
                        //ibCummVolume = ibCummVolume + Volume[i];
                    }

                    Print(Time[0].ToString());
                    Print(Bars.BarsSinceSession);

                    // int sessionBarSince = Bars.BarsSinceSession;
                    //dailyHigh = High[HighestBar(High, sessionBarSince)];
                    //dailyLow = Low[LowestBar(Low, sessionBarSince)];
                    //dailyClose = Close[0];


                    ibEOD = new InitialBalance()
                    {
                        IBStartTime = Time[Bars.BarsSinceSession],
                        IBEndTime   = Time[0],
                        IBClose     = Close[0],
                        IBOpen      = Open[Bars.BarsSinceSession],
                        IBDate      = datenum
                    };

                    ibEOD.IBLow  = dailyLow;
                    ibEOD.IBHigh = dailyHigh;

                    dIB30.Add(dayIndex, ibEOD);
                    dayIndex++;

                    recordFirstEODOnly = false;
                }
            }


            #region Properties
            #endregion
        }
        protected override void OnBarUpdate()
        {
            if (BarsInProgress == 0)
            {
                double ibHigh       = 0;
                double ibLow        = 9999;
                double ibCummVolume = 0;
                lastOpenBullPrice = 0;
                lastOpenBearPrice = 0;

                if (Bars.BarsSinceSession == 0)
                {
                    recordFirstItemOnly = true;
                    scalpLongLimitEntry = scalpShortLimitEntry = swingLongLimitEntry = swingShortLimitEntry = swingShortEntry = swingLongEntry = null;
                }

                //if (Position.MarketPosition != MarketPosition.Flat)
                //{
                //    if (IsFirstEntryLong == false && Close[0] >= (ib30.IBHigh - (ib30.IBHigh - ib30.IBLow) / 2) && swingShortLimitEntry != null && scalpShortLimitEntry == null)
                //        scalpShortLimitEntry = SubmitOrder(0, OrderAction.SellShort, OrderType.Stop, scalpQty, 0, (ib30.IBHigh - (ib30.IBHigh - ib30.IBLow) / 2), "IBEntry", "SC.BEAR.STP");
                //    if (IsFirstEntryLong == true && (Close[0] <= ib30.IBLow + (ib30.IBHigh - ib30.IBLow) / 2) && swingLongLimitEntry != null && scalpLongLimitEntry == null)
                //        scalpLongLimitEntry = SubmitOrder(0, OrderAction.Buy, OrderType.Stop, scalpQty, 0, (ib30.IBLow + (ib30.IBHigh - ib30.IBLow) / 2), "IBEntry", "SC.BULL.STP");
                //}

                if (Time[0].TimeOfDay >= ib30Time && recordFirstItemOnly == true)
                {
                    ibBarSinceSession = Bars.BarsSinceSession;
                    lineStartTime     = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 9, 30, 00);
                    lineEndTime       = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 15, 59, 59);

                    ib30 = new InitialBalance()
                    {
                        IBStartTime = Time[Bars.BarsSinceSession],
                        IBEndTime   = Time[0],
                        IBClose     = Close[0],
                        IBOpen      = Open[Bars.BarsSinceSession]
                    };

                    for (int i = 0; i <= Bars.BarsSinceSession; i++)
                    {
                        ibHigh       = Math.Max(ibHigh, High[i]);
                        ibLow        = Math.Min(ibLow, Low[i]);
                        ibCummVolume = ibCummVolume + Volume[i];
                    }

                    ib30.IBLow    = ibLow;
                    ib30.IBHigh   = ibHigh;
                    ib30.IBVolume = ibCummVolume;

                    dIB30.Add(dayIndex, ib30);
                    dayIndex++;

                    recordFirstItemOnly = false;

                    if (probabilityRange() == true)   // Limit Orders for Trading Range Days
                    {
                        if (enableRangeStrategy)      // Long Entry Orders (OCO)
                        {
                            if (Close[0] >= ib30.IBHigh && swingShortLimitEntry == null)
                            {
                                swingShortLimitEntry = SubmitOrder(0, OrderAction.SellShort, OrderType.Market, swingQty, 0, 0, "IBEntrySwing", "SW.BEAR.MKT");
                            }
                            if (Close[0] < ib30.IBHigh && swingShortLimitEntry == null)
                            {
                                swingShortLimitEntry = SubmitOrder(0, OrderAction.SellShort, OrderType.Limit, swingQty, ib30.IBHigh, 0, "IBEntrySwing", "SW.BEAR.LMT");
                            }
                        }
                        if (enableRangeStrategy)    // Short Entry Orders (OCO)
                        {
                            if (Close[0] <= ib30.IBLow && swingLongLimitEntry == null)
                            {
                                swingLongLimitEntry = SubmitOrder(0, OrderAction.Buy, OrderType.Market, swingQty, 0, 0, "IBEntrySwing", "SW.BULL.MKT");
                            }
                            if (Close[0] > ib30.IBLow && swingLongLimitEntry == null)
                            {
                                swingLongLimitEntry = SubmitOrder(0, OrderAction.Buy, OrderType.Limit, swingQty, ib30.IBLow, 0, "IBEntrySwing", "SW.BULL.LMT");
                            }
                        }
                    }

                    //if (probabilityTrend() == true)             // Stop Orders for Trending Range Days
                    //{
                    //    if (enableTrendStrategy)      // Long Entry Orders (OCO)
                    //    {
                    //        if (Close[0] >= ib30.IBHigh && swingLongEntry == null)
                    //            swingLongEntry = SubmitOrder(0, OrderAction.Buy, OrderType.Market, swingQty, 0, 0, "IBEntrySwing", "SW.BULL.MKT");
                    //        if (Close[0] < ib30.IBHigh && swingLongEntry == null)
                    //            swingLongEntry = SubmitOrder(0, OrderAction.Buy, OrderType.Stop, swingQty, 0,ib30.IBHigh, "IBEntrySwing", "SW.BULL.STP");
                    //    }
                    //    if (enableTrendStrategy)    // Short Entry Orders (OCO)
                    //    {
                    //        if (Close[0] <= ib30.IBLow && swingShortEntry == null)
                    //            swingShortEntry = SubmitOrder(0, OrderAction.SellShort, OrderType.Market, swingQty, 0, 0, "IBEntrySwing", "SW.BEAR.MKT");
                    //        if (Close[0] > ib30.IBLow && swingShortEntry == null)
                    //            swingShortEntry = SubmitOrder(0, OrderAction.SellShort, OrderType.Stop, swingQty, 0,ib30.IBLow, "IBEntrySwing", "SW.BEAR.STP");
                    //    }
                    //}

                    #region Draw Objects
                    DrawLine("IBHigh" + Time[0].Date, false, lineStartTime, ib30.IBHigh, lineEndTime, ib30.IBHigh, Color.Aqua, DashStyle.Solid, 2);
                    DrawLine("IBLow" + Time[0].Date, false, lineStartTime, ib30.IBLow, lineEndTime, ib30.IBLow, Color.Coral, DashStyle.Solid, 2);
                    DrawLine("IBHighTarget" + Time[0].Date, false, lineStartTime, (ib30.IBHigh + Math.Abs(ib30.IBLow - ib30.IBHigh) / stopLossDivisor), lineEndTime, (ib30.IBHigh + Math.Abs(ib30.IBLow - ib30.IBHigh) / stopLossDivisor), Color.Yellow, DashStyle.Dash, 1);
                    DrawLine("IBLowTarget" + Time[0].Date, false, lineStartTime, ib30.IBLow - Math.Abs(ib30.IBLow - ib30.IBHigh) / stopLossDivisor, lineEndTime, ib30.IBLow - Math.Abs(ib30.IBLow - ib30.IBHigh) / stopLossDivisor, Color.Yellow, DashStyle.Dash, 1);

                    if (Close[0] <= (ib30.IBLow + (Math.Abs(ib30.IBHigh - ib30.IBLow)) / 2))
                    {
                        DrawText("IBRnage" + Time[0].Date, String.Format("ib.{0}   adx.{1}", (ib30.IBHigh - ib30.IBLow).ToString("0.00"), ADX(14)[0].ToString("0"), ib30.IBVolume.ToString("0")), 0, ib30.IBHigh + 2 * TickSize, Color.Black);
                    }
                    else
                    {
                        DrawText("IBRnage" + Time[0].Date, String.Format("ib.{0}   adx.{1}", (ib30.IBHigh - ib30.IBLow).ToString("0.00"), ADX(14)[0].ToString("0"), ib30.IBVolume.ToString("0")), 0, ib30.IBLow - 2 * TickSize, Color.Black);
                    }
                    #endregion

                    if (swingLongLimitEntry != null && swingLongLimitEntry.Filled > 0)
                    {
                        double ibSMA = SMA(ibBarSinceSession)[0];
                        DrawText("IBRnage" + Time[0].Date, String.Format("adx.{0}   sma.{1}", ADX(14)[0].ToString("0"), ibSMA.ToString("0.00")), 0, ib30.IBHigh + 2 * TickSize, Color.Black);
                    }
                    else if (swingShortLimitEntry != null && swingShortLimitEntry.Filled > 0)
                    {
                        double ibSMA = SMA(ibBarSinceSession)[0];
                        DrawText("IBRnage" + Time[0].Date, String.Format("adx.{0}   sma.{1}", ADX(14)[0].ToString("0"), ibSMA.ToString("0.00")), 0, ib30.IBLow - 2 * TickSize, Color.Black);
                    }
                }
            }
        }
Example #3
0
        protected override void OnBarUpdate()
        {
            if (Bars.BarsSinceSession == 0)
            {
                ibCummVolUp               = ibCummVolDown = 0;
                scalpLongLimitEntry       = scalpShortLimitEntry = swingLongLimitEntry = swingShortLimitEntry = swingLongProfitTarget = swingLongStopLoss =
                    scalpLongProfitTarget = scalpLongStopLoss = swingShortProfitTarget = swingShortStopLoss = scalpShortProfitTarget = scalpShortStopLoss = null;
            }

            if (Time[0].TimeOfDay >= ib30Time && Time[1].TimeOfDay < ib30Time)
            {
                ib30 = new InitialBalance()
                {
                    IBStartTime = Time[Bars.BarsSinceSession],
                    IBEndTime   = Time[0],
                    IBOpen      = Open[Bars.BarsSinceSession],
                    IBHigh      = MAX(High, Bars.BarsSinceSession)[0],
                    IBLow       = MIN(Low, Bars.BarsSinceSession)[0],
                    IBClose     = Close[0]
                };

                for (int i = 0; i <= Bars.BarsSinceSession; i++)
                {
                    if (Close[i] >= Open[i])
                    {
                        ibCummVolUp = ibCummVolUp + Volume[i];
                    }
                    else
                    {
                        ibCummVolDown = ibCummVolDown + Volume[i];
                    }
                }

                ib30.IBVolumeDown = ibCummVolDown;
                ib30.IBVolumeUp   = ibCummVolUp;

                dIB30.Add(dayIndex, ib30);
                dayIndex++;

                if (probability() == true)
                {
                    enableScalpTrade = true;

                    if (true)       // Long Entry Orders (OCO)
                    {
                        if (Close[0] >= ib30.IBHigh && swingShortLimitEntry == null)
                        {
                            swingShortLimitEntry = SubmitOrder(0, OrderAction.SellShort, OrderType.Market, swingQty, 0, 0, "IBEntrySwing", "SW.BEAR.MKT");
                        }
                        if (Close[0] < ib30.IBHigh && swingShortLimitEntry == null)
                        {
                            swingShortLimitEntry = SubmitOrder(0, OrderAction.SellShort, OrderType.Limit, swingQty, ib30.IBHigh, 0, "IBEntrySwing", "SW.BEAR.LMT");
                        }
                    }
                    if (true)     // Short Entry Orders (OCO)
                    {
                        if (Close[0] <= ib30.IBLow && swingLongLimitEntry == null)
                        {
                            swingLongLimitEntry = SubmitOrder(0, OrderAction.Buy, OrderType.Market, swingQty, 0, 0, "IBEntrySwing", "SW.BULL.MKT");
                        }
                        if (Close[0] > ib30.IBLow && swingLongLimitEntry == null)
                        {
                            swingLongLimitEntry = SubmitOrder(0, OrderAction.Buy, OrderType.Limit, swingQty, ib30.IBLow, 0, "IBEntrySwing", "SW.BULL.LMT");
                        }
                    }
                }
                #region Draw Objects
                DateTime lineStartTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 9, 30, 00);
                DateTime lineEndTime   = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 15, 59, 59);

                DrawLine("IBHigh" + Time[0].Date, false, lineStartTime, ib30.IBHigh, lineEndTime, ib30.IBHigh, Color.Aqua, DashStyle.Solid, 2);
                DrawLine("IBLow" + Time[0].Date, false, lineStartTime, ib30.IBLow, lineEndTime, ib30.IBLow, Color.Coral, DashStyle.Solid, 2);
                DrawLine("IBHighTarget" + Time[0].Date, false, lineStartTime, (ib30.IBHigh + Math.Abs(ib30.IBLow - ib30.IBHigh) / stopLossDivisor), lineEndTime, (ib30.IBHigh + Math.Abs(ib30.IBLow - ib30.IBHigh) / stopLossDivisor), Color.Yellow, DashStyle.Dash, 1);
                DrawLine("IBLowTarget" + Time[0].Date, false, lineStartTime, ib30.IBLow - Math.Abs(ib30.IBLow - ib30.IBHigh) / stopLossDivisor, lineEndTime, ib30.IBLow - Math.Abs(ib30.IBLow - ib30.IBHigh) / stopLossDivisor, Color.Yellow, DashStyle.Dash, 1);

                if (Close[0] <= (ib30.IBLow + (Math.Abs(ib30.IBHigh - ib30.IBLow)) / 2))
                {
                    DrawText("IBRnage" + Time[0].Date, String.Format("ib.{0}   adx.{1}", (ib30.IBHigh - ib30.IBLow).ToString("0.00"), ADX(14)[0].ToString("0"), ib30.IBVolume.ToString("0")), 0, ib30.IBHigh + 2 * TickSize, Color.Black);
                }
                else
                {
                    DrawText("IBRnage" + Time[0].Date, String.Format("ib.{0}   adx.{1}", (ib30.IBHigh - ib30.IBLow).ToString("0.00"), ADX(14)[0].ToString("0"), ib30.IBVolume.ToString("0")), 0, ib30.IBLow - 2 * TickSize, Color.Black);
                }
                #endregion
            }

            if (enableScalpTrade == true)
            {
                if (High[0] >= ib30.IBHigh)
                {
                    scalpShortLimitEntry = SubmitOrder(0, OrderAction.SellShort, OrderType.Stop, scalpQty, 0, (ib30.IBHigh - (ib30.IBHigh - ib30.IBLow) / 2), "IBEntry", "SC.BEAR.STP");
                    enableScalpTrade     = false;
                }
                if (Low[0] <= ib30.IBLow)
                {
                    scalpLongLimitEntry = SubmitOrder(0, OrderAction.Buy, OrderType.Stop, scalpQty, 0, (ib30.IBLow + (ib30.IBHigh - ib30.IBLow) / 2), "IBEntry", "SC.BULL.STP");
                    enableScalpTrade    = false;
                }
            }
        }
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        ///

        protected override void OnBarUpdate()
        {
            if (IB30 != null && Time[0].TimeOfDay >= IB30Time && Time[0].TimeOfDay <= IBCloseTrading)
            {
                if (ConfirmationNextBar == true)
                {
                    if (Close[0] > Open[0] && Low[0] < Open[0])
                    {
                        BackColor = Color.Tomato;
                        BarCounter++;
                        Print(BarCounter);
                    }

                    ConfirmationNextBar = false;
                }

                if (Low[0] < IB30.IBLow && Close[0] > IB30.IBLow && (Close[0] < Open[0]) &&
                    Low[0] < Bollinger(2, 14).Lower[0])
                {
                    BackColor = Color.Yellow;

                    ConfirmationNextBar = true;
                }
            }
            if (BarsInProgress == 0)
            {
                double ibHigh       = 0;
                double ibLow        = 9999;
                double ibCummVolume = 0;


                if (Bars.BarsSinceSession == 0)
                {
                    recFirstItemOnly = true;
                }

                if (Time[0].TimeOfDay >= IB30Time && recFirstItemOnly == true)
                {
                    LineStartTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 9, 30, 00);
                    LineEndTime   = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 15, 59, 59);

                    IB30 = new InitialBalance()
                    {
                        IBStartTime = Time[Bars.BarsSinceSession],
                        IBEndTime   = Time[0],
                        IBClose     = Close[0],
                        IBOpen      = Open[Bars.BarsSinceSession]
                    };

                    for (int i = 0; i <= Bars.BarsSinceSession; i++)
                    {
                        ibHigh       = Math.Max(ibHigh, High[i]);
                        ibLow        = Math.Min(ibLow, Low[i]);
                        ibCummVolume = ibCummVolume + Volume[i];
                    }

                    IB30.IBLow    = ibLow;
                    IB30.IBHigh   = ibHigh;
                    IB30.IBVolume = ibCummVolume;

                    DIB30.Add(dayIdx, IB30);
                    dayIdx++;

                    recFirstItemOnly = false;

                    if (Probability() == true)
                    {
                    }
                    #region Draw Objects
                    DrawLine("IBHigh" + Time[0].Date, false, LineStartTime, IB30.IBHigh, LineEndTime, IB30.IBHigh, Color.Aqua, DashStyle.Solid, 2);
                    DrawLine("IBLow" + Time[0].Date, false, LineStartTime, IB30.IBLow, LineEndTime, IB30.IBLow, Color.Coral, DashStyle.Solid, 2);
                    DrawLine("IBHighTarget" + Time[0].Date, false, LineStartTime, (IB30.IBHigh + Math.Abs(IB30.IBLow - IB30.IBHigh) / slDiv), LineEndTime, (IB30.IBHigh + Math.Abs(IB30.IBLow - IB30.IBHigh) / slDiv), Color.Yellow, DashStyle.Dash, 1);
                    DrawLine("IBLowTarget" + Time[0].Date, false, LineStartTime, IB30.IBLow - Math.Abs(IB30.IBLow - IB30.IBHigh) / slDiv, LineEndTime, IB30.IBLow - Math.Abs(IB30.IBLow - IB30.IBHigh) / slDiv, Color.Yellow, DashStyle.Dash, 1);

                    if (Close[0] <= (IB30.IBLow + (Math.Abs(IB30.IBHigh - IB30.IBLow)) / 2))
                    {
                        DrawText("IBRnage" + Time[0].Date, String.Format("ib.{0}   adx.{1}", (IB30.IBHigh - IB30.IBLow).ToString("0.00"), ADX(14)[0].ToString("0"), IB30.IBVolume.ToString("0")), 0, IB30.IBHigh + 2 * TickSize, Color.Black);
                    }
                    else
                    {
                        DrawText("IBRnage" + Time[0].Date, String.Format("ib.{0}   adx.{1}", (IB30.IBHigh - IB30.IBLow).ToString("0.00"), ADX(14)[0].ToString("0"), IB30.IBVolume.ToString("0")), 0, IB30.IBLow - 2 * TickSize, Color.Black);
                    }
                    #endregion
                }
            }
        }