Пример #1
0
        /// <summary>
        /// Defines a named chart pane.
        /// </summary>
        /// <param name="name">
        /// The unique pane name
        /// </param>
        public ChartPaneBuilder Add(string name)
        {
            ChartPane pane = new ChartPane(name);

            Container.Panes.Add(pane);

            return(new ChartPaneBuilder(pane));
        }
Пример #2
0
        /// <summary>
        /// Defines a chart pane.
        /// </summary>
        public ChartPaneBuilder Add()
        {
            ChartPane pane = new ChartPane();

            Container.Panes.Add(pane);

            return(new ChartPaneBuilder(pane));
        }
Пример #3
0
        /// <summary>
        /// Configures the a navigator pane.
        /// </summary>
        public ChartNavigatorBuilder <T> Pane(Action <ChartPaneBuilder> configurator)
        {
            var pane = new ChartPane();

            navigator.Pane = pane;

            configurator(new ChartPaneBuilder(pane));
            return(this);
        }
 void control_AddIndicatorEvent(PlatformIndicator indicator, ChartPane pane)
 {
     if (pane == null)
     {
         pane = chartControl.CreateSlavePane(indicator.Name, SlaveChartPane.MasterPaneSynchronizationModeEnum.XAxis, this.Height / 4);
         pane.RightMouseButtonSelectionMode = ChartPane.SelectionModeEnum.HorizontalZoom;
         pane.Add(indicator.ChartSeries);
         // Establish proper Y axis values.
         //pane.FitDrawingSpaceToScreen(true, true);
     }
     else
     {
         pane.Add(indicator.ChartSeries);
     }
 }
Пример #5
0
        public override void Draw(ChartPane managingPane, GraphicsWrapper g, int unitsUnification, RectangleF clippingRectangle, float itemWidth, float itemMargin)
        {
            if (this.Visible == false || Indicator == null)
            {
                return;
            }

            lock (Indicator.Results)
            {
                foreach (string name in Indicator.Results.SetsNamesUnsafe)
                {
                    LinesChartSeries.ChartTypeEnum?chartType = Indicator.Results.GetResultSetChartType(name);
                    if (chartType.HasValue == false)
                    {// No specific value assigned means go for default.
                        chartType = DefaultChartType;
                    }

                    base.DrawItemSet(chartType.Value, g, _outputResultSetsPens[name], _defaultBrush,
                                     unitsUnification, clippingRectangle, itemWidth, itemMargin, name);
                }
            }

            foreach (string name in Indicator.Parameters.DynamicNames)
            {// Render fixed lines.
                if (name.Contains(FixedLinePrefix))
                {
                    object value = Indicator.Parameters.GetDynamic(name);
                    if (value == null)
                    {
                        continue;
                    }

                    float floatValue = Convert.ToSingle(value);
                    int   dashMove   = 0;// ((int)x % DashSize);
                    g.DrawLine(_defaultDashedPen, clippingRectangle.X + dashMove, floatValue, clippingRectangle.X + clippingRectangle.Width, floatValue);
                }
            }
        }
Пример #6
0
        protected override void Execute()
        {
            string today      = DateTime.Now.ToString("yyyy-MM-dd");
            string workingDir = @"Z:\Win10D";
            string path       = Path.Combine(workingDir, "Data", today);

            if (!Directory.Exists(path))
            {
                throw new Exception("You must create the directory " + path);
            }

            PrintStatusBar(today + " Complete!");

            //Pushed indicator ChartPane statements
            ChartPane paneEquitySummaryScore1    = CreatePane(40, true, true);
            ChartPane paneEquitySummaryCategory1 = CreatePane(40, true, true);
            ChartPane paneEarnings1 = CreatePane(40, true, true);

            //Pushed indicator PlotSeries statements
            PlotFundamentalItems(paneEquitySummaryScore1, "equity summary score", Color.FromArgb(255, 255, 0, 0), LineStyle.Solid, 1);
            PlotFundamentalItems(paneEquitySummaryCategory1, "equity summary category", Color.FromArgb(255, 255, 0, 0), LineStyle.Solid, 1);
            PlotFundamentalItems(paneEarnings1, "estimated earnings", Color.FromArgb(255, 0, 128, 128), LineStyle.Solid, 1);
            PlotFundamentalItems(paneEarnings1, "earnings per share", Color.FromArgb(255, 255, 0, 0), LineStyle.Solid, 1);
        }
