Count missing tick

Created at 12 Aug 2018, 12:21
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!
TH

thongbaogiaodich

Joined 19.05.2018

Count missing tick
12 Aug 2018, 12:21


Dear cTrader,

My robot has long code inside OnTick() event, so I afraid that it will missing some tick coming, and cause bad trading. How can I know my robot missed tick or not, and how can I count how many tick lost? Which method or event I shouldn't use in OnTick() to have best excute time?

Beside that, I use

if (!Positions.Any(x => x.TradeType == TradeType.Buy))
{
   // close Long pos
}

to determine TradeType and close the Position.

I also use

if (!HavePosition("Buy"))
{
   // close Long pos
}

....

        private bool HavePosition(string tradeType)
        {
            bool PosCount = false;
            int numPos = Positions.Count - 1;
            if (tradeType == "Buy")
            {
                for (int i = 0; i <= numPos; i++)
                {
                    if (Positions[i].TradeType == TradeType.Buy)
                    {
                        PosCount = true;
                        break;
                    }
                }
            }
            return PosCount;
        }

that have same job, determine TradeType and close the Position.

My question is which code has better excute time?

Thanks!


@thongbaogiaodich
Replies

PanagiotisCharalampous
13 Aug 2018, 10:08

Hi thongbaogiaodich,

No tick should be missed. OnTick() should be executed for every incoming tick. The only side effect you should worry about is that the code for some ticks might be executed with some delay.

Best Regards,

Panagiotis


@PanagiotisCharalampous

thongbaogiaodich
13 Aug 2018, 10:32

Thanks Panagiotis, Regarding reduce Tick excuting delay, return to my questions: 1. Which method or event I shouldn't use in OnTick() to have best excute time? 2. Between 2 methods above, which code has better excute time? Thanks
@thongbaogiaodich

PanagiotisCharalampous
13 Aug 2018, 10:48

Ηι thongbaogiaodich,

If you want to save time from looping through positions and checking if there are buys and sells, I would propose to use counters for buy and sell on Positions.Opened and Positions.Closed events. This way you will avoid the loops. If you want, post the cBot code and I will make the modification for you.

Best Regards,

Panagiotis


@PanagiotisCharalampous