Skip to content

ProtectionType

enum cAlgo.API Since 5.1

DesktopCLICloud

The protection type for orders and positions.

Definition

public enum ProtectionType

Namespace: cAlgo.API · Group: Trading

Examples

Example 1

var result = PlaceLimitOrder(TradeType.Buy, SymbolName, 10000, Symbol.Bid - 20 * Symbol.PipSize, "myLabel", 20, 40, ProtectionType.Relative);
if (result.IsSuccessful)
    Print("Stop loss {0}, take profit {1}", result.PendingOrder.StopLoss, result.PendingOrder.TakeProfit);
result = api.PlaceLimitOrder(TradeType.Buy, api.SymbolName, 10000, api.Symbol.Bid - 20 * api.Symbol.PipSize, "myLabel", 20, 40, ProtectionType.Relative)
if result.IsSuccessful:
    api.Print(f"Stop loss {result.PendingOrder.StopLoss}, take profit {result.PendingOrder.TakeProfit}")

Example 2

var position = Positions.Find("myLabel");
if (position != null && position.TradeType == TradeType.Buy)
{
    var pipSize = position.Symbol.PipSize;
    ModifyPosition(position, position.EntryPrice - 20 * pipSize, position.EntryPrice + 40 * pipSize, ProtectionType.Absolute);
}
position = api.Positions.Find("myLabel")
if position is not None and position.TradeType == TradeType.Buy:
    pipSize = position.Symbol.PipSize
    api.ModifyPosition(position, position.EntryPrice - 20 * pipSize, position.EntryPrice + 40 * pipSize, ProtectionType.Absolute)

Values

Name Value Description
None 0 No protection.
Relative 1 Relative or distance based protection type.
Absolute 2 Absolute or price based protection type.