Пример #7
0
        /// <summary>
        /// 设置子属性
        /// </summary>
        protected override void SetChildElements()
        {
            ChartPane control = this.ControlHost.Content as ChartPane;

            this.HtmlWriter.AddAttribute("dojoType", "Controls/Charting/Chart");
            if (!IsPreview && !string.IsNullOrEmpty(this.ControlHost.Name))
            {
                this.HtmlWriter.AddAttribute("id", this.ControlHost.Name);
            }
            string chartTheme = control.ChartTheme.ToString();

            if (control.ChartTheme == EChartTheme.PlotKitBlue)
            {
                chartTheme = "PlotKit.blue";
            }
            if (control.ChartTheme == EChartTheme.PlotKitCyan)
            {
                chartTheme = "PlotKit.cyan";
            }
            if (control.ChartTheme == EChartTheme.PlotKitGreen)
            {
                chartTheme = "PlotKit.green";
            }
            if (control.ChartTheme == EChartTheme.PlotKitOrange)
            {
                chartTheme = "PlotKit.orange";
            }
            if (control.ChartTheme == EChartTheme.PlotKitPurple)
            {
                chartTheme = "PlotKit.purple";
            }
            if (control.ChartTheme == EChartTheme.PlotKitRed)
            {
                chartTheme = "PlotKit.red";
            }
            this.HtmlWriter.AddAttribute("theme", "dojox.charting.themes." + chartTheme);

            int           width    = 0;
            StringBuilder styleStr = new StringBuilder();

            if (control.Width != null && control.Width > 0)
            {
                width = width - 1;
            }
            if (width > 0)
            {
                styleStr.AppendFormat("width:{0}px !important;", control.Width.ToString());
            }
            else
            {
                styleStr.AppendFormat("width:calc(100% - 1px) !important;");
            }
            if (control.Height != null && control.Height > 0)
            {
                styleStr.AppendFormat("height:{0}px !important;", control.Height.ToString());
            }
            if (!string.IsNullOrEmpty(styleStr.ToString()))
            {
                this.HtmlWriter.AddAttribute("style", styleStr.ToString());
            }


            //
            this.HtmlWriter.RenderBeginTag(this.TagName);
            foreach (var c in this.ControlHost.Children)
            {
                var builder = c.GetBuilder(this.IsPreview, this.ScreenDefinition, this.Compile, this.ProjectDocument, this.PermissionData, this.HtmlWriter);
                builder.Parent = this;
                builder.Build();
            }
            this.HtmlWriter.RenderEndTag();
        }
Пример #8
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);
        }
Пример #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ChartPaneBuilder"/> class.
 /// </summary>
 /// <param name="pane">The phart pane.</param>
 public ChartPaneBuilder(ChartPane pane)
 {
     Pane = pane;
 }
Пример #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ChartPaneBuilder"/> class.
 /// </summary>
 /// <param name="pane">The phart pane.</param>
 public ChartPaneBuilder(ChartPane pane)
 {
     Pane = pane;
 }
