Alternative to the missing event "OnPendingOrderDeleted"?
            
                 20 Jan 2014, 17:16
            
                    
Hi guys. If after a period of 2 hours my Stop Order was deleted (expiry time = 2 in PlaceStopOrder () ), then I want to set a counter variable to zero. Unfortunately there is no event like OnPendingOrderDeleted. Any idea how I could it solve otherwise?
Replies
                     Old Account
                     21 Jan 2014, 09:51
                                    
You think somethin like this would work?
        private int _ExpTime;
        private int _Counter;
        private bool _PosOpend;
        protected override void OnStart()
        {
            Positions.Opened += OnPositionsOpened;
        }
        protected override void OnTick()
        {
            if (Symbol.Ask == Symbol.Bid)
            {
                PlaceStopOrder(TradeType.Sell, Symbol, 1000, Symbol.Ask, "Lable", 10, 10, DateTime.Now.AddHours(2));
                _ExpTime = Server.Time.Hour + 2;
                _PosOpend = false;
            }
            if (_ExpTime == Server.Time.Hour && !_PosOpend)
                _Counter = 0;
            else
                _Counter = _Counter + 1;
        }
        private void OnPositionsOpened(PositionOpenedEventArgs args)
        {
            _PosOpend = true;
        }
@Old Account
                     Old Account
                     21 Jan 2014, 09:56
                                    
RE:
The if should be if(....)
if (Symbol.Ask == Symbol.Bid)
You think somethin like this would work?
private int _ExpTime; private int _Counter; private bool _PosOpend; protected override void OnStart() { Positions.Opened += OnPositionsOpened; } protected override void OnTick() { if (Symbol.Ask == Symbol.Bid) { PlaceStopOrder(TradeType.Sell, Symbol, 1000, Symbol.Ask, "Lable", 10, 10, DateTime.Now.AddHours(2)); _ExpTime = Server.Time.Hour + 2; _PosOpend = false; } if (_ExpTime == Server.Time.Hour && !_PosOpend) _Counter = 0; else _Counter = _Counter + 1; } private void OnPositionsOpened(PositionOpenedEventArgs args) { _PosOpend = true; }
@Old Account
                     Old Account
                     21 Jan 2014, 10:44
                                    
if (_ExpTime == Server.Time.Hour && !_PosOpend)
        _Counter = 0;
    else
        _Counter = _Counter + 1;
Should be:
if (_ExpTime == Server.Time.Hour && !_PosOpend)
        _Counter = 0;
If(_ExpTime == Server.Time.Hour &&_PosOpend
I think
@Old Account
                     Old Account
                     21 Jan 2014, 10:46
                                    
RE:
MRSV said:
if (_ExpTime == Server.Time.Hour && !_PosOpend) _Counter = 0; else _Counter = _Counter + 1;Should be:
if (_ExpTime == Server.Time.Hour && !_PosOpend) _Counter = 0; If(_ExpTime == Server.Time.Hour &&_PosOpendI think
if (_ExpTime == Server.Time.Hour && !_PosOpend)
        _Counter = 0;
If(_ExpTime == Server.Time.Hour &&_PosOpend)
_Counter = _Counter + 1;
*
@Old Account
                     fzlogic
                     21 Jan 2014, 12:27
                                    
using System;
using System.Linq;
using cAlgo.API;
namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC)]
    public class NewRobot : Robot
    {
        private int _counter;
        [Parameter(DefaultValue = 5000)]
        public int Volume { get; set; }
        [Parameter(DefaultValue = 1)]
        public int expMinutes { get; set; }
        protected override void OnTick()
        {
            if (_counter < 2)
            {
                PlaceStopOrder(TradeType.Sell, Symbol, Volume, Symbol.Ask - Symbol.PipSize * 10, 
                          "Lable", 10, 10, Server.Time.AddMinutes(expMinutes));
                _counter++;
                Print(_counter);
            }
            else
            {
                var pendingOrder = PendingOrders.FirstOrDefault(order => order.Label == "Lable");
                if (pendingOrder == null)
                {
                    Position position = Positions.Find("Lable");
                    if (position == null)
                    {
                        _counter = 0;
                        Print("order expired counter = {0}", _counter);
                    }
                }
            }
        }
    }
}
@fzlogic

Spotware
21 Jan 2014, 09:07
We are planning to enhance the API with more trading event handlers. For the time being you can check if the pending order exists by setting a label when it is placed. If there is no position and no order with this label then it has expired.
@Spotware