DEFPARAM CumulateOrders = true
DEFPARAM FlatAfter = 220000
//
ONCE startT = 070000 //Starting TIME
ONCE endT = 190000 //Ending TIME
TimeRef = OpenTime //can be replaced by TIME, if needed
DayRef = OpenDayOfWeek //can be replaced by DAYOFWEEK, if needed
td0 = 0 AND DayRef = 0 AND TimeRef >= startT AND TimeRef <= endT //Sunday
td1 = 1 AND DayRef = 1 AND TimeRef >= startT AND TimeRef <= endT //Monday
td2 = 1 AND DayRef = 2 AND TimeRef >= startT AND TimeRef <= endT //Tuesday
td3 = 1 AND DayRef = 3 AND TimeRef >= startT AND TimeRef <= endT //Wednesday
td4 = 1 AND DayRef = 4 AND TimeRef >= startT AND TimeRef <= endT //Thursday
td5 = 1 AND DayRef = 5 AND TimeRef >= startT AND TimeRef <= endT //Friday
td6 = 0 AND DayRef = 6 AND TimeRef >= startT AND TimeRef <= endT //Saturday
tdCond = td0 OR td1 OR td2 OR td3 OR td4 OR td5 OR td6
//
ONCE nLots = 1 //1 lot to be traded by default
ONCE Offset = 30 * pipsize //30 pips above/below entry point
ONCE TP = 300 //300 pips Target Profit
ONCE SL = 50 //50 pips Stop Loss
//
ONCE LongMACD = 0
ONCE ShortMACD = 0
//
// MACD 12,26,9 (formula)
//
MyMACD = ExponentialAverage[12](close) - ExponentialAverage[26](close)
//MySignalLine = ExponentialAverage[9](MyMACD)
//MyHisto = MyMACD - MySignalLine
//
IF LongMACD = 0 THEN
LongMACD = MyMACD CROSSES OVER 0
IF LongMACD THEN
Entry = close + Offset
ShortMACD = 0
ENDIF
ENDIF
IF ShortMACD = 0 THEN
ShortMACD = MyMACD CROSSES UNDER 0
IF ShortMACD THEN
Entry = close - Offset
LongMACD = 0
ENDIF
ENDIF
// --- LONG
IF Not LongOnMarket AND tdCond AND LongMACD THEN
BUY nLots CONTRACTS AT Entry STOP
SET TARGET pPROFIT TP
SET STOP pLOSS SL
ENDIF
// --- SHORT
IF Not ShortOnMarket AND tdCond AND ShortMACD THEN
SELLSHORT nLots CONTRACTS AT Entry STOP
SET TARGET pPROFIT TP
SET STOP pLOSS 100
ENDIF