Day of Week Conditional Trading Logic

02 Sep 2022
0 comment
0 attachment

This code snippet demonstrates how to implement conditional logic based on the day of the week to decide whether to trade or not in the ProBuilder language. The logic is designed to exclude specific days from trading based on user-defined conditions.


if workday then
    if dayofweek = 0 then // 0 to trade; 1 to exclude monday
        weekday = 0
    elsif dayofweek = 0 then // 0 to trade; 2 to exclude tuesday
        weekday = 0
    elsif dayofweek = 0 then // 0 to trade; 3 to exclude wednesday
        weekday = 0
    elsif dayofweek = 0 then // 0 to trade; 4 to exclude thursday
        weekday = 0
    elsif dayofweek = 0 then // 0 to trade; 5 to exclude friday
        weekday = 0
    else
        weekday = 1
    endif
endif

Explanation of the code:

  • The code starts with a conditional check if workday to determine if the current day is a working day. This is a placeholder and should be defined elsewhere in your code or settings.
  • Within this block, a series of conditional checks are performed using elsif statements to evaluate the dayofweek variable. Each condition checks if the dayofweek equals a specific value (which should be the day of the week represented as an integer).
  • For each day, there is a comment indicating whether the day should be included in trading (0) or excluded (1-5). However, there seems to be a mistake in the code as all conditions check for dayofweek = 0. This should be corrected to match the respective day indices (e.g., 0 for Monday, 1 for Tuesday, etc.).
  • If none of the conditions are met, the weekday variable is set to 1, likely indicating a non-trading day.
  • The code is structured to easily allow modifications to include or exclude specific trading days by adjusting the conditions and the corresponding comments.

This snippet is useful for strategies that require disabling trading on certain days of the week, potentially based on historical performance data or external factors.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/dayopen-straddle-for-dax/page/9/#post-101565

Visit Link
What is a Snippet? A snippet is a small, reusable chunk of code designed to solve specific tasks quickly. Think of it as a shortcut that helps you achieve your coding goals without reinventing the wheel. How to Use: Simply copy the snippet and paste it into your project where needed. Don't forget to tweak it to fit your context. Snippets are not just time-savers; they're also learning tools to help you become a more efficient coder.
paul New
Operating in the shadows, I hack problems one by one. My bio is currently encrypted by a complex algorithm. Decryption underway...
Author’s Profile

Comments

Search Snippets

Showing some results...
Sorry, no result found!

Snippets Categories

global
35
indicator
133
strategy
171

Recent Snippets

How to Create a Simple MTF Trend Dashboard with EMA and SMA
indicator
This indicator builds a compact multi-timeframe (MTF) dashboard that shows whether price is trading above or below a [...]
How to Display Per-Bar Volume Accumulation in Real Time (Intrabar Updates)
global
This snippet tracks and displays the current bar’s accumulated volume while the bar is still forming, instead of only [...]
Ticks Counter: Count Tick Updates Per Bar on Tick or Time Charts
global
This snippet counts how many tick updates have occurred for the current bar by incrementing a per-bar counter on each [...]
How to Build a Step-Based Trailing Stop That Moves to Break-Even First
strategy
This snippet implements a step trailing stop that advances in fixed increments once price reaches predefined profit [...]
Utilizing Arrays to Track and Compare Indicator Values Within the Same Bar in ProBuilder
indicator
This ProBuilder code snippet demonstrates how to use arrays to compare the values of an indicator (RSI in this case) [...]
Logo Logo
Loading...