/// <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) { DmiAdx dmiAdx = (DmiAdx)_dependents[1]; bool isHigherTimeframeLong = Data.HigherTimeframeTrend[currentBar] > 0.0; // For a cross over. bool isAdxHighEnough = dmiAdx.Adx[currentBar] >= 20.0; bool isDmiAboutToCrossover = DataSeries.IsAboutToCrossAbove(dmiAdx.DmiPlus, dmiAdx.DmiMinus, currentBar); // Adx was low but just increased and our dmi lines are already crossed over. bool didAdxCrossover = DataSeries.CrossAbove(dmiAdx.Adx, 20.0, currentBar, 0) != -1; bool hasDmiCrossedover = DataSeries.CrossAbove(dmiAdx.DmiPlus, dmiAdx.DmiMinus, currentBar, 8) != -1; // Either case is good for an entry signal. bool isDmiAdxSignal = (isAdxHighEnough && isDmiAboutToCrossover) || (didAdxCrossover && hasDmiCrossedover); return(isHigherTimeframeLong && isDmiAdxSignal); }
/// <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); }