# MACD cross-over doesn't work on Streaks?

**URL:** <https://tradingqna.com/t/macd-cross-over-doesnt-work-on-streaks/112406>\
**Category:** Algos, strategies, code\
**Created:** [June 18, 2021, 3:15pm UTC](https://tradingqna.com/t/macd-cross-over-doesnt-work-on-streaks/112406 "2021-06-18T15:15:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![MangalaSV](https://tradingqna.com/letter_avatar_proxy/v4/letter/m/71e660/32.png) [@MangalaSV](https://tradingqna.com/u/MangalaSV)\
**Post date:** [June 18, 2021, 3:15pm UTC](https://tradingqna.com/t/macd-cross-over-doesnt-work-on-streaks/112406/1 "2021-06-18T15:15:18Z")

</div>

Hello,  
I have the following strategy:

Entry conditions:

1. MACD crosses above the signal (`macd(12,26,9,macd,0) crosses over macd(12,26,9,signal,0)`)
2. MACD histogram value less than 0 (`macd(12,26,9,histogram,0) lower than 0.0`)
3. CMP is higher than 200EMA (`Close(0) higher than EMA(close,200,0)`

This strategy was back-tested for MIS from 18.06.2020 to 18.06.2021 for SAIL, ONGC, and GAIL with 5m and 15m frequency. Back-test did not produce even one signal. I could identify quite a few manually though. What is wrong with the code?

Refer to this example for SAIL:

![image](https://tradingqna.com/uploads/default/original/3X/d/d/ddb9a9637835da17b18bcbc88ff488ca655383d9.png)

---

<div class="post-metadata">

**Author:** ![ShubhS9](https://tradingqna.com/user_avatar/tradingqna.com/shubhs9/32/32667_2.png) [@ShubhS9](https://tradingqna.com/u/ShubhS9)\
**Post date:** [June 18, 2021, 3:21pm UTC](https://tradingqna.com/t/macd-cross-over-doesnt-work-on-streaks/112406/2 "2021-06-18T15:21:36Z")

</div>

@Streak can you.

---

<div class="post-metadata">

**Author:** ![Streak](https://tradingqna.com/user_avatar/tradingqna.com/streak/32/89355_2.png) [@Streak](https://tradingqna.com/u/Streak)\
**Post date:** [June 19, 2021, 8:42am UTC](https://tradingqna.com/t/macd-cross-over-doesnt-work-on-streaks/112406/3 "2021-06-19T08:42:46Z")

</div>

Hi @MangalaSV ,

MACD histogram is calculated as the difference of MACD and MACD Signal (blue line - orange line).  
So when Macd crosses above Macd signal, so macd is higher than macd signal, so at that moment Macd histogram cannot be less than 0.

You have marked one candle before the cross-over(and that’s why your think histogram is lower than 0), once cross-over happens in the next candle(once you zoom in, you will see), at that moment Macd histogram has become higher than 0.

Macd histogram is just used to visualize the difference between MACD and MACD histogram.  
If you just remove the histogram condition you will see the trades, or even if you change the offset in histogram to -1 then also you will see the trade in the backtest.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![MangalaSV](https://tradingqna.com/letter_avatar_proxy/v4/letter/m/71e660/32.png) [@MangalaSV](https://tradingqna.com/u/MangalaSV)\
**Post date:** [June 19, 2021, 12:09pm UTC](https://tradingqna.com/t/macd-cross-over-doesnt-work-on-streaks/112406/4 "2021-06-19T12:09:12Z")

</div>

Sure thanks a lot that helped.  
@Streak Is there any preconditions to set start and end date for backtesting? As I enter the end date, the start date automatically set to only 3-months. I need to test for 1 year.

---

<div class="post-metadata">

**Author:** ![parveenkrish](https://tradingqna.com/letter_avatar_proxy/v4/letter/p/b38774/32.png) [@parveenkrish](https://tradingqna.com/u/parveenkrish)\
**Post date:** [June 21, 2021, 11:36am UTC](https://tradingqna.com/t/macd-cross-over-doesnt-work-on-streaks/112406/5 "2021-06-21T11:36:42Z")

</div>

A new strategy to work on streaks. Have to try to see how this MACD crossover works on streaks. Thanks for the entry conditions.

---

<div class="post-metadata">

**Author:** ![Krishnendu](https://tradingqna.com/user_avatar/tradingqna.com/krishnendu/32/20265_2.png) [@Krishnendu](https://tradingqna.com/u/Krishnendu)\
**Post date:** [June 22, 2021, 1:34pm UTC](https://tradingqna.com/t/macd-cross-over-doesnt-work-on-streaks/112406/6 "2021-06-22T13:34:42Z")

</div>

Hi @MangalaSV,

There is a limit on the amount of data you can backtest at a time. For example, a maximum of 3 months backtest is allowed of 5min timeframe. You will find the details here  
[https://help.streak.tech/create/#parameters-required](https://help.streak.tech/create/#parameters-required)

You can, however, test on older dates by changing the backtest start and stop date from the Advanced section in the create strategy page and testing them in tranches.

---

<div class="post-metadata">

**Author:** ![Krishnendu](https://tradingqna.com/user_avatar/tradingqna.com/krishnendu/32/20265_2.png) [@Krishnendu](https://tradingqna.com/u/Krishnendu)\
**Post date:** [June 22, 2021, 1:37pm UTC](https://tradingqna.com/t/macd-cross-over-doesnt-work-on-streaks/112406/7 "2021-06-22T13:37:57Z")

</div>

@parveenkrish  
You can follow the condition mentioned here

[https://help.streak.tech/indicators/#macd-and-macd-signal](https://help.streak.tech/indicators/#macd-and-macd-signal)
