콘텐츠로 이동

사용자 정의 알림

사용자 정의 알림 API에는 트레이딩 알고리즘이 cTrader에서 실시간 팝업 알림을 직접 전달할 수 있게 하는 타입이 포함되어 있습니다. 이 팝업은 cBot, 지표 및 플러그인이 진행 상황, 성공, 오류 또는 일반 정보를 시각적이고 상황에 맞게 사용자에게 전달할 수 있게 합니다.

사용자 정의 알림 API 지원으로, cBot은 더 이상 로그 탭, 차트 객체 또는 외부 Telegram 브리지에 의존하지 않아도 됩니다. 알고리즘은 단순히 cTrader의 표준 알림 시스템을 통해 트레이더에게 직접 상황을 알립니다. 알고리즘 개발자와 사용자는 복잡한 설정 없이도 속도, 신뢰성 및 명확성을 누릴 수 있습니다.

관련 API 인터페이스는 다음과 같습니다:

  • INotifications.ShowPopup(caption, message, state)는 주어진 제목, 메시지 및 상태(PopupNotificationState)로 팝업 알림을 표시합니다.
  • PopupNotification 인터페이스는 .Complete()를 호출하여 최종 상태를 업데이트함으로써 장기 실행 또는 진행 중인 알림을 프로그래밍 방식으로 제어합니다.

사용자 정의 알림 API에 의해 전달된 메시지는 즉시 나타나며, 상태에 따라 색상이 지정되고 나중에 완료될 수 있습니다. 알림 상태는 PopupNotificationState 열거형을 사용하여 정의됩니다:

  • InProgress는 장기 실행 프로세스 또는 보류 상태를 나타냅니다. 예:

  • Success는 작업이 성공적으로 완료되었음을 나타냅니다. 예:

  • Error는 실패 또는 예외를 신호합니다. 예:

  • Partial은 부분적으로 성공한 결과(예: 일부 주문 성공)를 전달합니다. 예:

  • Information은 일반 알림, 업데이트 또는 피드백을 위한 것입니다. 예:

팝업 알림을 사용하여 거래 활동을 추적하고, 로직 흐름을 디버그하며, 시장 이벤트 또는 데이터 오류에 대해 사용자에게 경고하고, 라이브 또는 수동 전략 운영 중에 동적 UI 피드백을 제공합니다.

알림 API 객체는 다음과 같은 작업을 수행하는 데 사용할 수 있습니다:

기능 또는 작업 예시
주문 추적 및 피드백 주문 실행 피드백 표시
TP/SL 종료 확인
추적 손절매 수정 추적
위험 및 규칙 기반 경고 낮은 증거금 수준 경고
차단된 거래에 대한 경고 표시
진행 상황 및 진단 팝업으로 분석 진행 상황 표시
수동 거래 상호작용 거래 작업에 대한 피드백 제공
수동 재정의 또는 개입에 대해 경고
시장 이벤트 및 신호 경고 신호 지표 교차
세션 개시 또는 가격 급등 알림
전략 디버깅 및 투명성 전략/로직 단계를 시각적으로 추적
로직 실패 보고

기본 예시

이 cBot 인스턴스가 차트에 추가되면, 알림 상태별로 하나씩 총 다섯 개의 버튼이 제공됩니다. 버튼을 클릭하면 팝업 알림이 트리거됩니다.

 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Internals;

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.None, AddIndicators = true)]
    public class PopupNotificationStatesDemo : Robot
    {
        protected override void OnStart()
        {
            var panel = new StackPanel
            {
                Orientation = Orientation.Vertical,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center
            };

            // InProgress
            var inProgressBtn = new Button { Text = "Show: InProgress", Margin = 5 };
            inProgressBtn.Click += _ =>
            {
                Notifications.ShowPopup(
                    "In progress",
                    "Starting a long-running task…",
                    PopupNotificationState.InProgress
                );
            };
            panel.AddChild(inProgressBtn);

            // Success
            var successBtn = new Button { Text = "Show: Success", Margin = 5 };
            successBtn.Click += _ =>
            {
                Notifications.ShowPopup(
                    "Success",
                    "The operation completed successfully.",
                    PopupNotificationState.Success
                );
            };
            panel.AddChild(successBtn);

            // Error
            var errorBtn = new Button { Text = "Show: Error", Margin = 5 };
            errorBtn.Click += _ =>
            {
                Notifications.ShowPopup(
                    "Error",
                    "Something went wrong. Please check the logs or try again.",
                    PopupNotificationState.Error
                );
            };
            panel.AddChild(errorBtn);

            // Partial
            var partialBtn = new Button { Text = "Show: Partial", Margin = 5 };
            partialBtn.Click += _ =>
            {
                Notifications.ShowPopup(
                    "Partial result",
                    "Completed with partial success (e.g. some orders filled).",
                    PopupNotificationState.Partial
                );
            };
            panel.AddChild(partialBtn);

            // Information
            var infoBtn = new Button { Text = "Show: Information", Margin = 5 };
            infoBtn.Click += _ =>
            {
                Notifications.ShowPopup(
                    "Information",
                    "General update: your settings were saved.",
                    PopupNotificationState.Information
                );
            };
            panel.AddChild(infoBtn);

            Chart.AddControl(panel);
        }

        protected override void OnTick()
        {
            // Handle price updates here if needed
        }

        protected override void OnStop()
        {
            // Cleanup if needed
        }
    }
}

