GomDeltaIndicator : GomRecorderIndicator
{
#region Variables
private GomCDCalculationModeType calcMode = GomCDCalculationModeType.BidAsk;
private bool backupMode = true;
private GomFilterModeType filterMode = GomFilterModeType.None;
private int filterSize = 1;
private int filterSizeHigher = 1;
private int filterSizeLower = 1;
private double lastprice = 0;
private int lastdirection = 0;
private bool startlookingforreversal = false;
private int bypassDelta = 0;
[Browsable(false)]
public int ByPassDelta { get {return bypassDelta;}}
#endregion
protected int CalcDelta(Gom.MarketDataType e)
{
return CalcDelta(e.TickType,e.Price,e.Volume,calcMode,bac kupMode,filterSize,filterMode);
}
protected int CalcDelta(TickTypeEnum tickType, double price, int volume)
{
return CalcDelta(tickType, price, volume, calcMode, backupMode, filterSize, filterMode);
}
private int CalcDelta(TickTypeEnum tickType, double price, int volume, GomCDCalculationModeType calcmode, bool backupmode, int filtersize, GomFilterModeType filtermode)
{
int delta = 0;
int direction = lastdirection;
bypassDelta = 0;
if ((calcmode == GomCDCalculationModeType.BidAsk) && (tickType != TickTypeEnum.Unknown) && (tickType != TickTypeEnum.BetweenBidAsk))
{
if ((tickType == TickTypeEnum.BelowBid) || (tickType == TickTypeEnum.AtBid))
delta = -volume;
else if ((tickType == TickTypeEnum.AboveAsk) || (tickType == TickTypeEnum.AtAsk))
delta = volume;
}
else if (calcmode == GomCDCalculationModeType.UpDownTick)
{
if (lastprice != 0)
{
if (price > lastprice) delta = volume;
if (price < lastprice) delta = -volume;
}
}
else if ((calcmode == GomCDCalculationModeType.UpDownTickWithContinuatio n) ||(calcmode == GomCDCalculationModeType.UpDownOneTickWithContinua tion)|| ((calcmode == GomCDCalculationModeType.BidAsk) && (backupmode == true)))
{
if (price > lastprice) //normal uptick/dn tick
direction = 1;
else if (price < lastprice)
direction = -1;
if (calcmode == GomCDCalculationModeType.UpDownOneTickWithContinua tion)
delta=direction;
else
delta = direction * volume;
}
// added
else if ((calcmode == GomCDCalculationModeType.Hybrid))
{
if (price > lastprice) //normal uptick/dn tick
{
direction = 1;
//price changed, we reinit the startlookingforreversal bool.
startlookingforreversal = false;
}
else if (price < lastprice)
{
direction = -1;
startlookingforreversal = false;
}
if (!startlookingforreversal)
if (direction == 1)
//if going up, we want to be hitting bid to be able to start to spot reversals (hitting the ask)
startlookingforreversal = (tickType == TickTypeEnum.AtBid) || (tickType == TickTypeEnum.BelowBid);
else
startlookingforreversal = (tickType == TickTypeEnum.AtAsk) || (tickType == TickTypeEnum.AboveAsk);
//what happens when price is same
if (price == lastprice)
{
//if going up, and we have already hit the bid (startlookingforreversal is true) at a price level,
// and start hitting the ask, let's reverse
if ((direction == 1) && startlookingforreversal && ((tickType == TickTypeEnum.AtAsk) || (tickType == TickTypeEnum.BetweenBidAsk)))
direction = -1;
else if ((direction == -1) && startlookingforreversal && ((tickType == TickTypeEnum.AtBid) || (tickType == TickTypeEnum.BetweenBidAsk)))
direction = 1; //buyers take control of ask
}
delta = direction * volume;
}
lastprice = price;
lastdirection = direction;
if ((filtermode == GomFilterModeType.OnlyLargerThan) && (volume <= filtersize))
{
bypassDelta = delta;
delta = 0;
}
if ((filtermode == GomFilterModeType.OnlySmallerThan) && (volume >= filtersize))
{
bypassDelta = delta;
delta = 0;
}
if ((filtermode == GomFilterModeType.InBetween) && ((volume >= filterSizeHigher) || (volume <= filterSizeLower)))
{
bypassDelta = delta;
delta = 0;
}
return delta;
}[/HTML]
Comment