Пример #11
0
        protected override void Execute()
        {
            int level;

            signleToSell     = false;
            priceAtCross     = 0;
            firstUp          = false;
            firstDown        = false;
            priceAtCrossDown = 0;
            rocAtCrossDown   = 0;

            topPrice   = 0;
            lastTop    = 0;
            breakPrice = 0;
            rocPrice   = 0;

            //Create and plot  period RSI
            RSI        rsi20       = RSI.Series(Close, 29);
            DataSeries senkouSpanA = SenkouSpanA.Series(Bars);
            DataSeries senkouSpanB = SenkouSpanB.Series(Bars);
            ChartPane  rsiPane     = CreatePane(50, true, true);

            PlotSeries(rsiPane, rsi20, Color.Navy, LineStyle.Solid, 3);
            DrawHorzLine(rsiPane, overbought.Value, Color.Green, LineStyle.Dotted, 2);


            ChartPane paneROC1 = CreatePane(40, true, true);

            PlotSeries(paneROC1, ROC.Series(Close, 20), Color.FromArgb(255, 112, 128, 144), LineStyle.Dotted, 2);
            DrawHorzLine(paneROC1, 0, Color.Red, LineStyle.Solid, 2);

            int period = Math.Max(29, 20);


            if (initPosition)
            {
                // init starting state to force buy into the market
                priceAtCrossDown = Close[period + 1];
                rocAtCrossDown   = ROC.Value(period + 1, Close, 20);
                firstDown        = true;
            }

            //Trading system main loop
            for (int bar = period + 1; bar < Bars.Count; bar++)
            {
                if (Close[bar] > topPrice)
                {
                    topPrice = Close[bar];
                }


                // Ichimoku  start
                if (
                    CrossOver(bar, Close, senkouSpanA))
                //				if (CrossUnder(bar, rsi20, level))
                {
                    if (!firstDown)
                    {
                        // first time to go below
                        // set cross happen and record the targit price
                        firstDown        = true;
                        priceAtCrossDown = Close[bar];
                        rocAtCrossDown   = ROC.Value(bar, Close, 20);
                    }
                }

                // play trayling
                int  addToPosition = 0;
                bool rsiOk         = false;
                bool priceOK       = false;
                if (firstDown)
                {
                    // ROC must improve by delta
                    double delta = Math.Abs(rocAtCrossDown * 0.2);

                    double newrocSMA = ROC.Value(bar, Close, 20);


                    if (bar == Bars.Count - 1)
                    {
                        rocPrice = rocAtCrossDown + delta;
                    }

                    if (newrocSMA <= (rocAtCrossDown + delta))
                    {
                        if (newrocSMA < rocAtCrossDown)
                        {
                            rocAtCrossDown = newrocSMA;
                        }
                    }
                    else
                    {
                        rsiOk = true;
                    }

                    double riseV = 2;
                    delta = priceAtCrossDown * (riseV / 1000.0 + 0.00017);

                    if (bar == Bars.Count - 1)
                    {
                        breakPrice = priceAtCrossDown + delta;
                    }

                    if (Close[bar] < (priceAtCrossDown + delta))
                    {
                        // DrawLabel(PricePane, "ready to buy, price is not rising: " + Close[bar].ToString() + " less than " + (priceAtCrossDown + delta).ToString());

                        if (Close[bar] < priceAtCrossDown)
                        {
                            priceAtCrossDown = Close[bar];
                        }
                    }
                    else
                    {
                        priceOK = true;
                    }

                    if (priceOK && rsiOk)
                    {
                        addToPosition++;
                        firstDown = false;
                    }
                }


                // you can  have only one active position
                foreach (Position pos in Positions)
                {
                    if (pos.Active && pos.PositionType == PositionType.Long)
                    {
                        addToPosition = 0;
                        break;
                    }
                }


                if (addToPosition > 0)
                {
                    // Close all shorts
                    foreach (Position pos in Positions)
                    {
                        if (pos.Active && pos.PositionType == PositionType.Short)
                        {
                            CoverAtMarket(bar + 1, pos);
                        }
                    }

                    //	    DrawLabel(PricePane, "buy at bar = " + bar.ToString());
                    Position p = BuyAtMarket(bar + 1);
                    firstUp = false;
                }


                level = overbought.ValueInt;
                int ClosedTrades = 0;
                signleToSell = false;
                if (CrossOver(bar, rsi20, overbought.ValueInt))
                {
                    if (!firstUp)
                    {
                        // first time to go above
                        // set cross happen and record the targit price
                        firstUp      = true;
                        priceAtCross = Close[bar];
                    }
                }

                if (firstUp)
                {
                    double riseV = 2;

                    double delta = priceAtCross * (riseV / 1000 + 0.00017);

                    priceOK = true;
                    if (Close[bar] >= (priceAtCross - delta))
                    {
                        if (Close[bar] > priceAtCross)
                        {
                            priceAtCross = Close[bar];
                        }
                    }
                    else
                    {
                        priceOK = false;
                    }

                    // keep as long ROC over zero
                    if (ROC.Value(bar, Close, 20) <= 0 && !priceOK)
                    {
                        signleToSell = true;
                        firstUp      = false;
                    }
                }


                // wait until price either move up or stopped out
                if (signleToSell)
                {
                    firstUp = false;
                    //DrawLabel(PricePane, ActivePositions.Count.ToString());
                    foreach (Position pos in Positions)
                    {
                        if (pos.Active && pos.PositionType == PositionType.Long)
                        {
                            SellAtMarket(bar + 1, pos);
                            ClosedTrades++;
                        }
                    }
                    signleToSell = false;
                }
                if (!IsLastPositionActive)
                {
                    if (CrossUnder(bar, Close, senkouSpanB))
                    {
                        // Short only after sell long position
                        if (!trend)
                        {
                            ShortAtMarket(bar + 1);
                        }
                    }
                }

                // sell on % lose
                foreach (Position pos in Positions)
                {
                    if (pos.Active &&
                        pos.PositionType == PositionType.Long &&
                        pos.EntryPrice > (Close[bar] + pos.EntryPrice * (0.008 + 0 * 0.001)) &&
                        bar >= pos.EntryBar
                        )
                    {
                        SellAtMarket(bar + 1, pos, "stop lose");
                        signleToSell = false;
                        firstUp      = false;
                        firstDown    = false;
                        continue;
                    }
                    if (pos.Active &&
                        pos.PositionType == PositionType.Short &&
                        Close[bar] > (pos.EntryPrice + pos.EntryPrice * (0.008 + 0 * 0.001)) &&
                        bar >= pos.EntryBar
                        )
                    {
                        CoverAtMarket(bar + 1, pos, "stop lose Short");
                    }
                }
            }
            double currentPrice = Close[Bars.Count - 1];

            DrawLabel(paneROC1, "Top: " + topPrice.ToString(), Color.Red);
            DrawLabel(paneROC1, "Current Price: " + currentPrice.ToString());

            DrawLabel(paneROC1, "Goal : " + " At +5%  " + (currentPrice * 1.05).ToString(), Color.BlueViolet);
            DrawLabel(paneROC1, "Goal : " + " At +8%  " + (currentPrice * 1.08).ToString(), Color.MediumSpringGreen);
            DrawLabel(paneROC1, "Goal : " + " At +10% " + (currentPrice * 1.10).ToString(), Color.DarkOliveGreen);


            DrawLabel(PricePane, "Drop          : " + " At -5%  " + (topPrice * 0.95).ToString(), Color.DarkGreen);
            DrawLabel(PricePane, "Correction   : " + " At -8%  " + (topPrice * 0.92).ToString(), Color.DarkBlue);
            DrawLabel(PricePane, "Correction   : " + " At -10% " + (topPrice * 0.90).ToString(), Color.Red);
            DrawLabel(PricePane, "Bear market: " + " At -20% " + (topPrice * 0.80).ToString(), Color.DarkRed);

            if (breakPrice > 0)
            {
                DrawLabel(PricePane, "Break above Price: " + breakPrice.ToString(), Color.DarkGoldenrod);
            }
            if (rocPrice > 0)
            {
                DrawLabel(PricePane, "Break above Momuntem: " + rocPrice.ToString(), Color.DarkGoldenrod);
            }


            DrawHorzLine(PricePane, currentPrice * 1.05, Color.BlueViolet, LineStyle.Solid, 6);
            DrawHorzLine(PricePane, currentPrice * 1.08, Color.MediumSpringGreen, LineStyle.Solid, 3);
            DrawHorzLine(PricePane, currentPrice * 1.10, Color.DarkOliveGreen, LineStyle.Solid, 3);


            DrawHorzLine(PricePane, topPrice * 0.95, Color.DarkGreen, LineStyle.Solid, 3);
            DrawHorzLine(PricePane, topPrice * 0.92, Color.DarkBlue, LineStyle.Solid, 3);
            DrawHorzLine(PricePane, topPrice * 0.90, Color.Red, LineStyle.Solid, 3);
            DrawHorzLine(PricePane, topPrice * 0.80, Color.DarkRed, LineStyle.Solid, 3);


            if (breakPrice > 0)
            {
                DrawHorzLine(PricePane, breakPrice, Color.DarkGoldenrod, LineStyle.Solid, 4);
            }

            //Pushed indicator PlotSeries statements
            PlotSeries(PricePane, KijunSen.Series(Bars), Color.FromArgb(255, 128, 0, 128), LineStyle.Solid, 3);
            PlotSeriesFillBand(PricePane, SenkouSpanA.Series(Bars), SenkouSpanB.Series(Bars), Color.FromArgb(255, 128, 0, 255), Color.FromArgb(63, 0, 0, 255), LineStyle.Solid, 3);
            PlotSeriesFillBand(PricePane, SenkouSpanB.Series(Bars), SenkouSpanA.Series(Bars), Color.FromArgb(255, 255, 0, 0), Color.FromArgb(63, 255, 0, 0), LineStyle.Solid, 3);
            PlotSeries(PricePane, TenkanSen.Series(Bars), Color.FromArgb(255, 0, 64, 128), LineStyle.Solid, 3);
        }
