In this article we take a global look at creating MultiCharts alerts with code, and briefly discuss the topics we’re going to explore in this chapter. Follow the links to the articles for programming examples and more information.
In this article:
Getting started: working with alerts in MultiCharts
With MultiCharts alerts we can trigger a visual and/or audio notification whenever a condition specified in the code of an indicator or signal is met (MultiCharts Wiki, 2013). That way our script can monitor price action and generate alerts based on predefined signals. While firing alerts based on prices is the most common, we can generate alerts for anything that’s accessible in the code of a PowerLanguage indicator or signal.
But before our script can generate any alert, we’ll have to turn on the ‘Enable Alerts’ checkbox (see image below). When that setting is disabled, our script cannot generate alerts – even when we’ve correctly implemented all of the required code. And so even when we generate alerts programmatically, the manual action of enabling that checkbox is still needed.

With that option enabled, our indicator or signal can generate an audio alert, notification window, and/or email alert (MultiCharts Wiki, 2013). Besides enabling or disabling alerts, there are also several manual alert settings that include options for specifying when and how the alerts should fire.
For instance, when we set alerts to use a notification window they appear like:

Usually, an alert notification window fades away after a couple of seconds. An audio alert is even easier to miss when we’re away from the computer. Luckily, we can lookup any alert generated by a script in the ‘Alerts’ tab of the Order and Position Tracker window. An example of that is:

Besides triggering alerts with an indicator or signal, it’s also possible to generate MultiCharts alerts with manual drawings. This has the advantage that we can generate alerts without having to write a script. It has a couple of disadvantages too.
First, we’ll need to configure, enable, disable, and update the drawing’s alert settings by hand; and each of these actions involves multiple steps. Second, the alerts that MultiCharts generates with manual drawings contain little information. This especially becomes a problem when we have multiple drawings on the chart. For instance, here the alert message simply says ‘Trend Line triggered’ for ‘Trend Line #1’:

