Implementing Time-Based Conditions in Trading Algorithms

21 Sep 2020
0 comment
0 attachment

This code snippet demonstrates how to implement time-based conditions in trading algorithms using the ProBuilder language. It is designed to enable trading only during specific time periods within a trading day.


IF time >= 090000 AND time <= 110000 THEN //trade from 9 to 11
    TradingON = 1
ELSIF time >= 130500 AND time <= 150000 THEN //trade from 13:05 to 15
    TradingON = 1
ELSIF time >= 163000 AND time <= 190000 THEN //trade from 16:30 to 19
    TradingON = 1
ELSE
    TradingON = 0 //do not trade outside above time ranges
ENDIF

The code snippet above is structured to control the trading activity based on the time of the day. Here's a step-by-step explanation:

  • IF statement: The first condition checks if the current time is between 09:00:00 and 11:00:00. If true, it sets the variable TradingON to 1, indicating that trading is allowed during this period.
  • ELSIF statements: Additional conditions are checked for other specific time intervals:
    • From 13:05:00 to 15:00:00
    • From 16:30:00 to 19:00:00

    If the current time falls within any of these ranges, TradingON is set to 1.

  • ELSE clause: If none of the specified conditions are met, TradingON is set to 0, disabling trading outside the defined time periods.

This approach is useful for traders who want to limit their trading activity to specific, potentially more profitable hours, or to comply with trading regulations or personal strategy preferences.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/multiple-trading-times-per-day/#post-96116

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.
robertogozzi Master
Roberto https://www.ots-onlinetradingsoftware.com
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...