Soon available

Not on the Chrome Web Store yet

ProRealCode Studio is on its way. As soon as it is published, this button will take you straight to its Chrome Web Store page.

Chapter 16 · Part IV — Alerts and strategies

Your code watches the chart. Studio tells you when.

Add one line to an indicator and it raises an alert the moment its condition comes true: a popup on the chart, a beep if you ask for one, a desktop notification if you switch them on. This chapter writes that line, then sets how each alert reaches you.

  1. 01Write an alert One line in the code, inside its condition.
  2. 02Open the Alerts window Every alert of the chart in one list.
  3. 03Choose how it reaches you Popup, sound, desktop notification.
  4. 04Mute, snooze, look back Silence one indicator, read what fired.

Four ways an alert can reach you

OutputWhen
Popup on the chartEvery time an alert fires, unless you muted or snoozed that indicator.
BeepOnly when the alert line asks for sound.
Desktop notificationOff until you switch it on in the Alerts window. Then it shows even when another window is in front.
Data for a webhookWhen the alert line carries a block of values. That is chapter 17.
Before you startYou know how to run a code on the chart (chapter 02). Keep the ProRealTime tab open the whole time: alerts are computed in that tab, and a closed tab raises none.
ProRealCode StudioUser guide · Chapter 16
01 · Task · Write an alert

One line inside the condition, and the code can call you.

From the example “4 · Oscillator, histogram, alert”, under Examples. The numbers on the left are the editor's line numbers.

42IF macdVal CROSSES OVER sig THEN43  alert("MACD", "crossed up at #close#, histogram #hist#", onceperbar, 1)44ENDIF45IF macdVal CROSSES UNDER sig THEN46  alert("MACD", "crossed down at #close#, histogram #hist#", onceperbar, 1)47ENDIF
ArgumentIn the exampleWhat it does
Title"MACD"The heading of the popup and of the notification. Optional: without it, the heading is the indicator's name.
Message"crossed up at #close#…"The text. Anything between two # is computed and inserted, so #close# becomes the price. Write it as one text in quotes: joining texts with + is refused.
FrequencyonceperbarHow often the line may fire. Optional: onceperbar when you leave it out.
Sound11 beeps, 0 stays silent. Optional: silent when you leave it out.

The three frequencies

freqallAt every price update of the live bar.
onceperbarOnce per bar at most.
onceperbarcloseOnce, when the bar closes.
  1. Open the example “4 · Oscillator, histogram, alert”, or type the line into your own code.The header shows the “Studio Only” chip: alert() is a ProRealCode Script addition (chapter 06).
  2. Click “Run”.The indicator draws in its own panel. Nothing fires yet.
Alerts fire on the live chart only“Run” computes the whole history, but no alert fires for a past bar. The first one comes from a new price, while the market is open.
ProRealCode StudioUser guide · Chapter 16
02 · Task · Open the Alerts window

The bell lists every alert on the chart before any of them fires.

The Alerts window: the Desktop notifications switch, on, and its explanation, Popup size set to Large, Alert sound with a Test button, then the indicator 4 · Oscillator, histogram, alert with a bell, the line 2 alert() sites · never fired, its two MACD alert lines and the snooze list. 1 2 3 4 5 6
The Alerts window, with the example of task 1 on the chart.
  1. “Desktop notifications”. System notifications, off at first (task 3).
  2. “Popup size”. Small, Medium or Large for the popups on the chart. Medium at first.
  3. “Test” plays the alert beep now, so you know your speakers work.
  4. Your indicator, with how many alert lines it holds and when one last fired: “never fired” until the first.
  5. The bell of the indicator. One click mutes it (task 4).
  6. One row per alert line: title, message, then frequency and “sound” in brackets. Click it to open the code at that line.
  1. Click the bell on the rail, on the left edge of the editor. The “Alerts” row of the ƒ launcher does the same.The window opens beside the editor. A number on the bell counts the alerts fired since you last opened it.
  2. Find your indicator in the list.“No armed alerts”: no code on the chart holds an alert() line yet.
ProRealCode StudioUser guide · Chapter 16
03 · Task · Choose how it reaches you

