Skip to content

Range bar strategies in cTrader

A range chart is built to represent a specified range of price movements regardless of how long it takes the price to make that movement. This filters out price movements that are smaller than the range size, making trends easier to visualise. In cTrader, the process for developing automated trading strategies that make decisions based on range bars is the same as the process for creating such strategies based on standard time-based candlesticks. In this article and its corresponding video, we will demonstrate how you can develop and backtest a simple strategy based on range bars.

Define the buy and sell signals

We will briefly outline our trading logic.

  • Buy signal - occurs when a bullish range bar that follows a bearish range bar and closes above the opening price of the bearish bar.
  • Sell signal - occurs when a bearish range bar follows a bullish range bar and closes below the opening price of the bullish bar.

The interpretation of the buy signal is that, when a bearish trend is met with strong resistance, it is time to buy in expectation of a rebound. The reverse setup applies to the sell signal: a bullish trend is met with resistance, and we must capitalise on this by placing a sell order.

Create an example cBot

We can start creating our cBot. We will first define the necessary parameters.

1
2
3
4
5
6
7
8
[Parameter(DefaultValue = 10000)]
public double Volume { get; set; }

[Parameter(DefaultValue = 20)]
public double StopLoss { get; set; }

[Parameter(DefaultValue = 20)]
public double TakeProfit { get; set; }

We can code our buy signal as follows.

1
2
3
4
if (Bars.Last(0).Close > Bars.Last(0).Open && Bars.Last(1).Close < Bars.Last(1).Open && Bars.Last(0).Close > Bars.Last(1).Open)
{
    ExecuteMarketOrder(TradeType.Buy, SymbolName, Volume,InstanceId, StopLoss, TakeProfit);
}

Our sell signal looks as follows.

1
2
3
4
if (Bars.Last(0).Close < Bars.Last(0).Open && Bars.Last(1).Close > Bars.Last(1).Open && Bars.Last(0).Close < Bars.Last(1).Open)
{
    ExecuteMarketOrder(TradeType.Sell, SymbolName, Volume,InstanceId, StopLoss, TakeProfit);
}

Backtest the strategy

After building our new cBot, we switch to the Backtesting tab and run a backtest. Here are the results.

Note

Range bar strategies use the same data structures as strategies based on candlesticks. For example, we used the Bars collection to retrieve our range bars; we would have used the same collection when trying to retrieve candlesticks. This feature of cTrader allows you to develop strategies that can be tested and run on any chart type without the need for any modifications.

In this tutorial, we demonstrated how you can quickly develop a simple strategy based on range charts. We also suggested that such strategies can be freely reused on charts containing time-based candlesticks.

Subscribe to our YouTube channel