Przejdź do treści

Jak dodać chmury do wskaźników cTrader

cTrader Algo umożliwia rysowanie chmur między liniami na wykresie. Takie chmury pozwalają szybko identyfikować kluczowe obszary na wykresach i wykrywać zmiany w zachowaniu rynku.

W tym artykule i odpowiadającym mu filmie pokażemy Ci, jak dodawać i dostosowywać chmury we wskaźnikach.

Dodaj wskaźnik

Typowy wskaźnik Bollinger Bands składa się z górnego pasma, dolnego pasma i prostej średniej ruchomej pośrodku. Aby ulepszyć wygląd wskaźnika, planujemy wypełnić przestrzeń między pasmami chmurą.

Aby utworzyć wskaźnik, otwórz aplikację Algo i przejdź do karty Wskaźniki. Kliknij przycisk Nowy, wpisz nazwę wskaźnika, na przykład „Bollinger Bands Cloud", a następnie kliknij przycisk Utwórz.

Możemy teraz zmodyfikować kod wskaźnika. Uczynimy nasz przykład wskaźnikiem nakładanym.

1
[Indicator(AccessRights = AccessRights.None, IsOverlay = true)]

Następnie dodamy trzy linie wyjściowe wymagane do narysowania Bollinger Bands na wykresie.

