I use IQFeed, and have noticed that they consistently send bad ticks which can be removed by using the "Force Backfill" function.
However, I must first detect these bad ticks before I can click the Force Backfill button.
Here's my experimental code for detecting and adjusting these bad ticks.
This code looks for wicks that are 5 times larger than the body and also 2 times larger than the ATR, and replaces the High and Low arrays with the median value of the past 3 bars.
I would appreciate any ideas about detecting them better, or optimizing the function so it runs as fast as possible.
// Experimental code to fix bad wicks from IQFeed.
// Coded by Peter Deal
// 20230524
function FixBadWicks()
{
// To smooth out bad ticks from the H/L fields using a 3-bar median. Assumes that O and C fields are ok.
// 20230524
CBT = Max( O, C ); // candle body top
CBB = Min( O, C ); // candle body bottom
Body = CBT - CBB;
WickT = H - CBT;
WickB = CBB - L;
ATR10 = Ref( ATR(10), -1 );
TestT = WickT > 5 * Body AND WickT > 2 * ATR10;
TestB = WickB > 5 * Body AND WickB > 2 * ATR10;
H = IIf( TestT, Median( Ref( H, -1 ), 3 ), H );
L = IIf( TestB, Median( Ref( L, -1 ), 3 ), L );
return TestT OR TestB;
}
SetBarFillColor( colorLightOrange );
Plot( C, "Close", colorLightOrange, styleCandle | styleNoLabel | styleNoTitle, Null, Null, Null, -1 );
FixBadWicks();
Plot( C, "Close", colorDefault, styleCandle, Null, Null, Null, 0 );
Many thanks!