This ProBuilder code snippet is designed to prevent trading on the last working day of the month. It calculates the end of the month and sets a flag to disable trading on that day.
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
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
Explanation of the code:
OpenMonth <> OpenMonth[1]). This is crucial to reset calculations at the start of each new month.OM), day (OD), day of the week (ODW), and year (OY) are initialized.EOM (End Of Month) is set to the last working day calculated.TradeON is used to enable or disable trading. It is set to 0 (disabled) if the current day is the last working day of the month.This snippet is useful for traders using automated systems who wish to avoid entering new positions on the last working day of the month, potentially due to increased volatility or accounting reasons.
Check out this related content for more information:
https://www.prorealcode.com/topic/codes-for-not-opening-trades-at-month-end/#post-175920
Visit Link