주문 추적 및 피드백

주문 실행 피드백 표시

팝업 알림을 사용하여 시장 주문이 성공했는지 여부를 즉시 확인할 수 있습니다. 예를 들어, cBot이 매수 주문을 한 후, 거래가 체결되면 성공 팝업이 표시되고 중개인이 거부하면 오류 팝업이 표시됩니다.

1
2
3
var result = ExecuteMarketOrder(TradeType.Buy, SymbolName, 1000);
var state = result.IsSuccessful ? PopupNotificationState.Success : PopupNotificationState.Error;
Notifications.ShowPopup("Order Execution", $"Order result: {result.Error}", state);

TP 또는 SL 종료 확인

cBot 거래가 이익실현 또는 손절매로 종료될 때 알림을 받습니다. 팝업은 종료 이유와 함께 종료된 포지션의 손익을 표시합니다. 종료 시점의 실시간 피드백은 거래를 추적하고 활성 포지션의 결과를 최신 상태로 유지하는 데 도움이 됩니다.

1
2
3
4
5
6
protected override void OnPositionClosed(PositionClosedEventArgs args)
{
    var pos = args.Position;
    var reason = pos.ClosingReason.ToString();
    Notifications.ShowPopup("Position Closed", $"Closed due to {reason}. PnL: {pos.GrossProfit}", PopupNotificationState.Information);
}

추적 손절매 수정 추적

추적 손절매가 포지션의 손절매를 업데이트할 때마다 팝업을 확인합니다. 알림에는 새로운 손절매 값이 포함되며 추적 손절매가 가격 움직임을 어떻게 추적하는지 보여줍니다. 이러한 경고를 통해 패널을 열지 않고도 거래 보호가 어떻게 조정되는지 모니터링할 수 있습니다.

1
2
3
4
5
6
7
protected override void OnPositionModified(PositionModifiedEventArgs args)
{
    if (args.Reason == PositionModificationReason.TrailingStop)
    {
        Notifications.ShowPopup("Trailing Stop Moved", $"New SL: {args.Position.StopLoss}", PopupNotificationState.Information);
    }
}

위험 및 규칙 기반 경고

낮은 증거금 수준 경고

계정의 증거금 수준이 임계값(예: 80%) 이하로 떨어지면 팝업 경고를 받습니다. 이 경고는 강제 청산 또는 마진콜을 피하기 위해 포지션을 청산하거나 자금을 추가하는 등 시기적절한 조치를 취할 수 있도록 도와줍니다. 팝업은 실시간 위험 데이터를 기반으로 한 자동화된 안전 장치 역할을 합니다.

1
2
3
4
5
6
7
protected override void OnTick()
{
    if (Account.MarginLevel < 80)
    {
        Notifications.ShowPopup("Low Margin Warning", $"Current margin level: {Account.MarginLevel:0.00}%", PopupNotificationState.Error);
    }
}

차단된 거래에 대한 경고 표시

일부 cBot은 낮은 평가금 또는 과도한 드로다운과 같은 내부 안전 규칙이 트리거되면 거래를 중단하도록 프로그래밍되어 있습니다. 팝업은 차단 이유와 어떤 조건이 위반되었는지 설명할 수 있습니다. 이 알림은 신호가 건너뛰어진 이유를 이해하고 규율 있는 전략 행동을 강화하는 데 도움이 됩니다.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
protected override void OnBar()
{
    if (Account.Equity < 100)
    {
        Notifications.ShowPopup("Trade Blocked", "Equity too low to place trade", PopupNotificationState.Error);
        return;
    }

    ExecuteMarketOrder(TradeType.Sell, SymbolName, 1000);
}

진행 상황 및 진단

팝업으로 분석 진행 상황 표시

데이터 검증 또는 백테스트 준비와 같은 장기 실행 프로세스의 시작을 나타내기 위해 InProgress 팝업을 사용합니다. 작업이 완료되면 팝업을 Success 또는 Error 상태로 업데이트합니다. 표시된 진행 보고서는 로그 또는 디버그 메시지를 확인할 필요 없이 정보를 제공합니다.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
private PopupNotification _progressPopup;

protected override void OnStart()
{
    _progressPopup = Notifications.ShowPopup("Analysis Started", "Running analysis...", PopupNotificationState.InProgress);
    Timer.Start(4); // Simulate 4-second task
}

protected override void OnTimer()
{
    _progressPopup.Complete(PopupNotificationState.Success);
    Timer.Stop();
}

수동 거래 상호작용

버튼 트리거 거래 후 사용자에게 알림

