Implementing Seasonal Trading Filters in ProBuilder

24 Jan 2018
0 comment
0 attachment

This code snippet demonstrates how to implement a seasonal trading filter in ProBuilder, specifically designed to avoid trading during certain months which are historically less profitable. The strategy avoids trading in July, August, September, and January, based on observed market behaviors.


// Define the holiday months
IF Month = 7 OR Month = 8 OR Month = 9 OR Month = 1 THEN
    NoTrade = 1
ELSE
    NoTrade = 0
ENDIF

// Trading logic
IF NoTrade = 0 AND Close > Open THEN
    Buy = 1
ELSE
    Buy = 0
ENDIF

IF Buy[1] = 1 AND (Close > Close[1] OR NoTrade = 1) THEN
    Sell = 1
ELSE
    Sell = 0
ENDIF

The code snippet above is structured to control trading activities based on the month of the year, specifically to avoid trading during certain months identified as less profitable or higher risk.

  • Defining Holiday Months: The first block uses an IF statement to check if the current month (Month) is July, August, September, or January. If it is one of these months, it sets the NoTrade variable to 1 (true), otherwise to 0 (false).
  • Trading Logic for Buying: The second block checks if it is not a holiday month (NoTrade = 0) and if the closing price of the current bar is greater than its opening price (Close > Open). If both conditions are met, it sets the Buy variable to 1 (true), indicating a buy signal.
  • Conditions for Selling: The third block checks if there was a buy signal on the previous bar (Buy[1] = 1) and if the current closing price is higher than the previous closing price (Close > Close[1]) or if it is a holiday month (NoTrade = 1). If either condition is satisfied, it sets the Sell variable to 1 (true), indicating a sell signal.

This example is useful for understanding how to incorporate time-based conditions into trading strategies using ProBuilder, enhancing decision-making by avoiding potentially unfavorable trading periods.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/take-a-holiday-and-make-money/#post-106104

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.
Vonasi Master
V-oyaging ON A S-mall I-ncome
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...