Implementing Expiration and Warning Notifications in ProBuilder

15 Oct 2017
0 comment
0 attachment

This ProBuilder code snippet demonstrates how to set an expiration date for an indicator and provide advance warnings to the user. The code is useful for scenarios where an indicator should only be used until a certain date, after which it becomes obsolete or needs renewal.


expirydate = 20180101
advancewarningdate = 20171201
if opendate >= advancewarningdate then
    if not donewarning then
        drawtext("Warning - this indicator will expire in one month",barindex,result[1],SansSerif,Bold,16)coloured(128,0,0)
        donewarning = 1
    endif
endif
if opendate < expirydate then
    result = average[200] //replace with your indicator code
else
    result = undefined
    if not done then
        drawtext("Warning - this indicator has expired",barindex,result[1],SansSerif,Bold,16)coloured(128,0,0)
        done = 1
    endif
endif
return result

This code snippet includes several key programming concepts:

  • Conditional Statements: Uses if and endif to control the flow of the program based on the date conditions.
  • Variables: Utilizes variables like expirydate, advancewarningdate, donewarning, and done to store dates and state information.
  • Text Drawing: Employs drawtext function to display messages directly on the chart, which is useful for alerts.
  • Color and Style Formatting: The text is styled and colored to ensure visibility and impact.
  • Logical Operators: The not operator is used to check if a warning has already been issued, preventing repeated alerts.

Step-by-step explanation:

  • The code first checks if the current date (opendate) is equal to or later than the advancewarningdate. If true, and if no previous warning has been issued (donewarning is false), it displays a warning message about the impending expiration.
  • If the current date is still before the expirydate, the indicator calculates and returns its usual result (in this case, a 200-period average).
  • If the current date is past the expirydate, the result is set to undefined, and an expiration message is displayed if not already done.

This example is particularly useful for developers looking to add time-sensitive features to their ProBuilder scripts, ensuring users are aware of the validity period of the indicators.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/how-can-i-code-a-indicator-with-end-date-of-using/#post-110164

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
132
strategy
171

Recent Snippets

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) [...]
Calculating Break-Even Points in ProBuilder
strategy
This ProBuilder code snippet demonstrates how to calculate the break-even point for a trading position. The break-even [...]
Logo Logo
Loading...