How to know a position was closed by a stop loss?
Created at 25 Mar 2020, 04:55
CT
How to know a position was closed by a stop loss?
25 Mar 2020, 04:55
Hi,
I would like to change the value of a variable after a position is closed by a stop loss.
How can I check my position was closed by a stop loss?
Replies
ctid444989
31 Mar 2020, 05:20
RE: Thank you.
PanagiotisCharalampous said:
Hi,
You can use PositionCloseReason to check if a position is closed by a stop loss. See below
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class NewcBot : Robot { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } protected override void OnStart() { Positions.Closed += Positions_Closed; } private void Positions_Closed(PositionClosedEventArgs obj) { if (obj.Reason == PositionCloseReason.StopLoss) { } } protected override void OnTick() { // Put your core logic here } protected override void OnStop() { // Put your deinitialization logic here } } }
Best Regards,
Panagiotis
@ctid444989
PanagiotisCharalampous
26 Mar 2020, 09:01
Hi,
You can use PositionCloseReason to check if a position is closed by a stop loss. See below
Best Regards,
Panagiotis
Join us on Telegram
@PanagiotisCharalampous