Multiple duplicate position Opened -- Issue

Created at 17 Jul 2018, 10: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!
10

1001606

Joined 17.07.2018

Multiple duplicate position Opened -- Issue
17 Jul 2018, 10:22


Hi All,

Please Help.

As per the script below, there should only be one trade execute at a spacing of 10 pips when the price is above EMA XX.. it has been working fine for the past year, but it seems that there is some issue on the starting of this weeks, which open up hundreds of duplicate position.

 

Is there anything wrong with the script or is a one time off bug ?

https://pepperstone.ctrader.com/images/screens/L0S6n.png

 



namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.EasternStandardTime)]
    public class xxx : Robot
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }

        [Parameter("Periods", DefaultValue = xx)]
        public int Periods { get; set; }

        [Parameter("Order Spacing (pips)", DefaultValue = 10, MinValue = 1)]
        public double OrderSpacing { get; set; }

        [Parameter("Volume", DefaultValue = 1000, MinValue = 1)]
        public int Volume { get; set; }

        private ExponentialMovingAverage ema;

        protected override void OnStart()
        {
            ema = Indicators.ExponentialMovingAverage(Source, Periods);
        }

        protected override void OnTick()
        {
            if (Trade.IsExecuting)
                return;

            double lastEma = ema.Result.Last(1);

            if (Symbol.Ask > lastEma)
            {
                OpenPosition(TradeType.Buy, OrderSpacing * Symbol.PipSize);
            }
            else
            {
                OpenPosition(TradeType.Buy, OrderSpacing * Symbol.PipSize * 100);
                //OpenPosition(TradeType.Buy, OrderSpacing);
            }
        }

        private void OpenPosition(TradeType tradeType, double orderSpacing)
        {
            foreach (Position position in Positions.FindAll("xxx"))
            {
                if ((Symbol.Ask - orderSpacing) <= position.EntryPrice && (Symbol.Ask + orderSpacing) >= position.EntryPrice)
                {
                    //Print("Open Positions: {0}", Positions.Count);
                    return;
                }
            }
        }
    }
}


@1001606
Replies

ctid418503
18 Jul 2018, 23:32

Hi 1001606,

Sometimes I see (fairly regularly actually - every few months) in my broker's tick data massive swings up to 50 pips one way and 50 pips back many times within the same second.  I've always wondered if this was genuine or not.  But anyway, because of this I now never code anything which can be affected by that because it can wipe out a real account balance in a few seconds.

Consider adding a time spacing as well/instead of a pip spacing rule, or literally just make it so only one position can be open at one time for that Symbol & Cbot Label.

It seems impossible for this to happen so I suspected the broker's tick data was manipulated or corrupted, however, I have seen some realtime price movements swinging wildly one way and the other within the same second, so I am not sure.

ZZ


@ctid418503

ctid418503
18 Jul 2018, 23:34

Actually, just making sure that only one position can be open at a time would not work because your SL/TP could be hit again and again within the same second too.  You just need to get out of the market when price is acting like that.


@ctid418503

weiss_omi
26 Jul 2018, 17:39

Hi 418503,

Thanks for sharing your experience. But when the script is tested in the back-testing, it is working fine.

And this infrequent event seems to put the account at risk of being wipe out. 


@weiss_omi

ctid418503
27 Jul 2018, 13:59

Hi weiss_omi,

Can you say whether you are backtesting with M1 or tick data?  You would not see the effect I am talking about in backtesting if you are using M1 data, but you would see it if you are using Tick Data.  Interestingly my broker is also Pepperstone.


@ctid418503