示例#1
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);
        }
示例#2
0
        private static Arc ArcCore(NinjaScriptBase owner, bool isAutoScale, string tag,
                                   int startBarsAgo, DateTime startTime, double startY, int endBarsAgo, DateTime endTime, double endY,
                                   Brush brush, DashStyleHelper dashStyle, int width, bool isGlobal, string templateName)
        {
            if (owner == null)
            {
                throw new ArgumentException("owner");
            }

            if (startTime == Core.Globals.MinDate && endTime == Core.Globals.MinDate && startBarsAgo == int.MinValue && endBarsAgo == int.MinValue)
            {
                throw new ArgumentException("bad start/end date/time");
            }

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

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

            Arc newArc = DrawingTool.GetByTagOrNew(owner, typeof(Arc), tag, templateName) as Arc;

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

            DrawingTool.SetDrawingToolCommonValues(newArc, tag, isAutoScale, owner, isGlobal);

            // dont nuke existing anchor refs on the instance
            ChartAnchor startAnchor = DrawingTool.CreateChartAnchor(owner, startBarsAgo, startTime, startY);
            ChartAnchor endAnchor   = DrawingTool.CreateChartAnchor(owner, endBarsAgo, endTime, endY);

            startAnchor.CopyDataValues(newArc.StartAnchor);
            endAnchor.CopyDataValues(newArc.EndAnchor);

            if (brush != null)
            {
                newArc.Stroke = new Stroke(brush, dashStyle, width, 50)
                {
                    RenderTarget = newArc.Stroke.RenderTarget
                };
                newArc.ArcStroke = new Stroke(brush, dashStyle, width)
                {
                    RenderTarget = newArc.ArcStroke.RenderTarget
                };
            }
            newArc.SetState(State.Active);
            return(newArc);
        }
示例#3
0
        private static AndrewsPitchfork AndrewsPitchforkCore(NinjaScriptBase owner,
                                                             string tag, bool isAutoScale,
                                                             int anchor1BarsAgo, DateTime anchor1Time, double anchor1Y,
                                                             int anchor2BarsAgo, DateTime anchor2Time, double anchor2Y,
                                                             int anchor3BarsAgo, DateTime anchor3Time, double anchor3Y,
                                                             Brush brush, DashStyleHelper dashStyle, int width,
                                                             bool isGlobal, string templateName)
        {
            if (owner == null)
            {
                throw new ArgumentException("owner");
            }

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

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

            AndrewsPitchfork pitchfork = DrawingTool.GetByTagOrNew(owner, typeof(AndrewsPitchfork), tag, templateName) as AndrewsPitchfork;

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

            DrawingTool.SetDrawingToolCommonValues(pitchfork, tag, isAutoScale, owner, isGlobal);

            ChartAnchor startAnchor = DrawingTool.CreateChartAnchor(owner, anchor1BarsAgo, anchor1Time, anchor1Y);
            ChartAnchor endAnchor   = DrawingTool.CreateChartAnchor(owner, anchor2BarsAgo, anchor2Time, anchor2Y);
            ChartAnchor extAnchor   = DrawingTool.CreateChartAnchor(owner, anchor3BarsAgo, anchor3Time, anchor3Y);

            startAnchor.CopyDataValues(pitchfork.StartAnchor);
            endAnchor.CopyDataValues(pitchfork.EndAnchor);
            extAnchor.CopyDataValues(pitchfork.ExtensionAnchor);

            if (string.IsNullOrEmpty(templateName) || brush != null)
            {
                pitchfork.AnchorLineStroke.Width = width;
                pitchfork.RetracementLineStroke  = new Stroke(brush, dashStyle, width)
                {
                    RenderTarget = pitchfork.RetracementLineStroke.RenderTarget
                };
            }

            pitchfork.SetState(State.Active);
            return(pitchfork);
        }