사용자 정의 컨트롤 또는 버튼을 클릭한 후, cBot은 주문을 하고 즉시 결과를 팝업으로 표시할 수 있습니다. 알림은 수동 작업이 성공했는지 실패했는지 확인하고 중개인이 반환한 오류를 표시합니다. 이 시각적 피드백은 추측을 줄이고 수동 개입에 대한 자신감을 높입니다.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
protected override void OnStart()
{
    var panel = new StackPanel();
    var button = new Button { Text = "Manual Buy" };

    button.Click += args =>
    {
        var result = ExecuteMarketOrder(TradeType.Buy, SymbolName, 1000);
        var status = result.IsSuccessful ? PopupNotificationState.Success : PopupNotificationState.Error;
        Notifications.ShowPopup("Manual Trade", $"Buy order result: {result.Error}", status);
    };

    panel.AddChild(button);
    Chart.AddControl(panel);
}

수동 재정의 또는 개입에 대해 경고

자동화된 로직을 재정의하거나 수동 재정의(예: 차단 상태에서 강제로 거래)를 수행할 때 팝업으로 작업을 확인할 수 있습니다.

1
2
3
4
5
button.Click += args =>
{
    Notifications.ShowPopup("Manual Override", "User manually triggered a trade", PopupNotificationState.Information);
    ExecuteMarketOrder(TradeType.Sell, SymbolName, 1000);
};

시장 이벤트 및 신호 경고

신호 지표 교차

이동 평균 교차 또는 RSI 임계값과 같은 주요 기술적 이벤트를 모니터링하고 발생 시 팝업 경고를 표시합니다. 알림은 지표와 충족된 조건(예: 강세 교차)을 강조합니다. 이를 통해 기술적 신호를 계속 확인하고 전략을 더 투명하고 추적 가능하게 만듭니다.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
private MovingAverage _fast, _slow;

protected override void OnStart()
{
    _fast = Indicators.MovingAverage(MarketSeries.Close, 5, MovingAverageType.Exponential);
    _slow = Indicators.MovingAverage(MarketSeries.Close, 20, MovingAverageType.Exponential);
}

protected override void OnBar()
{
    int i = MarketSeries.Close.Count - 1;
    if (_fast.Result[i] > _slow.Result[i] && _fast.Result[i - 1] <= _slow.Result[i - 1])
    {
        Notifications.ShowPopup("MA Crossover", "Fast MA crossed above Slow MA", PopupNotificationState.Information);
    }
}

세션 개시 또는 가격 급등 알림

런던 세션 개시 또는 짧은 기간 내 급격한 가격 변동과 같은 중요한 시장 이벤트가 발생할 때 트리거되는 팝업을 생성합니다. 이러한 알림은 상황 인식 도구 역할을 하며 잠재적 변동성에 대응하거나 시장 활동을 준비하는 데 도움이 됩니다.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
protected override void OnBar()
{
    var time = Server.Time;
    if (time.TimeOfDay.Hours == 8 && time.TimeOfDay.Minutes == 0)
    {
        Notifications.ShowPopup("London Session Open", "London market has opened", PopupNotificationState.Information);
    }

    if (Math.Abs(Symbol.Bid - Symbol.Ask) / Symbol.PipSize > 15)
    {
        Notifications.ShowPopup("Spread Spike", "Spread exceeded 15 pips!", PopupNotificationState.Warning);
    }
}

전략 디버깅 및 투명성

전략 단계를 시각적으로 추적

팝업 시퀀스를 사용하여 전략의 논리적 흐름을 표시합니다. 예를 들어, 추세 확인, 신호 확인 또는 위험 검증 시 메시지를 표시합니다. 각 팝업은 특정 체크포인트를 나타내며, 전략이 실시간으로 어떻게 결정을 내리는지 따라갈 수 있도록 합니다.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
protected override void OnBar()
{
    Notifications.ShowPopup("Step 1", "Checking market condition", PopupNotificationState.Information);

    if (MarketSeries.Close.Last(1) > MarketSeries.Open.Last(1))
    {
        Notifications.ShowPopup("Step 2", "Bullish candle detected", PopupNotificationState.Information);
    }

    Notifications.ShowPopup("Step 3", "Trade logic complete", PopupNotificationState.Success);
}

로직 실패 또는 예상치 못한 데이터 보고

전략이 가격 불일치 또는 사용 불가능한 지표와 같은 오류 또는 유효하지 않은 데이터를 만나면 팝업을 사용하여 정확한 문제를 표시합니다. 이 설정은 개발 및 데모/라이브 거래 중 버그 또는 데이터 격차를 식별하는 데 도움이 되어 더 빠른 디버깅과 더 견고한 로직을 가능하게 합니다.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
protected override void OnBar()
{
    try
    {
        // Assume some strategy logic
        if (Symbol.Bid < 0) throw new Exception("Invalid price feed");

        Notifications.ShowPopup("Logic OK", "Price validation passed", PopupNotificationState.Success);
    }
    catch (Exception ex)
    {
        Notifications.ShowPopup("Logic error", ex.Message, PopupNotificationState.Error);
    }
}