Beispiel #1
0
        public SmartMoneyIndex(Bars bars, string description)
            : base(bars, description)
        {
            Helper.CompatibilityCheck();

            base.FirstValidValue = 1;
            double am = 0, pm = 0, tc = 0, yc = 0, op = 0;

            if (!bars.IsIntraday)
            {
                return;
            }

            for (int bar = FirstValidValue; bar < bars.Count; bar++)
            {
                if (bars.IntradayBarNumber(bar) == 0)
                {
                    yc = bars.Close[bar - 1];
                }

                if (GetTime(bars, bar) == 1000)
                {
                    am = bars.Close[bar];
                }
                if (GetTime(bars, bar) == 1500)
                {
                    pm = bars.Close[bar];
                }
                if (GetTime(bars, bar) == 0930)
                {
                    op = bars.Open[bar];
                }

                if (bars.IsLastBarOfDay(bar))
                {
                    tc = bars.Close[bar];

                    //base[bar] = (tc - pm) - (op - am) + base[bar];
                    base[bar] = base[bar] - (op - am) + (tc - pm);
                }
                else
                {
                    base[bar] = base[bar - 1];
                }
            }
        }
Beispiel #2
0
        public LastHour(Bars bars, string description)
            : base(bars, description)
        {
            base.FirstValidValue = 1;
            double am = 0; double pm = 0;
            double tc = 0; double yc = 0;

            if (!bars.IsIntraday)
            {
                return;
            }

            for (int bar = FirstValidValue; bar < bars.Count; bar++)
            {
                if (bars.IntradayBarNumber(bar) == 0)
                {
                    yc = bars.Close[bar - 1];
                }

                if (GetTime(bars, bar) == 1030)
                {
                    am = bars.Close[bar];
                }
                if (GetTime(bars, bar) == 1500)
                {
                    pm = bars.Close[bar];
                }

                if (bars.IsLastBarOfDay(bar))
                {
                    tc = bars.Close[bar];

                    base[bar] = (tc - pm) - (am - yc);
                }
                else
                {
                    base[bar] = base[bar - 1];
                }
            }
        }
