Filling at an extreme price - way above the high of the bar?

qumentaqumenta Posts: 10
edited April 2018 in Support

Getting an entry way above the high of the bar. What 's it happening there?

How must I deal with it? Makes my backtest invalid if it is a common error in the database.

Please look at chart in dropbox link

https://www.dropbox.com/s/3t5wpdah84vt7o5/Captura de pantalla 2018-04-12 14.55.12.png?dl=0

Tagged:

Comments

  • ptunneyptunney Posts: 246
    edited April 2018

    You didnt give us a symbol or a date, but looking at the chart, the time is 9:31.
    Is it possible you are attempting to trade before the open (or even at the open without an opening auction order)?

    If you place any order at any time and the bid or ask is "way out" the sim will fill you based on the bid/ask at the time.

    If there is no bid or ask then they can often be set by default to 0 and 199999.99 and you will be filled at these prices.

    Depending on the type of model you are writing it is often good practice to ensure the spread is not too large

    md.L1.ask-md.L1.bid<md.stat.prev_close*0.01 # spread is less than 1% of the close price.

    You do not want to get into the habit of loosely sending out market orders without checking bid, ask and spread, particularly with HFT algo's around!

    Run the code below to see all symbols on a particular day that still have not opened after 9:31 with a spread of more than 5% of the previous close...

    # CQ ELITE SCRIPT : USES ON_TRADE
    # Note that md.L1.open does not contain the opening print, it is simply the first print after 9:30 
    # md.L1.opening_print is the actual O print and is nan until md.L1.trade_condition contains an 'O'
    
    from cloudquant.interfaces import Strategy
    
    class Open_Test(Strategy):
    
        @classmethod
        def is_symbol_qualified(cls, symbol, md, service, account):
            return True
    
        def on_trade(self, event, md, order, service, account):
            if "O" in md.L1.trade_condition:
                service.terminate()
            elif event.timestamp>service.time(9,31) and event.timestamp<service.time(9,35) and (md.L1.ask-md.L1.bid)>md.stat.prev_close*0.05:
                print ("%s\t %s\t Last:%8.2f\t Ask:%8.2f\t Bid:%8.2f\t Open:%8.2f\t OpeningTrade:%8.2f\t TradeCondition:%s" %(service.time_to_string(event.timestamp),self.symbol,md.L1.last,md.L1.ask,md.L1.bid,md.L1.open, md.L1.opening_trade, md.L1.trade_condition))
    

    Sample Output

    09:31:00.948     BAC-L   Last: 1281.48   Ask: 1650.49    Bid: 1225.84    Open: 1281.48   OpeningTrade:     nan   TrdCd:@
    09:31:01.870     LGC     Last:    9.60   Ask:   10.60    Bid:    9.52    Open:     nan   OpeningTrade:     nan   TrdCd:I
    09:31:04.485     ALL-A   Last:   25.16   Ask:   32.48    Bid:   18.28    Open:     nan   OpeningTrade:     nan   TrdCd:I
    09:31:14.283     NVMM    Last:    3.40   Ask:    3.93    Bid:    3.40    Open:    3.40   OpeningTrade:     nan   TrdCd:@
    09:31:15.362     RRTS    Last:    2.61   Ask:    2.80    Bid:    2.61    Open:    2.75   OpeningTrade:     nan   TrdCd:@
    09:31:15.362     RRTS    Last:    2.64   Ask:    2.80    Bid:    2.61    Open:    2.75   OpeningTrade:     nan   TrdCd:@
    09:31:26.625     MRRL    Last:   15.15   Ask:   17.15    Bid:   15.15    Open:   15.23   OpeningTrade:     nan   TrdCd:I
    09:31:35.004     MX      Last:    9.40   Ask:    9.95    Bid:    9.40    Open:    9.50   OpeningTrade:     nan   TrdCd:@
    09:31:35.004     MX      Last:    9.40   Ask:    9.95    Bid:    9.40    Open:    9.50   OpeningTrade:     nan   TrdCd:@
    09:31:35.004     MX      Last:    9.40   Ask:    9.95    Bid:    9.40    Open:    9.50   OpeningTrade:     nan   TrdCd:@
    09:31:35.004     MX      Last:    9.40   Ask:    9.95    Bid:    9.40    Open:    9.50   OpeningTrade:     nan   TrdCd:@
    09:31:35.004     MX      Last:    9.40   Ask:    9.95    Bid:    9.40    Open:    9.50   OpeningTrade:     nan   TrdCd:@
    09:31:45.002     LKSD    Last:   16.25   Ask:   17.15    Bid:   15.20    Open:   16.25   OpeningTrade:     nan   TrdCd:@
    09:31:45.774     MKC.V   Last:  109.50   Ask:  111.82    Bid:  102.95    Open:     nan   OpeningTrade:     nan   TrdCd:I
    09:31:48.388     MKC.V   Last:  109.49   Ask:  109.49    Bid:  102.96    Open:     nan   OpeningTrade:     nan   TrdCd:I
    09:32:00.197     TAGS    Last:   23.92   Ask:   25.48    Bid:   22.96    Open:     nan   OpeningTrade:     nan   TrdCd:I
    09:32:12.552     BBDO    Last:   10.75   Ask:   13.48    Bid:   10.75    Open:   10.64   OpeningTrade:     nan   TrdCd:@
    09:32:27.089     CCI-A   Last: 1120.61   Ask: 1120.61    Bid: 1036.32    Open:     nan   OpeningTrade:     nan   TrdCd:F I
    
Sign In or Register to comment.