Skip to content

PendingOrder

Summary

Provides access to properties of pending orders

Signature

1
public abstract interface PendingOrder

Namespace

cAlgo.API

Examples

1
2
3
 PlaceLimitOrder(TradeType.Buy, Symbol, 10000,Symbol.Bid);
 var order = LastResult.PendingOrder;
 Print("The pending order's ID: {0}", order.Id);
 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
 using cAlgo.API;
 using System;
 using System.Globalization;
 namespace cAlgo.Robots
 {
     // This sample bot shows how to place different types of pending orders
     [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
     public class PendingOrderPlacingSample : Robot
     {
         [Parameter("Type", DefaultValue = PendingOrderType.Limit)]
         public PendingOrderType OrderType { get; set; }
         [Parameter("Direction", DefaultValue = TradeType.Buy)]
         public TradeType OrderTradeType { get; set; }
         [Parameter("Volume (Lots)", DefaultValue = 0.01)]
         public double VolumeInLots { get; set; }
         [Parameter("Distance (Pips)", DefaultValue = 20, MinValue = 1)]
         public double DistanceInPips { get; set; }
         [Parameter("Stop (Pips)", DefaultValue = 10, MinValue = 0)]
         public double StopInPips { get; set; }
         [Parameter("Target (Pips)", DefaultValue = 10, MinValue = 0)]
         public double TargetInPips { get; set; }
         [Parameter("Limit Range (Pips)", DefaultValue = 10, MinValue = 1)]
         public double LimitRangeInPips { get; set; }
         [Parameter("Expiry", DefaultValue = "00:00:00")]
         public string Expiry { get; set; }
         [Parameter("Label")]
         public string Label { get; set; }
         [Parameter("Comment")]
         public string Comment { get; set; }
         [Parameter("Trailing Stop", DefaultValue = false)]
         public bool HasTrailingStop { get; set; }
         [Parameter("Stop Loss Method", DefaultValue = StopTriggerMethod.Trade)]
         public StopTriggerMethod StopLossTriggerMethod { get; set; }
         [Parameter("Stop Order Method", DefaultValue = StopTriggerMethod.Trade)]
         public StopTriggerMethod StopOrderTriggerMethod { get; set; }
         [Parameter("Async", DefaultValue = false)]
         public bool IsAsync { get; set; }
         protected override void OnStart()
         {
             var volumeInUnits = Symbol.QuantityToVolumeInUnits(VolumeInLots);
             DistanceInPips *= Symbol.PipSize;
             var stopLoss = StopInPips == 0 ? null : (double?)StopInPips;
             var takeProfit = TargetInPips == 0 ? null : (double?)TargetInPips;
             TimeSpan expiry;
             if (!TimeSpan.TryParse(Expiry, CultureInfo.InvariantCulture, out expiry))
             {
                 Print("Invalid expiry");
                 Stop();
             }
             var expiryTime = expiry != TimeSpan.FromSeconds(0) ? (DateTime?)Server.Time.Add(expiry) : null;
             TradeResult result = null;
             switch (OrderType)
             {
                 case PendingOrderType.Limit:
                     var limitPrice = OrderTradeType == TradeType.Buy ? Symbol.Ask - DistanceInPips : Symbol.Ask + DistanceInPips;
                     if (IsAsync)
                         PlaceLimitOrderAsync(OrderTradeType, SymbolName, volumeInUnits, limitPrice, Label, stopLoss, takeProfit, expiryTime, Comment, HasTrailingStop, StopLossTriggerMethod, OnCompleted);
                     else
                         result = PlaceLimitOrder(OrderTradeType, SymbolName, volumeInUnits, limitPrice, Label, stopLoss, takeProfit, expiryTime, Comment, HasTrailingStop, StopLossTriggerMethod);
                     break;
                 case PendingOrderType.Stop:
                     var stopPrice = OrderTradeType == TradeType.Buy ? Symbol.Ask + DistanceInPips : Symbol.Ask - DistanceInPips;
                     if (IsAsync)
                         PlaceStopOrderAsync(OrderTradeType, SymbolName, volumeInUnits, stopPrice, Label, stopLoss, takeProfit, expiryTime, Comment, HasTrailingStop, StopLossTriggerMethod, StopOrderTriggerMethod, OnCompleted);
                     else
                         result = PlaceStopOrder(OrderTradeType, SymbolName, volumeInUnits, stopPrice, Label, stopLoss, takeProfit, expiryTime, Comment, HasTrailingStop, StopLossTriggerMethod, StopOrderTriggerMethod);
                     break;
                 case PendingOrderType.StopLimit:
                     var stopLimitPrice = OrderTradeType == TradeType.Buy ? Symbol.Ask + DistanceInPips : Symbol.Ask - DistanceInPips;
                     if (IsAsync)
                         PlaceStopLimitOrderAsync(OrderTradeType, SymbolName, volumeInUnits, stopLimitPrice, LimitRangeInPips, Label, stopLoss, takeProfit, expiryTime, Comment, HasTrailingStop, StopLossTriggerMethod, StopOrderTriggerMethod, OnCompleted);
                     else
                         result = PlaceStopLimitOrder(OrderTradeType, SymbolName, volumeInUnits, stopLimitPrice, LimitRangeInPips, Label, stopLoss, takeProfit, expiryTime, Comment, HasTrailingStop, StopLossTriggerMethod, StopOrderTriggerMethod);
                     break;
                 default:
                     Print("Invalid order type");
                     throw new ArgumentOutOfRangeException("OrderType");
             }
             if (!IsAsync) OnCompleted(result);
         }
         private void OnCompleted(TradeResult result)
         {
             if (!result.IsSuccessful) Print("Error: ", result.Error);
             Stop();
         }
     }
 }
 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
94
95
96
 using cAlgo.API;
 using System;
 using System.Globalization;
 using System.Linq;
 namespace cAlgo.Robots
 {
     // This sample shows how to modify a pending order
     // It uses order comment to find the order, you can use order label instead if you want to
     // Set stop loss and take profit to 0 if you don't want to change it
     // Leave expiry parameter empty if you don't want to change it or 0 if you want to remove it
     // If you don't want to change the target price set it to 0
     // If you don't want to change the volume set it to 0
     [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
     public class PendingOrderModificationSample : Robot
     {
         [Parameter("Order Comment")]
         public string OrderComment { get; set; }
         [Parameter("Order Label")]
         public string OrderLabel { get; set; }
         [Parameter("Target Price", DefaultValue = 0.0)]
         public double TargetPrice { get; set; }
         [Parameter("Stop Loss (Pips)", DefaultValue = 10)]
         public double StopLossInPips { get; set; }
         [Parameter("Stop Loss Trigger Method", DefaultValue = StopTriggerMethod.Trade)]
         public StopTriggerMethod StopLossTriggerMethod { get; set; }
         [Parameter("Take Profit (Pips)", DefaultValue = 10)]
         public double TakeProfitInPips { get; set; }
         [Parameter("Expiry (HH:mm:ss)")]
         public string Expiry { get; set; }
         [Parameter("Volume (Lots)", DefaultValue = 0.01)]
         public double VolumeInLots { get; set; }
         [Parameter("Has Trailing Stop", DefaultValue = false)]
         public bool HasTrailingStop { get; set; }
         [Parameter("Order Trigger Method", DefaultValue = StopTriggerMethod.Trade)]
         public StopTriggerMethod OrderTriggerMethod { get; set; }
         [Parameter("Limit Range (Pips)", DefaultValue = 10)]
         public double LimitRangeInPips { get; set; }
         protected override void OnStart()
         {
             PendingOrder order = null;
             if (!string.IsNullOrWhiteSpace(OrderComment) && !string.IsNullOrWhiteSpace(OrderComment))
             {
                 order = PendingOrders.FirstOrDefault(iOrder => string.Equals(iOrder.Comment, OrderComment, StringComparison.OrdinalIgnoreCase) && string.Equals(iOrder.Label, OrderLabel, StringComparison.OrdinalIgnoreCase));
             }
             else if (!string.IsNullOrWhiteSpace(OrderComment))
             {
                 order = PendingOrders.FirstOrDefault(iOrder => string.Equals(iOrder.Comment, OrderComment, StringComparison.OrdinalIgnoreCase));
             }
             else if (!string.IsNullOrWhiteSpace(OrderLabel))
             {
                 order = PendingOrders.FirstOrDefault(iOrder => string.Equals(iOrder.Label, OrderLabel, StringComparison.OrdinalIgnoreCase));
             }
             if (order == null)
             {
                 Print("Couldn't find the order, please check the comment and label");
                 Stop();
             }
             var targetPrice = TargetPrice == 0 ? order.TargetPrice : TargetPrice;
             var orderSymbol = Symbols.GetSymbol(order.SymbolName);
             var stopLossInPips = StopLossInPips == 0 ? order.StopLossPips : (double?)StopLossInPips;
             var takeProfitInPips = TakeProfitInPips == 0 ? order.TakeProfitPips : (double?)TakeProfitInPips;
             DateTime? expiryTime;
             if (string.IsNullOrWhiteSpace(Expiry))
             {
                 expiryTime = order.ExpirationTime;
             }
             else if (Expiry.Equals("0", StringComparison.OrdinalIgnoreCase))
             {
                 expiryTime = null;
             }
             else
             {
                 var expiryTimeSpan = default(TimeSpan);
                 if (!TimeSpan.TryParse(Expiry, CultureInfo.InvariantCulture, out expiryTimeSpan))
                 {
                     Print("Your provided value for expiry is not valid, please use HH:mm:ss format");
                     Stop();
                 }
                 expiryTime = expiryTimeSpan == default(TimeSpan) ? null : (DateTime?)Server.Time.Add(expiryTimeSpan);
             }
             var volumeInUnits = VolumeInLots == 0 ? order.VolumeInUnits : orderSymbol.QuantityToVolumeInUnits(VolumeInLots);
             if (order.OrderType == PendingOrderType.Limit)
             {
                 ModifyPendingOrder(order, targetPrice, stopLossInPips, takeProfitInPips, expiryTime, volumeInUnits, HasTrailingStop, StopLossTriggerMethod);
             }
             else if (order.OrderType == PendingOrderType.Stop)
             {
                 ModifyPendingOrder(order, targetPrice, stopLossInPips, takeProfitInPips, expiryTime, volumeInUnits, HasTrailingStop, StopLossTriggerMethod, OrderTriggerMethod);
             }
             else if (order.OrderType == PendingOrderType.StopLimit)
             {
                 ModifyPendingOrder(order, targetPrice, stopLossInPips, takeProfitInPips, expiryTime, volumeInUnits, HasTrailingStop, StopLossTriggerMethod, OrderTriggerMethod, LimitRangeInPips);
             }
         }
     }
 }
 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
 using cAlgo.API;
 using System;
 using System.Linq;
 namespace cAlgo.Robots
 {
     // This sample shows how to cancel a pending order
     [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
     public class PendingOrderCancelationSample : Robot
     {
         [Parameter("Order Comment")]
         public string OrderComment { get; set; }
         [Parameter("Order Label")]
         public string OrderLabel { get; set; }
         protected override void OnStart()
         {
             PendingOrder order = null;
             if (!string.IsNullOrWhiteSpace(OrderComment) && !string.IsNullOrWhiteSpace(OrderLabel))
             {
                 order = PendingOrders.FirstOrDefault(iOrder => string.Equals(iOrder.Comment, OrderComment, StringComparison.OrdinalIgnoreCase) && string.Equals(iOrder.Label, OrderLabel, StringComparison.OrdinalIgnoreCase));
             }
             else if (!string.IsNullOrWhiteSpace(OrderComment))
             {
                 order = PendingOrders.FirstOrDefault(iOrder => string.Equals(iOrder.Comment, OrderComment, StringComparison.OrdinalIgnoreCase));
             }
             else if (!string.IsNullOrWhiteSpace(OrderLabel))
             {
                 order = PendingOrders.FirstOrDefault(iOrder => string.Equals(iOrder.Label, OrderLabel, StringComparison.OrdinalIgnoreCase));
             }
             if (order == null)
             {
                 Print("Couldn't find the order, please check the comment and label");
                 Stop();
             }
             CancelPendingOrder(order);
         }
     }
 }
 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
 using cAlgo.API;
 namespace cAlgo.Robots
 {
     // This sample shows how to use PendingOrders events
     [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
     public class PendingOrderEvents : Robot
     {
         protected override void OnStart()
         {
             PendingOrders.Cancelled += PendingOrders_Cancelled;
             PendingOrders.Modified += PendingOrders_Modified;
             PendingOrders.Filled += PendingOrders_Filled;
         }
         private void PendingOrders_Filled(PendingOrderFilledEventArgs obj)
         {
             var pendingOrderThatFilled = obj.PendingOrder;
             var filledPosition = obj.Position;
         }
         private void PendingOrders_Modified(PendingOrderModifiedEventArgs obj)
         {
             var modifiedOrder = obj.PendingOrder;
         }
         private void PendingOrders_Cancelled(PendingOrderCancelledEventArgs obj)
         {
             var cancelledOrder = obj.PendingOrder;
             var cancellationReason = obj.Reason;
         }
     }
 }

Methods

ModifyStopLossPips

Summary

Shortcut for Robot.ModifyPendingOrder method to change Stop Loss

Signature

1
public abstract TradeResult ModifyStopLossPips(double? stopLossPips)

Parameters

Name Type Description
stopLossPips double? New Stop Loss value in Pips

Return Value

TradeResult

ModifyTakeProfitPips

Summary

Shortcut for Robot.ModifyPendingOrder method to change Take Profit

Signature

1
public abstract TradeResult ModifyTakeProfitPips(double? takeProfitPips)

Parameters

Name Type Description
takeProfitPips double? New Take Profit value in Pips

Return Value

TradeResult

ModifyStopLimitRange

Summary

Shortcut for Robot.ModifyPendingOrder method to change Stop Limit Range

Signature

1
public abstract TradeResult ModifyStopLimitRange(double stopLimitRangePips)

Parameters

Name Type Description
stopLimitRangePips double New Stop Limit Range value in Pips

Return Value

TradeResult

ModifyExpirationTime

Summary

Shortcut for Robot.ModifyPendingOrder method to change Expiration Time

Signature

1
public abstract TradeResult ModifyExpirationTime(DateTime? expirationTime)

Parameters

Name Type Description
expirationTime DateTime? New Expiration Time

Return Value

TradeResult

ModifyVolume

Summary

Shortcut for Robot.ModifyPendingOrder method to change VolumeInUnits

Signature

1
public abstract TradeResult ModifyVolume(double volume)

Parameters

Name Type Description
volume double New Volume in Units

Return Value

TradeResult

ModifyTargetPrice

Summary

Shortcut for Robot.ModifyPendingOrder method to change Target Price

Signature

1
public abstract TradeResult ModifyTargetPrice(double targetPrice)

Parameters

Name Type Description
targetPrice double New Target Price

Return Value

TradeResult

Cancel

Summary

Shortcut for Robot.CancelPendingOrder method

Signature

1
public abstract TradeResult Cancel()

Return Value

TradeResult

Properties

TradeType

Summary

Specifies whether this order is to buy or sell.

Signature

1
public abstract TradeType TradeType {get;}

Return Value

TradeType

Examples

1
2
 PlaceLimitOrder(TradeType.Buy, Symbol, 10000, targetPrice);
 Print(LastResult.PendingOrder.TradeType);

VolumeInUnits

Summary

Volume of this order.

Signature

1
public abstract double VolumeInUnits {get;}

Return Value

double

Examples

1
2
3
 var result = PlaceLimitOrder(TradeType.Buy, Symbol, 10000, targetPrice);
 var order = result.PendingOrder;
 Print("The order's volume is: {0}", order.VolumeInUnits);

Id

Summary

Unique order Id.

Signature

1
public abstract int Id {get;}

Return Value

int

Examples

1
2
3
 var result = PlaceLimitOrder(TradeType.Buy, Symbol, 10000, targetPrice);
 var order = result.PendingOrder;
 Print("The pending order's ID: {0}", order.Id);

OrderType

Summary

Specifies whether this order is Stop or Limit.

Signature

1
public abstract PendingOrderType OrderType {get;}

Return Value

PendingOrderType

Examples

1
2
3
 var result = PlaceLimitOrder(TradeType.Buy, Symbol, 10000, targetPrice);
 var order = result.PendingOrder;
 Print("Order type = {0}", order.OrderType);

TargetPrice

Summary

The order target price.

Signature

1
public abstract double TargetPrice {get;}

Return Value

double

Examples

1
2
 var targetPrice = Symbol.Bid;
 var result = PlaceLimitOrder(TradeType.Buy, Symbol, 10000, targetPrice);

ExpirationTime

Summary

The order Expiration timeThe Timezone used is set in the Robot attribute

Signature

1
public abstract DateTime? ExpirationTime {get;}

Return Value

DateTime?

Examples

1
2
3
 DateTime expiration = Server.Time.AddMinutes(120);
 PlaceLimitOrder(TradeType.Buy, Symbol, 10000,
     Symbol.Bid, null, 10, 10, expiration);

StopLoss

Summary

The order stop loss in price

Signature

1
public abstract double? StopLoss {get;}

Return Value

double?

Examples

1
2
3
4
 var result = PlaceLimitOrder(TradeType.Buy, Symbol, 10000,
 Symbol.Bid, null, 10, 10);
 var order = result.PendingOrder;
 Print("Order SL price = {0}", order.StopLoss);

StopLossPips

Summary

The order stop loss in pips

Signature

1
public abstract double? StopLossPips {get;}

Return Value

double?

Examples

1
2
3
4
 var result = PlaceLimitOrder(TradeType.Buy, Symbol, 10000,
                     Symbol.Bid, null, 10, 10);
 var order = result.PendingOrder;
 Print("Order SL pips = {0}", order.StopLossPips);

TakeProfit

Summary

The order take profit in price

Signature

1
public abstract double? TakeProfit {get;}

Return Value

double?

Examples

1
2
3
4
 var result = PlaceLimitOrder(TradeType.Buy, Symbol, 10000,
 Symbol.Bid, null, 10, 10);
 var order = result.PendingOrder;
 Print("Order TP price = {0}", order.TakeProfit);

TakeProfitPips

Summary

The order take profit in pips

Signature

1
public abstract double? TakeProfitPips {get;}

Return Value

double?

Examples

1
2
3
4
 var result = PlaceLimitOrder(TradeType.Buy, Symbol, 10000,
 Symbol.Bid, null, 10, 10);
 var order = result.PendingOrder;
 Print("TP Pips = {0}", order.TakeProfitPips);

Label

Summary

User assigned identifier for the order.

Signature

1
public abstract string Label {get;}

Return Value

string

Examples

1
2
3
4
5
6
7
 var result = PlaceLimitOrder(TradeType.Buy, Symbol, 10000,
 Symbol.Bid, "myLabel", 10, 10);
 if(result.IsSuccessful)
 {
     var order = result.PendingOrder;
     Print("Label = {0}", order.Label);
 }

Comment

Summary

User assigned Order Comment

Signature

1
public abstract string Comment {get;}

Return Value

string

Examples

1
2
3
4
 var result = PlaceLimitOrder(TradeType.Buy, Symbol, 10000,
                 Symbol.Bid, null, 10, 10, null, "this is a comment");
 var order = result.PendingOrder;
 Print("comment = {0}", order.Comment);

Quantity

Summary

Quantity (lots) of this order

Signature

1
public abstract double Quantity {get;}

Return Value

double

HasTrailingStop

Summary

When HasTrailingStop set to true,server updates Stop Loss every time position moves in your favor.

Signature

1
public abstract bool HasTrailingStop {get;}

Return Value

bool

Examples

1
2
 ExecuteMarketOrder(TradeType.Buy, Symbol, 10000, "myLabel", 10, 10, 2, "comment", true);
 Print("Position was opened, has Trailing Stop = {0}", result.Position.HasTrailingStop);

StopLossTriggerMethod

Summary

Trigger method for position's StopLoss

Signature

1
public abstract StopTriggerMethod? StopLossTriggerMethod {get;}

Return Value

StopTriggerMethod?

StopOrderTriggerMethod

Summary

Determines how pending order will be triggered in case it's a StopOrder

Signature

1
public abstract StopTriggerMethod? StopOrderTriggerMethod {get;}

Return Value

StopTriggerMethod?

StopLimitRangePips

Summary

Maximum limit from order target price, where order can be executed.

Signature

1
public abstract double? StopLimitRangePips {get;}

Return Value

double?

Examples

1
2
 var targetPrice = Symbol.Ask;
 var result = PlaceStopLimitOrder(TradeType.Buy, Symbol, 10000, targetPrice, 2.0);

SymbolName

Summary

Gets the symbol name.

Signature

1
public abstract string SymbolName {get;}

Return Value

string

Symbol

Summary

Gets the order symbol.

Signature

1
public abstract Symbol Symbol {get;}

Return Value

Symbol

CurrentPrice

Summary

Gets the current price of the symbol for which the pending order is placed.

Signature

1
public abstract double CurrentPrice {get;}

Return Value

double

DistancePips

Summary

Gets the distance in pips between the current price of the symbol and the target price of the pending order (via TargetPrice).

Signature

1
public abstract double DistancePips {get;}

Return Value

double

SymbolCode

Signature

1
public abstract string SymbolCode {get;}

Return Value

string

Volume

Signature

1
public abstract long Volume {get;}

Return Value

long