Skip to content

PositionCloseReason

Summary

The reason for closing the position.

Signature

1
public enum PositionCloseReason

Namespace

cAlgo.API

Fields

Name Description
Closed Positions was closed by the trader.
StopLoss Position was closed by the Stop Loss.
TakeProfit Position was closed by the Take Profit.
StopOut Position was closed because the Stop Out level reached.

Examples

 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
 using cAlgo.API;
 namespace cAlgo.Robots
 {
     // This sample shows how to use PositionCloseReason
     [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
     public class PositionCloseReasonSample : Robot
     {
         protected override void OnStart()
         {
             Positions.Closed += Positions_Closed;
         }
         private void Positions_Closed(PositionClosedEventArgs obj)
         {
             Print(obj.Reason);
             switch (obj.Reason)
             {
                 case PositionCloseReason.Closed:
                     // Do something if position closed
                     break;
                 case PositionCloseReason.StopLoss:
                     // Do something if position stop loss got hit
                     break;
                 case PositionCloseReason.StopOut:
                     // Do something if position stopped out
                     break;
                 case PositionCloseReason.TakeProfit:
                     // Do something if position take profit got hit
                     break;
             }
         }
     }
 }

See Also


Last update: March 17, 2023