/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { bars.update(); var nextFilt = filter.next((bars.High + bars.Low) * 0.5); var slope = linreg.next(nextFilt); if ((nextFilt > lastFilt) && (slope <= 0)) { ProxyLine.Set(lastProxy); } else if ((nextFilt < lastFilt) && (slope >= 0)) { ProxyLine.Set(lastProxy); } else { // either everything is flat, or the // med and slope agree... bool assumeUp = (slope > 0); if (slope == 0) { if (nextFilt != lastFilt) { assumeUp = (nextFilt > lastFilt); } else { assumeUp = dirUp; } } if (assumeUp) { ProxyLine.Set(Math.Max(lastProxy, nextFilt)); } else { ProxyLine.Set(Math.Min(lastProxy, nextFilt)); } } var newDirUp = dirUp; if (ProxyLine[0] > lastProxy) { newDirUp = true; } else if (ProxyLine[0] < lastProxy) { newDirUp = false; } bool upbar = bars.Close > bars.Open; bool dnbar = bars.Close < bars.Open; // if we're based on bars, use the actual bars themselves, too... if (onBasicBars) { upbar = upbar || (Close[0] > Open[0]) || (High[0] == Close[0]); dnbar = dnbar || (Close[0] < Open[0]) || (Low[0] == Close[0]); } double upRefLoc = 0; double dnRefLoc = 0; if (onBasicBars) { upRefLoc = High[0]; dnRefLoc = Low[0]; } else { upRefLoc = Input[0]; dnRefLoc = Input[0]; } // exceptions that hold the proxy in place for a bit... if ((!newDirUp && dirUp && upbar) || (newDirUp && !dirUp && dnbar) || (!newDirUp && dirUp && (lastProxy <= (upRefLoc + actualTolerance))) || (newDirUp && !dirUp && (lastProxy >= (dnRefLoc - actualTolerance))) || ((ProxyLine[0] > lastProxy) && (dnbar || (upRefLoc < ProxyLine[0]))) || ((ProxyLine[0] < lastProxy) && (upbar || (dnRefLoc > ProxyLine[0]))) ) { newDirUp = dirUp; ProxyLine.Set(lastProxy); } PlotColors[0][0] = (newDirUp?upColor:dnColor); dirUp = newDirUp; lastFilt = nextFilt; lastProxy = ProxyLine[0]; }