/* We use the maximum of the high pricesof the last ten bars as the Y coordinate. */varhorizontalLine=Chart.DrawHorizontalLine("line",Bars.HighPrices.Maximum(10),Color.Red);
/* We draw a line from the low price of the first visible bar to the high price of the last visible bar on the chart. */vartrendLine=Chart.DrawTrendLine("line",Chart.FirstVisibleBarIndex,Bars.LowPrices[Chart.FirstVisibleBarIndex],Chart.LastVisibleBarIndex,Bars.HighPrices[Chart.LastVisibleBarIndex],Color.Red);// Alternatively, consider the following.vartrendLine=Chart.DrawTrendLine("line",Bars.OpenTimes[Chart.FirstVisibleBarIndex],Bars.LowPrices[Chart.FirstVisibleBarIndex],Bars.OpenTimes[Chart.LastVisibleBarIndex],Bars.HighPrices[Chart.LastVisibleBarIndex],Color.Red);
長方形
長方形を描画するには、DrawRectangle()メソッドを使用します。
1234567
varrectangle=Chart.DrawRectangle("rectangle",Chart.FirstVisibleBarIndex+1,Bars.LowPrices[Chart.FirstVisibleBarIndex+1],Chart.LastVisibleBarIndex,Bars.HighPrices[Chart.LastVisibleBarIndex],Color.Red);/* We fill the rectangle with a transparent color.By using its current color, we only change the alphachannel. */rectangle.IsFilled=true;rectangle.Color=Color.FromArgb(80,rectangle.Color);
三角形
三角形を描画するには、DrawTriangle()メソッドを使用します。
1 2 3 4 5 6 7 8 910111213
varmiddleX=Chart.FirstVisibleBarIndex+(Chart.LastVisibleBarIndex-Chart.FirstVisibleBarIndex)/2;varmiddleY=Bars.LowPrices[Chart.FirstVisibleBarIndex]+(Bars.HighPrices[Chart.LastVisibleBarIndex]-Bars.LowPrices[Chart.FirstVisibleBarIndex])/2;vartriangle=Chart.DrawTriangle("triangle",Chart.FirstVisibleBarIndex,Bars.LowPrices[Chart.FirstVisibleBarIndex],middleX,middleY,Chart.LastVisibleBarIndex,Bars.LowPrices[Chart.FirstVisibleBarIndex],Color.Red);// We fill the triangle with a transparent color// by using it's current color, we change only the alpha channel/* We fill the triangle with a transparent color.By using its current color, we only change the alphachannel. */triangle.IsFilled=true;triangle.Color=Color.FromArgb(80,triangle.Color);
usingcAlgo.API;usingSystem.Linq;namespaceNewIndicator{[Indicator(IsOverlay = true, AccessRights = AccessRights.None)]publicclassNewIndicator:Indicator{protectedoverridevoidInitialize(){foreach(varchartObjectinChart.Objects){/* If the object is a trend line we change its Y1/2 properties */if(chartObjectisChartTrendLinetrendLine){trendLine.Y1=Chart.BottomY;trendLine.Y2=Chart.TopY;}}/* Here, we filter all objects of the 'ChartRectangle' type. */varrectangles=fromchartObjectinChart.ObjectswherechartObjectisChartRectangleselectchartObjectasChartRectangle;/* We select only the chart objects with a name that begins with "MyObjects". */varmyObjects=fromchartObjectinChart.ObjectswherechartObject.Name.StartsWith("MyObjects",System.StringComparison.OrdinalIgnoreCase)selectchartObject;/* We select only interactive objects. If an object is interactive, it will not be removed when the indicator is removed or reloaded. */varinteractiveObjects=fromchartObjectinChart.ObjectswherechartObject.IsInteractiveselectchartObject;/* We remove all objects with a name that begins with "ToRemove". */varchartObjectsCopy=Chart.Objects.ToArray();foreach(varchartObjectinchartObjectsCopy){if(chartObject.Name.StartsWith("ToRemove",System.StringComparison.OrdinalIgnoreCase)){/* Chart 'RemoveObject' gets the object name as a parameter. */Chart.RemoveObject(chartObject.Name);}}}publicoverridevoidCalculate(intindex){}}}
usingcAlgo.API;namespaceNewIndicator{[Indicator(IsOverlay = true, AccessRights = AccessRights.None)]publicclassNewIndicator:Indicator{privateChartVerticalLine_verticalLine;protectedoverridevoidInitialize(){_verticalLine=Chart.DrawVerticalLine("line1",Chart.LastVisibleBarIndex,Color.Red);_verticalLine.IsInteractive=true;Chart.ObjectsRemoved+=Chart_ObjectsRemoved;Print(_verticalLine.IsAlive);}privatevoidChart_ObjectsRemoved(ChartObjectsRemovedEventArgsobj){Print(_verticalLine.IsAlive);/* If the object is removed, we should rid of its reference. Otherwise, it will remain in memory. */if(_verticalLine.IsAliveisfalse){_verticalLine=null;Print("Object reference removed");}}publicoverridevoidCalculate(intindex){}}}