示例#4
0
        private static T DrawRangeProfileTypeCore <T>(NinjaScriptBase owner, bool isAutoScale, string tag,
                                                      int startBarsAgo, DateTime startTime, double startY, int endBarsAgo, DateTime endTime, double endY,
                                                      Brush brush, DashStyleHelper dashStyle, int width, bool isGlobal, string templateName, Model model) where T : RangeProfile
        {
            if (owner == null)
            {
                throw new ArgumentException("owner");
            }

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

            if (isGlobal && tag[0] != GlobalDrawingToolManager.GlobalDrawingToolTagPrefix)
            {
                tag = string.Format("{0}{1}", GlobalDrawingToolManager.GlobalDrawingToolTagPrefix, tag);
            }

            T lineT = DrawingTool.GetByTagOrNew(owner, typeof(T), tag, templateName) as T;

            lineT.model = model;


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

            if (startTime == Core.Globals.MinDate && endTime == Core.Globals.MinDate && startBarsAgo == int.MinValue && endBarsAgo == int.MinValue)
            {
                throw new ArgumentException("bad start/end date/time");
            }

            DrawingTool.SetDrawingToolCommonValues(lineT, tag, isAutoScale, owner, isGlobal);


            // dont nuke existing anchor refs on the instance
            ChartAnchor startAnchor;

            startAnchor = DrawingTool.CreateChartAnchor(owner, startBarsAgo, startTime, startY);
            ChartAnchor endAnchor = DrawingTool.CreateChartAnchor(owner, endBarsAgo, endTime, endY);

            startAnchor.CopyDataValues(lineT.StartAnchor);
            endAnchor.CopyDataValues(lineT.EndAnchor);

            /*if (brush != null)
             *                  lineT.LineStroke = new Stroke(brush, dashStyle, width);*/

            lineT.SetState(State.Active);
            return(lineT);
        }
示例#5
0
文件: Polygon.cs 项目: theprofe8/nt8
        private static Polygon PolygonCore(NinjaScriptBase owner, string tag, bool isAutoScale, List <ChartAnchor> chartAnchors, Brush brush,
                                           DashStyleHelper dashStyle, Brush areaBrush, int areaOpacity, bool isGlobal, string templateName)
        {
            if (owner == null)
            {
                throw new ArgumentException("owner");
            }

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

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

            Polygon polygon = DrawingTool.GetByTagOrNew(owner, typeof(Polygon), tag, templateName) as Polygon;

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

            DrawingTool.SetDrawingToolCommonValues(polygon, tag, isAutoScale, owner, isGlobal);

            if (chartAnchors != null)
            {
                polygon.ChartAnchors = chartAnchors;
            }

            if (brush != null)
            {
                polygon.OutlineStroke = new Stroke(brush, dashStyle, 2);
            }

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

            if (areaOpacity > -1)
            {
                polygon.AreaOpacity = areaOpacity;
            }

            polygon.SetState(State.Active);
            return(polygon);
        }
示例#6
0
        private static PathTool PathCore(NinjaScriptBase owner, string tag, bool isAutoScale, List <ChartAnchor> chartAnchors, Brush brush, DashStyleHelper dashStyle, bool isGlobal, string templateName)
        {
            if (owner == null)
            {
                throw new ArgumentException("owner");
            }

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

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

            PathTool path = DrawingTool.GetByTagOrNew(owner, typeof(PathTool), tag, templateName) as PathTool;

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

            DrawingTool.SetDrawingToolCommonValues(path, tag, isAutoScale, owner, isGlobal);

            if (chartAnchors != null)
            {
                path.ChartAnchors = chartAnchors;

                for (int i = 1; i < chartAnchors.Count; i++)
                {
                    path.PathToolSegments.Add(new PathToolSegment(chartAnchors[i - 1], chartAnchors[i], string.Format("{0} {1}", Custom.Resource.NinjaScriptDrawingToolPathSegment, i)));
                }
            }

            if (brush != null)
            {
                path.OutlineStroke = new Stroke(brush, dashStyle, 2);
            }

            path.SetState(State.Active);
            return(path);
        }
示例#7
0
        private static Ruler RulerCore(NinjaScriptBase owner, string tag, bool isAutoScale, int startBarsAgo, DateTime startTime, double startY,
                                       int endBarsAgo, DateTime endTime, double endY, int textBarsAgo, DateTime textTime, double textY, bool isGlobal, string templateName)
        {
            if (owner == null)
            {
                throw new ArgumentException("owner");
            }
            if (startTime == Core.Globals.MinDate && endTime == Core.Globals.MinDate && startBarsAgo == int.MinValue && endBarsAgo == int.MinValue)
            {
                throw new ArgumentException("bad start/end date/time");
            }

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

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

            Ruler ruler = DrawingTool.GetByTagOrNew(owner, typeof(Ruler), tag, templateName) as Ruler;

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

            DrawingTool.SetDrawingToolCommonValues(ruler, tag, isAutoScale, owner, isGlobal);

            ChartAnchor startAnchor = DrawingTool.CreateChartAnchor(owner, startBarsAgo, startTime, startY);
            ChartAnchor endAnchor   = DrawingTool.CreateChartAnchor(owner, endBarsAgo, endTime, endY);
            ChartAnchor txtAnchor   = DrawingTool.CreateChartAnchor(owner, textBarsAgo, textTime, textY);

            startAnchor.CopyDataValues(ruler.StartAnchor);
            endAnchor.CopyDataValues(ruler.EndAnchor);
            txtAnchor.CopyDataValues(ruler.TextAnchor);
            ruler.SetState(State.Active);
            return(ruler);
        }
