Unsubscribe Positions.Closed Event
Created at 18 May 2015, 22:33
Unsubscribe Positions.Closed Event
18 May 2015, 22:33
Once an event has been added to be triggered when a position is closed, how can the event be removed?
Even after I use:
Positions.Closed -= OnPositionsClosed;
the event still fires.
The example below demonstrates the problem. Items closed by this line should NOT be reopened!
foreach (var position in Positions) ClosePosition(position);
using System; using cAlgo.API; using cAlgo.API.Internals; namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class MoneySalad : Robot { int ii = 0; protected override void OnStart() { Positions.Closed += OnPositionsClosed; ExecuteMarketOrder(TradeType.Buy, Symbol, Symbol.NormalizeVolume(100000, RoundingMode.ToNearest), "Initial", null, null, null, "Initial"); ExecuteMarketOrder(TradeType.Buy, Symbol, Symbol.NormalizeVolume(100000, RoundingMode.ToNearest), "Initial", null, null, null, "Initial"); ExecuteMarketOrder(TradeType.Buy, Symbol, Symbol.NormalizeVolume(100000, RoundingMode.ToNearest), "Initial", null, null, null, "Initial"); } protected override void OnTick() { if (ii++ > 30) { ii = 0; Positions.Closed -= OnPositionsClosed; foreach (var position in Positions) ClosePosition(position); Positions.Closed += OnPositionsClosed; } } private void OnPositionsClosed(PositionClosedEventArgs args) { var position = args.Position; ExecuteMarketOrder(position.TradeType, MarketData.GetSymbol(position.SymbolCode), 100000, "Mart_" + position.Id, null, null, null, "Mart_" + position.Id); } } }
Spotware
16 Jun 2015, 17:25
Dear Trader,
Thank you for noticing this. Our Team will investigate.
@Spotware