Indicators

Plotting Indicators

Introduction

LEAN provides helper methods to make it simple to create indicator plots.

Plot Update Events

To plot all of the values of some indicators, in the Initializeinitialize method, call the PlotIndicatorplot_indicator method. The method plots each indicator value as the indicator updates. The method accepts up to four indicators.

var symbol = AddEquity("SPY");
var smaShort = SMA(symbol, 10);
var smaLong = SMA(symbol, 20);
PlotIndicator("<chartName>", smaShort, smaLong)
symbol = self.add_equity("SPY")
sma_short = self.sma(symbol, 10)
sma_long = self.sma(symbol, 20)
self.plot_indicator("<chartName>", sma_short, sma_long)

Plot Current Values

To plot the current value of indicators, call the Plotplot method. The method accepts up to four indicators.

// In Initialize
var symbol = AddEquity("SPY");
var smaShort = SMA(symbol, 10);
var smaLong = SMA(symbol, 20);

// In OnData
Plot("<chartName>", smaShort, smaLong)
# In Initialize
symbol = self.add_equity("SPY")
sma_short = self.sma(symbol, 10)
sma_long = self.sma(symbol, 20)

# In OnData
self.plot("<chartName>", sma_short, sma_long)

View Charts

The following table describes where you can access your charts, depending on how to deploy your algorithms:

LocationAlgorithm Lab AlgorithmsCLI Cloud AlgorithmsCLI Local Algorithms
Backtest results pagegreen checkgreen check
Live results pagegreen checkgreen check
/backtests/read endpointgreen checkgreen check
/live/read endpointgreen checkgreen check
ReadBacktest methodgreen checkgreen check
ReadLiveAlgorithm methodgreen checkgreen check
Local JSON file in your <projectName> / backtests / <timestamp> or <projectName> / live / <timestamp> directorygreen checkgreen check

Chart Limits

Not all indicators share the same base type(T), so you may not be able to plot them together since some indicators require points while others require TradeBars.

// Plot indicators that extend the "Indicator" type
PlotIndicators("All Indicator Values", sma, rsi);
Plot("Current Indicator Values", sma, rsi); 

// Plot indicators that extend the "TradeBarIndicator" type
PlotIndicators("All Indicator Values", atr, aroon);
Plot("Current Indicator Values", atr, aroon);
# Plot indicators that extend the "Indicator" type
self.plot_indicators("All Indicator Values", sma, rsi)
self.plot("Current Indicator Values", sma, rsi); 

# Plot indicators that extend the "TradeBarIndicator" type
self.plot_indicators("All Indicator Values", atr, aroon)
self.plot("Current Indicator Values", atr, aroon); 

If your indicator plots are complex, call the Plotplot method with one indicator and plot its Current.Valuecurrent.value property. For more information about plotting, see Charting.

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: