/// <summary> /// Called when the order has been filled during the bar update. /// </summary> /// <param name="currentBar">Current bar of the simulation for the order</param> /// <returns>True if the order was closed</returns> public override bool OnUpdate(int currentBar) { // Don't sell if the indicator is wobbily. if (_order.BuyBar >= currentBar - 2) { return(false); } TickerData data = _order.Ticker; double crossoverValue = _series2 != null ? _series2[currentBar] : _value; if (_crossoverType == CrossoverType.Above && ((_series2 == null && DataSeries.CrossAbove(_series1, crossoverValue, currentBar, 0) != -1) || (_series2 != null && DataSeries.CrossAbove(_series1, _series2, currentBar, 0) != -1))) { _order.Sell(data.Close[currentBar], currentBar, "Cross Above"); return(true); } else if (_crossoverType == CrossoverType.Below && ((_series2 == null && DataSeries.CrossBelow(_series1, crossoverValue, currentBar, 0) != -1) || (_series2 != null && DataSeries.CrossBelow(_series1, _series2, currentBar, 0) != -1))) { _order.Sell(data.Close[currentBar], currentBar, "Cross Below"); return(true); } // Didn't sell. return(false); }
/// <summary> /// Called on every new bar of data. /// </summary> /// <param name="currentBar">The current bar of the simulation</param> protected override void OnBarUpdate(int currentBar) { base.OnBarUpdate(currentBar); Dmi ind = (Dmi)Dependents[0]; if (DataSeries.CrossBelow(ind.Value, 0, currentBar, 0) != -1) { WasFound[currentBar] = true; } }
/// <summary> /// Called on every new bar of data. /// </summary> /// <param name="currentBar">The current bar of the simulation</param> protected override void OnBarUpdate(int currentBar) { base.OnBarUpdate(currentBar); Bollinger ind = (Bollinger)Dependents[0]; if (DataSeries.CrossBelow(Data.Close, ind.Lower, currentBar, 0) != -1) { WasFound[currentBar] = true; } }
/// <summary> /// Called on every new bar of data. /// </summary> /// <param name="currentBar">The current bar of the simulation</param> protected override void OnBarUpdate(int currentBar) { base.OnBarUpdate(currentBar); Trix ind = (Trix)Dependents[0]; if (DataSeries.CrossBelow(ind.Default, ind.Signal, currentBar, 0) != -1) { WasFound[currentBar] = true; } }
/// <summary> /// Called on every new bar of data. /// </summary> /// <param name="currentBar">The current bar of the simulation</param> protected override void OnBarUpdate(int currentBar) { base.OnBarUpdate(currentBar); Rsi rsi = (Rsi)Dependents[0]; if (DataSeries.CrossBelow(rsi.Value, 70, currentBar, 0) != -1) { WasFound[currentBar] = true; } }
/// <summary> /// Called on every new bar of data. /// </summary> /// <param name="currentBar">The current bar of the simulation</param> protected override void OnBarUpdate(int currentBar) { base.OnBarUpdate(currentBar); Macd macd = (Macd)Dependents[0]; if (DataSeries.CrossBelow(macd.Value, macd.Avg, currentBar, 0) != -1) { WasFound[currentBar] = true; } }
/// <summary> /// Called on every new bar of data. /// </summary> /// <param name="currentBar">The current bar of the simulation</param> protected override void OnBarUpdate(int currentBar) { base.OnBarUpdate(currentBar); Sma sma = (Sma)Dependents[0]; if (DataSeries.CrossBelow(Data.Close, sma.Avg, currentBar, 0) != -1) { WasFound[currentBar] = true; } }
/// <summary> /// Called on every new bar of data. /// </summary> /// <param name="currentBar">The current bar of the simulation</param> protected override void OnBarUpdate(int currentBar) { base.OnBarUpdate(currentBar); StochasticsFast ind = (StochasticsFast)Dependents[0]; if (DataSeries.IsAbove(ind.D, 80, currentBar, 0) != -1) { if (DataSeries.CrossBelow(ind.K, ind.D, currentBar, 0) != -1) { WasFound[currentBar] = true; } } }
/// <summary> /// Called when the order has been filled during the bar update. /// </summary> /// <param name="currentBar">Current bar of the simulation for the order</param> /// <returns>True if the order was closed</returns> public override bool OnUpdate(int currentBar) { if (_order.BuyBar == currentBar) { return(false); } TickerData data = _order.Ticker; if (_order.Type == Order.OrderType.Long) { // If the oscillator moves out from the oversold area but then goes back in it // then it's not going to be able to go back up so we should sell it. if (DataSeries.CrossAbove(_oscillator.SD, DtOscillator.OversoldZone, currentBar, 4) != -1 && DataSeries.CrossBelow(_oscillator.SD, DtOscillator.OversoldZone, currentBar, 0) != -1) { _order.Sell(data.Close[currentBar], currentBar, "DTosc Fail"); return(true); } // If we reverse out of the overbought area then the cycle is coming back down and we should // take our profits. if (DataSeries.CrossBelow(_oscillator.SD, DtOscillator.OverboughtZone, currentBar, 0) != -1) { _order.Sell(data.Close[currentBar], currentBar, "DTosc Reverse"); return(true); } } // Comments are just the same for short orders but the opposite direction. else if (_order.Type == Order.OrderType.Short) { if (DataSeries.CrossBelow(_oscillator.SD, DtOscillator.OverboughtZone, currentBar, 4) != -1 && DataSeries.CrossAbove(_oscillator.SD, DtOscillator.OverboughtZone, currentBar, 0) != -1) { _order.Sell(data.Close[currentBar], currentBar, "DTosc Fail"); return(true); } if (DataSeries.CrossAbove(_oscillator.SD, DtOscillator.OversoldZone, currentBar, 0) != -1) { _order.Sell(data.Close[currentBar], currentBar, "DTosc Reverse"); return(true); } } // Didn't sell. return(false); }
/// <summary> /// Called on every new bar of data. /// </summary> /// <param name="currentBar">The current bar of the simulation</param> protected override void OnBarUpdate(int currentBar) { base.OnBarUpdate(currentBar); if (currentBar < 1) { return; } DtOscillator ind = (DtOscillator)Dependents[0]; if (DataSeries.IsAbove(ind.SK, 75, currentBar, 1) != -1) { if (DataSeries.CrossBelow(ind.SK, ind.SD, currentBar, 0) != -1) { WasFound[currentBar] = true; } } }
/// <summary> /// Returns true if we pass all the conditions to buy short. /// </summary> /// <param name="currentBar">Current bar of the simulation</param> /// <returns>See summary</returns> private bool ShouldBuyShort(int currentBar) { GavalasZones zones = (GavalasZones)_dependents[0]; // Higher timeframe if (Data.HigherTimeframeTrend[currentBar] > 0.0) { return(false); } // Zones buy direction if (_lastZoneHitDirection > 0.0) { return(false); } // Verify with the mechanical buy signal. DtOscillator dtosc = (DtOscillator)_dependents[1]; if (DataSeries.IsAbove(dtosc.SK, DtOscillator.OverboughtZone, currentBar, 3) == -1 || DataSeries.CrossBelow(dtosc.SK, dtosc.SD, currentBar, 0) == -1) { return(false); } // If we are trending make sure the best fits lines are negative. DmiAdx dmiAdx = (DmiAdx)_dependents[3]; if (dmiAdx.Adx[currentBar] >= 25) { double angle = UtilityMethods.RadianToDegree(Math.Atan(zones.AllBestFitLineSlope[currentBar])); if (angle > 0) { return(false); } } // TODO? // If we are not trending make sure we are close to the top of the channel? return(true); }
/// <summary> /// Returns true if we pass all the conditions to buy short. /// </summary> /// <param name="currentBar">Current bar of the simulation</param> /// <returns>See summary</returns> private bool ShouldBuyShort(int currentBar) { // Higher timeframe if (Data.HigherTimeframeTrend[currentBar] > 0.0) { return(false); } KeltnerChannel kelt = (KeltnerChannel)_dependents[2]; //if (DataSeries.CrossAbove(Data.High, kelt.Upper, currentBar, 5) == -1) //{ // return false; //} if (Math.Min(Data.Open[currentBar], Data.Close[currentBar]) < kelt.Midline[currentBar]) { return(false); } DtOscillator dtosc = (DtOscillator)_dependents[3]; if (DataSeries.IsAbove(dtosc.SD, DtOscillator.OverboughtZone, currentBar, 3) == -1 || DataSeries.IsAbove(dtosc.SK, DtOscillator.OverboughtZone, currentBar, 3) == -1 || DataSeries.CrossBelow(dtosc.SK, dtosc.SD, currentBar, 0) == -1) { return(false); } // Make sure we are not in a heavy trend the other way. //DmiAdx dmiAdx = (DmiAdx)_dependents[1]; //if (dmiAdx.Adx[currentBar] > 30 && dmiAdx.DmiPlus[currentBar] > dmiAdx.DmiMinus[currentBar] && // UtilityMethods.LineAngle(currentBar - 2, dmiAdx.Adx[currentBar - 2], currentBar, dmiAdx.Adx[currentBar]) > 5) //{ // return false; //} return(true); }