示例#8
0
        private static Region Region(NinjaScriptBase owner, string tag,
                                     int startBarsAgo, DateTime startTime, int endBarsAgo, DateTime endTime,
                                     ISeries <double> series1, ISeries <double> series2, double price,
                                     Brush outlineBrush, Brush areaBrush, int areaOpacity, int displacement)
        {
            Region region = DrawingTool.GetByTagOrNew(owner, typeof(Region), tag, null) as Region;

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

            DrawingTool.SetDrawingToolCommonValues(region, tag, false, owner, false);

            ChartAnchor startAnchor = DrawingTool.CreateChartAnchor(owner, startBarsAgo, startTime, 0);
            ChartAnchor endAnchor   = DrawingTool.CreateChartAnchor(owner, endBarsAgo, endTime, 0);

            startAnchor.CopyDataValues(region.StartAnchor);
            endAnchor.CopyDataValues(region.EndAnchor);

            if (series1 == null && series2 == null)
            {
                throw new ArgumentException("At least one series is required");
            }

            region.Series1      = series1;
            region.Series2      = series2;
            region.Price        = price;
            region.Displacement = displacement;

            region.AreaBrush   = areaBrush;
            region.AreaOpacity = areaOpacity;

            region.OutlineStroke = outlineBrush != null ? new Stroke(outlineBrush) : null;

            region.SetState(State.Active);
            region.DrawingState = DrawingState.Normal;
            region.IsSelected   = false;
            return(region);
        }
示例#9
0
        private static GannFan GannFanCore(NinjaScriptBase owner, bool isAutoScale, string tag, int barsAgo, DateTime time, double y, bool isGlobal, string templateName)
        {
            if (owner == null)
            {
                throw new ArgumentException("owner");
            }
            if (time == Core.Globals.MinDate && barsAgo == int.MinValue)
            {
                throw new ArgumentException("bad start/end date/time");
            }

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

            if (isGlobal && tag[0] != '@')
            {
                tag = "@" + tag;
            }

            GannFan gannFan = DrawingTool.GetByTagOrNew(owner, typeof(GannFan), tag, templateName) as GannFan;

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

            DrawingTool.SetDrawingToolCommonValues(gannFan, tag, isAutoScale, owner, isGlobal);

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

            anchor.CopyDataValues(gannFan.Anchor);

            gannFan.SetState(State.Active);
            return(gannFan);
        }
        private static T RegionHighlightCore <T>(NinjaScriptBase owner, string tag,
                                                 bool isAutoScale,
                                                 int startBarsAgo, DateTime startTime, double startY,
                                                 int endBarsAgo, DateTime endTime, double endY,
                                                 Brush brush, Brush areaBrush, int areaOpacity, bool isGlobal, string templateName) where T : RegionHighlightBase
        {
            if (owner == null)
            {
                throw new ArgumentException("owner");
            }

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

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

            T regionHighlight = DrawingTool.GetByTagOrNew(owner, typeof(T), tag, templateName) as T;

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

            RegionHighlightMode mode = regionHighlight.Mode = typeof(T) == typeof(RegionHighlightX) ? RegionHighlightMode.Time : RegionHighlightMode.Price;

            DrawingTool.SetDrawingToolCommonValues(regionHighlight, tag, isAutoScale, owner, isGlobal);

            ChartAnchor startAnchor;
            ChartAnchor endAnchor;

            if (mode == RegionHighlightMode.Time)
            {
                startAnchor = DrawingTool.CreateChartAnchor(owner, startBarsAgo, startTime, startY);
                endAnchor   = DrawingTool.CreateChartAnchor(owner, endBarsAgo, endTime, endY);
            }
            else
            {
                // just create on current bar
                startAnchor = DrawingTool.CreateChartAnchor(owner, 0, owner.Time[0], startY);
                endAnchor   = DrawingTool.CreateChartAnchor(owner, 0, owner.Time[0], endY);
            }

            startAnchor.CopyDataValues(regionHighlight.StartAnchor);
            endAnchor.CopyDataValues(regionHighlight.EndAnchor);

            // brushes can be null when using a templateName
            if (regionHighlight.AreaBrush != null && areaBrush != null)
            {
                regionHighlight.AreaBrush = areaBrush.Clone();
            }

            if (areaOpacity >= 0)
            {
                regionHighlight.AreaOpacity = areaOpacity;
            }
            if (brush != null)
            {
                regionHighlight.OutlineStroke = new Stroke(brush);
            }

            regionHighlight.SetState(State.Active);
            return(regionHighlight);
        }
