Skip to content

Symbol sentiment

The SymbolSentiment interface and SymbolSentimentUpdatedEventArgs class allow you to access real-time market sentiment data via API. For any given symbol:

  • Symbol.Sentiment.BuyPercentage provides the aggregate percentage of buy activity, while Symbol.Sentiment.SellPercentage returns the aggregate percentage of sell activity.
  • SymbolSentimentUpdatedEventArgs is a data carrier for sentiment update events. This class allows you to access the updated sentiment data for the corresponding symbol.

Warning

Symbol sentiment API objects are supported only in .NET 6 algorithms and do not function in Cloud or cTrader CLI.

Tip

Integrate market sentiment data into automated trading strategies to enhance decision making, increase the likelihood of profitable trades and strengthen risk management.

Symbol sentiment API objects can be used to do the following in algorithms:

Feature or operation Examples
Sentiment-driven trading Trade with sentiment bias
Trade against extreme sentiment
Combine sentiment with candles
Exit on sentiment divergence
Adaptive risk configuration Filter out noisy trades
Scale trades with sentiment
Throttle strategy based on market activity
Set stop loss based on sentiment
Monitoring and analysis Create sentiment-based alerts
Run sentiment heatmap strategy
Spot breakouts through sentiment
Validate indicator signals

Note

As sentiment data is only available in real time, it cannot be used for backtesting or optimisation, since there is no historical or stored data.

Sentiment-driven trading

Trade with sentiment bias

You can program a cBot to confirm trend bias before entering trades or trade only if sentiment matches the direction. For example, the cBot executes a buy if at least 70% of sentiment is bullish, and a sell if 70% is bearish.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
protected override void OnBar()
{
    if (Symbol.Sentiment.BuyPercentage > 70)
    {
        ExecuteMarketOrder(TradeType.Buy, "EURUSD", 10000);
    }
    else if (Symbol.Sentiment.SellPercentage > 70)
    {
        ExecuteMarketOrder(TradeType.Sell, "EURUSD", 10000);
    }
}

Trade against extreme sentiment

Consider a cBot that enters trades against strong sentiment consensus. The reversal approach in the algorithm assumes the crowd is often wrong at extremes or believes that when a very high proportion of traders are on one side, the market may be ready to turn. For example, if more than 80% of traders are buying, the cBot executes a sell, expecting a reversal. The same logic applies when most are selling.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
protected override void OnBar()
{
    if (Symbol.Sentiment.BuyPercentage > 80)
    {
        // Everyone is buying. Consider selling
        ExecuteMarketOrder(TradeType.Sell, "EURUSD", 10000);
    }
    else if (Symbol.Sentiment.SellPercentage > 80)
    {
        // Everyone is selling. Consider buying
        ExecuteMarketOrder(TradeType.Buy, "EURUSD", 10000);
    }
}

Combine sentiment with candles

You can configure a cBot to act only when both market sentiment and candle direction agree. If it gets a bullish candle and sentiment is above 60% bullish, the cBot buys. If the candle is bearish and the sentiment agrees, the cBot sells. This approach helps you filter out weak signals and avoid false entries.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
protected override void OnBar()
{
    bool bullishCandle = Bars.LastBar.Close > Bars.LastBar.Open;
    if (bullishCandle && Symbol.Sentiment.BuyPercentage > 60)
    {
        ExecuteMarketOrder(TradeType.Buy, "EURUSD", 10000);
    }

    bool bearishCandle = Bars.LastBar.Close < Bars.LastBar.Open;
    if (bearishCandle && Symbol.Sentiment.SellPercentage > 60)
    {
        ExecuteMarketOrder(TradeType.Sell, "EURUSD", 10000);
    }
}

Exit on sentiment divergence

A cBot can help you exit trades when sentiment no longer supports your position. For example, if you are holding a buy and sentiment flips to over 60% bearish, the cBot closes it. It does the same for sell trades when sentiment turns bullish.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
protected override void OnBar()
{
    foreach (var position in Positions)
    {
        if (position.TradeType == TradeType.Buy && Symbol.Sentiment.SellPercentage > 60)
            ClosePosition(position);
        if (position.TradeType == TradeType.Sell && Symbol.Sentiment.BuyPercentage > 60)
            ClosePosition(position);
    }
}

Adaptive risk configuration

Filter out noisy trades

You can develop a cBot that avoids trading when there is no clear sentiment bias. For example, if sentiment is nearly split and the difference is under 10%, the cBot skips the trade. This setup filters out noise and protects you from indecisive markets.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
protected override void OnBar()
{
    var diff = Math.Abs(Symbol.Sentiment.BuyPercentage - Symbol.Sentiment.SellPercentage);

    if (diff < 10)
    {
        // Sentiment is too neutral. Avoid trading
        return;
    }

    // Continue strategy logic here
}

Scale trades with sentiment

