Search code examples
pine-scriptpine-script-v5tradingalgorithmic-trading

Need help - how to ignore specific dates for my strategy


I'm looking for a solution for my strategy.

I want to exclude trades that took place on specific dates.

E.g. I do not want to trade on days where extrem news appear (e.g. CPI, Nonfarm Payroll). So is there a way that I can say:

No trades on (e.g.) 03.02.2023, XX.XX.XXXX, etc.

And the other way - can I somehow say, do only trade on specific dates? e.g. 03.02.2023?

Thanks in advance!


Solution

  • You can check specific dates with the built-in variables year, month and dayofmonth.

    Use these three to figure out if it is a day that you want to trade. Add this to your entry condition with a not operator.

    no_trade_day_1 = (year == 2023) and (month == 2) and (dayofmonth == 3)  // 03.02.2023
    trade_cond = (your_trade_cond) and not no_trade_day_1  // Trade if you have a valid signal and if it is NOT 03.02.2023