Occurs when the new position was placed (after order execution). Can be used when parameters are changed or position is closed.


SYNTAX


public event Action<Position> PositionAdded


EXAMPLE


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using PTLRuntime.NETScript;

namespace PositionCollection_
{
    public class PositionCollection_:NETStrategy
    {
        Instrument instr;
        Account acc;
        NewOrderRequest request;
        Position lastPosByOrder, lastPos;
       
        string ordID = "-1", posID;

        public override void Init()
        {
            instr = Instruments.Current;
            acc = Accounts.Current;

            Positions.PositionAdded += OnNewPosition;
            
            Instruments.Subscribe(instr, QuoteTypes.Quote);
        }

        private void OnNewPosition(Position pos)
        {
            Alert("Added position with ID " + pos.Id);
        }

        public override void OnQuote()
        {
            if (ordID == "-1")
            {
                request = new NewOrderRequest
                {
                    Instrument = instr,
                    Account = acc,
                    Side = Operation.Buy,
                    Type = OrdersType.Market,
                    Price = instr.LastQuote.Ask,
                    Amount = 1,
                    TimeInForce = TimeInForce.GTC,
                    MarketRange = 1000,
                };

                ordID = Orders.Send(request);

                if (ordID == "-1")
                {
                    Alert("Order was't open, error: " + GetLastError());
                    return;
                }
                else
                {
                    lastPosByOrder = Positions.GetPositionByOpenOrderId(ordID);
                    posID = lastPosByOrder.Id;
                    Alert("Order set on price: " + lastPosByOrder.OpenPrice);
                }
            }
        }


        public override void Complete()
        {

            bool closeByAcc = Positions.CloseAllByAccount(acc);

            Positions.PositionAdded -= OnNewPosition;

            Instruments.Unsubscribe(instr, QuoteTypes.Quote);
        }
    }
}