DEFPARAM CumulateOrders = FALSE
LongSL = 50 * PipSize
ShortSL = LongSL
//
IF Month <> Month[1] THEN //When the current bar's month <> previous one's then a new month just started...
WeekDay = DayOfWeek //...so we need to start counting weekdays from scratch
ThisMonth = Month
ThisYear = Year
LastDay = 31
Last3rd = 99
Last8th = 99
Tally = 0
TradeON = Not OnMarket
If ThisMonth = 4 or ThisMonth = 6 or ThisMonth = 9 or ThisMonth = 11 Then
LastDay = 30
Endif
//Check if it's a Leap year
If ThisMonth = 2 Then
LastDay = 28
If ThisYear mod 4 = 0 Then
If ThisYear mod 100 = 0 Then
If ThisYear mod 400 = 0 Then
LastDay = 29
Endif
Else
LastDay = 29
Endif
Endif
Endif
//Start Counting
EOM = 0 //EOM = End Of Month
FOR i = 2 TO LastDay
WeekDay = WeekDay + 1
If WeekDay <= 5 Then
EOM = i
Elsif WeekDay = 7 Then
WeekDay = 0
Endif
Next
Endif
//
Last8th = EOM - 8 //Eighth Last Day of the month (it can't be known if it's a holiday)
Last3rd = EOM - 3 //Third Last Day of the month (it can't be known if it's a holiday)
//
IF Not OnMarket AND Day > Last8th AND Day <> Day[1] AND Day < Last3rd AND TradeON THEN
SELLSHORT 1 CONTRACT AT MARKET
SET STOP pLOSS ShortSL
TradeON = 0
Tally = 1
ENDIF
IF ShortOnMarket AND Day <> Day[1] THEN
Tally = Tally + 1
IF Tally >= 4 THEN
Tally = 0
TradeON = 1
EXITSHORT AT MARKET
ENDIF
ENDIF
//
IF Day >= Last3rd AND Day <= LastDay AND Day > Last8th AND Day <> Day[1] AND TradeON THEN
BUY 1 CONTRACT AT MARKET
SET STOP pLOSS LongSL
TradeON = 0
Tally = 99
ENDIF
IF LongOnMarket AND Day <> Day[1] AND Tally < 3 THEN
Tally = Tally + 1
IF Tally = 3 THEN
Tally = 0
TradeON = 1
SELL AT MARKET
ENDIF
ENDIF
//graph LastDay
//graph Last8th
//graph Last3rd
//graph Day
//graph Tally