Any ideas to code a reference to the price of the last filled position?

Created at 16 May 2014, 22:22
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
LE

leo8three

Joined 14.05.2014

Any ideas to code a reference to the price of the last filled position?
16 May 2014, 22:22


Hello everybody,

  I'm a very beginner in this field, but I'd like to create a robot that can open new positions following the trend, based on a pip step, set by the GUI:

        protected override void OnTick()
        {
            var bid = Symbol.Bid;
            var ask = Symbol.Ask;
            var pipsize = Symbol.PipSize;
            var longPosition = Positions.Find(label, Symbol, TradeType.Buy);
            var shortPosition = Positions.Find(label, Symbol, TradeType.Sell);
            var lastPrice = // at this point I need help..  "lastPrice" is intended as the price the last position was filled in.
            
            if (Trade.IsExecuting)
            {
                return;
            }
            
            if (longPosition != null && bid >= (lastPrice + pipsize * Trigger)) //Trigger is the number of pips, set by the GUI; by the way, i think this code line isn't correct

                ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, label);

            else if    // and so on

        } 

The first position is intended to be generated by a buy/sell signal (by the most common indicators), whereas the following are generated by this code.

Closing signal can be set by other indicators or equity amount (for simplicity I assume this robot will work alone...).

Thank you for attention :-)

 

leo8three


@leo8three