カスタム通知 カスタム通知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つずつ、合計5つのボタンが提供されます。 ボタンをクリックすると、ポップアップ通知がトリガーされます。
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が買い注文を出した後、取引が約定した場合は成功ポップアップが表示され、ブローカーが注文を拒否した場合はエラーポップアップが表示されます。
var result = ExecuteMarketOrder ( TradeType . Buy , SymbolName , 1000 );
var state = result . IsSuccessful ? PopupNotificationState . Success : PopupNotificationState . Error ;
Notifications . ShowPopup ( "Order Execution" , $"Order result: {result.Error}" , state );
利食いまたは損切りによる終了を確認 cBotの取引が利食いまたは損切りによって終了した際に通知を受け取ります。 ポップアップには終了理由とともに、決済されたポジションの利益または損失が表示されます。 このリアルタイムのフィードバックにより、取引を追跡し、アクティブなポジションの結果を常に把握できます。
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 );
}
トレーリングストップの変更を追跡 トレーリングストップがポジションの損切りを更新するたびにポップアップが表示されます。 通知には新しい損切り値が含まれ、トレーリングストップが価格変動をどのように追跡しているかが示されます。 これらのアラートにより、パネルを開くことなく取引保護の調整を監視できます。
protected override void OnPositionModified ( PositionModifiedEventArgs args )
{
if ( args . Reason == PositionModificationReason . TrailingStop )
{
Notifications . ShowPopup ( "Trailing Stop Moved" , $"New SL: {args.Position.StopLoss}" , PopupNotificationState . Information );
}
}
リスクおよびルールベースのアラート 低い証拠金水準を警告 アカウントの証拠金水準が重要な閾値(例:80%)を下回った場合にポップアップアラートを受け取ります。 この警告により、強制決済やマージンコールを避けるために、ポジションを決済したり資金を追加したりするタイムリーな対応が可能になります。 ポップアップは、リアルタイムのリスクデータに基づく自動的な保護機能として機能します。
protected override void OnTick ()
{
if ( Account . MarginLevel < 80 )
{
Notifications . ShowPopup ( "Low Margin Warning" , $"Current margin level: {Account.MarginLevel:0.00}%" , PopupNotificationState . Error );
}
}
ブロックされた取引のアラートを表示 一部のcBotは、低い有効証拠金や過度のドローダウンなどの内部安全ルールがトリガーされた場合に取引を停止するようにプログラムされています。 ポップアップはブロックの理由を説明し、どの条件が違反されたかを示します。 この通知により、シグナルがスキップされた理由を理解し、戦略の行動を規律正しく強化できます。
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 );
}
マニュアルオーバーライドまたは介入を警告 自動化されたロジックをオーバーライドしたり、マニュアルオーバーライドを実行したりした場合(例:ブロック状態中に取引を強制する)、ポップアップでそのアクションを確認できます。
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 );
}
}
戦略のデバッグと透明性 戦略のステップを視覚的に追跡 ポップアップのシーケンスを使用して、戦略の論理的な流れを表示します。 例えば、トレンドを確認する際、シグナルを確認する際、またはリスクを検証する際にメッセージを表示します。 各ポップアップは特定のチェックポイントを表し、戦略がリアルタイムでどのように意思決定を行うかを追跡できます。
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 );
}
}