You can set up a cBot to adjust the position size based on how strongly sentiment leans in one direction. For example, if bullish sentiment outweighs bearish by a large margin, the cBot increases trade volume. If sentiment is close to neutral, the cBot trades smaller.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
protected override void OnBar()
{
    double sentimentStrength = Math.Abs(Symbol.Sentiment.BuyPercentage - Symbol.Sentiment.SellPercentage);
    long volume = (long)(10000 * (sentimentStrength / 100.0)); // Adjust volume dynamically

    if (Symbol.Sentiment.BuyPercentage > Symbol.Sentiment.SellPercentage)
    {
        ExecuteMarketOrder(TradeType.Buy, "EURUSD", 10000);
    }
    else
    {
        ExecuteMarketOrder(TradeType.Sell, "EURUSD", 10000);
    }
}

Throttle strategy based on market activity

Your strategy can be set up to pause trading when sentiment shows signs of a crowded market. For example, if more than 90% of traders are either buying or selling, the cBot stops trading to avoid entering a position just as the market is likely to reverse.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
protected override void OnBar()
{
    if (Symbol.Sentiment.BuyPercentage > 90 || Symbol.Sentiment.SellPercentage > 90)
    {
        Print("Extreme sentiment detected. Halting trading temporarily.");
        return;
    }

    // Continue normal trading logic
}

Set stop loss according to sentiment

You can instruct a cBot to measure sentiment strength and respond with appropriate stop loss sizing. For example, when bullish sentiment exceeds 80%, the cBot uses a tighter stop of 20 pips. If sentiment is less confident, the cBot sets a wider stop of 50 pips to allow more breathing room.

1
2
3
4
5
6
7
8
protected override void OnBar()
{
    double stopLossPips = Symbol.Sentiment.BuyPercentage > 80 ? 20 : 50;
    if (Symbol.Sentiment.BuyPercentage > Symbol.Sentiment.SellPercentage)
    {
        ExecuteMarketOrder(TradeType.Buy, "EURUSD", 10000, "buy", stopLossPips, null);
    }
}

Monitoring and analysis

Create sentiment-based alerts

Consider a cBot that monitors sentiment in real time and alerts you when extreme levels are reached. For example, if buy sentiment exceeds 90%, the cBot logs or prints a bullish alert. If sell sentiment crosses the same threshold, it notifies you of extreme bearishness.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
// This method handles the SymbolSentiment_Updated event
// It is triggered whenever the symbol sentiment data is updated
private void SymbolSentiment_Updated(SymbolSentimentUpdatedEventArgs obj)
{
    if (obj.Sentiment.BuyPercentage > 90)
        Print("Extreme bullish sentiment detected!");

    if (obj.Sentiment.SellPercentage > 90)
        Print("Extreme bearish sentiment detected!");
}

Run sentiment heatmap strategy

Consider a cBot that runs a sentiment scan across multiple assets and identifies the best trading opportunities. For example, the cBot loops through all available symbols and prints the buy and sell percentages, and then you can focus on those with the most extreme bullish or bearish sentiment.

1
2
3
4
5
6
7
8
protected override void OnStart()
{
    var symbols = Symbols.GetSymbols();
    foreach (var sym in symbols)
    {
        Print($"{sym.Name} - Buy %: {sym.Sentiment.BuyPercentage}, Sell %: {sym.Sentiment.SellPercentage}");
    }
}

Spot breakouts through sentiment

A cBot can be programmed to detect rapid changes in sentiment as a potential sign of a breakout or heightened market volatility. For example, if buy sentiment jumps or drops by more than 15%, the cBot logs the spike as an early indication of a volatile move.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
// Field to store the previous buy percentage value
private double previousBuy;

protected override void OnStart()
{
    previousBuy = Symbol.Sentiment.BuyPercentage;

    // Subscribe to the sentiment updated event
    // This will trigger the SymbolSentiment_Updated method whenever sentiment data is updated    
    Symbol.Sentiment.Updated += SymbolSentiment_Updated;
}

// obj is an instance of SymbolSentimentUpdatedEventArgs, which carries the updated sentiment data
private void SymbolSentiment_Updated(SymbolSentimentUpdatedEventArgs obj)
{
    double change = Math.Abs(obj.Sentiment.BuyPercentage - previousBuy);
    if (change > 15)
        Print("Spike in sentiment detected. Breakout or heightened volatility coming soon");

    previousBuy = obj.Sentiment.BuyPercentage;
}

Validate indicator signals

Rather than relying on indicators alone, you can enhance your strategy by programming your cBot to only act when both indicator and sentiment conditions align. For example, when RSI shows oversold and sentiment is over 70% bullish, the cBot buys. If RSI signals overbought and sentiment exceeds 70% bearish, the cBot sells.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
private RelativeStrengthIndex rsi;

protected override void OnStart()
{
    rsi = Indicators.RelativeStrengthIndex(Bars.ClosePrices, 14);
}

protected override void OnBar()
{
    if (rsi.Result.LastValue < 30 && Symbol.Sentiment.BuyPercentage > 70)
    {
        ExecuteMarketOrder(TradeType.Buy, "EURUSD", 10000);
    }

    if (rsi.Result.LastValue > 70 && Symbol.Sentiment.SellPercentage > 70)
    {
        ExecuteMarketOrder(TradeType.Sell, "EURUSD", 10000);
    }
}