Click or drag to resize

SignalOnCalculate Method (MarketDataEventArgs, Int32, SignalDirection)

Override in inherited class to implement calculation (validation) of signals based on Level 1 market data.

Namespace:  MZpack.NT8.Algo
Assembly:  MZpack.NT8.Pro (in MZpack.NT8.Pro.dll) Version: 3.18.1.0 (3.18.1.0)
Syntax
C#
public override void OnCalculate(
	MarketDataEventArgs e,
	int barIdx,
	SignalDirection allowed
)

Parameters

e
Type: MarketDataEventArgs
Level 1 market data event.
barIdx
Type: SystemInt32
Current bar index. For signals calculated on bar barIdx is the index of just closed bar, but e belongs to the next bar.
allowed
Type: MZpack.NT8.AlgoSignalDirection
Allowed direction of the signal. When OnCalculate() is called for filters (ie. for signals from filters tree), allowed is equal to the direction of validated signals tree. Use allowd to optimize the calculation.
Examples
C#
public override void OnCalculate(MarketDataEventArgs e, int barIdx, SignalDirection allowed)
{
    IFootprintBar _bar;
    if (indicator.FootprintBars.TryGetValue(barIdx, out _bar))
    {
        int buyAbsCnt = _bar.AbsorptionSRZones.Zones[(int)TradeSide.Ask].Count;
        int sellAbsCnt = _bar.AbsorptionSRZones.Zones[(int)TradeSide.Bid].Count;

        SignalDirection dir;
        if (buyAbsCnt > 0 && sellAbsCnt == 0)
            dir = SignalDirection.Short;
        else
        if (sellAbsCnt > 0 && buyAbsCnt == 0)
            dir = SignalDirection.Long;
        else
            dir = SignalDirection.None;

        dir = Signal.ResolveDirection(dir, allowed);  // Resolve calculated direction using allowed one.

        if (Signal.IsDetermined(dir))  // This signal must be LONG or SHORT only.
        {
            Direction = dir;
            Time = e.Time;
           EntryPrice = e.Price;
            ChartRange = new ChartRange() { MinBarIdx = barIdx, MaxBarIdx = barIdx, Low = e.Price, High = e.Price };
            Description = $"{GetType().Name}: Buy absoprtion zone(s) {buyAbsCnt}, Sell absoprtion zone(s) {sellAbsCnt}";

            bar = _bar;
           // Show plots of the signal in partially visible mode during pattern validation process
            bar.PartiallyVisible = true;
        }
    }
}
See Also