Implementing Time-Based Strategy Optimization in ProBuilder

28 Jun 2015
0 comment
0 attachment

This code snippet demonstrates how to implement a time-based strategy optimization in ProBuilder. It sets up a trading strategy that buys and sells based on the RSI indicator, but only within a specified time window that is optimized for every possible 15-minute interval within a day.


once starttime = starttime * 10000
once addedhours = addedhours * 10000
once addedendminutes = addedendminutes * 100
once addedstartminutes = addedstartminutes * 100
once starttime = starttime + addedstartminutes
once endtime = starttime + addedhours + addedendminutes
if endtime > 240000 then quit endif
if endtime = 240000 then endtime = 0 endif
if time >= starttime and time < endtime then
    if not onmarket and rsi[14] < 30 then
        buy 1 contract at market
    endif
endif
if onmarket and rsi[14] > 70 then
    sell at market
endif
graph starttime
graph endtime

The code snippet above is structured to optimize the execution times of a trading strategy based on the Relative Strength Index (RSI). Here’s a step-by-step explanation:

  • Time Calculation: The variables starttime, addedhours, addedendminutes, and addedstartminutes are adjusted to represent times in a ‘HHMMSS’ format. This is done by multiplying and adding appropriate constants to convert hours and minutes into a continuous number that represents time.
  • Setting End Time: The end time for the strategy is calculated by adding the start time, the additional hours, and the additional end minutes. If the calculated end time exceeds ‘240000’ (which represents 24:00:00 in this format), the script is instructed to quit, optimizing processing time by ignoring non-feasible times.
  • Trading Window: The trading operations are confined within the calculated start and end times. The strategy checks if the current time is within this window before executing any trades.
  • Buy/Sell Conditions: Within the defined time window, the strategy buys one contract when the market is not already entered (checked by onmarket) and the RSI is below 30. It sells when the RSI goes above 70, assuming the market has been entered previously.
  • Graphing: The start and end times are graphed for visualization, which can help in debugging or understanding the strategy’s operation over time.

This example illustrates the use of time and technical indicators in optimizing a trading strategy, highlighting the flexibility and power of the ProBuilder language for backtesting in financial markets.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/about-trading-times/#post-110925

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...