Trail Stop (trail.stop
) 🛑¶
Stops a local trailing stop previously started with trail.start
.
This cancels the client‑side trailing loop for a given position. No server RPC is required.
Alias: trstop
Purpose¶
- Cancel the active trailing logic for a specific position ticket.
- Useful when you no longer want SL to auto‑adjust.
Usage đź’»¶
dotnet run -- trail.stop -p demo -t 123456
Input Parameters ⬇️¶
Parameter | Type | Required | Description |
---|---|---|---|
--profile , -p |
string | yes | Profile name (from profiles.json ). |
--ticket , -t |
ulong | yes | Position ticket (numeric ID). |
Output ⬆️¶
Text
âś” trailing stopped for #<ticket>
— success (exit code0
).No active trailing for #<ticket>
— nothing to stop (exit code2
).- Errors are printed with details; fatal error sets exit code
1
.
Notes & Safety 🛡️¶
- Trailing is client‑side — it runs only while your app/CLI is running.
- Stopping a trailer does not modify SL/TP on the server; it only stops further automatic updates.
- You can manually adjust SL/TP afterwards using Modify or Position.modify.points.
Method Signatures¶
// Preferred, if implemented in service layer
public void StopTrailing(ulong ticket)
{
if (_activeTrails.TryRemove(ticket, out var cts))
¶
// Preferred, if implemented in service layer
public void StopTrailing(ulong ticket)
{
if (_activeTrails.TryRemove(ticket, out var cts))
Code Reference đź§©¶
var trTicketOpt = new Option<ulong>(new[] { "--ticket", "-t" }, "Position ticket") { IsRequired = true };
var trailStop = new Command("trail.stop", "Stop local trailing stop for a position");
trailStop.AddOption(profileOpt);
trailStop.AddOption(trTicketOpt);
trailStop.SetHandler((string profile, ulong ticket) =>
{
Validators.EnsureProfile(profile);
Validators.EnsureTicket(ticket);
if (StopTrailingLocal(ticket))
Console.WriteLine($"\u2714 trailing stopped for #{ticket}");
else
{
Console.WriteLine($"No active trailing for #{ticket}");
Environment.ExitCode = 2;
}
}, profileOpt, trTicketOpt);
// Helper in Program:
static readonly ConcurrentDictionary<ulong, CancellationTokenSource> _trailSessions = new();
static bool StopTrailingLocal(ulong ticket)
{
return _trailSessions.TryRemove(ticket, out var cts) && TryCancel(cts);
}
static bool TryCancel(CancellationTokenSource cts)
{
try { cts.Cancel(); return true; } catch { return false; }
}
See also¶
- Trail.start — start a local trailing session
- Modify — set SL/TP by absolute price
- Position.modify.points — set SL/TP by distance in points
- Subscribe — streaming quotes used by trailing