1
2
3
4
5
6
7
8
[Output("Main", LineColor = "Yellow", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries Main { get; set; }

[Output("Top", LineColor = "Red", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries Top { get; set; }

[Output("Bottom", LineColor = "Red", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries Bottom { get; set; }

Deklarujemy nasz wskaźnik Bollinger Bands.

1
private BollingerBands _bollingerBands;

Inicjalizujemy wskaźnik.

1
_bollingerBands = Indicators.BollingerBands(Bars.ClosePrices, 20, 2, MovingAverageType.Simple);

Wypełniamy linie wartościami wskaźnika w metodzie Calculate().

1
2
3
Main[index] = _bollingerBands.Main[index];
Top[index] = _bollingerBands.Top[index];
Bottom[index] = _bollingerBands.Bottom[index];

Możesz skopiować pełny kod poniżej:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Indicator(AccessRights = AccessRights.None, IsOverlay = true)]

    public class BollingerBandsCloud : Indicator
    {

        [Output("Main", LineColor = "Yellow", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries Main { get; set; }

        [Output("Top", LineColor = "Red", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries Top { get; set; }

        [Output("Bottom", LineColor = "Red", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries Bottom { get; set; }

        private BollingerBands _bollingerBands;


        protected override void Initialize()
        {
            _bollingerBands = Indicators.BollingerBands(Bars.ClosePrices, 20, 2, MovingAverageType.Simple);
        }

        public override void Calculate(int index)
        {
            Main[index] = _bollingerBands.Main[index];
            Top[index] = _bollingerBands.Top[index];
            Bottom[index] = _bollingerBands.Bottom[index];
        }
    }
}

Kliknij Zbuduj lub użyj skrótu Ctrl+B, aby zbudować wskaźnik.

Dodaj instancję wskaźnika dla symbolu EURUSD.

Powinieneś(-naś) zobaczyć typowy wskaźnik Bollinger Bands na wykresie.

Dodaj chmurę do Bollinger Bands

Teraz wracamy do edytora kodu, a następnie pracujemy nad dodaniem chmury między pasmami.

Aby osiągnąć nasz cel, dodajemy atrybut Cloud do istniejącego wskaźnika. Atrybut Cloud instruuje wskaźnik, aby narysował chmurę między liniami Top i Bottom.

1
[Cloud("Top", "Bottom", Opacity = 0.2)]

Możesz skopiować pełny zmieniony kod poniżej:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Indicator(AccessRights = AccessRights.None, IsOverlay = true)]
    [Cloud("Top", "Bottom", Opacity = 0.2)]

    public class BollingerBandsCloud : Indicator
    {

        [Output("Main", LineColor = "Yellow", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries Main { get; set; }

        [Output("Top", LineColor = "Red", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries Top { get; set; }

        [Output("Bottom", LineColor = "Red", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries Bottom { get; set; }

        private BollingerBands _bollingerBands;

        protected override void Initialize()
        {
            _bollingerBands = Indicators.BollingerBands(Bars.ClosePrices, 20, 2, MovingAverageType.Simple);
        }

        public override void Calculate(int index)
        {
            Main[index] = _bollingerBands.Main[index];
            Top[index] = _bollingerBands.Top[index];
            Bottom[index] = _bollingerBands.Bottom[index];
        }
    }
}

Przebudowujemy algorytm, a następnie sprawdzamy nasz wskaźnik, aby zobaczyć, co się zmieniło.

Powinieneś(-naś) zobaczyć czerwoną chmurę między pasmami. Jeśli zmienisz kolor linii Top, kolor chmury zostanie automatycznie zaktualizowany.

Wracamy do edytora kodu i zmieniamy atrybut Cloud, aby rysował chmurę tylko przed linią Main (żółtą).

1
[Cloud("Top", "Main", Opacity = 0.2)]

Przebuduj wskaźnik, a następnie sprawdź go, aby potwierdzić jego nowy wygląd.

Dodaj chmurę do przecięcia MA

Utworzymy nowy wskaźnik i użyjemy go do zademonstrowania, jak chmury o różnych kolorach mogą być dodawane do wykresu. Zamierzamy opracować wskaźnik przecięcia średniej ruchomej (MA) z zieloną chmurą dla trendów wzrostowych i czerwoną chmurą dla trendów spadkowych.

Powtórz kroki z poprzedniej sekcji, aby utworzyć nowy wskaźnik. Tym razem nazwa wskaźnika powinna brzmieć „MA Cloud".

Zaczynamy modyfikować nowy wskaźnik, ustawiając jego właściwość IsOverlay na True.

1
[Indicator(AccessRights = AccessRights.None, IsOverlay = true)]

Dodaj wymagany atrybut Cloud.

1
[Cloud("Fast", "Slow", Opacity = 0.2)]

Dodaj linie wyjściowe i zadeklaruj średnie ruchome.

1
2
3
4
5
6
7
8
[Output("Fast", LineColor = "Green", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries Fast { get; set; }

[Output("Slow", LineColor = "Red", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries Slow { get; set; }

SimpleMovingAverage _fastMA;
SimpleMovingAverage _slowMA;

Powtórz krok z poprzedniego przykładu (Bollinger Bands). Zainicjalizuj średnie ruchome i przekaż wynikowe wartości do linii, aby były wyświetlane na wykresie.

1
2
3
4
5
_fastMA = Indicators.SimpleMovingAverage(Bars.ClosePrices, 7);
_slowMA = Indicators.SimpleMovingAverage(Bars.ClosePrices, 13);

Fast[index] = _fastMA.Result[index];
Slow[index] = _slowMA.Result[index];

Możesz skopiować pełny kod poniżej:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Indicator(AccessRights = AccessRights.None, IsOverlay = true)]
    [Cloud("Top", "Bottom", Opacity = 0.2)]

    public class BollingerBandsCloud : Indicator
    {

        [Output("Main", LineColor = "Yellow", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries Main { get; set; }

        [Output("Top", LineColor = "Red", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries Top { get; set; }

        [Output("Bottom", LineColor = "Red", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries Bottom { get; set; }

        private BollingerBands _bollingerBands;

        protected override void Initialize()
        {
            _bollingerBands = Indicators.BollingerBands(Bars.ClosePrices, 20, 2, MovingAverageType.Simple);
        }

        public override void Calculate(int index)
        {
            Main[index] = _bollingerBands.Main[index];
            Top[index] = _bollingerBands.Top[index];
            Bottom[index] = _bollingerBands.Bottom[index];
        }
    }
}

Zbuduj wskaźnik i dodaj instancję, aby wyświetlić wskaźnik na wykresie.

Kolory chmury zmieniają się przy każdym przecięciu (przecięciu się) średnich ruchomych.

Ten artykuł pokazał Ci, jak dodawać przydatne chmury do wskaźników w cTrader.

Image title