Implementing Conditional Logic and Screeners in ProBuilder

08 Jun 2017
0 comment
0 attachment

This ProBuilder code snippet demonstrates how to use conditional logic to manipulate data and create a custom screener output based on multiple trading indicators. The example focuses on RSI values and price extremes over a specified period.

// Result hh ll
// 9 9 (no match)
// 1 9
// 9 1
// 1 1
MyRsi = Rsi[14](close)
c1 = MyRsi < 30
hh = (high = highest[20](high))
ll = (low = lowest[20](low))
x = 90
IF hh THEN
  x = 10
ENDIF
IF ll THEN
  x = x + 1
ELSE
  x = x + 9
ENDIF
IF x = 99 THEN
  x = 0
ENDIF
Result = x
IF c1 = 0 THEN
  Result = 0
ENDIF
SCREENER[Result](Result AS "HL")

This code snippet is structured to evaluate certain conditions and adjust a variable accordingly, which is then used to filter results in a screener. Here's a breakdown of its functionality:

  • RSI Calculation: The relative strength index (RSI) is calculated over a 14-period window using closing prices.
  • Condition Check: It checks if the RSI is less than 30, which typically indicates an oversold condition.
  • Price Extremes: Variables hh and ll are used to check if the current high is the highest in the last 20 periods, and if the current low is the lowest, respectively.
  • Variable Manipulation: The variable x starts at 90. If the highest high condition (hh) is true, x is set to 10. Depending on whether the lowest low condition (ll) is true, x is adjusted by adding either 1 or 9.
  • Final Adjustment: If x equals 99 after adjustments, it is reset to 0.
  • Result Assignment: The final value of x is assigned to Result. If the initial RSI condition (c1) is not met (i.e., RSI is not less than 30), Result is set to 0.
  • Screener Output: The screener function is used to display the Result with a label "HL". This output can help in identifying specific conditions in trading data.

This example is useful for understanding how to combine multiple conditions and outputs in a screener using ProBuilder's programming capabilities.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/multiple-column-screener-results-display/#post-104130

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