Hi,
Is there a code that tell your algo not to open any trade at month end? Month-end here will mean the last business day of the month and not the last day of the month. Thank you.
There you go (not tested):
If OpenMonth <> OpenMonth[1] Then
OM = OpenMonth
OD = OpenDay
ODW = OpenDayOfWeek
OY = OpenYear
LastDay = 31
If OM = 4 or OM = 6 or OM = 9 or OM = 11 Then
LastDay = 30
Endif
If OM = 2 Then
LastDay = 28
If OY mod 4 = 0 Then
If OY mod 100 = 0 Then
If OY mod 400 = 0 Then
LastDay = 29
Endif
Else
LastDay = 29
Endif
Endif
Endif
EOM = OD //EOM=End Of Month
For i = OD + 1 To LastDay
ODW = ODW + 1
If ODW <= 5 Then
EOM = i
Elsif ODW = 7 Then
ODW = 0
Endif
Next
Endif
//
TradeON = 1
If Day = EOM Then
TradeON = 0
Endif
//
If MyLongConditions And TradeON And Not OnMarket Then
Buy 1 contract at Market
Endif
Use TradeON to enter a new trade.
EOM only recognizes regular weekend days, not National, Bank, Labor holidays, etc…
Thanks Roberto! I was just thinking maybe need to hard-code a set of specific dates to tell the algo not to trade on those dates but the algo that you have suggested is awesome! Thank you!
Link to code above added as Log 303 here …
Snippet Link Library
Yes, you can certainly add any date not to be traded in addition to EOM.
Usually holidays are known well before Jan. 1st.