IsEmaBullishCross Or IsEmaBearishCross Always false
See original GitHub issueHello I am trying to figure out how to know if the Ema is Bullish or Bearish.
I did a backtesting using IsEmaBullishCross and IsEmaBearishCross and they are working fine
` var buyRule = Rule.Create(ic => ic.IsEmaBullishCross(21, 55)); var sellRule = Rule.Create(ic => ic.IsEmaBearishCross(21, 55));
var runner = new Trady.Analysis.Backtest.Builder()
.Add(candles)
.Buy(buyRule)
.Sell(sellRule)`
The problem is when I am trying to get the buy signal and sell signal from the exchange always is False.
I am using the IndexedCandle like this:
` var ic = new IndexedCandle(candles, candles.Count - 1); var buyRule =(ic => ic.IsEmaBullishCross(21, 55)); var sellRule = (ic => ic.IsEmaBearishCross(21, 55));
`
Maybe I am doing something wrong.
I would appreciate some help.
I did my own testing and I found something very interesting I implemented my own indicator called TemaIndicator I followed the examples and I did thisd
//public static bool IsTemaBullishCross(this IIndexedOhlcv ic, int periodCount1, int periodCount2) // => ic.Get<ExponentialMovingAverageOscillator>(periodCount1, periodCount2).ComputeNeighbour(ic.Index) // .IsTrue((prev, current, _) => prev.Tick.IsNegative() && current.Tick.IsPositive());
//public static bool IsTemaBearishCross(this IIndexedOhlcv ic, int periodCount1, int periodCount2)
// => ic.Get<TemaIndicatorOcillator>(periodCount1, periodCount2).ComputeNeighbour(ic.Index)
// .IsTrue((prev, current, _) => prev.Tick.IsPositive() && current.Tick.IsNegative());
Same as many extensions when I use them with back testing is working fine but with real data never always they return false like macd crossing, emabearishcross, emabullishcross etc…
I modified this extension like this:
public static bool IsTemaBullishCross(this IIndexedOhlcv ic, int periodCount1, int periodCount2)
{
// original code var test = ic.Get<ExponentialMovingAverageOscillator>(periodCount1, periodCount2).ComputeNeighbour(ic.Index) .IsTrue((prev, current, _) => prev.Tick.IsNegative() && current.Tick.IsPositive());
// traditional way var tema1 = ic.Get<TemaIndicator>(periodCount1).Compute()[ic.Index]; var tema2 = ic.Get<TemaIndicator>(periodCount2).Compute()[ic.Index]; if (tema1.Tick.Value > tema2.Tick.Value) { return true; } else { return false; }
}
and finally the cross was fired …
there is a bug with the extensions.
I would like to help to fix the problem but for now is the only way I found to fix them.
Thank you!
Issue Analytics
- State:
- Created 5 years ago
- Comments:16 (9 by maintainers)
Top GitHub Comments
@lppkarl thank you Now is working properly!
@RikardoPons Once you’ve tested ok, it would be good to help to close this issue. Thanks.