Ejemplo n.º 1
0
 protected override void OnStateChange()
 {
     if (State == State.SetDefaults)
     {
         Name      = Custom.Resource.NinjaScriptDrawingToolText;
         Alignment = TextAlignment.Left;
         Anchor    = new ChartAnchor {
             IsEditing = true, DrawingTool = this, DisplayName = Custom.Resource.NinjaScriptDrawingToolAnchor
         };
         Font = new Gui.Tools.SimpleFont()
         {
             Size = 14
         };
         OutlineStroke = new Stroke(Brushes.Transparent, 2f);
         TextBrush     = textBrush;
         AreaBrush     = Brushes.Transparent;
         AreaOpacity   = 100;
         YPixelOffset  = 0;
     }
     else if (State == State.Terminated)
     {
         TextBrush = null;
         textBrush = null;
         Dispose();
     }
 }
Ejemplo n.º 2
0
        protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
        {
            // Create a Font, Brush and TextFormat to draw our text.
            // For more information on drawing Text, please see the source code for the Text DrawingTool
            var font = new Gui.Tools.SimpleFont("Arial", 20);

            SharpDX.Direct2D1.Brush        tmpBrush   = Brushes.Red.ToDxBrush(RenderTarget);
            SharpDX.DirectWrite.TextFormat textFormat = font.ToDirectWriteTextFormat();

            // Create a TextLayout for our text to draw.
            var cachedTextLayout = new SharpDX.DirectWrite.TextLayout(Core.Globals.DirectWriteFactory, "Hello, I am sideways text.", textFormat, 600, textFormat.FontSize);

            // Rotate the RenderTarget by setting the Matrix3x2 Transform property
            // Matrix3x2.Rotation() will return a rotated Matrix3x2 based off of the angle specified, and the center point where you draw the object
            RenderTarget.Transform = Matrix3x2.Rotation(1.5708f, new Vector2(100, 100));

            // Draw the text on the rotated RenderTarget
            RenderTarget.DrawTextLayout(new SharpDX.Vector2(100, 100), cachedTextLayout, tmpBrush, SharpDX.Direct2D1.DrawTextOptions.NoSnap);

            // Dispose of resources
            textFormat.Dispose();
            cachedTextLayout.Dispose();
            tmpBrush.Dispose();

            // Rotate the RenderTarget back
            RenderTarget.Transform = Matrix3x2.Identity;

            // Return rendering to base class
            base.OnRender(chartControl, chartScale);
        }
Ejemplo n.º 3
0
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                Description       = Custom.Resource.NinjaScriptIndicatorDescriptionCandlestickPattern;
                Name              = Custom.Resource.NinjaScriptIndicatorNameCandlestickPattern;
                Calculate         = Calculate.OnBarClose;
                IsOverlay         = true;
                DrawOnPricePanel  = true;
                DisplayInDataBox  = false;
                IsAutoScale       = false;
                PaintPriceMarkers = false;
                Pattern           = ChartPattern.MorningStar;
                ShowAlerts        = true;
                ShowPatternCount  = true;
                TrendStrength     = 4;
                TextFont          = new Gui.Tools.SimpleFont()
                {
                    Size = 14
                };

                downColor = Brushes.DimGray;
                upColor   = Brushes.DimGray;
                textColor = Brushes.DimGray;

                AddPlot(Brushes.Transparent, Custom.Resource.CandlestickPatternFound);
            }
            else if (State == State.Configure)
            {
                if (Calculate == Calculate.OnEachTick || Calculate == Calculate.OnPriceChange)
                {
                    Calculate = Calculate.OnBarClose;
                }
            }
            else if (State == State.DataLoaded)
            {
                logic = new CandleStickPatternLogic(this, TrendStrength);
            }
            else if (State == State.Historical)
            {
                if (ChartControl != null)
                {
                    downColor = ChartControl.Properties.AxisPen.Brush;                           // Get the color of the chart axis brush
                    textColor = ChartControl.Properties.ChartText;
                }

                if (((SolidColorBrush)downColor).Color == ((SolidColorBrush)upColor).Color)
                {
                    upColor = Brushes.Transparent;
                }
                else
                {
                    upColor = Brushes.DimGray;
                }
            }
        }
