Hi guys,
I'm trying to use a dual MACD strategy, it checks if the weekly MACDLine is over its Signal Line and then look at the daily MACD and enter when a crossover of the MacdLine on its signalLine occurs.
Here is how I made it so far:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © vincentdufour67
strategy("Dual MACD", overlay=true,initial_capital=10000, default_qty_type=strategy.percent_of_equity,default_qty_value=100)
week_close = request.security(syminfo.tickerid,'1W',close)
ema_weekly_12 = ta.ema(week_close,12)
ema_weekly_26 = ta.ema(week_close,26)
macdLine_weekly = ema_weekly_12 - ema_weekly_26
signalLine_weekly = ta.ema(macdLine_weekly,9)
[macdLine, signalLine,_] = ta.macd(close, 12, 26, 9)
longCondition = ta.crossover(macdLine,signalLine) and (macdLine_weekly > signalLine_weekly) and time > timestamp(2016,01,01,00,00,00)
if (longCondition)
strategy.entry("Buy", strategy.long)
sellCondition = (ta.crossunder(macdLine,signalLine) or ta.crossunder(macdLine_weekly,signalLine_weekly)) and time > timestamp(2016,01,01,00,00,00)
if(sellCondition)
strategy.close("Buy")
Problem, on a particular trade it enters when the daily MACDLine is under its SignalLine... here is a capture of the case.
If anyone can help me that would be great :)
Cheers