Пример #12
0
        protected override void Execute()
        {
            int level;

            signleToSell     = false;
            priceAtCross     = 0;
            firstUp          = false;
            firstDown        = false;
            priceAtCrossDown = 0;
            rocAtCrossDown   = 0;

            topPrice   = 0;
            lastTop    = 0;
            breakPrice = 0;
            rocPrice   = 0;

            //Create and plot  period RSI
            RSI       rsi20   = RSI.Series(Close, rsiPeriod.ValueInt);
            ChartPane rsiPane = CreatePane(50, true, true);

            PlotSeries(rsiPane, rsi20, Color.Navy, LineStyle.Solid, 3);
            DrawHorzLine(rsiPane, oversold.Value, Color.Red, LineStyle.Dotted, 2);
            DrawHorzLine(rsiPane, overbought.Value, Color.Green, LineStyle.Dotted, 2);


            ChartPane paneROC1 = CreatePane(40, true, true);

            PlotSeries(paneROC1, ROC.Series(Close, rocPeriod.ValueInt), Color.FromArgb(255, 112, 128, 144), LineStyle.Dotted, 2);
            DrawHorzLine(paneROC1, 0, Color.Red, LineStyle.Solid, 2);

            int period = Math.Max(rsiPeriod.ValueInt, rocPeriod.ValueInt);


            if (initPosition)
            {
                // init starting state to force buy into the market
                priceAtCrossDown = Close[period + 1];
                rocAtCrossDown   = ROC.Value(period + 1, Close, rocPeriod.ValueInt);
                firstDown        = true;
            }

            double High60           = 0;
            double Low60            = 0;
            int    n                = Bars.BarInterval;
            int    num              = (60 / n) - 1; // the first hour bar
            int    firstIntradayBar = -1;


            //Trading system main loop
            for (int bar = period + 1; bar < Bars.Count; bar++)
            {
                if (Bars.IntradayBarNumber(bar) == 0)
                {
                    firstIntradayBar = bar;
                }

                if (Bars.IntradayBarNumber(bar) <= num)                    // highlight the first hour
                {
                    SetBarColor(bar, Color.Silver);
                }

                if (Bars.IntradayBarNumber(bar) == num)                    // get the highest high and the lowest low after first hour
                {
                    High60 = Highest.Series(Bars.High, num + 1)[bar];
                    Low60  = Lowest.Series(Bars.Low, num + 1)[bar];

                    if (firstIntradayBar > -1)
                    {
                        DrawLine(PricePane, bar, High60, firstIntradayBar, High60, Color.Blue, LineStyle.Dashed, 1);
                        DrawLine(PricePane, bar, Low60, firstIntradayBar, Low60, Color.Red, LineStyle.Dashed, 1);
                    }
                }

                if (Close[bar] > topPrice)
                {
                    topPrice = Close[bar];
                }

                level = oversold.ValueInt;

                if (CrossUnder(bar, rsi20, level))
                {
                    if (!firstDown)
                    {
                        // first time to go below
                        // set cross happen and record the targit price
                        firstDown        = true;
                        priceAtCrossDown = Close[bar];
                        rocAtCrossDown   = ROC.Value(bar, Close, rocPeriod.ValueInt);
                    }
                }

                // play trayling
                int  addToPosition = 0;
                bool rsiOk         = false;
                bool priceOK       = false;
                if (firstDown)
                {
                    // ROC must improve by delta
                    double delta = Math.Abs(rocAtCrossDown * 0.2);

                    double newrocSMA = ROC.Value(bar, Close, rocPeriod.ValueInt);


                    if (bar == Bars.Count - 1)
                    {
                        rocPrice = rocAtCrossDown + delta;
                    }

                    if (newrocSMA <= (rocAtCrossDown + delta))
                    {
                        if (newrocSMA < rocAtCrossDown)
                        {
                            rocAtCrossDown = newrocSMA;
                        }
                    }
                    else
                    {
                        rsiOk = true;
                    }

                    double riseV = priceRise.ValueInt;
                    delta = priceAtCrossDown * (riseV / 1000.0 + 0.00017);

                    if (bar == Bars.Count - 1)
                    {
                        breakPrice = priceAtCrossDown + delta;
                    }

                    if (Close[bar] < (priceAtCrossDown + delta))
                    {
                        // DrawLabel(PricePane, "ready to buy, price is not rising: " + Close[bar].ToString() + " less than " + (priceAtCrossDown + delta).ToString());

                        if (Close[bar] < priceAtCrossDown)
                        {
                            priceAtCrossDown = Close[bar];
                        }
                    }
                    else
                    {
                        priceOK = true;
                    }

                    if (priceOK && rsiOk)
                    {
                        addToPosition++;
                        firstDown = false;
                    }
                }

                // you can  have only one active position
                foreach (Position pos in Positions)
                {
                    if (pos.Active && pos.PositionType == PositionType.Long)
                    {
                        addToPosition = 0;
                        break;
                    }
                }

                if (addToPosition > 0)
                {
                    // OverSold
                    // Close all shorts
                    foreach (Position pos in Positions)
                    {
                        if (pos.Active && pos.PositionType == PositionType.Short)
                        {
                            CoverAtMarket(bar + 1, pos);
                        }
                    }

                    //	    DrawLabel(PricePane, "buy at bar = " + bar.ToString());
                    Position p = BuyAtMarket(bar + 1);
                    firstUp = false;
                }


                level = overbought.ValueInt;
                int ClosedTrades = 0;
                signleToSell = false;
                if (CrossOver(bar, rsi20, overbought.ValueInt))
                {
                    if (!firstUp)
                    {
                        // first time to go above
                        // set cross happen and record the targit price
                        firstUp      = true;
                        priceAtCross = Close[bar];
                    }
                }

                if (firstUp)
                {
                    double riseV = priceRise.ValueInt;

                    double delta = priceAtCross * (riseV / 1000 + 0.00017);

                    priceOK = true;
                    if (Close[bar] >= (priceAtCross - delta))
                    {
                        if (Close[bar] > priceAtCross)
                        {
                            priceAtCross = Close[bar];
                        }
                    }
                    else
                    {
                        priceOK = false;
                    }

                    // keep as long ROC over zero
                    if (ROC.Value(bar, Close, rocPeriod.ValueInt) <= 0 && !priceOK)
                    {
                        signleToSell = true;
                        firstUp      = false;
                    }
                }

                // sync real account with strategy
                //			if (Bars.Date[bar] == syncDate)
                //			{
                //				signleToSell = true;  // close postions
                //			}

                // Over Bought
                // wait until price either move up or stopped out
                if (signleToSell)
                {
                    firstUp = false;
                    //DrawLabel(PricePane, ActivePositions.Count.ToString());
                    foreach (Position pos in Positions)
                    {
                        if (pos.Active && pos.PositionType == PositionType.Long)
                        {
                            SellAtMarket(bar + 1, pos);
                            ClosedTrades++;
                        }
                    }
                    signleToSell = false;

                    if (ClosedTrades > 0)
                    {
                        // Short only after sell long position
                        if (!trend)
                        {
                            ShortAtMarket(bar + 1);
                        }
                    }
                }
                // sell on % lose
                foreach (Position pos in Positions)
                {
                    if (pos.Active &&
                        pos.PositionType == PositionType.Long &&
                        pos.EntryPrice > (Close[bar] + pos.EntryPrice * (0.01 + stopLose.ValueInt * 0.001)) &&
                        bar >= pos.EntryBar
                        )
                    {
                        SellAtMarket(bar + 1, pos, "stop lose");
                        signleToSell = false;
                        firstUp      = false;
                        firstDown    = false;
                        continue;
                    }
                    if (pos.Active &&
                        pos.PositionType == PositionType.Short &&
                        Close[bar] > (pos.EntryPrice + pos.EntryPrice * (0.01 + stopLose.ValueInt * 0.001)) &&
                        bar >= pos.EntryBar
                        )
                    {
                        CoverAtMarket(bar + 1, pos, "stop lose Short");
                    }
                }
            }
            double currentPrice = Close[Bars.Count - 1];

            DrawLabel(paneROC1, "Top: " + topPrice.ToString(), Color.Red);
            DrawLabel(paneROC1, "Current Price: " + currentPrice.ToString());

            DrawLabel(paneROC1, "Goal : " + " At +5%  " + (currentPrice * 1.05).ToString(), Color.BlueViolet);
            DrawLabel(paneROC1, "Goal : " + " At +8%  " + (currentPrice * 1.08).ToString(), Color.MediumSpringGreen);
            DrawLabel(paneROC1, "Goal : " + " At +10% " + (currentPrice * 1.10).ToString(), Color.DarkOliveGreen);


            DrawLabel(PricePane, "Drop          : " + " At -5%  " + (topPrice * 0.95).ToString(), Color.DarkGreen);
            DrawLabel(PricePane, "Correction   : " + " At -8%  " + (topPrice * 0.92).ToString(), Color.DarkBlue);
            DrawLabel(PricePane, "Correction   : " + " At -10% " + (topPrice * 0.90).ToString(), Color.Red);
            DrawLabel(PricePane, "Bear market: " + " At -20% " + (topPrice * 0.80).ToString(), Color.DarkRed);

            if (breakPrice > 0)
            {
                DrawLabel(PricePane, "Break above Price: " + breakPrice.ToString(), Color.DarkGoldenrod);
            }
            if (rocPrice > 0)
            {
                DrawLabel(PricePane, "Break above Momuntem: " + rocPrice.ToString(), Color.DarkGoldenrod);
            }


            DrawHorzLine(PricePane, currentPrice * 1.05, Color.BlueViolet, LineStyle.Solid, 6);
            DrawHorzLine(PricePane, currentPrice * 1.08, Color.MediumSpringGreen, LineStyle.Solid, 3);
            DrawHorzLine(PricePane, currentPrice * 1.10, Color.DarkOliveGreen, LineStyle.Solid, 3);


            DrawHorzLine(PricePane, topPrice * 0.95, Color.DarkGreen, LineStyle.Solid, 3);
            DrawHorzLine(PricePane, topPrice * 0.92, Color.DarkBlue, LineStyle.Solid, 3);
            DrawHorzLine(PricePane, topPrice * 0.90, Color.Red, LineStyle.Solid, 3);
            DrawHorzLine(PricePane, topPrice * 0.80, Color.DarkRed, LineStyle.Solid, 3);


            if (breakPrice > 0)
            {
                DrawHorzLine(PricePane, breakPrice, Color.DarkGoldenrod, LineStyle.Solid, 4);
            }
        }