Ejemplo n.º 4
0
        protected override void OnStateChange()
        {
            base.OnStateChange();

            if (State == State.SetDefaults)
            {
                Description = @"An arrow line with a price marker attached.";
                Name        = "irArrowLine";

                Font = new Gui.Tools.SimpleFont()
                {
                    Size = 14
                };
                TextColor = Stroke.Brush;
                Text      = "";
            }
            else if (State == State.Configure)
            {
            }
        }
Ejemplo n.º 5
0
        protected void DrawPriceLevelText(double minX, double maxX, Point endPoint, PriceLevel priceLevel, ChartPanel panel)
        {
            Gui.Tools.SimpleFont           wpfFont      = panel.ChartControl.Properties.LabelFont ?? new Gui.Tools.SimpleFont();
            SharpDX.DirectWrite.TextFormat dxTextFormat = wpfFont.ToDirectWriteTextFormat();
            string str = string.Format("{0}", (priceLevel.Value / 100).ToString("P"));

            SharpDX.DirectWrite.TextLayout textLayout = new SharpDX.DirectWrite.TextLayout(Core.Globals.DirectWriteFactory, str, dxTextFormat, panel.H, dxTextFormat.FontSize);

            float  usedFontHeight = textLayout.Metrics.Height;
            float  usedFontWidth  = textLayout.Metrics.Width;
            Point  textEndPoint   = endPoint;
            double maxWidth       = panel.X + panel.W;
            double maxHeight      = panel.Y + panel.H;
            double minWidth       = panel.X;
            double minHeight      = panel.Y;

            if (textEndPoint.Y + usedFontHeight >= maxHeight)
            {
                textEndPoint.Y = maxHeight - usedFontHeight; // Set to bottom
            }
            if (textEndPoint.Y < minHeight)                  // Set to top
            {
                textEndPoint.Y = minHeight;
            }

            if (textEndPoint.X + usedFontWidth >= maxWidth)
            {
                textEndPoint.X = maxWidth - usedFontWidth;                 //Set to right side;
            }
            if (textEndPoint.X < minWidth)
            {
                textEndPoint.X = minWidth;                 // Set to left side;
            }
            RenderTarget.DrawTextLayout(new SharpDX.Vector2((float)(textEndPoint.X), (float)(textEndPoint.Y)), textLayout,
                                        priceLevel.Stroke.BrushDX, SharpDX.Direct2D1.DrawTextOptions.NoSnap);

            dxTextFormat.Dispose();
            textLayout.Dispose();
        }
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                Description             = @"Enter the description for your new custom Indicator here.";
                Name                    = "GuerillaAcdMasterIndicator";
                Calculate               = Calculate.OnBarClose;
                IsOverlay               = true;
                IsAutoScale             = false;
                DisplayInDataBox        = true;
                DrawOnPricePanel        = true;
                DrawHorizontalGridLines = true;
                DrawVerticalGridLines   = true;
                PaintPriceMarkers       = true;
                ScaleJustification      = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                //See Help Guide for additional information.
                IsSuspendedWhileInactive = true;

                textFont = new Gui.Tools.SimpleFont()
                {
                    Size = 14
                };
                textColor = Brushes.WhiteSmoke;

                ATicks        = 28;
                CTicks        = 16;
                ProjectHour   = 13;
                ProjectMinute = 0;
                AddPlot(new Stroke(openingRangeBrush, DashStyleHelper.Dash, 2), PlotStyle.Square, "OpenHigh");
                AddPlot(new Stroke(openingRangeBrush, DashStyleHelper.Dash, 2), PlotStyle.Square, "OpenLow");
                AddPlot(new Stroke(aBrush, DashStyleHelper.Dash, 2), PlotStyle.Square, "AUp");
                AddPlot(new Stroke(aBrush, DashStyleHelper.Dash, 2), PlotStyle.Square, "ADown");
                AddPlot(new Stroke(cBrush, DashStyleHelper.Dash, 2), PlotStyle.Square, "CUp");
                AddPlot(new Stroke(cBrush, DashStyleHelper.Dash, 2), PlotStyle.Square, "CDown");
                AddPlot(new Stroke(pivotBrush, DashStyleHelper.Dash, 2), PlotStyle.Square, "PivotHigh");
                AddPlot(new Stroke(pivotBrush, DashStyleHelper.Dash, 2), PlotStyle.Square, "PivotLow");
                AddPlot(new Stroke(rollingPivotBrush, DashStyleHelper.Dash, 2), PlotStyle.Square, "RollingPivotHigh");
                AddPlot(new Stroke(rollingPivotBrush, DashStyleHelper.Dash, 2), PlotStyle.Square, "RollingPivotLow");
                AddPlot(new Stroke(transparentBrush, DashStyleHelper.Dash, 2), PlotStyle.Square, "MyOpen");
            }
            else if (State == State.Configure)
            {
                AddDataSeries(BarsPeriodType.Second, 30);
                AddDataSeries(BarsPeriodType.Day, 1);

                currentDate         = Core.Globals.MinDate;
                sessionIterator     = null;
                fastSessionIterator = null;

                opening      = 0;
                openingHigh  = 0;
                openingLow   = 0;
                currentAUp   = 0;
                currentADown = 0;
                currentCUp   = 0;
                currentCDown = 0;

                currentClose  = 0;
                currentHigh   = 0;
                currentLow    = 0;
                priorDayClose = 0;
                priorDayHigh  = 0;
                priorDayLow   = 0;
                priorDayLow   = 0;
                priorDayLow   = 0;

                aUpBreachedBar   = 0;
                aUpSuccessBar    = 0;
                aDownBreachedBar = 0;
                aDownSuccessBar  = 0;
                cUpBreachedBar   = 0;
                cUpSuccessBar    = 0;
                pivotUpperBound  = 0;
                pivotLowerBound  = 0;
            }
            else if (State == State.DataLoaded)
            {
                sessionIterator      = new Data.SessionIterator(BarsArray[0]);
                fastPivotPriceSeries = new Series <double>(BarsArray[1]);
                fastSessionIterator  = new Data.SessionIterator(BarsArray[1]);
                halfTimeFrame        = BarsArray[0].BarsPeriod.Value / 2;
                halfTimeFrameBars    = halfTimeFrame * 2;
                openingBars          = BarsArray[0].BarsPeriod.Value * 2;

                trueRangeSeries = new Series <double>(BarsArray[2]);
                aSeries         = new Series <double>(BarsArray[2]);
                cSeries         = new Series <double>(BarsArray[2]);

                dayNumberLineSeries = new Series <double>(BarsArray[2]);
                numberLineSeries    = new Series <double>(BarsArray[2]);
            }
        }