Luckily, when we generate alerts programmatically we can create our own, actionable alert messages.
Using code to generate MultiCharts alerts
After we examined those features of working with MultiCharts alerts, the remainder of the chapter explores the different ways to use MultiCharts alerts programmatically. We start those articles with the basics:
- In firing a MultiCharts alert programmatically we discuss how to trigger an alert in PowerLanguage and how to specify a custom alert message.
To make alert messages more meaningful, we can include dynamic values in them:
- In adding numerical values and variables to alert messages we look at how we can include numbers in alert messages. We’ll also discuss how to format them so they appear with a specific number of decimals.
- In including time values in alert messages we explore how the time of day can be inserted into an alert message with a format of our choosing.
- And in using alert messages with dates we look at how we can insert dates in alert messages, and use a format that makes them easy to read and understand.
Besides how to generate an alert and create a custom alert message, there are a couple of other ways to programmatically work with MultiCharts alerts:
- In using code to check if alerts are enabled we look at two PowerLanguage keywords that tell us whether the important ‘Enable Alerts’ option is enabled or disabled.
- While we can generate an alert programmatically, in using code to cancel an alert we discuss how our script can prevent a triggered alert from firing.
- To make matters a bit more complicated, we can also programmatically re-enable a cancelled alert. While the possibility of using code to cancel and re-enable alerts sounds helpful, later on in the chapter we’ll discuss why cancelling and re-enabling alerts isn’t a good idea.
- It’s also possible to define a code block that only executes when alerts are turned on. That way we can create a script that behaves differently depending on whether the ‘Enable Alerts’ option is enabled or disabled.
After looking at how to generate and cancel alerts, next we examine how we can prevent many alerts from firing quickly after each other.
Preventing an overwhelming flood of MultiCharts alerts
When our script executes the appropriate PowerLanguage keyword, MultiCharts generates an alert when the script’s manual alert settings are enabled. Sometimes, however, the indicator or signal generates a bunch of alert messages quickly after each other.
Since too many alerts are distracting and as helpful as no alerts, the next part of the chapter discusses ways to limit the number of alerts a script generates:
- In firing alerts when the price bar closes we discuss how we can program an alert to fire only when the bar closes, while the rest of the script processes every real-time price update. This not only limits the number of alerts per bar, but can make the script run more efficient too.
- In triggering an alert once per bar we look at how we can program indicators and signals to only generate an alert once per bar. That way the alert can fire when the price bar is still active or has just closed.
- When we trade a high time frame, an alert that fires once per bar might give too much time between alerts. In that case we can generate an alert at most a certain number of times per bar. That gives multiple alerts per bar, but not so much that they become distracting.
- Another way to limit alerts is to trigger an alert every number of times the alert condition happens. This approach gives an alert the first time the alert condition happens, and then every nth time the alert condition occurs again. That way we get occasional reminder alerts without getting too many.
- The previous approaches to limit the number of alerts are all (indirectly) based on price bars, which makes them depend on the instrument’s time frame and inconsistent across charts. One way to limit alerts regardless of the time frame is by keeping a certain number of seconds between alerts.
- Another way to limit the number of alerts generated by a script is by only generating alerts during a certain time period. That way when our trading hours end, we don’t get irrelevant and distracting alerts.
- Of course, we can use the approaches for limiting alerts together when we generate multiple alerts in our script. One example of that is combining an intra-bar alert with one that only fires when the bar closes.
After discussing ways to limit the number of alerts, we turn our attention to more tips for working with MultiCharts alerts programmatically.
Programming tips for MultiCharts alerts
Those tips and insights to make working with MultiCharts alerts easier are:
- While we can cancel an alert programmatically and then use code to re-enable it, the first suggestion is not to cancel alerts and turn them back on. That’s because when we generate an alert when a specific condition happens, then cancel it when something else happens, and then re-enable the alert when a different situation occurs, our code becomes unclear, needlessly complicated, and hard to untangle.
- Another tip are 5 ways to limit the amount of alerts a script generates. That way an indicator or signal doesn’t generate so many alert that they become noise.
- Alerts can only fire if we enable the alert setting. When our script generates important alerts (like for risk management or trading signals), we can generate an error message when alerts are turned off. This way we know for sure that, when the script runs, its alert option is enabled and it can generate alerts when needed.
- Because those error messages also turn off the indicator or signal, they can be a bit annoying. An alternative is to create a text box when alerts are disabled. That way we get a clear visual notification that the ‘Enable Alerts’ checkbox is disabled, but without the script halting its calculations.
- MultiCharts alerts only generate when the indicator or signal calculates, and that calculation usually only happens when there’s a new price update. That means in a slow market with few price updates (like with extended trading hours), alerts can lag (especially if they’re based on time). Similarly, when our instrument is closed, we also cannot generate alerts normally. Luckily, we can address both by recalculating a script periodically. When we do, those time-based calculations can fire alerts independent from price updates.
After these tips and suggestions, next up in the chapter are a couple of ways to use MultiCharts alerts.
Examples of using MultiCharts alerts
A couple of examples of different ways to use MultiCharts alerts include:
- In generating alerts with moving averages we explore how we can programmatically trigger an alert whenever a quick moving average crosses above or below a slower one.
- One way in which alerts can help with risk management is by triggering an alert when there’s a possible data feed issue. With such a notification, we can take the necessary actions whenever the data feed, exchange, or internet connection experiences issues.
- To turn a script’s ‘Enable Alerts’ checkbox on or off, we have to take several manual actions. And once we change that setting the script also recalculates and processes all price bars again. Luckily, by using MultiCharts mouse clicks in our indicator or signal, it’s also possible to enable or disable alerts with a single mouse click.
- While we can generate alerts with manual drawings, we can also create drawings with code and then generate alerts programmatically. This way we spend less time updating and managing the drawing, have more options to specify when the alert should fire, and can also generate more meaningful alert messages. We take a closer look at this approach in generating alerts with a MultiCharts trend line.
- Even though most articles use code to set the alert’s price level, sometimes it’s also useful to quickly create an alert at a specific price. One convenient way for doing that is by generating a semi-automatic alert. With that approach, a single click on the chart is enough to have the script generate an alert at that price level.
After discussing these examples of using MultiCharts alerts, next in the chapter we look at incorporating alerts in trading strategies.
Generating alerts with MultiCharts trading strategies
In the last part of the chapter we look at how we can use alerts with trading strategies. Those approaches include:
- In generating an alert when automated order execution isn’t enabled we program a signal that fires an alert when automated trading isn’t on by a certain time. Such a notification helps when we auto trade from multiple charts in multiple workspaces and overlooked a chart’s automated trading status before the session begins.
- When automated trading is enabled, there are several situations that can turn it off (like when there’s a connection loss between MultiCharts and the broker). We can address that by triggering an alert when automated trading gets disabled, which helps to quickly intervene and prevent a small issue from becoming a big problem.
- Besides alerts for when there’s an automated trading issue, we can also trigger an alert when the strategy’s position changes. With that information we can closely track a strategy’s behaviour in real time without having to monitor its chart, and can quickly jump in when something seems off.
- Another automated trading risk is a miscommunication between MultiCharts and the broker. When MultiCharts and the broker disagree about the market position, MultiCharts can end up trading a different position than that’s currently open at the broker. This creates different problems, including the strategy not going flat when it should. To help combat that issue, we can generate an alert when the broker’s position doesn’t match MultiCharts’ position.
We end the MultiCharts alerts chapter with a summary of generating MultiCharts alerts, in which we reiterate the most important points.
References
MultiCharts Wiki (2013, May 10). Using Alerts. Retrieved on January 28, 2017, from https://www.multicharts.com/trading-software/index.php/Using_Alerts
Visit programming tutorials for more helpful coding articles.