Mastering ProRealTime: A Step-by-Step Guide to Coding Your Own Custom Indicators

Category: Programming

Are you ready to take your trading to the next level? If you’re using ProRealTime, one of the most powerful features is the ability to create custom indicators. Whether you’re a beginner or have some coding experience, this guide will walk you through the process step by step. By the end, you’ll be coding your own indicators like a pro, giving you an edge in analyzing markets.

In this tutorial, we’ll cover everything from the basics of ProRealTime’s programming language to building practical examples. No prior coding knowledge is required—we’ll keep it simple and engaging. Let’s dive in!

Understanding ProRealTime’s Programming Basics

ProRealTime uses its own scripting language, which is straightforward. It’s designed for creating indicators, strategies, and screeners.

Key concepts to know:

  • Variables: These store data, like prices or calculations.
  • Functions: Built-in tools for common tasks, such as calculating averages.
  • Loops and Conditions: For more complex logic, like if-then statements.

To start coding, open ProRealTime and navigate to the “Programming” section. Click on “Indicators” to create a new one. You’ll see an editor where you can write your code.

Step 1: Setting Up Your First Indicator

Let’s create a simple custom indicator: a basic moving average crossover signal. This will plot two moving averages and highlight when they cross.

First, in the indicator editor, give your indicator a name, like “Simple MACrossover.”

Now, enter this code:

//Define variables
maShort = Average[10](Close)
maLong = Average[20](Close)
//Plot the lines
RETURN maShort COLOURED(0,255,0), maLong COLOURED(255,0,0)

This code calculates a 10-period and 20-period simple moving average of the closing price and plots them in green and red.

Tip: Always test your indicator on a chart by applying it to a symbol like EUR/USD.

Step 2: Adding Logic and Conditions

To make it more useful, let’s add a condition to detect crossovers.

Update your code like this:

// Define variables
maShort = Average[10](Close)
maLong = Average[20](Close)
// Detect crossover
IF CROSSES OVER(maShort, maLong) THEN
signal = 1 // Buy signal
ELSIF CROSSES UNDER(maShort, maLong) THEN
signal = -1 // Sell signal
ELSE
signal = 0
ENDIF
// Plot
RETURN maShort COLOURED(0,255,0), maLong COLOURED(255,0,0), signal AS “Signal”

Here, we’re using the CROSSES OVER and CROSSES UNDER functions to detect when the short MA crosses the long one. The signal is plotted as a histogram for easy visualization.

Customizing Parameters

To make your indicator flexible, add user inputs. Wrap variables in parameters:

shortPeriod = 10 // Input for short MA
longPeriod = 20 // Input for long MA
maShort = Average[shortPeriod](Close)
maLong = Average[longPeriod](Close)
// Rest of the code…

Users can now adjust periods from the indicator settings.

Step 3: Building a Practical Example – RSI with Alerts

Let’s create a custom RSI indicator that alerts when it enters overbought or oversold zones.

Code:

// Inputs
rsiPeriod = 14
overbought = 70
oversold = 30
// Calculate RSI
myRSI = RSI[rsiPeriod](Close)
// Conditions
IF myRSI > overbought THEN
alert = 1 // Overbought
ELSIF myRSI < oversold THEN
alert = -1 // Oversold
ELSE
alert = 0
ENDIF
// Plot
RETURN myRSI COLOURED(0,0,255), overbought, oversold, alert AS  “Alert” STYLE(HISTOGRAM)

This plots the RSI line, threshold lines, and a histogram for alerts. You can even add email notifications in ProRealTime settings.

Common Mistakes and Debugging Tips

As a beginner, you might encounter errors. Here’s how to fix them:

  1. Syntax Errors: Check for missing parentheses or misspelled functions.
  2. Undefined Variables: Ensure all variables are declared.
  3. Testing: Use the “tooltip” button in the editor to catch issues.

Pro Tip: Start small—build and test one part at a time.

Advanced Techniques: Loops and Arrays

For more complex indicators, use loops. Here’s a simple example to calculate the highest high over 50 bars:

highest = Close[0]
FOR i = 1 TO 49 DO
IF Close[i] > highest THEN
highest = Close[i]
ENDIF
ENDFOR
RETURN highest

This loops through the last 50 closes to find the max.

Final Thoughts and Next Steps

Congratulations! You’ve mastered the basics of coding custom indicators in ProRealTime. Practice by modifying these examples or creating your own based on trading ideas.

Join our community forums to share your creations and get feedback. Happy coding, and may your trades be profitable!

Logo Logo
Loading...