Ejemplo n.º 7
0
        // draw text fixed  //get rid of isOutlineVisible
        /// <summary>
        /// Texts the fixed core.
        /// </summary>
        /// <param name="owner">The hosting NinjaScript object which is calling the draw method</param>
        /// <param name="tag">A user defined unique id used to reference the draw object</param>
        /// <param name="text">The text you wish to draw</param>
        /// <param name="textPosition">The TextPosition of the text</param>
        /// <param name="textBrush">The brush used to color the text of the draw object</param>
        /// <param name="font">A SimpleFont object</param>
        /// <param name="outlineBrush">The brush used to color the region outline of draw object</param>
        /// <param name="areaBrush">The brush used to color the fill region area of the draw object</param>
        /// <param name="areaOpacity"> Sets the level of transparency for the fill color. Valid values between 0 - 100. (0 = completely transparent, 100 = no opacity)</param>
        /// <param name="isGlobal">Determines if the draw object will be global across all charts which match the instrument</param>
        /// <param name="templateName">The name of the drawing tool template the object will use to determine various visual properties</param>
        /// <param name="outlineDashStyle">The outline dash style.</param>
        /// <param name="outlineWidth">Width of the outline.</param>
        /// <returns></returns>
        private static TextFixed TextFixedCore(NinjaScriptBase owner, string tag, string text,
                                               TextPosition textPosition, Brush textBrush, Gui.Tools.SimpleFont font, Brush outlineBrush,
                                               Brush areaBrush, int?areaOpacity, bool isGlobal, string templateName, DashStyleHelper outlineDashStyle, int outlineWidth)
        {
            TextFixed txtFixed = DrawingTool.GetByTagOrNew(owner, typeof(TextFixed), tag, templateName) as TextFixed;

            if (txtFixed == null)
            {
                return(null);
            }

            DrawingTool.SetDrawingToolCommonValues(txtFixed, tag, false, owner, isGlobal);

            // set defaults, then apply ns properties so they dont get trampled
            txtFixed.SetState(State.Active);

            txtFixed.DisplayText  = text;
            txtFixed.TextPosition = textPosition;
            if (textBrush != null)
            {
                txtFixed.TextBrush = textBrush;
            }

            if (txtFixed.TextBrush == null)
            {
                txtFixed.UseChartTextBrush = true;
            }

            if (outlineBrush != null)
            {
                txtFixed.OutlineStroke = new Stroke(outlineBrush, outlineDashStyle, outlineWidth)
                {
                    RenderTarget = txtFixed.OutlineStroke.RenderTarget
                }
            }
            ;

            if (areaBrush != null)
            {
                txtFixed.AreaBrush = areaBrush;
            }

            if (areaOpacity != null)
            {
                txtFixed.AreaOpacity = areaOpacity.Value;
            }

            if (font != null)
            {
                txtFixed.Font = font;
            }

            return(txtFixed);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Draws text.
 /// </summary>
 /// <param name="owner">The hosting NinjaScript object which is calling the draw method</param>
 /// <param name="tag">A user defined unique id used to reference the draw object</param>
 /// <param name="isAutoScale">Determines if the draw object will be included in the y-axis scale</param>
 /// <param name="text">The text you wish to draw</param>
 /// <param name="time"> The time the object will be drawn at.</param>
 /// <param name="y">The y value or Price for the object</param>
 /// <param name="yPixelOffset">The offset value in pixels from within the text box area</param>
 /// <param name="textBrush">The brush used to color the text of the draw object</param>
 /// <param name="font">A SimpleFont object</param>
 /// <param name="alignment">The TextAlignment for the textbox</param>
 /// <param name="outlineBrush">The brush used to color the region outline of draw object</param>
 /// <param name="areaBrush">The brush used to color the fill region area of the draw object</param>
 /// <param name="areaOpacity"> Sets the level of transparency for the fill color. Valid values between 0 - 100. (0 = completely transparent, 100 = no opacity)</param>
 /// <param name="outlineDashStyle">The outline dash style.</param>
 /// <param name="outlineWidth">Width of the outline.</param>
 /// <param name="isGlobal">Determines if the draw object will be global across all charts which match the instrument</param>
 /// <param name="templateName">The name of the drawing tool template the object will use to determine various visual properties</param>
 /// <returns></returns>
 public static Text Text(NinjaScriptBase owner, string tag, bool isAutoScale, string text, DateTime time, double y, int yPixelOffset, Brush textBrush, Gui.Tools.SimpleFont font,
                         TextAlignment alignment, Brush outlineBrush, Brush areaBrush, int areaOpacity, DashStyleHelper outlineDashStyle, int outlineWidth, bool isGlobal, string templateName)
 {
     return(TextCore(owner, tag, isAutoScale, text, int.MinValue, time, y, yPixelOffset, textBrush, alignment, font, outlineBrush, areaBrush, areaOpacity, isGlobal,
                     templateName, outlineDashStyle, outlineWidth));
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Draws text.
 /// </summary>
 /// <param name="owner">The hosting NinjaScript object which is calling the draw method</param>
 /// <param name="tag">A user defined unique id used to reference the draw object</param>
 /// <param name="isAutoScale">Determines if the draw object will be included in the y-axis scale</param>
 /// <param name="text">The text you wish to draw</param>
 /// <param name="time"> The time the object will be drawn at.</param>
 /// <param name="y">The y value or Price for the object</param>
 /// <param name="yPixelOffset">The offset value in pixels from within the text box area</param>
 /// <param name="textBrush">The brush used to color the text of the draw object</param>
 /// <param name="font">A SimpleFont object</param>
 /// <param name="alignment">The TextAlignment for the textbox</param>
 /// <param name="outlineBrush">The brush used to color the region outline of draw object</param>
 /// <param name="areaBrush">The brush used to color the fill region area of the draw object</param>
 /// <param name="areaOpacity"> Sets the level of transparency for the fill color. Valid values between 0 - 100. (0 = completely transparent, 100 = no opacity)</param>
 /// <returns></returns>
 public static Text Text(NinjaScriptBase owner, string tag, bool isAutoScale, string text, DateTime time, double y, int yPixelOffset,
                         Brush textBrush, Gui.Tools.SimpleFont font, TextAlignment alignment, Brush outlineBrush, Brush areaBrush, int areaOpacity)
 {
     return(TextCore(owner, tag, isAutoScale, text, int.MinValue, time, y, yPixelOffset, textBrush, alignment, font, outlineBrush, areaBrush, areaOpacity, false,
                     null, DashStyleHelper.Solid, 2));
 }
Ejemplo n.º 10
0
        private static Text TextCore(NinjaScriptBase owner, string tag, bool autoScale, string text,
                                     int barsAgo, DateTime time, double y, int?yPixelOffset, Brush textBrush, TextAlignment?textAlignment,
                                     Gui.Tools.SimpleFont font, Brush outlineBrush, Brush areaBrush, int?areaOpacity, bool isGlobal, string templateName,
                                     DashStyleHelper outlineDashStyle, int outlineWidth)
        {
            if (barsAgo == int.MinValue && time == Core.Globals.MinDate)
            {
                throw new ArgumentException("Text: Bad barsAgo/time parameters");
            }

            if (string.IsNullOrWhiteSpace(tag))
            {
                throw new ArgumentException(@"tag cant be null or empty", "tag");
            }

            if (isGlobal && tag[0] != GlobalDrawingToolManager.GlobalDrawingToolTagPrefix)
            {
                tag = GlobalDrawingToolManager.GlobalDrawingToolTagPrefix + tag;
            }

            Text txt = DrawingTool.GetByTagOrNew(owner, typeof(Text), tag, templateName) as Text;

            if (txt == null)
            {
                return(null);
            }

            DrawingTool.SetDrawingToolCommonValues(txt, tag, autoScale, owner, isGlobal);

            ChartAnchor anchor = DrawingTool.CreateChartAnchor(owner, barsAgo, time, y);

            anchor.CopyDataValues(txt.Anchor);

            // set defaults, then apply ns properties so they dont get trampled
            txt.SetState(State.Active);

            txt.DisplayText = text;
            if (textBrush != null)
            {
                txt.TextBrush = textBrush;
            }

            if (txt.TextBrush == null)
            {
                txt.UseChartTextBrush = true;
            }

            if (textAlignment != null)
            {
                txt.Alignment = textAlignment.Value;
            }
            else if (string.IsNullOrEmpty(templateName))
            {
                txt.Alignment = TextAlignment.Center;
            }

            if (outlineBrush != null)
            {
                txt.OutlineStroke = new Stroke(outlineBrush, outlineDashStyle, outlineWidth)
                {
                    RenderTarget = txt.OutlineStroke.RenderTarget
                }
            }
            ;

            if (areaBrush != null)
            {
                txt.AreaBrush = areaBrush;
            }

            if (areaOpacity != null)
            {
                txt.AreaOpacity = areaOpacity.Value;
            }

            if (font != null)
            {
                txt.Font = font.Clone() as Gui.Tools.SimpleFont;
            }

            if (yPixelOffset != null)
            {
                txt.YPixelOffset = yPixelOffset.Value;
            }

            return(txt);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Draws text in one of 5 available pre-defined fixed locations on panel 1 (price panel) of a chart.
 /// </summary>
 /// <param name="owner">The hosting NinjaScript object which is calling the draw method</param>
 /// <param name="tag">A user defined unique id used to reference the draw object</param>
 /// <param name="text">The text you wish to draw</param>
 /// <param name="textPosition">The TextPosition of the text</param>
 /// <param name="textBrush">The brush used to color the text of the draw object</param>
 /// <param name="font">A SimpleFont object</param>
 /// <param name="outlineBrush">The brush used to color the region outline of draw object</param>
 /// <param name="areaBrush">The brush used to color the fill region area of the draw object</param>
 /// <param name="areaOpacity"> Sets the level of transparency for the fill color. Valid values between 0 - 100. (0 = completely transparent, 100 = no opacity)</param>
 /// <param name="outlineDashStyle">The outline dash style.</param>
 /// <param name="outlineWidth">Width of the outline.</param>
 /// <param name="isGlobal">Determines if the draw object will be global across all charts which match the instrument</param>
 /// <param name="templateName">The name of the drawing tool template the object will use to determine various visual properties</param>
 /// <returns></returns>
 public static TextFixed TextFixed(NinjaScriptBase owner, string tag, string text, TextPosition textPosition, Brush textBrush,
                                   Gui.Tools.SimpleFont font, Brush outlineBrush, Brush areaBrush, int areaOpacity, DashStyleHelper outlineDashStyle, int outlineWidth, bool isGlobal, string templateName)
 {
     return(TextFixedCore(owner, tag, text, textPosition, textBrush, font, outlineBrush, areaBrush, areaOpacity, isGlobal, templateName, outlineDashStyle, outlineWidth));
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Draws text in one of 5 available pre-defined fixed locations on panel 1 (price panel) of a chart.
 /// </summary>
 /// <param name="owner">The hosting NinjaScript object which is calling the draw method</param>
 /// <param name="tag">A user defined unique id used to reference the draw object</param>
 /// <param name="text">The text you wish to draw</param>
 /// <param name="textPosition">The TextPosition of the text</param>
 /// <param name="textBrush">The brush used to color the text of the draw object</param>
 /// <param name="font">A SimpleFont object</param>
 /// <param name="outlineBrush">The brush used to color the region outline of draw object</param>
 /// <param name="areaBrush">The brush used to color the fill region area of the draw object</param>
 /// <param name="areaOpacity"> Sets the level of transparency for the fill color. Valid values between 0 - 100. (0 = completely transparent, 100 = no opacity)</param>
 /// <returns></returns>
 public static TextFixed TextFixed(NinjaScriptBase owner, string tag, string text, TextPosition textPosition, Brush textBrush,
                                   Gui.Tools.SimpleFont font, Brush outlineBrush, Brush areaBrush, int areaOpacity)
 {
     return(TextFixedCore(owner, tag, text, textPosition, textBrush, font, outlineBrush, areaBrush, areaOpacity, false, null, DashStyleHelper.Solid, 2));
 }
Ejemplo n.º 13
0
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                Description             = @"Enter the description for your new custom Indicator here.";
                Name                    = "JBMarketProfileLevels";
                Calculate               = Calculate.OnEachTick;
                IsOverlay               = true;
                DisplayInDataBox        = true;
                DrawOnPricePanel        = true;
                DrawHorizontalGridLines = true;
                DrawVerticalGridLines   = true;
                PaintPriceMarkers       = true;
                ScaleJustification      = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                //See Help Guide for additional information.
                IsSuspendedWhileInactive = true;

                LineWidth = 2;
                LineStyle = DashStyleHelper.Dot;

                ShowPOC        = true;
                ShowONPOC      = true;
                ShowVA         = false;
                ShowONVA       = false;
                ShowHILO       = true;
                ShowONHILO     = true;
                ShowSettlement = true;

                HILOColor = Brushes.Red;
                VAColor   = Brushes.White;
                POCColor  = Brushes.Magenta;

                ONHILOColor = Brushes.Red;
                ONVAColor   = Brushes.White;
                ONPOCColor  = Brushes.Magenta;

                SettlementColor = Brushes.DarkOrange;

                Opacity       = 100;
                BrokenOpacity = 45;

                LabelFont = new Gui.Tools.SimpleFont("Arial", 8);

                RTHTemplate = "CME US Index Futures RTH";
                ONTemplate  = "Overnight Template";

                tpoProfiles = new List <JBTPOProfile>();

                initDone = false;
            }
            else if (State == State.Configure)
            {
                try {
                    TradingHours.String2TradingHours(RTHTemplate).GetPreviousTradingDayEnd(DateTime.Now);                     // Test if template exists
                    AddDataSeries(BarsArray[0].Instrument.FullName, new BarsPeriod {
                        BarsPeriodType = BarsPeriodType.Minute, Value = 30
                    }, RTHTemplate);
                    try {
                        TradingHours.String2TradingHours(ONTemplate).GetPreviousTradingDayEnd(DateTime.Now);                          // Test if template exists
                        AddDataSeries(BarsArray[0].Instrument.FullName, new BarsPeriod {
                            BarsPeriodType = BarsPeriodType.Minute, Value = 30
                        }, ONTemplate);
                        initDone = true;
                    } catch (Exception e) {
                        Draw.TextFixed(this, "NinjaScriptInfo", "JBMarketProfileLevels error loading trading hours with template name '" + ONTemplate + "', check properties", TextPosition.Center);
                        Log("JBMarketProfileLevels could not load specified trading hours templates", LogLevel.Error);
                    }
                } catch (Exception e) {
                    Draw.TextFixed(this, "NinjaScriptInfo", "JBMarketProfileLevels error loading trading hours with template name '" + RTHTemplate + "', check properties", TextPosition.Center);
                    Log("JBMarketProfileLevels could not load specified trading hours templates", LogLevel.Error);
                }
                AllowRemovalOfDrawObjects = true;

                //test();
            }
            else if (State == State.Historical)
            {
                if (!initDone)
                {
                    return;
                }
                if (!Bars.IsTickReplay)
                {
                    Draw.TextFixed(this, "NinjaScriptInfo", "JBMarketProfileLevels needs tick replay enabled on the data series", TextPosition.Center);
                    Log("JBMarketProfileLevels needs tick replay enabled on the data series", LogLevel.Error);
                    initDone = false;
                }
                else
                {
                    rthSessionIterator = new SessionIterator(BarsArray[RTH]);
                    ethSessionIterator = new SessionIterator(BarsArray[ETH]);

                    SetZOrder(-1);
                }
            }
            else if (State == State.Transition)
            {
                if (!initDone)
                {
                    return;
                }
                if (tpoProfile != null)
                {
                    update(tpoProfile);
                }
                requestAndDrawSettlement(DateTime.Now);
            }
            else if (State == State.Realtime)
            {
                if (Instrument != null && Instrument.MarketData != null && Instrument.MarketData.Settlement != null)
                {
                    settlement = Instrument.MarketData.Settlement.Price;
                    requestAndDrawSettlement(DateTime.Now);
                }
            }
        }
Ejemplo n.º 14
0
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                Description             = @"JBWeisWave";
                Name                    = "JBWeisWave";
                Calculate               = Calculate.OnBarClose;
                IsOverlay               = true;
                DisplayInDataBox        = true;
                DrawOnPricePanel        = true;
                DrawHorizontalGridLines = true;
                DrawVerticalGridLines   = true;
                PaintPriceMarkers       = true;
                ScaleJustification      = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                //See Help Guide for additional information.
                IsSuspendedWhileInactive = true;
                Length                = 9;
                Style                 = SwingStyle.Close;
                WaveLineWidth         = 2;
                WaveColor             = Brushes.DeepSkyBlue;
                DownVolColor          = Brushes.White;
                UpVolColor            = Brushes.White;
                DownDeltaColor        = Brushes.Magenta;
                UpDeltaColor          = Brushes.Cyan;
                VolumeLabelBarSpacing = 30;
                DeltaLabelBarSpacing  = 50;
                WaveLineStyle         = DashStyleHelper.Solid;
                ShowVolumes           = true;
                ShowLines             = true;
                ShowDeltas            = true;
                ShowTail              = false;

                VolumeTextFont = new Gui.Tools.SimpleFont("Arial", 11);
                DeltaTextFont  = new Gui.Tools.SimpleFont("Arial", 11);
            }
            else if (State == State.Configure)
            {
                if (Calculate != Calculate.OnBarClose)
                {
                    Draw.TextFixed(this, "NinjaScriptInfo", "JBWeisWave only works with calculation set to 'on bar close'", TextPosition.BottomRight);
                    Log("JBWeisWave only works with calculation set to 'on bar close'", LogLevel.Error);
                    validConfig = false;
                }
            }
            else if (State == State.Historical)
            {
                if (ShowDeltas && !Bars.IsTickReplay)
                {
                    Draw.TextFixed(this, "NinjaScriptInfo", "JBWeisWave needs tick replay enabled on the data series when using delta", TextPosition.BottomRight);
                    Log("JBWeisWave needs tick replay enabled on the data series when using delta", LogLevel.Error);
                }
            }
            else if (State == State.DataLoaded)
            {
                this.atr             = ATR(Length);
                this.close           = new Series <double>(this, MaximumBarsLookBack.TwoHundredFiftySix);
                this.extreme         = new Series <double>(this, MaximumBarsLookBack.TwoHundredFiftySix);
                this.direction       = new Series <int>(this, MaximumBarsLookBack.TwoHundredFiftySix);
                this.extremeBar      = new Series <int>(this, MaximumBarsLookBack.TwoHundredFiftySix);
                this.waveVolume      = new Series <double>(this, MaximumBarsLookBack.TwoHundredFiftySix);
                this.waveVolumeDelta = new Series <double>(this, MaximumBarsLookBack.TwoHundredFiftySix);
                this.barVolumeDelta  = new Series <double>(this, MaximumBarsLookBack.TwoHundredFiftySix);
            }
        }