Beispiel #3
0
        protected override void Execute()
        {
            SMA       sma10 = SMA.Series(Close, 10);
            EMA       ema30 = EMA.Series(Close, 30, EMACalculation.Modern);
            WilliamsR wlm   = WilliamsR.Series(Bars, 3);

            BBandLower LB          = BBandLower.Series(Close, 29, 2.5);
            BBandUpper UB          = BBandUpper.Series(Close, 29, 2.5);
            SolidBrush shadowBrush = new SolidBrush(Color.FromArgb(10, Color.FromArgb(102, 0, 0, 255)));

            PlotSeriesFillBand(PricePane, LB, UB, Color.FromArgb(255, 176, 196, 222), shadowBrush, LineStyle.Solid, 2);

            DateTime        nextReportDate = new DateTime(2010, 1, 1);
            FundamentalItem fi             = GetFundamentalItem(Bars.Count - 1, Bars.Symbol, "earnings per share");

            bool crossOver  = false;
            bool pullback   = false;
            bool crossUnder = false;
            bool pullup     = false;


            for (int bar = 30; bar < Bars.Count; bar++)
            {
                SetContext("SPY", true);

                bool signal  = sma10[bar] > ema30[bar];
                bool goLong  = false;
                bool goShort = false;
                if (signal && wlm[bar] < 20)
                {
                    goLong = true;
                }
                if (!signal && wlm[bar] > 80)
                {
                    crossOver = false;
                    goShort   = true;
                }

                RestoreContext();

                //goLong = true;
                if (!IsLastPositionActive)
                {
                    if (goLong)
                    {
                        if (CrossOver(bar, sma10, ema30))
                        {
                            crossOver  = true;
                            pullback   = false;
                            crossUnder = false;
                            pullup     = false;
                            continue;
                        }

                        if (crossOver && Close[bar] < sma10[bar] && pullback == false)
                        {
                            pullback = true;
                        }

                        if (pullback && Close[bar] > sma10[bar])
                        {
                            //	DrawCircle( PricePane, 10, bar, High[bar], Color.Green, Color.DarkGreen, WealthLab.LineStyle.Solid, 2, true );
                            //	crossOver = false;
                            pullback = false;
                            BuyAtMarket(bar + 1, "SMA 10 is above EMA 30 and pull back is done ");
                        }
                    }
                    else
                    if (goShort)
                    {
                        if (CrossUnder(bar, sma10, ema30))
                        {
                            crossUnder = true;
                            pullup     = false;
                            crossOver  = false;
                            pullback   = false;
                            continue;
                        }

                        if (crossUnder && Close[bar] > sma10[bar] && pullup == false)
                        {
                            pullup = true;
                        }

                        if (pullup && Close[bar] < sma10[bar])
                        {
                            //	DrawCircle( PricePane, 10, bar, High[bar], Color.Green, Color.DarkGreen, WealthLab.LineStyle.Solid, 2, true );
                            //	crossOver = false;
                            pullup = false;
                            ShortAtMarket(bar + 1, "SMA 10 is below EMA 30 and pull back is done ");
                        }
                        //	DrawCircle( PricePane, 10, bar, High[bar], Color.Blue, Color.Black, WealthLab.LineStyle.Solid, 2, true );
                    }
                }
                else
                {
                    if (LastActivePosition.PositionType == PositionType.Long)
                    {
                        double b = LB[bar];
                        if (
                            LastActivePosition.EntryPrice > Close[bar] && Close[bar] < b &&
                            bar >= LastActivePosition.EntryBar
                            )
                        {
                            SellAtMarket(bar + 1, LastActivePosition, "stop lose");
                            crossOver = false;
                            pullback  = false;
                            continue;
                        }

                        if (Bars.IntradayBarNumber(bar) == 0 && EarningsDate.InWindow(this, bar, "earnings per share", 365, 0))
                        {
                            //DrawLabel(PricePane, "Next Earnings: " + Date[bar].ToString());
                            PrintDebug(Date[bar].ToString());
                        }

                        if (Date[bar].Day > (LastActivePosition.EntryDate.Day + 4) && Bars.IsLastBarOfDay(bar))
                        {
                            SellAtMarket(bar + 1, LastActivePosition, "Close on 5th day");
                            crossOver = false;
                            pullback  = false;
                            continue;
                        }
                        else

                        if (CrossUnder(bar, sma10, ema30))
                        {
                            SellAtMarket(bar + 1, LastActivePosition, "Take profit");
                            crossOver = false;
                            pullback  = false;
                            continue;
                        }
                    }
                    else if (LastActivePosition.PositionType == PositionType.Short)
                    {
                        double b = UB[bar];
                        if (
                            LastActivePosition.EntryPrice < Close[bar] && Close[bar] > b &&
                            bar >= LastActivePosition.EntryBar
                            )
                        {
                            CoverAtMarket(bar + 1, LastActivePosition, "Short stop lose");
                            crossUnder = false;
                            pullup     = false;
                            continue;
                        }


                        if (Date[bar].Day > (LastActivePosition.EntryDate.Day + 4) && Bars.IsLastBarOfDay(bar))
                        {
                            CoverAtMarket(bar + 1, LastActivePosition, "Close on 5th day");
                            crossUnder = false;
                            pullup     = false;
                            continue;
                        }
                        else

                        if (CrossOver(bar, sma10, ema30))
                        {
                            CoverAtMarket(bar + 1, LastActivePosition, "Take profit");
                            crossUnder = false;
                            pullup     = false;
                            continue;
                        }
                    }
                }
            }
            //Pushed indicator ChartPane statements
            ChartPane paneWilliamsR1 = CreatePane(40, true, true);

            //Pushed indicator PlotSeries statements
            PlotSeries(PricePane, sma10, Color.DarkGreen, LineStyle.Solid, 2);
            PlotSeries(PricePane, ema30, Color.Blue, LineStyle.Solid, 2);
            PlotSeries(paneWilliamsR1, wlm, Color.OliveDrab, LineStyle.Solid, 2);
        }