Topics
20 Apr 2013, 00:48
 4297
 7
Replies

TheEconomist
23 Apr 2013, 18:21

RE:
cAlgo_Fanatic said:

To hedge all positions in the Account:

        [Parameter(DefaultValue = 100000)]
        public int Volume { get; set; }

        protected override void OnStart()
        {
            foreach (var position in Account.Positions)
            {
                if (position.TradeType == TradeType.Buy)
                {
                    Trade.CreateSellMarketOrder(Symbol, Volume);
                    //break; // optional break to hedge only one position
                }
                else
                {
                    Trade.CreateBuyMarketOrder(Symbol, Volume);
                    //break; // optional break to hedge only one position
                }
            }
        }



Thanks! I understand from the code that Positions are like market orders in MT4. Otherwise creating a Sell with the same volume of the buy as a market order would close the position. 

After the execution of the market orders, they will be incorporated in the Positions collection, am I correct?


@TheEconomist

TheEconomist
23 Apr 2013, 12:24

RE:
cAlgo_Fanatic said:

OnPositionOpened is triggered when the pending order is filled. Positions do represent market orders. Do you need help with the code to do hedging?

Yes, do you have a sample?


@TheEconomist