A popup by default. A beep and a notification if you ask.

An alert popup with a bell and the title Guide, reading Close 26250.75, RSI 48.6179.
The popup of a fired alert, top right of the chart.
Illustration. The same alert as a desktop notification. Its look depends on your system.
OutputWhat to know
PopupTop right of the page: the title after a bell, the message under it. It leaves after 6 seconds; click it to close it sooner.
BeepOnly for an alert line whose sound is 1. If you hear nothing, click “Test”: the line under it reports what the last beep did.
Desktop notificationThe alert's title and message. Silent unless the alert has sound. At most one every 2 seconds and 8 a minute: the others still pop up on the chart and still go into the list.
  1. In the Alerts window, switch on “Desktop notifications”.The next alert also appears as a notification of your system.
  2. When one has fired, read the line under the switch.“last notification delivered at …”: all is well. “suppressed” or “⚠ notification failed”: your system held it back. Check its notification settings, “Do not disturb” first.
The ProRealTime tab must stay openIt need not be the tab in front, but a closed tab raises nothing: there is no alert in the background. A tab left behind another one is slowed down by the browser, so its alerts can arrive up to about a minute late, and an alert set to onceperbarclose can skip bars.
ProRealCode StudioUser guide · Chapter 16
04 · Task · Mute, snooze, look back

Silence one indicator for an hour. It still keeps a record.

Muting and snoozing stop the noise, not the alert. A silenced indicator still fires, and every alert it raises still goes into the list at the bottom of the window.

In the Alerts windowWhat it does
The indicator's bellOne click mutes the indicator: the bell is crossed out and the row turns pale. No popup, no beep, no notification until you click it again.
“snooze”15 min, 1 hour or 8 hours of the same silence, ending on its own. The row reads “snoozed until” and the time. Reloading the page does not end it; “cancel snooze” does.
“Fired this session”Every alert that fired, newest first: the time, the title, the message, the indicator and its bar. A screen after the title means a desktop notification went out, a speaker that it had sound. The last 60 are kept until you close or reload the tab; “Clear” empties the list.
“Hidden indicators”Indicators with alert lines that you hid on the chart. A hidden indicator is not computed, so its alerts cannot fire, and the bars it misses stay missed. The eye at the end of the row shows it again.
  1. To mute an indicator, click the bell at the end of its row.The row turns pale. Click again to hear it.
  2. To snooze it, pick a duration in “snooze”.The row reads “snoozed until” and the time it ends.
  3. To see what fired, scroll down to “Fired this session”.“Nothing has fired yet.” until the first alert.
Silence is not a stopA muted or snoozed indicator keeps sending the data of its alerts to a webhook, if you set one up (chapter 17). To stop an alert for good, remove its line from the code and click “Run”.
ProRealCode StudioUser guide · Chapter 16
Chapter 16 · In short

Write the line, open the bell, choose the noise.

An alert() line inside a condition is all a code needs. The Alerts window lists those lines as soon as the code runs, and decides how loud each indicator may be.

Three limits hold everywhere: alerts fire on live prices only, the ProRealTime tab must stay open, and desktop notifications wait for you to switch them on.

DefaultValue
Frequencyonceperbar
Soundoff
Notificationsoff
Popup sizeMedium

I clicked “Run” and no alert fired. Is it broken?

No. “Run” computes the past bars, and alerts never fire on the past. Wait for a new price on the live bar, with the market open.

The popup shows, but I hear nothing.

The alert line needs 1 as its sound argument. Then click “Test” in the Alerts window: if the test is silent too, check your system's volume.

My notification came a minute late.

The ProRealTime tab was behind another one, and the browser slows such tabs down. Keep it visible when the timing matters.

Can I get alerts with ProRealTime closed?

No. Alerts are computed in the open tab. A minimised window is fine; a closed tab is not.

The bell carries a number. What is it?

The alerts fired since you last opened the window. Opening it clears the number.

Next

Chapter 17 · Sending signals to a webhook

The same alerts, sent as data to a program of your choice: a bot, an automation, your own server.

ProRealCode StudioUser guide · Chapter 16
ProRealCode ProRealCode
Loading...