usingcAlgo.API;usingcAlgo.API.Indicators;usingSystem;namespacecAlgo{/// <summary>/// This indicator shows how to make a built-in cTrader indicator multi time frame and how to use cloud attribute/// </summary>[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None), Cloud("Top", "Bottom", Opacity = 0.2)]publicclassBollingerBandsMTFCloudSample:Indicator{privateBollingerBands_bollingerBands;privateBars_baseBars;[Parameter("Base TimeFrame", DefaultValue = "Daily")]publicTimeFrameBaseTimeFrame{get;set;}[Parameter("Source", DefaultValue = DataSeriesType.Close)]publicDataSeriesTypeDataSeriesType{get;set;}[Parameter("Periods", DefaultValue = 14, MinValue = 0)]publicintPeriods{get;set;}[Parameter("Standard Deviation", DefaultValue = 2, MinValue = 0)]publicdoubleStandardDeviation{get;set;}[Parameter("MA Type", DefaultValue = MovingAverageType.Simple)]publicMovingAverageTypeMaType{get;set;}[Output("Main", LineColor = "Yellow", PlotType = PlotType.Line, Thickness = 1)]publicIndicatorDataSeriesMain{get;set;}[Output("Top", LineColor = "Red", PlotType = PlotType.Line, Thickness = 1)]publicIndicatorDataSeriesTop{get;set;}[Output("Bottom", LineColor = "Red", PlotType = PlotType.Line, Thickness = 1)]publicIndicatorDataSeriesBottom{get;set;}protectedoverridevoidInitialize(){_baseBars=MarketData.GetBars(BaseTimeFrame);varbaseSeries=GetBaseSeries();_bollingerBands=Indicators.BollingerBands(baseSeries,Periods,StandardDeviation,MaType);}publicoverridevoidCalculate(intindex){varbaseIndex=_baseBars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);Main[index]=_bollingerBands.Main[baseIndex];Top[index]=_bollingerBands.Top[baseIndex];Bottom[index]=_bollingerBands.Bottom[baseIndex];}privateDataSeriesGetBaseSeries(){switch(DataSeriesType){caseDataSeriesType.Open:return_baseBars.OpenPrices;caseDataSeriesType.High:return_baseBars.HighPrices;caseDataSeriesType.Low:return_baseBars.LowPrices;caseDataSeriesType.Close:return_baseBars.ClosePrices;default:thrownewArgumentOutOfRangeException("DataSeriesType");}}}publicenumDataSeriesType{Open,High,Low,Close}}
CloudAttribute 생성자는 두 개의 출력 라인 이름을 받습니다. 그 후, 이 두 출력 사이의 공간에 맞게 클라우드를 자동으로 플롯합니다.
Opacity 속성을 사용하여 클라우드의 불투명도를 설정할 수도 있습니다. 클라우드 색상을 설정하려면 FirstColor 속성을 사용하세요. 기본적으로 클라우드의 색상은 지표 출력의 첫 번째 라인 색상과 일치합니다.
색상 작업
Algo API에는 Chart 객체, 차트 컨트롤 및 출력을 위한 색상을 구성하는 데 사용할 수 있는 Colorenum이 포함되어 있습니다.
Colorenum의 값은 일반적으로 사용되는 색상을 나타냅니다. 16진수 또는 ARGB 색상 코드를 다룰 필요 없이 이를 사용할 수 있습니다.
출력을 사용자 정의할 때, LineColor 문자열 속성을 사용하여 색상을 설정할 수 있습니다. 아래와 같이, 이는 명명된 색상과 16진수 색상 코드를 모두 허용합니다.
1234
_=Chart.DrawStaticText("NamedColor","This is text using Color class color name properties",VerticalAlignment.Center,HorizontalAlignment.Center,Color.Red);_=Chart.DrawStaticText("HexadecimalColor","This is text using Hexadecimal color",VerticalAlignment.Bottom,HorizontalAlignment.Center,Color.FromHex("#FF5733"));_=Chart.DrawStaticText("ARGBColor","This is text using ARGB color",VerticalAlignment.Top,HorizontalAlignment.Center,Color.FromArgb(255,200,100,60));_=Chart.DrawStaticText("ParsedNameColor","This is text using color name by parsing it from string",VerticalAlignment.Center,HorizontalAlignment.Left,Color.FromName("Yellow"));
1 2 3 4 5 6 7 8 910111213
varstackPanel=newStackPanel{Orientation=Orientation.Vertical,HorizontalAlignment=HorizontalAlignment.Center,VerticalAlignment=VerticalAlignment.Center};stackPanel.AddChild(newTextBlock{Text="Red Color property",BackgroundColor=Color.Red});stackPanel.AddChild(newTextBlock{Text="Hexadecimal Color code",BackgroundColor=Color.FromHex("#FF5733")});stackPanel.AddChild(newTextBlock{Text="ARGB Color",BackgroundColor=Color.FromArgb(200,100,40,80)});stackPanel.AddChild(newTextBlock{Text="Color Name",BackgroundColor=Color.FromName("Green")});Chart.AddControl(stackPanel);