Realistic sanity check: Eliminate AtLimit order when Low hits buy limit price
Author: 123blee9
Creation Date: 8/25/2017 6:48 PM
profile picture

123blee9

#1
I am modeling a stock using 60-min bars along with buy limit and sell limit prices. Given there are many instances of price lows hitting my buy limit prices and price highs hitting my sell limit prices that never actually fill in real trading, my goal is to eliminate any such simulated backtesting trades whereby long entries never occur exactly at a bar's low price and long exits never occur exactly at the bar's high price.

As such, I simply added a condition that checks to see if the next bar's low occurs exactly at the model's buy limit price if currently flat (if true, no long position is taken in the simulation). I performed something similar with long exits using high prices, though I will focus just on the long entry side.

My code for the conditional backtested market entry is provided below.

Oddly, simulated long entry (exit) trades are still taken exactly a bar's low (high) price in the event the 2 prices coincide on the same bar. It's important to note that many trades which were meant to be skipped were skipped, while others were not.

When I change "<" to "==" in the code below, it appears to eliminate the trades that should have been eliminated when using "<." It also appears to reinstate those that were eliminated correctly using the "<" sign.

It seems simple enough, though my coding error escapes me. My guess is it has something to do with rounding.

Prices are rounded to 2 decimals in Preferences.



CODE:
Please log in to see this code.
profile picture

Eugene

#2
Brian,

Have you tried "Turn off limit/stop order rounding entirely" in Preferences > Backtest Settings?
profile picture

123blee9

#3
Hi Eugene,

That had an impact of lowering overall equity (not sure why when price decimal rounding = 2 and limit orders are rounding to 2 decimals ), though several instances of buying at the low and selling at the high still remain.

See attached as an example.
profile picture

123blee9

#4
I think I just figured it out.

I need to additionally eliminate long entries (exists) where "Bar +1" Open = "Bar +1" Low (High).



I just completed the correction. That eliminates over 99% of the original equity.

I highly recommend intraday, limit order traders use this technique.

The BuyLimit code changes to the below.

CODE:
Please log in to see this code.
profile picture

Eugene

#5
I have a hard time understanding all this peeking into the future, first with SellAtLimit (while the following BuyAtLimit may trigger before it since the order of High/Low is unknown for EOD data without special tricks), then peeking at the Low[bar+1] (which becomes available only when the following bar+2 starts) and jumping in the past at bar+1 to buy. It may make sense with SetTimeOfDayPriority applied or on after a rewrite to use on intraday data, though.
profile picture

123blee9

#6
It's not a trading technique; rather, it's simply a sanity check of the viability of an intraday model. My model indicated a cumulative equity of $4.5 billion (with a B). Since intraday fills at bar highs/lows are suspect (even in 10+ million share markets traded daily in my personal experience), I desire a more realistic view of model's potential to actually trade. That is, assume no fills at intraday bar highs/lows. Such analysis indicates I should not trade this model, as 99+% of the equity is generated assuming the bulk of the trade fills occur at bar highs/lows. Without looking into the future, I would not be able to reach this conclusion.