Пример #13
0
 public override void DrawInitialActualSpaceOverlays(ChartPane managingPane, GraphicsWrapper g)
 {
     base.DrawInitialActualSpaceOverlays(managingPane, g);
 }
Пример #14
0
        public override PointF DrawCustomMessages(ChartPane managingPane, GraphicsWrapper g, PointF drawingLocation)
        {
            if (Visible == false)
            {
                return(drawingLocation);
            }

            // Draw any standard messages first (if any).
            drawingLocation = base.DrawCustomMessages(managingPane, g, drawingLocation);

            Font font = managingPane.TitleFont;

            if (CustomMessagesFont != null)
            {
                font = CustomMessagesFont;
            }

            foreach (FFNewsCustom.NewsEvent eventItem in Indicator.VisibleNewsEvents)
            {
                TimeSpan span  = (eventItem.DateTime - DateTime.UtcNow);
                int      hours = (int)Math.Abs(Math.Floor(span.TotalHours));

                string message;
                if (span.TotalSeconds < 0)
                {
                    message = hours.ToString() + " hrs " + Math.Abs(span.Minutes).ToString() + " mins since " + eventItem.Country + ": " + eventItem.Title;
                }
                else
                {
                    message = hours.ToString() + " hrs " + span.Minutes.ToString() + " mins until " + eventItem.Country + ": " + eventItem.Title;
                }
                drawingLocation = DrawCustomMessage(g, font, Indicator.TitleBrush, message, drawingLocation);

                float drawingLocationOriginalX = drawingLocation.X;
                SizeF size = new SizeF();
                if (font != null && Indicator.ImpactBrush != null)
                {
                    // Draw impact part.
                    string impactString = "Impact: " + eventItem.Impact.ToString();
                    size = g.MeasureString(impactString, font);
                    g.DrawString(impactString, font, Indicator.ImpactBrush, drawingLocation);
                    drawingLocation.X += size.Width;
                }

                // Draw previous part.
                if (string.IsNullOrEmpty(eventItem.Previous) == false)
                {
                    if (font != null && Indicator.PreviousBrush != null)
                    {
                        string previousString = "Previous: " + eventItem.Previous;
                        size = g.MeasureString(previousString, font);
                        g.DrawString(previousString, font, Indicator.PreviousBrush, drawingLocation);
                        drawingLocation.X += size.Width;
                    }
                }

                if (string.IsNullOrEmpty(eventItem.Forecast) == false)
                {
                    if (font != null && Indicator.ForecastBrush != null)
                    {
                        string forecastString = "Forecast: " + eventItem.Forecast;
                        size = g.MeasureString(forecastString, font);
                        g.DrawString(forecastString, font, Indicator.ForecastBrush, drawingLocation);
                        drawingLocation.X += size.Width;
                    }
                }

                drawingLocation.X  = drawingLocationOriginalX;
                drawingLocation.Y += size.Height;
            }

            return(drawingLocation);
        }