示例#11
0
        private static RiskReward RiskRewardCore(NinjaScriptBase owner, string tag,
                                                 bool isAutoScale,
                                                 int entryBarsAgo, DateTime entryTime, double entryY,
                                                 int stopBarsAgo, DateTime stopTime, double stopY,
                                                 int targetBarsAgo, DateTime targetTime, double targetY,
                                                 double ratio, bool isStop, bool isGlobal, string templateName)
        {
            if (owner == null)
            {
                throw new ArgumentException("owner");
            }

            if (entryBarsAgo == int.MinValue && entryTime == Core.Globals.MinDate)
            {
                throw new ArgumentException("entry value required");
            }

            if (stopBarsAgo == int.MinValue && stopTime == Core.Globals.MinDate &&
                targetBarsAgo == int.MinValue && targetTime == Core.Globals.MinDate)
            {
                throw new ArgumentException("a stop or target value is required");
            }

            if (isGlobal && tag[0] != GlobalDrawingToolManager.GlobalDrawingToolTagPrefix)
            {
                tag = string.Format("{0}{1}", GlobalDrawingToolManager.GlobalDrawingToolTagPrefix, tag);
            }

            RiskReward riskReward = DrawingTool.GetByTagOrNew(owner, typeof(RiskReward), tag, templateName) as RiskReward;

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

            DrawingTool.SetDrawingToolCommonValues(riskReward, tag, isAutoScale, owner, isGlobal);

            // this is a little tricky, we use entry + (stop or target) to calculate the (target or stop) from ratio
            ChartAnchor entryAnchor = DrawingTool.CreateChartAnchor(owner, entryBarsAgo, entryTime, entryY);
            ChartAnchor stopAnchor;
            ChartAnchor targetAnchor;

            double yDiff;

            if (isStop)
            {
                stopAnchor   = DrawingTool.CreateChartAnchor(owner, stopBarsAgo, stopTime, stopY);
                yDiff        = entryY - stopY;
                targetAnchor = new ChartAnchor();
                // copy entry to target so x aligned, then adjust y by our ratio
                entryAnchor.CopyDataValues(targetAnchor);
                targetAnchor.Price = entryY + yDiff * ratio;
            }
            else
            {
                targetAnchor = DrawingTool.CreateChartAnchor(owner, targetBarsAgo, targetTime, targetY);
                yDiff        = entryY - targetY;
                stopAnchor   = new ChartAnchor();
                // copy entry to stop so x aligned, then adjust y by our ratio
                entryAnchor.CopyDataValues(stopAnchor);
                stopAnchor.Price = entryY + yDiff / ratio;
            }

            entryAnchor.CopyDataValues(riskReward.EntryAnchor);
            stopAnchor.CopyDataValues(riskReward.RiskAnchor);
            targetAnchor.CopyDataValues(riskReward.RewardAnchor);

            riskReward.SetState(State.Active);
            return(riskReward);
        }
示例#12
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);
        }
示例#13
0
        private static TimeCycles TimeCyclesCore(NinjaScriptBase owner, string tag, int startBarsAgo, int endBarsAgo,
                                                 DateTime startTime, DateTime endTime, Brush brush, Brush areaBrush, int areaOpacity, bool isGlobal, string templateName)
        {
            if (owner == null)
            {
                throw new ArgumentException("owner");
            }

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

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

            TimeCycles drawingTool = DrawingTool.GetByTagOrNew(owner, typeof(TimeCycles), tag, templateName) as TimeCycles;

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

            if (startTime < Core.Globals.MinDate)
            {
                throw new ArgumentException(drawingTool + " startTime must be greater than the minimum Date but was " + startTime);
            }
            else if (endTime < Core.Globals.MinDate)
            {
                throw new ArgumentException(drawingTool + " endTime must be greater than the minimum Date but was " + endTime);
            }

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

            // dont overwrite existing anchor references
            ChartAnchor startAnchor = DrawingTool.CreateChartAnchor(owner, startBarsAgo, startTime, 0);
            ChartAnchor endAnchor   = DrawingTool.CreateChartAnchor(owner, endBarsAgo, endTime, 0);

            startAnchor.CopyDataValues(drawingTool.StartAnchor);
            endAnchor.CopyDataValues(drawingTool.EndAnchor);

            // these can be null when using a templateName so mind not overwriting them
            if (brush != null)
            {
                drawingTool.OutlineStroke = new Stroke(brush, DashStyleHelper.Solid, 2f)
                {
                    RenderTarget = drawingTool.OutlineStroke.RenderTarget
                }
            }
            ;

            if (areaOpacity >= 0)
            {
                drawingTool.AreaOpacity = areaOpacity;
            }

            if (areaBrush != null)
            {
                drawingTool.AreaBrush = areaBrush.Clone();
                if (drawingTool.AreaBrush.CanFreeze)
                {
                    drawingTool.AreaBrush.Freeze();
                }
            }

            drawingTool.SetState(State.Active);
            return(drawingTool);
        }