コード例 #1
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);
        }
コード例 #2
0
ファイル: AndrewsPitchfork.cs プロジェクト: theprofe8/nt8
        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);
        }
コード例 #3
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);
        }
コード例 #4
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);
        }
コード例 #5
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);
        }
コード例 #6
0
        private static PathTool PathBasic(NinjaScriptBase owner, string tag, bool isAutoScale,
                                          int anchor1BarsAgo, DateTime anchor1Time, double anchor1Y, int anchor2BarsAgo, DateTime anchor2Time, double anchor2Y,
                                          int anchor3BarsAgo, DateTime anchor3Time, double anchor3Y, int anchor4BarsAgo, DateTime anchor4Time, double anchor4Y,
                                          int anchor5BarsAgo, DateTime anchor5Time, double anchor5Y)
        {
            List <ChartAnchor> chartAnchors = new List <ChartAnchor>();

            chartAnchors.Add(DrawingTool.CreateChartAnchor(owner, anchor1BarsAgo, anchor1Time, anchor1Y));
            chartAnchors.Add(DrawingTool.CreateChartAnchor(owner, anchor2BarsAgo, anchor2Time, anchor2Y));
            chartAnchors.Add(DrawingTool.CreateChartAnchor(owner, anchor3BarsAgo, anchor3Time, anchor3Y));

            if (anchor4BarsAgo != int.MinValue || anchor4Time != DateTime.MinValue)
            {
                chartAnchors.Add(DrawingTool.CreateChartAnchor(owner, anchor4BarsAgo, anchor4Time, anchor4Y));
            }

            if (anchor5BarsAgo != int.MinValue || anchor5Time != DateTime.MinValue)
            {
                chartAnchors.Add(DrawingTool.CreateChartAnchor(owner, anchor5BarsAgo, anchor5Time, anchor5Y));
            }

            return(PathCore(owner, tag, isAutoScale, chartAnchors, null, DashStyleHelper.Solid, false, string.Empty));
        }
コード例 #7
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);
        }
コード例 #8
0
        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);
        }
コード例 #9
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);
        }
コード例 #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);
        }
コード例 #11
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);
        }